This repository has been archived by the owner on Sep 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (61 loc) · 1.63 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
67
68
69
70
const path = require('path')
const { spawn } = require('child_process')
const mkdirp = require('mkdirp')
const chalk = require('chalk')
const { log, logError } = require('./util/log')
function runProcess (command, args, options) {
return new Promise(function (resolve, reject) {
const npmProcess = spawn(command, args, options)
npmProcess.stdout.on('data', function (data) {
console.log(data.toString())
})
npmProcess.stderr.on('data', function (data) {
console.log('error', data.toString())
})
npmProcess.on('close', function (code) {
if (code === 0) {
process.nextTick(resolve)
} else {
reject()
}
})
})
}
function setupPackageJson (targetFolder) {
log('Setting up ' + chalk.bold('package.json'))
return runProcess('npm', ['init', '-y'], {
cwd: targetFolder
}).catch(function (error) {
if (error) {
logError(error.stack)
} else {
logError('Command failed, exiting')
}
})
}
function installSagui (targetFolder) {
log('Installing...')
return runProcess('yarn', ['add', 'sagui', '--dev'], {
cwd: targetFolder
}).catch(function (error) {
if (error) {
logError(error.stack)
} else {
logError('Command failed, exiting')
}
})
}
module.exports = {
cli: function (args) {
const targetFolder = args[2]
? path.resolve(process.cwd(), args[2])
: process.cwd()
if (targetFolder !== process.cwd()) {
log('In folder ' + chalk.bold(targetFolder))
mkdirp.sync(targetFolder)
}
setupPackageJson(targetFolder)
.then(installSagui(targetFolder))
.then(function () {})
}
}