1 | var fs = require('fs')
|
2 | var path = require('path')
|
3 | var dotjson = require('dotjson')
|
4 |
|
5 | var optimist = require('optimist')
|
6 | .usage(require('heredoc')(function(){ |
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | }))
|
24 | .alias('h','help')
|
25 | .boolean('h')
|
26 | .describe('h', 'show help')
|
27 | .alias('r','registry')
|
28 | .describe('r', 'gets or sets the current module\'s registry url')
|
29 | .alias('l','licenseText')
|
30 | .describe('l', 'The text to save in LICENSE as a SPDX-compatible license file')
|
31 | .default('l', '(c) '+(new Date()).getFullYear()+' Jane Doe')
|
32 | var argv = optimist.argv
|
33 |
|
34 |
|
35 | if (argv.help) {
|
36 | optimist.showHelp()
|
37 | process.exit()
|
38 | }
|
39 |
|
40 | const LICENSE_FILENAME = 'LICENSE'
|
41 | const LICENSE_VALUE = 'LicenseRef-LICENSE'
|
42 | const LOCAL = path.resolve(process.cwd(), 'package.json')
|
43 |
|
44 | if (argv.registry || argv.licenseText) {
|
45 | if (argv.registry) {
|
46 | dotjson.set(LOCAL, {
|
47 | 'publishConfig.registry': argv.registry
|
48 | })
|
49 | }
|
50 | if (argv.licenseText) {
|
51 | fs.writeFileSync(LICENSE_FILENAME, argv.licenseText)
|
52 | dotjson.set(LOCAL, {
|
53 | 'license': LICENSE_VALUE
|
54 | })
|
55 | }
|
56 | process.exit()
|
57 | }
|