-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·83 lines (67 loc) · 1.96 KB
/
bin.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
71
72
73
74
75
76
77
78
79
80
81
#!/bin/env node
// not cross-platform -_-
try {
var regedit = require('regedit')
} catch (e) {}
const mkdirp = require('mkdirp')
const fs = require('fs')
const minimist = require('minimist')
const path = require('path')
const setup = require('./')
const args = minimist(process.argv.slice(2), {boolean: ['global', 'rm', 'h', 'help']})
if (args.h || args.help) {
console.log(`
Usage:
native-installer manifest.json
--browser ${setup.BROWSERS.join(', ')} - default to all
--global - install globally (might require privilege), default to local user
--rm - removes the file/registry
`)
return
}
const local = args.global === true ? false : true
let browsers = setup.BROWSERS
if (args.browser) {
if (!Array.isArray(args.browser)) { args.browser = [args.browser] }
browsers = browsers.filter((e) => ~args.browser.indexOf(e))
}
if (!args._[0]) {
throw new Error('Missing app.json argument.')
}
const results = setup(require(path.resolve(process.cwd(), args._[0])), {local, browsers})
results.forEach((e) => {
if (process.platform === 'win32') {
if (args.rm === true) {
regedit.deleteKey(e.path, function (err) {
if (err) throw err
console.log('Registry key removed: %s', e.path)
})
return
}
const manifestPath = path.resolve(process.cwd(), 'manifest-' + Date.now() + '.json')
fs.writeFileSync(manifestPath, e.JSONmanifest)
regedit.createKey(e.path, (err) => {
if (err) throw err
regedit.putValue({
[e.path]: {
[e.manifest.name]: {
value: manifestPath,
type: 'REG_DEFAULT'
}
}
}, function (err) {
if (err) throw err
console.log('Registry key created: %s', e.path)
})
})
return
}
mkdirp.sync(path.dirname(e.path))
if (args.rm === true) {
fs.unlinkSync(e.path)
console.log('File removed: %s', e.path)
return
}
fs.writeFileSync(e.path, e.JSONmanifest)
console.log('File written: %s', e.path)
})