npm-auth-to-token-npm-1.0.0-c288ce201f 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. diff --git a/cli.js b/cli.js
  2. index 43b59bb85665ccff53a62c86162093dd1d64ba6d..40bf4d43317a2ffb1dad0c2f7e1f02f4421469a3 100755
  3. --- a/cli.js
  4. +++ b/cli.js
  5. @@ -1,45 +1,43 @@
  6. #!/usr/bin/env node
  7. -const program = require('commander');
  8. -const { version } = require('./package.json');
  9. -var RegClient = require('npm-registry-client');
  10. -const fs = require('fs');
  11. +"use strict";
  12. +
  13. +const program = require("commander");
  14. +const { version } = require("./package.json");
  15. +var RegClient = require("npm-registry-client");
  16. var client = new RegClient();
  17. let args = process.argv;
  18. if (args.length === 3) {
  19. - args = [args[0], args[1]].concat(args[2].split(' '));
  20. + args = [args[0], args[1]].concat(args[2].split(" "));
  21. }
  22. program
  23. .version(version)
  24. - .option('-u, --username <username>', 'username')
  25. - .option('-p, --password <password>', 'password')
  26. - .option('-e, --email <email>', 'email')
  27. - .option('-r, --registry <registry>', 'registry', 'https://registry.npmjs.org/')
  28. + .option("-u, --username <username>", "username")
  29. + .option("-p, --password <password>", "password")
  30. + .option("-e, --email <email>", "email")
  31. + .option(
  32. + "-r, --registry <registry>",
  33. + "registry",
  34. + "https://registry.npmjs.org/"
  35. + )
  36. .parse(args);
  37. -const {
  38. - username,
  39. - password,
  40. - email,
  41. - registry
  42. -} = program;
  43. +const { username, password, email, registry } = program;
  44. -client.adduser(registry, {
  45. - auth: {
  46. - username,
  47. - password,
  48. - email,
  49. - alwaysAuth: true
  50. - }
  51. -}, (err, res) => {
  52. - if (err) throw err;
  53. - const path = `${process.cwd()}/.npmrc`;
  54. - let base = registry.substr(registry.indexOf('/'), registry.length);
  55. - if (base.lastIndexOf('/') !== registry.length - 1) {
  56. - base += '/';
  57. +client.adduser(
  58. + registry,
  59. + {
  60. + auth: {
  61. + username,
  62. + password,
  63. + email,
  64. + alwaysAuth: true,
  65. + },
  66. + },
  67. + (err, res) => {
  68. + if (err) throw err;
  69. + console.log(res.token);
  70. }
  71. - fs.writeFileSync(path, `registry=${registry}\n${base}:_authToken=${res.token}`);
  72. - console.log('Done');
  73. -});
  74. +);