@metamask/snaps-cli 0.34.0-flask.1 → 0.35.0-flask.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/cjs/builders.js +149 -0
  3. package/dist/{builders.js.map → cjs/builders.js.map} +1 -1
  4. package/dist/cjs/cli.js +35 -0
  5. package/dist/cjs/cli.js.map +1 -0
  6. package/dist/cjs/cmds/build/buildHandler.js +36 -0
  7. package/dist/cjs/cmds/build/buildHandler.js.map +1 -0
  8. package/dist/cjs/cmds/build/bundle.js +83 -0
  9. package/dist/{cmds → cjs/cmds}/build/bundle.js.map +1 -1
  10. package/dist/cjs/cmds/build/index.js +32 -0
  11. package/dist/cjs/cmds/build/index.js.map +1 -0
  12. package/dist/cjs/cmds/build/utils.js +79 -0
  13. package/dist/cjs/cmds/build/utils.js.map +1 -0
  14. package/dist/cjs/cmds/eval/evalHandler.js +24 -0
  15. package/dist/cjs/cmds/eval/evalHandler.js.map +1 -0
  16. package/dist/cjs/cmds/eval/index.js +31 -0
  17. package/dist/cjs/cmds/eval/index.js.map +1 -0
  18. package/dist/cjs/cmds/index.js +30 -0
  19. package/dist/cjs/cmds/index.js.map +1 -0
  20. package/dist/cjs/cmds/manifest/index.js +44 -0
  21. package/dist/cjs/cmds/manifest/index.js.map +1 -0
  22. package/dist/cjs/cmds/manifest/manifestHandler.js +46 -0
  23. package/dist/cjs/cmds/manifest/manifestHandler.js.map +1 -0
  24. package/dist/cjs/cmds/serve/index.js +31 -0
  25. package/dist/cjs/cmds/serve/index.js.map +1 -0
  26. package/dist/cjs/cmds/serve/serveHandler.js +62 -0
  27. package/dist/cjs/cmds/serve/serveHandler.js.map +1 -0
  28. package/dist/cjs/cmds/serve/serveUtils.js +37 -0
  29. package/dist/cjs/cmds/serve/serveUtils.js.map +1 -0
  30. package/dist/cjs/cmds/watch/index.js +32 -0
  31. package/dist/cjs/cmds/watch/index.js.map +1 -0
  32. package/dist/cjs/cmds/watch/watchHandler.js +91 -0
  33. package/dist/cjs/cmds/watch/watchHandler.js.map +1 -0
  34. package/dist/cjs/index.js +52 -0
  35. package/dist/cjs/index.js.map +1 -0
  36. package/dist/cjs/main.js +20 -0
  37. package/dist/cjs/main.js.map +1 -0
  38. package/dist/cjs/utils/index.js +21 -0
  39. package/dist/cjs/utils/index.js.map +1 -0
  40. package/dist/cjs/utils/misc.js +141 -0
  41. package/dist/cjs/utils/misc.js.map +1 -0
  42. package/dist/cjs/utils/snap-config.js +101 -0
  43. package/dist/cjs/utils/snap-config.js.map +1 -0
  44. package/dist/{builders.js → esm/builders.js} +27 -29
  45. package/dist/esm/builders.js.map +1 -0
  46. package/dist/esm/cli.js +26 -0
  47. package/dist/esm/cli.js.map +1 -0
  48. package/dist/esm/cmds/build/buildHandler.js +36 -0
  49. package/dist/esm/cmds/build/buildHandler.js.map +1 -0
  50. package/dist/{cmds → esm/cmds}/build/bundle.js +40 -39
  51. package/dist/esm/cmds/build/bundle.js.map +1 -0
  52. package/dist/esm/cmds/build/index.js +17 -0
  53. package/dist/esm/cmds/build/index.js.map +1 -0
  54. package/dist/{cmds → esm/cmds}/build/utils.js +22 -34
  55. package/dist/esm/cmds/build/utils.js.map +1 -0
  56. package/dist/esm/cmds/eval/evalHandler.js +20 -0
  57. package/dist/esm/cmds/eval/evalHandler.js.map +1 -0
  58. package/dist/esm/cmds/eval/index.js +16 -0
  59. package/dist/esm/cmds/eval/index.js.map +1 -0
  60. package/dist/esm/cmds/index.js +15 -0
  61. package/dist/esm/cmds/index.js.map +1 -0
  62. package/dist/esm/cmds/manifest/index.js +29 -0
  63. package/dist/esm/cmds/manifest/index.js.map +1 -0
  64. package/dist/esm/cmds/manifest/manifestHandler.js +43 -0
  65. package/dist/esm/cmds/manifest/manifestHandler.js.map +1 -0
  66. package/dist/esm/cmds/serve/index.js +16 -0
  67. package/dist/esm/cmds/serve/index.js.map +1 -0
  68. package/dist/esm/cmds/serve/serveHandler.js +54 -0
  69. package/dist/esm/cmds/serve/serveHandler.js.map +1 -0
  70. package/dist/esm/cmds/serve/serveUtils.js +30 -0
  71. package/dist/esm/cmds/serve/serveUtils.js.map +1 -0
  72. package/dist/esm/cmds/watch/index.js +17 -0
  73. package/dist/esm/cmds/watch/index.js.map +1 -0
  74. package/dist/esm/cmds/watch/watchHandler.js +87 -0
  75. package/dist/esm/cmds/watch/watchHandler.js.map +1 -0
  76. package/dist/esm/index.js +3 -0
  77. package/dist/esm/index.js.map +1 -0
  78. package/dist/esm/main.js +11 -0
  79. package/dist/esm/main.js.map +1 -0
  80. package/dist/esm/utils/index.js +4 -0
  81. package/dist/esm/utils/index.js.map +1 -0
  82. package/dist/{utils → esm/utils}/misc.js +32 -50
  83. package/dist/esm/utils/misc.js.map +1 -0
  84. package/dist/{utils → esm/utils}/snap-config.js +26 -39
  85. package/dist/esm/utils/snap-config.js.map +1 -0
  86. package/dist/{cmds → types/cmds}/build/bundle.d.ts +0 -1
  87. package/dist/{cmds/serve → types/cmds/build}/index.d.ts +2 -2
  88. package/dist/{cmds/build → types/cmds/eval}/index.d.ts +2 -2
  89. package/dist/{cmds → types/cmds}/manifest/index.d.ts +2 -2
  90. package/dist/{cmds/eval → types/cmds/serve}/index.d.ts +2 -2
  91. package/dist/types/cmds/watch/index.d.ts +9 -0
  92. package/dist/{utils → types/utils}/snap-config.d.ts +0 -1
  93. package/package.json +56 -18
  94. package/dist/cli.js +0 -51
  95. package/dist/cli.js.map +0 -1
  96. package/dist/cmds/build/buildHandler.js +0 -37
  97. package/dist/cmds/build/buildHandler.js.map +0 -1
  98. package/dist/cmds/build/index.js +0 -29
  99. package/dist/cmds/build/index.js.map +0 -1
  100. package/dist/cmds/build/utils.js.map +0 -1
  101. package/dist/cmds/eval/evalHandler.js +0 -25
  102. package/dist/cmds/eval/evalHandler.js.map +0 -1
  103. package/dist/cmds/eval/index.js +0 -15
  104. package/dist/cmds/eval/index.js.map +0 -1
  105. package/dist/cmds/index.js +0 -13
  106. package/dist/cmds/index.js.map +0 -1
  107. package/dist/cmds/manifest/index.js +0 -24
  108. package/dist/cmds/manifest/index.js.map +0 -1
  109. package/dist/cmds/manifest/manifestHandler.js +0 -50
  110. package/dist/cmds/manifest/manifestHandler.js.map +0 -1
  111. package/dist/cmds/serve/index.js +0 -15
  112. package/dist/cmds/serve/index.js.map +0 -1
  113. package/dist/cmds/serve/serveHandler.js +0 -59
  114. package/dist/cmds/serve/serveHandler.js.map +0 -1
  115. package/dist/cmds/serve/serveUtils.js +0 -39
  116. package/dist/cmds/serve/serveUtils.js.map +0 -1
  117. package/dist/cmds/watch/index.d.ts +0 -9
  118. package/dist/cmds/watch/index.js +0 -32
  119. package/dist/cmds/watch/index.js.map +0 -1
  120. package/dist/cmds/watch/watchHandler.js +0 -99
  121. package/dist/cmds/watch/watchHandler.js.map +0 -1
  122. package/dist/index.js +0 -28
  123. package/dist/index.js.map +0 -1
  124. package/dist/main.js +0 -15
  125. package/dist/main.js.map +0 -1
  126. package/dist/utils/index.js +0 -19
  127. package/dist/utils/index.js.map +0 -1
  128. package/dist/utils/misc.js.map +0 -1
  129. package/dist/utils/snap-config.js.map +0 -1
  130. /package/dist/{builders.d.ts → types/builders.d.ts} +0 -0
  131. /package/dist/{cli.d.ts → types/cli.d.ts} +0 -0
  132. /package/dist/{cmds → types/cmds}/build/buildHandler.d.ts +0 -0
  133. /package/dist/{cmds → types/cmds}/build/utils.d.ts +0 -0
  134. /package/dist/{cmds → types/cmds}/eval/evalHandler.d.ts +0 -0
  135. /package/dist/{cmds → types/cmds}/index.d.ts +0 -0
  136. /package/dist/{cmds → types/cmds}/manifest/manifestHandler.d.ts +0 -0
  137. /package/dist/{cmds → types/cmds}/serve/serveHandler.d.ts +0 -0
  138. /package/dist/{cmds → types/cmds}/serve/serveUtils.d.ts +0 -0
  139. /package/dist/{cmds → types/cmds}/watch/watchHandler.d.ts +0 -0
  140. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  141. /package/dist/{main.d.ts → types/main.d.ts} +0 -0
  142. /package/dist/{utils → types/utils}/index.d.ts +0 -0
  143. /package/dist/{utils → types/utils}/misc.d.ts +0 -0
@@ -1,23 +1,17 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.trimPathString = exports.writeError = exports.logError = exports.sanitizeInputs = exports.booleanStringToBoolean = exports.setSnapGlobals = exports.CONFIG_FILE = exports.permRequestKeys = void 0;
7
- const snaps_utils_1 = require("@metamask/snaps-utils");
8
- const utils_1 = require("@metamask/utils");
9
- const fs_1 = require("fs");
10
- const path_1 = __importDefault(require("path"));
11
- exports.permRequestKeys = [
1
+ import { logError as logErrorUtil } from '@metamask/snaps-utils';
2
+ import { hasProperty } from '@metamask/utils';
3
+ import { promises as filesystem } from 'fs';
4
+ import path from 'path';
5
+ export const permRequestKeys = [
12
6
  '@context',
13
7
  'id',
14
8
  'parentCapability',
15
9
  'invoker',
16
10
  'date',
17
11
  'caveats',
18
- 'proof',
12
+ 'proof'
19
13
  ];
20
- exports.CONFIG_FILE = 'snap.config.js';
14
+ export const CONFIG_FILE = 'snap.config.js';
21
15
  // CLI arguments whose values are file paths
22
16
  const pathArguments = new Set([
23
17
  'src',
@@ -27,7 +21,7 @@ const pathArguments = new Set([
27
21
  'bundle',
28
22
  'b',
29
23
  'root',
30
- 'r',
24
+ 'r'
31
25
  ]);
32
26
  /**
33
27
  * Sets global variable snaps which tracks user settings:
@@ -35,22 +29,22 @@ const pathArguments = new Set([
35
29
  * warnings.
36
30
  *
37
31
  * @param argv - Arguments as an object generated by `yargs`.
38
- */
39
- function setSnapGlobals(argv) {
40
- if (['w', 'watch'].includes(argv._[0])) {
32
+ */ export function setSnapGlobals(argv) {
33
+ if ([
34
+ 'w',
35
+ 'watch'
36
+ ].includes(argv._[0])) {
41
37
  global.snaps.isWatching = true;
42
- }
43
- else {
38
+ } else {
44
39
  global.snaps.isWatching = false;
45
40
  }
46
- if ((0, utils_1.hasProperty)(argv, 'verboseErrors')) {
41
+ if (hasProperty(argv, 'verboseErrors')) {
47
42
  global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);
48
43
  }
49
- if ((0, utils_1.hasProperty)(argv, 'suppressWarnings')) {
44
+ if (hasProperty(argv, 'suppressWarnings')) {
50
45
  global.snaps.suppressWarnings = booleanStringToBoolean(argv.suppressWarnings);
51
46
  }
52
47
  }
53
- exports.setSnapGlobals = setSnapGlobals;
54
48
  /**
55
49
  * Attempts to convert a string to a boolean and throws if the value is invalid.
56
50
  *
@@ -58,59 +52,51 @@ exports.setSnapGlobals = setSnapGlobals;
58
52
  * @returns `true` if the value is the string `"true"`, `false` if it is the
59
53
  * string `"false"`, the value if it is already a boolean, or an error
60
54
  * otherwise.
61
- */
62
- function booleanStringToBoolean(value) {
55
+ */ export function booleanStringToBoolean(value) {
63
56
  if (typeof value === 'boolean') {
64
57
  return value;
65
- }
66
- else if (value === 'true') {
58
+ } else if (value === 'true') {
67
59
  return true;
68
- }
69
- else if (value === 'false') {
60
+ } else if (value === 'false') {
70
61
  return false;
71
62
  }
72
63
  throw new Error(`Expected a boolean or the strings "true" or "false". Received: "${String(value)}"`);
73
64
  }
74
- exports.booleanStringToBoolean = booleanStringToBoolean;
75
65
  /**
76
66
  * Sanitizes inputs. Currently normalizes "./" paths to ".".
77
67
  * Yargs handles other path normalization as specified in builders.
78
68
  *
79
69
  * @param argv - Arguments as an object generated by yargs.
80
- */
81
- function sanitizeInputs(argv) {
82
- Object.keys(argv).forEach((key) => {
70
+ */ export function sanitizeInputs(argv) {
71
+ Object.keys(argv).forEach((key)=>{
83
72
  if (typeof argv[key] === 'string') {
84
73
  // Node's path.normalize() does not do this
85
74
  if (argv[key] === './') {
86
75
  argv[key] = '.';
87
76
  }
88
77
  if (pathArguments.has(key)) {
89
- argv[key] = path_1.default.normalize(argv[key]);
78
+ argv[key] = path.normalize(argv[key]);
90
79
  }
91
80
  }
92
81
  });
93
82
  }
94
- exports.sanitizeInputs = sanitizeInputs;
95
83
  /**
96
84
  * Logs an error message to console. Logs original error if it exists and
97
85
  * the verboseErrors global is true.
98
86
  *
99
87
  * @param message - The error message.
100
88
  * @param error - The original error.
101
- */
102
- function logError(message, error) {
89
+ */ export function logError(message, error) {
103
90
  if (message !== null) {
104
- (0, snaps_utils_1.logError)(message);
91
+ logErrorUtil(message);
105
92
  }
106
93
  if (error && global.snaps.verboseErrors) {
107
- (0, snaps_utils_1.logError)(error);
94
+ logErrorUtil(error);
108
95
  }
109
- if (message === null && (!error || (error && !global.snaps.verboseErrors))) {
110
- (0, snaps_utils_1.logError)('Unknown error.');
96
+ if (message === null && (!error || error && !global.snaps.verboseErrors)) {
97
+ logErrorUtil('Unknown error.');
111
98
  }
112
99
  }
113
- exports.logError = logError;
114
100
  /**
115
101
  * Logs an error, attempts to unlink the destination file, and kills the
116
102
  * process.
@@ -119,8 +105,7 @@ exports.logError = logError;
119
105
  * @param message - The error message.
120
106
  * @param error - The original error.
121
107
  * @param destFilePath - The output file path.
122
- */
123
- async function writeError(prefix, message, error, destFilePath) {
108
+ */ export async function writeError(prefix, message, error, destFilePath) {
124
109
  let processedPrefix = prefix;
125
110
  if (!prefix.endsWith(' ')) {
126
111
  processedPrefix += ' ';
@@ -128,10 +113,9 @@ async function writeError(prefix, message, error, destFilePath) {
128
113
  logError(processedPrefix + message, error);
129
114
  try {
130
115
  if (destFilePath) {
131
- await fs_1.promises.unlink(destFilePath);
116
+ await filesystem.unlink(destFilePath);
132
117
  }
133
- }
134
- catch (unlinkError) {
118
+ } catch (unlinkError) {
135
119
  logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);
136
120
  }
137
121
  // unless the watcher is active, exit
@@ -141,16 +125,14 @@ async function writeError(prefix, message, error, destFilePath) {
141
125
  process.exit(1);
142
126
  }
143
127
  }
144
- exports.writeError = writeError;
145
128
  /**
146
129
  * Trims leading and trailing periods "." and forward slashes "/" from the
147
130
  * given path string.
148
131
  *
149
132
  * @param pathString - The path string to trim.
150
133
  * @returns The trimmed path string.
151
- */
152
- function trimPathString(pathString) {
134
+ */ export function trimPathString(pathString) {
153
135
  return pathString.replace(/^[./]+|[./]+$/gu, '');
154
136
  }
155
- exports.trimPathString = trimPathString;
137
+
156
138
  //# sourceMappingURL=misc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { Arguments } from 'yargs';\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.js';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress\n * warnings.\n *\n * @param argv - Arguments as an object generated by `yargs`.\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\n );\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - Arguments as an object generated by yargs.\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"],"names":["logError","logErrorUtil","hasProperty","promises","filesystem","path","permRequestKeys","CONFIG_FILE","pathArguments","Set","setSnapGlobals","argv","includes","_","global","snaps","isWatching","verboseErrors","booleanStringToBoolean","suppressWarnings","value","Error","String","sanitizeInputs","Object","keys","forEach","key","has","normalize","message","error","writeError","prefix","destFilePath","processedPrefix","endsWith","unlink","unlinkError","process","exit","trimPathString","pathString","replace"],"mappings":"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"}
@@ -1,18 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.applyConfig = exports.loadConfig = exports.isSnapConfig = exports.SnapConfigStruct = void 0;
7
- const utils_1 = require("@metamask/utils");
8
- const path_1 = __importDefault(require("path"));
9
- const superstruct_1 = require("superstruct");
10
- const yargs_parser_1 = __importDefault(require("yargs-parser"));
11
- const builders_1 = __importDefault(require("../builders"));
12
- const misc_1 = require("./misc");
13
- exports.SnapConfigStruct = (0, superstruct_1.object)({
14
- cliOptions: (0, superstruct_1.optional)((0, superstruct_1.object)()),
15
- bundlerCustomizer: (0, superstruct_1.optional)((0, superstruct_1.func)()),
1
+ import { hasProperty } from '@metamask/utils';
2
+ import path from 'path';
3
+ import { object, optional, func, is } from 'superstruct';
4
+ import yargsParse from 'yargs-parser';
5
+ import builders from '../builders';
6
+ import { CONFIG_FILE, logError } from './misc';
7
+ export const SnapConfigStruct = object({
8
+ cliOptions: optional(object()),
9
+ bundlerCustomizer: optional(func())
16
10
  });
17
11
  /**
18
12
  * Check if the given value is a {@link SnapConfig} object. Note that this
@@ -22,11 +16,9 @@ exports.SnapConfigStruct = (0, superstruct_1.object)({
22
16
  * @param value - The value to check.
23
17
  * @returns `true` if the value is a valid {@link SnapConfig} object, `false`
24
18
  * otherwise.
25
- */
26
- function isSnapConfig(value) {
27
- return (0, superstruct_1.is)(value, exports.SnapConfigStruct);
19
+ */ export function isSnapConfig(value) {
20
+ return is(value, SnapConfigStruct);
28
21
  }
29
- exports.isSnapConfig = isSnapConfig;
30
22
  let snapConfigCache;
31
23
  /**
32
24
  * Attempt to load the snap config file (`snap.config.js`). By default will use
@@ -36,32 +28,29 @@ let snapConfigCache;
36
28
  *
37
29
  * @param cached - Whether to use the cached config. Defaults to `true`.
38
30
  * @returns The snap config.
39
- */
40
- function loadConfig(cached = true) {
31
+ */ export function loadConfig(cached = true) {
41
32
  if (snapConfigCache !== undefined && cached) {
42
33
  return snapConfigCache;
43
34
  }
44
35
  let config;
45
36
  try {
46
37
  // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
47
- config = require(path_1.default.resolve(process.cwd(), misc_1.CONFIG_FILE));
48
- }
49
- catch (error) {
38
+ config = require(path.resolve(process.cwd(), CONFIG_FILE));
39
+ } catch (error) {
50
40
  if (error.code === 'MODULE_NOT_FOUND') {
51
41
  snapConfigCache = {};
52
42
  return snapConfigCache;
53
43
  }
54
- (0, misc_1.logError)(`Error during parsing of ${misc_1.CONFIG_FILE}`, error);
44
+ logError(`Error during parsing of ${CONFIG_FILE}`, error);
55
45
  return process.exit(1);
56
46
  }
57
47
  if (!isSnapConfig(config)) {
58
- (0, misc_1.logError)(`Can't validate ${misc_1.CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
48
+ logError(`Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
59
49
  return process.exit(1);
60
50
  }
61
51
  snapConfigCache = config;
62
52
  return config;
63
53
  }
64
- exports.loadConfig = loadConfig;
65
54
  // Note that the below function is necessary because yargs' .config() function
66
55
  // leaves much to be desired.
67
56
  //
@@ -78,8 +67,7 @@ exports.loadConfig = loadConfig;
78
67
  * @param processArgv - The command line arguments, i.e., `process.argv`.
79
68
  * @param yargsArgv - The processed `yargs` arguments.
80
69
  * @param yargsInstance - An instance of `yargs`.
81
- */
82
- function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
70
+ */ export function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
83
71
  // Instances of yargs has a number of undocumented functions, including
84
72
  // getOptions. This function returns an object with properties "key" and
85
73
  // "alias", which specify the options associated with the current command and
@@ -92,26 +80,25 @@ function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
92
80
  // If we set args that aren't valid for the current command, yargs will error
93
81
  // during validation.
94
82
  const { alias: aliases, key: options } = yargsInstance.getOptions();
95
- const parsedProcessArgv = (0, yargs_parser_1.default)(processArgv, {
96
- alias: aliases,
83
+ const parsedProcessArgv = yargsParse(processArgv, {
84
+ alias: aliases
97
85
  });
98
86
  delete parsedProcessArgv._; // irrelevant yargs parser artifact
99
87
  const commandOptions = new Set(Object.keys(options));
100
- const shouldSetArg = (key) => {
101
- return commandOptions.has(key) && !(0, utils_1.hasProperty)(parsedProcessArgv, key);
88
+ const shouldSetArg = (key)=>{
89
+ return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);
102
90
  };
103
91
  const config = snapConfig.cliOptions ?? {};
104
- for (const key of Object.keys(config)) {
105
- if ((0, utils_1.hasProperty)(builders_1.default, key)) {
92
+ for (const key of Object.keys(config)){
93
+ if (hasProperty(builders, key)) {
106
94
  if (shouldSetArg(key)) {
107
95
  yargsArgv[key] = config[key];
108
96
  }
109
- }
110
- else {
111
- (0, misc_1.logError)(`Error: Encountered unrecognized config property "options.${key}" in config file "${misc_1.CONFIG_FILE}". Remove the property and try again.`);
97
+ } else {
98
+ logError(`Error: Encountered unrecognized config property "options.${key}" in config file "${CONFIG_FILE}". Remove the property and try again.`);
112
99
  process.exit(1);
113
100
  }
114
101
  }
115
102
  }
116
- exports.applyConfig = applyConfig;
103
+
117
104
  //# sourceMappingURL=snap-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/snap-config.ts"],"sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport { object, optional, func, Infer, is } from 'superstruct';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n process.exit(1);\n }\n }\n}\n"],"names":["hasProperty","path","object","optional","func","is","yargsParse","builders","CONFIG_FILE","logError","SnapConfigStruct","cliOptions","bundlerCustomizer","isSnapConfig","value","snapConfigCache","loadConfig","cached","undefined","config","require","resolve","process","cwd","error","code","exit","applyConfig","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","_","commandOptions","Set","Object","keys","shouldSetArg","has"],"mappings":"AAAA,SAASA,WAAW,QAAQ,kBAAkB;AAE9C,OAAOC,UAAU,OAAO;AACxB,SAASC,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAASC,EAAE,QAAQ,cAAc;AAEhE,OAAOC,gBAAgB,eAAe;AAGtC,OAAOC,cAAc,cAAc;AACnC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,SAAS;AAI/C,OAAO,MAAMC,mBAAmBR,OAAO;IACrCS,YAAYR,SAASD;IACrBU,mBAAmBT,SAASC;AAC9B,GAAG;AASH;;;;;;;;CAQC,GACD,OAAO,SAASS,aAAaC,KAAc;IACzC,OAAOT,GAAGS,OAAOJ;AACnB;AAEA,IAAIK;AAEJ;;;;;;;;CAQC,GACD,OAAO,SAASC,WAAWC,SAAS,IAAI;IACtC,IAAIF,oBAAoBG,aAAaD,QAAQ;QAC3C,OAAOF;IACT;IAEA,IAAII;IACJ,IAAI;QACF,iHAAiH;QACjHA,SAASC,QAAQnB,KAAKoB,OAAO,CAACC,QAAQC,GAAG,IAAIf;IAC/C,EAAE,OAAOgB,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCV,kBAAkB,CAAC;YACnB,OAAOA;QACT;QACAN,SAAS,CAAC,wBAAwB,EAAED,YAAY,CAAC,EAAEgB;QACnD,OAAOF,QAAQI,IAAI,CAAC;IACtB;IAEA,IAAI,CAACb,aAAaM,SAAS;QACzBV,SACE,CAAC,eAAe,EAAED,YAAY,iGAAiG,CAAC;QAElI,OAAOc,QAAQI,IAAI,CAAC;IACtB;IACAX,kBAAkBI;IAClB,OAAOA;AACT;AAEA,8EAA8E;AAC9E,6BAA6B;AAC7B,EAAE;AACF,wEAAwE;AACxE,4DAA4D;AAE5D;;;;;;;;;;;CAWC,GACD,OAAO,SAASQ,YACdC,UAAsB,EACtBC,WAAqB,EACrBC,SAAoB,EACpBC,aAA2B;IAE3B,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,+BAA+B;IAC/B,EAAE;IACF,8EAA8E;IAC9E,2EAA2E;IAC3E,oBAAoB;IACpB,EAAE;IACF,6EAA6E;IAC7E,qBAAqB;IACrB,MAAM,EAAEC,OAAOC,OAAO,EAAEC,KAAKC,OAAO,EAAE,GAAG,AACvCJ,cACAK,UAAU;IAKZ,MAAMC,oBAAoB/B,WAAWuB,aAAa;QAChDG,OAAOC;IACT;IACA,OAAOI,kBAAkBC,CAAC,EAAE,mCAAmC;IAE/D,MAAMC,iBAAiB,IAAIC,IAAIC,OAAOC,IAAI,CAACP;IAE3C,MAAMQ,eAAe,CAACT;QACpB,OAAOK,eAAeK,GAAG,CAACV,QAAQ,CAAClC,YAAYqC,mBAAmBH;IACpE;IAEA,MAAMf,SAAkCS,WAAWjB,UAAU,IAAI,CAAC;IAClE,KAAK,MAAMuB,OAAOO,OAAOC,IAAI,CAACvB,QAAS;QACrC,IAAInB,YAAYO,UAAU2B,MAAM;YAC9B,IAAIS,aAAaT,MAAM;gBACrBJ,SAAS,CAACI,IAAI,GAAGf,MAAM,CAACe,IAAI;YAC9B;QACF,OAAO;YACLzB,SACE,CAAC,yDAAyD,EAAEyB,IAAI,kBAAkB,EAAE1B,YAAY,qCAAqC,CAAC;YAExIc,QAAQI,IAAI,CAAC;QACf;IACF;AACF"}
@@ -1,4 +1,3 @@
1
- /// <reference types="watchify" />
2
1
  import { BrowserifyObject } from 'browserify';
3
2
  import { YargsArgs } from '../../types/yargs';
4
3
  /**
@@ -1,9 +1,9 @@
1
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const _default: {
3
+ declare const command: {
4
4
  command: string[];
5
5
  desc: string;
6
6
  builder: (yarg: yargs.Argv) => void;
7
7
  handler: (argv: YargsArgs) => Promise<void>;
8
8
  };
9
- export = _default;
9
+ export default command;
@@ -1,9 +1,9 @@
1
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const _default: {
3
+ declare const command: {
4
4
  command: string[];
5
5
  desc: string;
6
6
  builder: (yarg: yargs.Argv) => void;
7
7
  handler: (argv: YargsArgs) => Promise<void>;
8
8
  };
9
- export = _default;
9
+ export default command;
@@ -1,9 +1,9 @@
1
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const _default: {
3
+ declare const command: {
4
4
  command: string[];
5
5
  desc: string;
6
6
  builder: (yarg: yargs.Argv) => void;
7
7
  handler: (argv: YargsArgs) => Promise<void>;
8
8
  };
9
- export = _default;
9
+ export default command;
@@ -1,9 +1,9 @@
1
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const _default: {
3
+ declare const command: {
4
4
  command: string[];
5
5
  desc: string;
6
6
  builder: (yarg: yargs.Argv) => void;
7
7
  handler: (argv: YargsArgs) => Promise<void>;
8
8
  };
9
- export = _default;
9
+ export default command;
@@ -0,0 +1,9 @@
1
+ import yargs from 'yargs';
2
+ import { YargsArgs } from '../../types/yargs';
3
+ declare const command: {
4
+ command: string[];
5
+ desc: string;
6
+ builder: (yarg: yargs.Argv) => void;
7
+ handler: (argv: YargsArgs) => Promise<void>;
8
+ };
9
+ export default command;
@@ -1,4 +1,3 @@
1
- /// <reference types="watchify" />
2
1
  import type browserify from 'browserify';
3
2
  import { Infer } from 'superstruct';
4
3
  import { Arguments } from 'yargs';
package/package.json CHANGED
@@ -1,26 +1,61 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "0.34.0-flask.1",
3
+ "version": "0.35.0-flask.1",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/MetaMask/snaps.git"
8
8
  },
9
9
  "license": "ISC",
10
- "main": "dist/index.js",
10
+ "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/esm/index.js",
14
+ "require": "./dist/cjs/index.js",
15
+ "types": "./dist/types/index.d.ts"
16
+ },
17
+ "./dist/cjs/*": {
18
+ "require": "./dist/cjs/*.js",
19
+ "types": "./dist/types/*.d.ts"
20
+ },
21
+ "./dist/esm/*": {
22
+ "import": "./dist/esm/*.js",
23
+ "types": "./dist/types/*.d.ts"
24
+ }
25
+ },
26
+ "main": "./dist/cjs/index.js",
27
+ "module": "./dist/esm/index.js",
28
+ "types": "./dist/types/index.d.ts",
29
+ "typesVersions": {
30
+ "*": {
31
+ "*": [
32
+ "./dist/types/*"
33
+ ],
34
+ "./dist/cjs/*": [
35
+ "./dist/types/*"
36
+ ],
37
+ "./dist/esm/*": [
38
+ "./dist/types/*"
39
+ ]
40
+ }
41
+ },
11
42
  "bin": {
12
- "mm-snap": "./dist/main.js"
43
+ "mm-snap": "./dist/cjs/main.js"
13
44
  },
14
45
  "files": [
15
- "dist/"
46
+ "dist/cjs/**",
47
+ "dist/esm/**",
48
+ "dist/types/**"
16
49
  ],
17
50
  "scripts": {
18
- "shasum": "node ./scripts/computeSnapShasum.js",
19
- "build:tsc": "tsc --project ./tsconfig.build.json",
20
- "build:chmod": "chmod +x ./dist/main.js",
21
- "build:readme": "node ./scripts/updateReadme.js",
22
- "build": "yarn build:tsc && yarn build:post-tsc",
51
+ "build": "yarn build:source && yarn build:types",
52
+ "build:source": "yarn build:esm && yarn build:cjs",
53
+ "build:types": "tsc --project tsconfig.build.json",
54
+ "build:esm": "swc src --out-dir dist/esm --config-file ../../.swcrc.build.json --config module.type=es6",
55
+ "build:cjs": "swc src --out-dir dist/cjs --config-file ../../.swcrc.build.json --config module.type=commonjs",
23
56
  "build:post-tsc": "yarn build:chmod && yarn build:readme",
57
+ "build:chmod": "chmod +x ./dist/esm/main.js && chmod +x ./dist/cjs/main.js",
58
+ "build:readme": "node ./scripts/updateReadme.js",
24
59
  "build:clean": "yarn clean && yarn build",
25
60
  "build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
26
61
  "clean": "rimraf '*.tsbuildinfo' 'dist/*'",
@@ -29,12 +64,13 @@
29
64
  "test:watch": "yarn test --watch",
30
65
  "test:ci": "yarn test",
31
66
  "lint:changelog": "yarn auto-changelog validate",
32
- "lint:eslint": "eslint . --cache --ext js,ts",
33
- "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
34
- "lint": "yarn lint:eslint && yarn lint:misc --check",
67
+ "lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
68
+ "lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
69
+ "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog",
35
70
  "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
36
71
  "prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
37
- "publish:preview": "yarn npm publish --tag preview"
72
+ "publish:preview": "yarn npm publish --tag preview",
73
+ "lint:ci": "yarn lint"
38
74
  },
39
75
  "dependencies": {
40
76
  "@babel/core": "^7.20.12",
@@ -45,9 +81,9 @@
45
81
  "@babel/plugin-transform-runtime": "^7.16.7",
46
82
  "@babel/preset-env": "^7.20.12",
47
83
  "@babel/preset-typescript": "^7.20.12",
48
- "@metamask/snaps-browserify-plugin": "^0.34.0-flask.1",
49
- "@metamask/snaps-utils": "^0.34.0-flask.1",
50
- "@metamask/utils": "^6.0.0",
84
+ "@metamask/snaps-browserify-plugin": "^0.35.0-flask.1",
85
+ "@metamask/snaps-utils": "^0.35.0-flask.1",
86
+ "@metamask/utils": "^6.0.1",
51
87
  "babelify": "^10.0.0",
52
88
  "browserify": "^17.0.0",
53
89
  "chokidar": "^3.5.2",
@@ -65,10 +101,13 @@
65
101
  "@metamask/eslint-config-jest": "^11.0.0",
66
102
  "@metamask/eslint-config-nodejs": "^11.0.1",
67
103
  "@metamask/eslint-config-typescript": "^11.0.0",
104
+ "@swc/cli": "^0.1.62",
105
+ "@swc/core": "^1.3.66",
106
+ "@swc/jest": "^0.2.26",
68
107
  "@types/browserify": "^12.0.37",
69
108
  "@types/is-url": "^1.2.28",
70
109
  "@types/jest": "^27.5.1",
71
- "@types/node": "^17.0.36",
110
+ "@types/node": "^20.3.1",
72
111
  "@types/rimraf": "^3.0.0",
73
112
  "@types/serve-handler": "^6.1.0",
74
113
  "@types/yargs": "^17.0.24",
@@ -92,7 +131,6 @@
92
131
  "prettier": "^2.7.1",
93
132
  "prettier-plugin-packagejson": "^2.2.11",
94
133
  "rimraf": "^4.1.2",
95
- "ts-jest": "^29.0.2",
96
134
  "ts-node": "^10.9.1",
97
135
  "tsc-watch": "^4.5.0",
98
136
  "typescript": "~4.8.4"
package/dist/cli.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cli = void 0;
7
- const yargs_1 = __importDefault(require("yargs"));
8
- const builders_1 = __importDefault(require("./builders"));
9
- const utils_1 = require("./utils");
10
- /**
11
- * The main CLI entry point function. This processes the command line args, and
12
- * runs the appropriate function.
13
- *
14
- * @param argv - The raw command line arguments, i.e., `process.argv`.
15
- * @param commands - The list of commands to use.
16
- */
17
- function cli(argv, commands) {
18
- const rawArgv = argv.slice(2);
19
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-floating-promises
20
- (0, yargs_1.default)(rawArgv)
21
- .scriptName('mm-snap')
22
- .usage('Usage: $0 <command> [options]')
23
- .example('$0 init', `\tInitialize a snap project in the current directory`)
24
- .example('$0 init my-snap', `\tInitialize a snap project in the 'my-snap' directory`)
25
- .example('$0 build -s src/index.js -d out', `\tBuild 'src/index.js' as './out/bundle.js'`)
26
- .example('$0 build -s src/index.js -d out -n snap.js', `\tBuild 'src/index.js' as './out/snap.js'`)
27
- .example('$0 serve -r out', `\tServe files in './out' on port 8080`)
28
- .example('$0 serve -r out -p 9000', `\tServe files in './out' on port 9000`)
29
- .example('$0 watch -s src/index.js -d out', `\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`)
30
- .command(commands)
31
- .option('verboseErrors', builders_1.default.verboseErrors)
32
- .option('suppressWarnings', builders_1.default.suppressWarnings)
33
- .strict()
34
- // Typecast: The @types/yargs type for .middleware is incorrect.
35
- // yargs middleware functions receive the yargs instance as a second parameter.
36
- // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation
37
- .middleware(((yargsArgv, yargsInstance) => {
38
- (0, utils_1.applyConfig)((0, utils_1.loadConfig)(), rawArgv, yargsArgv, yargsInstance);
39
- (0, utils_1.setSnapGlobals)(yargsArgv);
40
- (0, utils_1.sanitizeInputs)(yargsArgv);
41
- }), true)
42
- .fail((message, error, _yargs) => {
43
- (0, utils_1.logError)(message, error);
44
- process.exitCode = 1;
45
- })
46
- .demandCommand(1, 'You must specify at least one command.')
47
- .help()
48
- .alias('help', 'h').argv;
49
- }
50
- exports.cli = cli;
51
- //# sourceMappingURL=cli.js.map
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyC;AAGzC,0DAAkC;AAClC,mCAMiB;AAEjB;;;;;;GAMG;AACH,SAAgB,GAAG,CAAC,IAAc,EAAE,QAAa;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,6GAA6G;IAC7G,IAAA,eAAK,EAAC,OAAO,CAAC;SACX,UAAU,CAAC,SAAS,CAAC;SACrB,KAAK,CAAC,+BAA+B,CAAC;SAEtC,OAAO,CAAC,SAAS,EAAE,sDAAsD,CAAC;SAC1E,OAAO,CACN,iBAAiB,EACjB,wDAAwD,CACzD;SACA,OAAO,CACN,iCAAiC,EACjC,6CAA6C,CAC9C;SACA,OAAO,CACN,4CAA4C,EAC5C,2CAA2C,CAC5C;SACA,OAAO,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;SACnE,OAAO,CAAC,yBAAyB,EAAE,uCAAuC,CAAC;SAC3E,OAAO,CACN,iCAAiC,EACjC,gGAAgG,CACjG;SAEA,OAAO,CAAC,QAAQ,CAAC;SAEjB,MAAM,CAAC,eAAe,EAAE,kBAAQ,CAAC,aAAa,CAAC;SAE/C,MAAM,CAAC,kBAAkB,EAAE,kBAAQ,CAAC,gBAAgB,CAAC;SAErD,MAAM,EAAE;QAET,gEAAgE;QAChE,+EAA+E;QAC/E,0FAA0F;SACzF,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,aAA+B,EAAE,EAAE;QACzD,IAAA,mBAAW,EAAC,IAAA,kBAAU,GAAE,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QAC7D,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;QAC1B,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAQ,EACT,IAAI,CACL;SAEA,IAAI,CAAC,CAAC,OAAe,EAAE,KAAY,EAAE,MAAM,EAAE,EAAE;QAC9C,IAAA,gBAAQ,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC;SAED,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAE1D,IAAI,EAAE;SACN,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAxDD,kBAwDC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\nimport builders from './builders';\nimport {\n applyConfig,\n loadConfig,\n sanitizeInputs,\n setSnapGlobals,\n logError,\n} from './utils';\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport function cli(argv: string[], commands: any): void {\n const rawArgv = argv.slice(2);\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-floating-promises\n yargs(rawArgv)\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize a snap project in the current directory`)\n .example(\n '$0 init my-snap',\n `\\tInitialize a snap project in the 'my-snap' directory`,\n )\n .example(\n '$0 build -s src/index.js -d out',\n `\\tBuild 'src/index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s src/index.js -d out -n snap.js',\n `\\tBuild 'src/index.js' as './out/snap.js'`,\n )\n .example('$0 serve -r out', `\\tServe files in './out' on port 8080`)\n .example('$0 serve -r out -p 9000', `\\tServe files in './out' on port 9000`)\n .example(\n '$0 watch -s src/index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`,\n )\n\n .command(commands)\n\n .option('verboseErrors', builders.verboseErrors)\n\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n // Typecast: The @types/yargs type for .middleware is incorrect.\n // yargs middleware functions receive the yargs instance as a second parameter.\n // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation\n .middleware(\n ((yargsArgv: Arguments, yargsInstance: typeof yargsType) => {\n applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((message: string, error: Error, _yargs) => {\n logError(message, error);\n process.exitCode = 1;\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"]}