479eaf834e9297e5ff46a0600c46d41773ff0b1fd7c2679010a9b094e9fc7b2c62ceb88860d55d22ce04798472410a3602e4a85ce997764080ba4a14a9dd71 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env node
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. const package_json_1 = require("../package.json");
  5. const usage = () => `
  6. usage: mkdirp [DIR1,DIR2..] {OPTIONS}
  7. Create each supplied directory including any necessary parent directories
  8. that don't yet exist.
  9. If the directory already exists, do nothing.
  10. OPTIONS are:
  11. -m<mode> If a directory needs to be created, set the mode as an octal
  12. --mode=<mode> permission string.
  13. -v --version Print the mkdirp version number
  14. -h --help Print this helpful banner
  15. -p --print Print the first directories created for each path provided
  16. --manual Use manual implementation, even if native is available
  17. `;
  18. const dirs = [];
  19. const opts = {};
  20. let doPrint = false;
  21. let dashdash = false;
  22. let manual = false;
  23. for (const arg of process.argv.slice(2)) {
  24. if (dashdash)
  25. dirs.push(arg);
  26. else if (arg === '--')
  27. dashdash = true;
  28. else if (arg === '--manual')
  29. manual = true;
  30. else if (/^-h/.test(arg) || /^--help/.test(arg)) {
  31. console.log(usage());
  32. process.exit(0);
  33. }
  34. else if (arg === '-v' || arg === '--version') {
  35. console.log(package_json_1.version);
  36. process.exit(0);
  37. }
  38. else if (arg === '-p' || arg === '--print') {
  39. doPrint = true;
  40. }
  41. else if (/^-m/.test(arg) || /^--mode=/.test(arg)) {
  42. // these don't get covered in CI, but work locally
  43. // weird because the tests below show as passing in the output.
  44. /* c8 ignore start */
  45. const mode = parseInt(arg.replace(/^(-m|--mode=)/, ''), 8);
  46. if (isNaN(mode)) {
  47. console.error(`invalid mode argument: ${arg}\nMust be an octal number.`);
  48. process.exit(1);
  49. }
  50. /* c8 ignore stop */
  51. opts.mode = mode;
  52. }
  53. else
  54. dirs.push(arg);
  55. }
  56. const index_js_1 = require("./index.js");
  57. const impl = manual ? index_js_1.mkdirp.manual : index_js_1.mkdirp;
  58. if (dirs.length === 0) {
  59. console.error(usage());
  60. }
  61. // these don't get covered in CI, but work locally
  62. /* c8 ignore start */
  63. Promise.all(dirs.map(dir => impl(dir, opts)))
  64. .then(made => (doPrint ? made.forEach(m => m && console.log(m)) : null))
  65. .catch(er => {
  66. console.error(er.message);
  67. if (er.code)
  68. console.error(' code: ' + er.code);
  69. process.exit(1);
  70. });
  71. /* c8 ignore stop */
  72. //# sourceMappingURL=bin.js.map