UNPKG

1.33 kBJavaScriptView Raw
1var fs = require('fs')
2var path = require('path')
3var dotjson = require('dotjson')
4
5var optimist = require('optimist')
6 .usage(require('heredoc')(function(){/*
7Usage: $0 [options]
8
9 set module's registry to global default
10 $0
11
12 get module registry
13 $0 -r, --registry
14
15 set module registry
16 $0 -r, --registry <registry url>
17
18 get global registry
19 $0-g, --global
20
21 set global registry
22 $0 -g, --global <registry url>
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')
32var argv = optimist.argv
33
34
35if (argv.help) {
36 optimist.showHelp()
37 process.exit()
38}
39
40const LICENSE_FILENAME = 'LICENSE'
41const LICENSE_VALUE = 'LicenseRef-LICENSE'
42const LOCAL = path.resolve(process.cwd(), 'package.json')
43
44if (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}