-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (29 loc) · 872 Bytes
/
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
const inquirer = require('inquirer')
const questions = require('./lib/questions')
module.exports = pkgi
var PKG = null
function pkgi (pkg) {
PKG = pkg
return function () {
inquirer.prompt(questions)
.then(startPkg)
.catch(raiseError)
}
}
function startPkg (answers) {
if (typeof PKG.exec !== 'function') throw Error('Make sure you passed a valid instance of pkg')
return new Promise(function (resolve, reject) {
PKG.exec(formatArgs(answers)).then(function (out) {
resolve(out)
}).catch(raiseError)
})
}
function formatArgs (answers) {
var pkgArgs = ['--target', `node${answers.nodeVersion}-${answers.os}-${answers.architecture}`, '--output', answers.output]
if (answers.input) pkgArgs = [answers.input].concat(pkgArgs)
console.log('args:', pkgArgs)
return pkgArgs
}
function raiseError (err) {
if (err) throw err
}