/
npm-auth-to-token-npm-1.0.0-c288ce201f
79 lines (74 loc) · 1.99 KB
/
npm-auth-to-token-npm-1.0.0-c288ce201f
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
diff --git a/cli.js b/cli.js
index 43b59bb85665ccff53a62c86162093dd1d64ba6d..40bf4d43317a2ffb1dad0c2f7e1f02f4421469a3 100755
--- a/cli.js
+++ b/cli.js
@@ -1,45 +1,43 @@
#!/usr/bin/env node
-const program = require('commander');
-const { version } = require('./package.json');
-var RegClient = require('npm-registry-client');
-const fs = require('fs');
+"use strict";
+
+const program = require("commander");
+const { version } = require("./package.json");
+var RegClient = require("npm-registry-client");
var client = new RegClient();
let args = process.argv;
if (args.length === 3) {
- args = [args[0], args[1]].concat(args[2].split(' '));
+ args = [args[0], args[1]].concat(args[2].split(" "));
}
program
.version(version)
- .option('-u, --username <username>', 'username')
- .option('-p, --password <password>', 'password')
- .option('-e, --email <email>', 'email')
- .option('-r, --registry <registry>', 'registry', 'https://registry.npmjs.org/')
+ .option("-u, --username <username>", "username")
+ .option("-p, --password <password>", "password")
+ .option("-e, --email <email>", "email")
+ .option(
+ "-r, --registry <registry>",
+ "registry",
+ "https://registry.npmjs.org/"
+ )
.parse(args);
-const {
- username,
- password,
- email,
- registry
-} = program;
+const { username, password, email, registry } = program;
-client.adduser(registry, {
- auth: {
- username,
- password,
- email,
- alwaysAuth: true
- }
-}, (err, res) => {
- if (err) throw err;
- const path = `${process.cwd()}/.npmrc`;
- let base = registry.substr(registry.indexOf('/'), registry.length);
- if (base.lastIndexOf('/') !== registry.length - 1) {
- base += '/';
+client.adduser(
+ registry,
+ {
+ auth: {
+ username,
+ password,
+ email,
+ alwaysAuth: true,
+ },
+ },
+ (err, res) => {
+ if (err) throw err;
+ console.log(res.token);
}
- fs.writeFileSync(path, `registry=${registry}\n${base}:_authToken=${res.token}`);
- console.log('Done');
-});
+);