-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (48 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const spawn = require('cross-spawn')
const commander = require('commander')
const packageJson = require('./package.json')
const endWithError = err => {
console.error('\n' + err)
process.exit(1)
}
const createApp = () => {
let appDir
const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('<project-directory>')
.usage(`<project-directory>`)
.action(name => (appDir = name))
.parse(process.argv)
if (!appDir) endWithError('Specify app directory')
appDir = path.resolve(appDir)
if (fs.existsSync(appDir)) endWithError('Directory already exists')
console.log(`\nCreating a new Gnarly app in ${appDir}.\n`)
fs.mkdirSync(appDir)
const appName = path.basename(appDir)
const appPackageJson = {
name: appName,
version: '0.1.0',
private: true,
}
fs.writeFileSync(
path.join(appDir, 'package.json'),
JSON.stringify(appPackageJson, null, 2) + '\n',
)
process.chdir(appDir)
const depName = '@gnarlycode/react-app-tools'
const args = ['install', '--save', depName]
const proc = spawn.sync('npm', args, { stdio: 'inherit' })
if (proc.status !== 0) endWithError(`Error while installing ${depName}`)
const initPath = path.resolve(
process.cwd(),
'node_modules',
depName,
'bin',
'init.js',
)
require(initPath)
}
createApp()