Skip to content

Commit

Permalink
split deps and devDeps
Browse files Browse the repository at this point in the history
  • Loading branch information
chicoxyzzy committed Jan 26, 2023
1 parent 314e526 commit 0de93a1
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,35 @@ async function help (templateNames) {
async function install () {
}

const DEFAULT_PACKAGES = [
'@socketsupply/socket-api',
const DEFAULT_DEPS = [
'@socketsupply/socket-api'
]

const DEFAULT_DEV_DEPS = [
'@socketsupply/tapzero',
'@socketsupply/test-dom'
]

const templates = {}

templates.vanilla = {
packages: ['esbuild']
devDeps: ['esbuild']
}
templates.tonic = {
packages: ['@socketsupply/tonic', 'esbuild']
deps: ['@socketsupply/tonic'],
devDeps: ['esbuild']
}
templates.react = {
packages: ['react', 'react-dom', 'esbuild']
deps: ['react', 'react-dom'],
devDeps: ['esbuild']
}
templates.vue = {
packages: ['vue', 'vite', '@vitejs/plugin-vue']
deps: ['vue'],
devDeps: ['vite','@vitejs/plugin-vue']
}

async function main (argv) {
const templateName = argv[0] || DEFAULT_TEMPLATE
const templateName = argv[0] ?? DEFAULT_TEMPLATE

const templateNames = await fs.readdir(path.join(__dirname, 'templates'))

Expand Down Expand Up @@ -128,14 +134,27 @@ async function main (argv) {
//
// Install an opinionated base of modules for building a simple app.
//
const packages = [
...DEFAULT_PACKAGES,
...templates[templateName]?.packages ?? []
const devDeps = [
...DEFAULT_DEV_DEPS,
...templates[templateName]?.devDeps ?? []
]
if (devDeps.length > 0) {
try {
process.stdout.write('\nInstalling developer dependencies...')
await exec(`npm install -D ${devDeps.join(' ')}`)
} catch (err) {
process.stderr.write(`\nUnable to run npm install: ${err.stack ?? err.message}\n`)
process.exit(1)
}
}
const deps = [
...DEFAULT_DEPS,
...templates[templateName]?.deps ?? []
]
if (packages.length > 0) {
if (deps.length > 0) {
try {
process.stdout.write('\nInstalling dependencies...')
await exec(`npm install ${packages.join(' ')}`)
await exec(`npm install ${deps.join(' ')}`)
} catch (err) {
process.stderr.write(`\nUnable to run npm install: ${err.stack ?? err.message}\n`)
process.exit(1)
Expand Down

0 comments on commit 0de93a1

Please sign in to comment.