@metamask/snaps-cli 0.35.0-flask.1 → 1.0.0-prerelease.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 (153) hide show
  1. package/CHANGELOG.md +3 -26
  2. package/README.md +6 -5
  3. package/dist/{esm/builders.js → builders.js} +29 -27
  4. package/dist/{cjs/builders.js.map → builders.js.map} +1 -1
  5. package/dist/cli.js +51 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/cmds/build/buildHandler.js +37 -0
  8. package/dist/cmds/build/buildHandler.js.map +1 -0
  9. package/dist/cmds/build/bundle.js +80 -0
  10. package/dist/cmds/build/bundle.js.map +1 -0
  11. package/dist/{types/cmds/serve → cmds/build}/index.d.ts +2 -2
  12. package/dist/cmds/build/index.js +29 -0
  13. package/dist/cmds/build/index.js.map +1 -0
  14. package/dist/{esm/cmds → cmds}/build/utils.js +34 -22
  15. package/dist/cmds/build/utils.js.map +1 -0
  16. package/dist/cmds/eval/evalHandler.js +25 -0
  17. package/dist/cmds/eval/evalHandler.js.map +1 -0
  18. package/dist/{types/cmds/manifest → cmds/eval}/index.d.ts +2 -2
  19. package/dist/cmds/eval/index.js +15 -0
  20. package/dist/cmds/eval/index.js.map +1 -0
  21. package/dist/cmds/index.js +14 -0
  22. package/dist/cmds/index.js.map +1 -0
  23. package/dist/{types/cmds/build → cmds/init}/index.d.ts +2 -2
  24. package/dist/cmds/init/index.js +34 -0
  25. package/dist/cmds/init/index.js.map +1 -0
  26. package/dist/cmds/init/initHandler.d.ts +26 -0
  27. package/dist/cmds/init/initHandler.js +69 -0
  28. package/dist/cmds/init/initHandler.js.map +1 -0
  29. package/dist/cmds/init/initUtils.d.ts +39 -0
  30. package/dist/cmds/init/initUtils.js +122 -0
  31. package/dist/cmds/init/initUtils.js.map +1 -0
  32. package/dist/{types/cmds/eval → cmds/manifest}/index.d.ts +2 -2
  33. package/dist/cmds/manifest/index.js +24 -0
  34. package/dist/cmds/manifest/index.js.map +1 -0
  35. package/dist/cmds/manifest/manifestHandler.js +50 -0
  36. package/dist/cmds/manifest/manifestHandler.js.map +1 -0
  37. package/dist/cmds/serve/index.d.ts +9 -0
  38. package/dist/cmds/serve/index.js +15 -0
  39. package/dist/cmds/serve/index.js.map +1 -0
  40. package/dist/cmds/serve/serveHandler.js +59 -0
  41. package/dist/cmds/serve/serveHandler.js.map +1 -0
  42. package/dist/cmds/serve/serveUtils.js +39 -0
  43. package/dist/cmds/serve/serveUtils.js.map +1 -0
  44. package/dist/cmds/watch/index.d.ts +9 -0
  45. package/dist/cmds/watch/index.js +32 -0
  46. package/dist/cmds/watch/index.js.map +1 -0
  47. package/dist/cmds/watch/watchHandler.js +100 -0
  48. package/dist/cmds/watch/watchHandler.js.map +1 -0
  49. package/dist/main.js +15 -0
  50. package/dist/main.js.map +1 -0
  51. package/dist/utils/index.js +19 -0
  52. package/dist/utils/index.js.map +1 -0
  53. package/dist/{esm/utils → utils}/misc.js +50 -32
  54. package/dist/utils/misc.js.map +1 -0
  55. package/dist/{esm/utils → utils}/snap-config.js +39 -26
  56. package/dist/utils/snap-config.js.map +1 -0
  57. package/package.json +27 -65
  58. package/dist/cjs/builders.js +0 -149
  59. package/dist/cjs/cli.js +0 -35
  60. package/dist/cjs/cli.js.map +0 -1
  61. package/dist/cjs/cmds/build/buildHandler.js +0 -36
  62. package/dist/cjs/cmds/build/buildHandler.js.map +0 -1
  63. package/dist/cjs/cmds/build/bundle.js +0 -83
  64. package/dist/cjs/cmds/build/bundle.js.map +0 -1
  65. package/dist/cjs/cmds/build/index.js +0 -32
  66. package/dist/cjs/cmds/build/index.js.map +0 -1
  67. package/dist/cjs/cmds/build/utils.js +0 -79
  68. package/dist/cjs/cmds/build/utils.js.map +0 -1
  69. package/dist/cjs/cmds/eval/evalHandler.js +0 -24
  70. package/dist/cjs/cmds/eval/evalHandler.js.map +0 -1
  71. package/dist/cjs/cmds/eval/index.js +0 -31
  72. package/dist/cjs/cmds/eval/index.js.map +0 -1
  73. package/dist/cjs/cmds/index.js +0 -30
  74. package/dist/cjs/cmds/index.js.map +0 -1
  75. package/dist/cjs/cmds/manifest/index.js +0 -44
  76. package/dist/cjs/cmds/manifest/index.js.map +0 -1
  77. package/dist/cjs/cmds/manifest/manifestHandler.js +0 -46
  78. package/dist/cjs/cmds/manifest/manifestHandler.js.map +0 -1
  79. package/dist/cjs/cmds/serve/index.js +0 -31
  80. package/dist/cjs/cmds/serve/index.js.map +0 -1
  81. package/dist/cjs/cmds/serve/serveHandler.js +0 -62
  82. package/dist/cjs/cmds/serve/serveHandler.js.map +0 -1
  83. package/dist/cjs/cmds/serve/serveUtils.js +0 -37
  84. package/dist/cjs/cmds/serve/serveUtils.js.map +0 -1
  85. package/dist/cjs/cmds/watch/index.js +0 -32
  86. package/dist/cjs/cmds/watch/index.js.map +0 -1
  87. package/dist/cjs/cmds/watch/watchHandler.js +0 -91
  88. package/dist/cjs/cmds/watch/watchHandler.js.map +0 -1
  89. package/dist/cjs/index.js +0 -52
  90. package/dist/cjs/index.js.map +0 -1
  91. package/dist/cjs/main.js +0 -20
  92. package/dist/cjs/main.js.map +0 -1
  93. package/dist/cjs/utils/index.js +0 -21
  94. package/dist/cjs/utils/index.js.map +0 -1
  95. package/dist/cjs/utils/misc.js +0 -141
  96. package/dist/cjs/utils/misc.js.map +0 -1
  97. package/dist/cjs/utils/snap-config.js +0 -101
  98. package/dist/cjs/utils/snap-config.js.map +0 -1
  99. package/dist/esm/builders.js.map +0 -1
  100. package/dist/esm/cli.js +0 -26
  101. package/dist/esm/cli.js.map +0 -1
  102. package/dist/esm/cmds/build/buildHandler.js +0 -36
  103. package/dist/esm/cmds/build/buildHandler.js.map +0 -1
  104. package/dist/esm/cmds/build/bundle.js +0 -81
  105. package/dist/esm/cmds/build/bundle.js.map +0 -1
  106. package/dist/esm/cmds/build/index.js +0 -17
  107. package/dist/esm/cmds/build/index.js.map +0 -1
  108. package/dist/esm/cmds/build/utils.js.map +0 -1
  109. package/dist/esm/cmds/eval/evalHandler.js +0 -20
  110. package/dist/esm/cmds/eval/evalHandler.js.map +0 -1
  111. package/dist/esm/cmds/eval/index.js +0 -16
  112. package/dist/esm/cmds/eval/index.js.map +0 -1
  113. package/dist/esm/cmds/index.js +0 -15
  114. package/dist/esm/cmds/index.js.map +0 -1
  115. package/dist/esm/cmds/manifest/index.js +0 -29
  116. package/dist/esm/cmds/manifest/index.js.map +0 -1
  117. package/dist/esm/cmds/manifest/manifestHandler.js +0 -43
  118. package/dist/esm/cmds/manifest/manifestHandler.js.map +0 -1
  119. package/dist/esm/cmds/serve/index.js +0 -16
  120. package/dist/esm/cmds/serve/index.js.map +0 -1
  121. package/dist/esm/cmds/serve/serveHandler.js +0 -54
  122. package/dist/esm/cmds/serve/serveHandler.js.map +0 -1
  123. package/dist/esm/cmds/serve/serveUtils.js +0 -30
  124. package/dist/esm/cmds/serve/serveUtils.js.map +0 -1
  125. package/dist/esm/cmds/watch/index.js +0 -17
  126. package/dist/esm/cmds/watch/index.js.map +0 -1
  127. package/dist/esm/cmds/watch/watchHandler.js +0 -87
  128. package/dist/esm/cmds/watch/watchHandler.js.map +0 -1
  129. package/dist/esm/index.js +0 -3
  130. package/dist/esm/index.js.map +0 -1
  131. package/dist/esm/main.js +0 -11
  132. package/dist/esm/main.js.map +0 -1
  133. package/dist/esm/utils/index.js +0 -4
  134. package/dist/esm/utils/index.js.map +0 -1
  135. package/dist/esm/utils/misc.js.map +0 -1
  136. package/dist/esm/utils/snap-config.js.map +0 -1
  137. package/dist/types/cmds/watch/index.d.ts +0 -9
  138. package/dist/types/index.d.ts +0 -1
  139. /package/dist/{types/builders.d.ts → builders.d.ts} +0 -0
  140. /package/dist/{types/cli.d.ts → cli.d.ts} +0 -0
  141. /package/dist/{types/cmds → cmds}/build/buildHandler.d.ts +0 -0
  142. /package/dist/{types/cmds → cmds}/build/bundle.d.ts +0 -0
  143. /package/dist/{types/cmds → cmds}/build/utils.d.ts +0 -0
  144. /package/dist/{types/cmds → cmds}/eval/evalHandler.d.ts +0 -0
  145. /package/dist/{types/cmds → cmds}/index.d.ts +0 -0
  146. /package/dist/{types/cmds → cmds}/manifest/manifestHandler.d.ts +0 -0
  147. /package/dist/{types/cmds → cmds}/serve/serveHandler.d.ts +0 -0
  148. /package/dist/{types/cmds → cmds}/serve/serveUtils.d.ts +0 -0
  149. /package/dist/{types/cmds → cmds}/watch/watchHandler.d.ts +0 -0
  150. /package/dist/{types/main.d.ts → main.d.ts} +0 -0
  151. /package/dist/{types/utils → utils}/index.d.ts +0 -0
  152. /package/dist/{types/utils → utils}/misc.d.ts +0 -0
  153. /package/dist/{types/utils → utils}/snap-config.d.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/cmds/build/utils.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAChD,2BAAoC;AAEpC,6CAAoD;AAEpD,uCAAyC;AAUzC;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,WAAW,EACX,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,OAAO,GACa;IACpB,IAAI,WAAW,EAAE;QACf,MAAM,IAAA,kBAAU,EAAC,cAAc,EAAE,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;KACpE;IAED,IAAI;QACF,MAAM,aAAE,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnD,IAAA,qBAAO,EAAC,mBAAmB,GAAG,iBAAiB,IAAI,IAAI,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAA,kBAAU,EAAC,cAAc,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;KAC9D;AACH,CAAC;AAlBD,0CAkBC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,IAAe;IACjD,MAAM,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C,IAAe;IACzD,IACE,IAAI,CAAC,eAAe;QACpB,IAAI,CAAC,iBAAiB,KAAK,6BAAkB,CAAC,YAAY,EAC1D;QACA,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;KACH;AACH,CAAC;AATD,kEASC","sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport { promises as fs } from 'fs';\n\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { writeError } from '../../utils';\n\ntype WriteBundleFileArgs = {\n bundleError: Error;\n bundleBuffer: Buffer;\n src: string;\n dest: string;\n resolve: (value: boolean) => void;\n};\n\n/**\n * Performs postprocessing on the bundle contents and writes them to disk.\n * Intended to be used in the callback passed to the Browserify `.bundle()`\n * call.\n *\n * @param options - Options bag.\n * @param options.bundleError - Any error received from Browserify.\n * @param options.bundleBuffer - The {@link Buffer} with the bundle contents\n * from Browserify.\n * @param options.src - The source file path.\n * @param options.dest - The destination file path.\n * @param options.resolve - A {@link Promise} resolution function, so that we\n * can use promises and `async`/`await` even though Browserify uses callbacks.\n */\nexport async function writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n}: WriteBundleFileArgs) {\n if (bundleError) {\n await writeError('Build error:', bundleError.message, bundleError);\n }\n\n try {\n await fs.writeFile(dest, bundleBuffer?.toString());\n logInfo(`Build success: '${src}' bundled as '${dest}'!`);\n resolve(true);\n } catch (error) {\n await writeError('Write error:', error.message, error, dest);\n }\n}\n\n/**\n * Processes dependencies and updates `argv` with an options object.\n *\n * @param argv - The Yargs arguments object.\n * @returns An object with options that can be passed to Babelify.\n */\nexport function processDependencies(argv: YargsArgs) {\n const { depsToTranspile, transpilationMode } = argv;\n const babelifyOptions: Record<string, any> = {};\n if (transpilationMode === TranspilationModes.LocalAndDeps) {\n const regexpStr = getDependencyRegExp(depsToTranspile as string[]);\n if (regexpStr !== null) {\n babelifyOptions.ignore = [regexpStr];\n }\n }\n return babelifyOptions;\n}\n\n/**\n * Processes a string of space delimited dependencies into one RegExp string.\n *\n * @param dependencies - An array of dependencies to add to the RegExp.\n * @returns A RegExp object.\n */\nexport function getDependencyRegExp(dependencies: string[]): RegExp | null {\n let regexp: string | null = null;\n if (!dependencies || dependencies.includes('.') || !dependencies.length) {\n return regexp;\n }\n const paths: string[] = sanitizeDependencyPaths(dependencies);\n regexp = `/node_modules/(?!${paths.shift() ?? ''}`;\n paths.forEach((path) => (regexp += `|${path}`));\n regexp += '/)';\n return RegExp(regexp, 'u');\n}\n\n/**\n * Helper function remove any leading and trailing slashes from dependency list.\n *\n * @param dependencies - An array of dependencies to sanitize.\n * @returns An array of sanitized paths.\n */\nexport function sanitizeDependencyPaths(dependencies: string[]): string[] {\n return dependencies.map((dependency) => {\n return dependency.replace(/^[/\\\\]+/u, '').replace(/[/\\\\]+$/u, '');\n });\n}\n\n/**\n * Check the Yargs argv object, to see if the provided options are valid. The\n * options are invalid if both `depsToTranspile` are provided, and\n * `transpilationMode` is not set to `localAndDeps`.\n *\n * @param argv - The Yargs arguments object.\n * @throws If the `depsToTranspile` is set, and `transpilationMode` is not set\n * to `localAndDeps`.\n */\nexport function processInvalidTranspilation(argv: YargsArgs) {\n if (\n argv.depsToTranspile &&\n argv.transpilationMode !== TranspilationModes.LocalAndDeps\n ) {\n throw new Error(\n '\"depsToTranspile\" can only be specified if \"transpilationMode\" is set to \"localAndDeps\" .',\n );\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evalHandler = void 0;
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
5
+ const utils_1 = require("@metamask/utils");
6
+ /**
7
+ * Runs the snap in a worker, to ensure SES compatibility.
8
+ *
9
+ * @param argv - The Yargs arguments object.
10
+ * @returns A promise that resolves once the eval has finished.
11
+ * @throws If the eval failed.
12
+ */
13
+ async function evalHandler(argv) {
14
+ const { bundle: bundlePath } = argv;
15
+ (0, utils_1.assert)(typeof bundlePath === 'string');
16
+ try {
17
+ await (0, snaps_utils_1.evalBundle)(bundlePath);
18
+ (0, snaps_utils_1.logInfo)(`Eval Success: evaluated '${bundlePath}' in SES!`);
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Snap evaluation error: ${error.message}`);
22
+ }
23
+ }
24
+ exports.evalHandler = evalHandler;
25
+ //# sourceMappingURL=evalHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,uDAA4D;AAC5D,2CAAyC;AAIzC;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEpC,IAAA,cAAM,EAAC,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC;IAEvC,IAAI;QACF,MAAM,IAAA,wBAAU,EAAC,UAAU,CAAC,CAAC;QAC7B,IAAA,qBAAO,EAAC,4BAA4B,UAAU,WAAW,CAAC,CAAC;KAC5D;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5D;AACH,CAAC;AAXD,kCAWC","sourcesContent":["import { evalBundle, logInfo } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\n/**\n * Runs the snap in a worker, to ensure SES compatibility.\n *\n * @param argv - The Yargs arguments object.\n * @returns A promise that resolves once the eval has finished.\n * @throws If the eval failed.\n */\nexport async function evalHandler(argv: YargsArgs): Promise<void> {\n const { bundle: bundlePath } = argv;\n\n assert(typeof bundlePath === 'string');\n\n try {\n await evalBundle(bundlePath);\n logInfo(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const command: {
3
+ declare const _default: {
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 command;
9
+ export = _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const builders_1 = __importDefault(require("../../builders"));
6
+ const evalHandler_1 = require("./evalHandler");
7
+ module.exports = {
8
+ command: ['eval', 'e'],
9
+ desc: 'Attempt to evaluate Snap bundle in SES',
10
+ builder: (yarg) => {
11
+ yarg.option('bundle', builders_1.default.bundle);
12
+ },
13
+ handler: async (argv) => (0, evalHandler_1.evalHandler)(argv),
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/eval/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,+CAA4C;AAE5C,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,wCAAwC;IAC9C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,kBAAQ,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAA,yBAAW,EAAC,IAAI,CAAC;CACtD,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { evalHandler } from './evalHandler';\n\nexport = {\n command: ['eval', 'e'],\n desc: 'Attempt to evaluate Snap bundle in SES',\n builder: (yarg: yargs.Argv) => {\n yarg.option('bundle', builders.bundle);\n },\n handler: async (argv: YargsArgs) => evalHandler(argv),\n};\n"]}
@@ -0,0 +1,14 @@
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
+ const build_1 = __importDefault(require("./build"));
7
+ const eval_1 = __importDefault(require("./eval"));
8
+ const init_1 = __importDefault(require("./init"));
9
+ const manifest_1 = __importDefault(require("./manifest"));
10
+ const serve_1 = __importDefault(require("./serve"));
11
+ const watch_1 = __importDefault(require("./watch"));
12
+ const commands = [build_1.default, eval_1.default, init_1.default, manifest_1.default, serve_1.default, watch_1.default];
13
+ exports.default = commands;
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmds/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,kDAA8B;AAC9B,kDAA0B;AAC1B,0DAAkC;AAClC,oDAA4B;AAC5B,oDAA4B;AAE5B,MAAM,QAAQ,GAAG,CAAC,eAAK,EAAE,cAAQ,EAAE,cAAI,EAAE,kBAAQ,EAAE,eAAK,EAAE,eAAK,CAAC,CAAC;AACjE,kBAAe,QAAQ,CAAC","sourcesContent":["import build from './build';\nimport evaluate from './eval';\nimport init from './init';\nimport manifest from './manifest';\nimport serve from './serve';\nimport watch from './watch';\n\nconst commands = [build, evaluate, init, manifest, serve, watch];\nexport default commands;\n"]}
@@ -1,9 +1,9 @@
1
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const command: {
3
+ declare const _default: {
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 command;
9
+ export = _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const snaps_utils_1 = require("@metamask/snaps-utils");
6
+ const builders_1 = __importDefault(require("../../builders"));
7
+ const buildHandler_1 = require("../build/buildHandler");
8
+ const initHandler_1 = require("./initHandler");
9
+ /**
10
+ * The main entrypoint for the init command. This calls the init handler to
11
+ * initialize the snap package, builds the snap, and then updates the manifest
12
+ * with the shasum of the built snap.
13
+ *
14
+ * @param argv - The Yargs arguments object.
15
+ */
16
+ async function init(argv) {
17
+ const newArgs = await (0, initHandler_1.initHandler)(argv);
18
+ process.chdir(newArgs.snapLocation);
19
+ await (0, buildHandler_1.build)({
20
+ ...newArgs,
21
+ manifest: false,
22
+ eval: true,
23
+ });
24
+ (0, snaps_utils_1.logInfo)('\nSnap project successfully initiated!');
25
+ }
26
+ module.exports = {
27
+ command: ['init [directory]', 'i [directory]'],
28
+ desc: 'Initialize Snap package',
29
+ builder: (yarg) => {
30
+ yarg.positional('directory', builders_1.default.directory);
31
+ },
32
+ handler: async (argv) => init(argv),
33
+ };
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAgD;AAGhD,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAW5C;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC;IAExC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEpC,MAAM,IAAA,oBAAK,EAAC;QACV,GAAG,OAAO;QACV,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,IAAI;KACX,CAAC,CAAC;IAEH,IAAA,qBAAO,EAAC,wCAAwC,CAAC,CAAC;AACpD,CAAC;AA5BD,iBAAS;IACP,OAAO,EAAE,CAAC,kBAAkB,EAAE,eAAe,CAAC;IAC9C,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,kBAAQ,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CAC/C,CAAC","sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler } from './initHandler';\n\nexport = {\n command: ['init [directory]', 'i [directory]'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg.positional('directory', builders.directory);\n },\n handler: async (argv: YargsArgs) => init(argv),\n};\n\n/**\n * The main entrypoint for the init command. This calls the init handler to\n * initialize the snap package, builds the snap, and then updates the manifest\n * with the shasum of the built snap.\n *\n * @param argv - The Yargs arguments object.\n */\nasync function init(argv: YargsArgs): Promise<void> {\n const newArgs = await initHandler(argv);\n\n process.chdir(newArgs.snapLocation);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n logInfo('\\nSnap project successfully initiated!');\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { YargsArgs } from '../../types/yargs';
2
+ /**
3
+ * Creates a new snap package, based on one of the provided templates. This
4
+ * creates all the necessary files, like `package.json`, `snap.config.js`, etc.
5
+ * to start developing a snap.
6
+ *
7
+ * @param argv - The Yargs arguments object.
8
+ * @returns The Yargs arguments augmented with the new `dist`, `outfileName` and
9
+ * `src` properties.
10
+ * @throws If initialization of the snap package failed.
11
+ */
12
+ export declare function initHandler(argv: YargsArgs): Promise<{
13
+ dist: string;
14
+ outfileName: string;
15
+ src: string;
16
+ snapLocation: string;
17
+ sourceMaps: boolean;
18
+ stripComments: boolean;
19
+ transformHtmlComments: boolean;
20
+ port: number;
21
+ eval: boolean;
22
+ serve: boolean;
23
+ directory?: string | undefined;
24
+ _?: (string | number)[] | undefined;
25
+ $0?: string | undefined;
26
+ }>;
@@ -0,0 +1,69 @@
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.initHandler = 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
+ const initUtils_1 = require("./initUtils");
12
+ const SATISFIED_VERSION = '>=16';
13
+ /**
14
+ * Creates a new snap package, based on one of the provided templates. This
15
+ * creates all the necessary files, like `package.json`, `snap.config.js`, etc.
16
+ * to start developing a snap.
17
+ *
18
+ * @param argv - The Yargs arguments object.
19
+ * @returns The Yargs arguments augmented with the new `dist`, `outfileName` and
20
+ * `src` properties.
21
+ * @throws If initialization of the snap package failed.
22
+ */
23
+ async function initHandler(argv) {
24
+ const { directory } = argv;
25
+ const isVersionSupported = (0, utils_1.satisfiesVersionRange)(process.version, SATISFIED_VERSION);
26
+ if (!isVersionSupported) {
27
+ throw new Error(`Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`);
28
+ }
29
+ const gitExists = (0, initUtils_1.isGitInstalled)();
30
+ if (!gitExists) {
31
+ throw new Error(`Init Error: git is not installed. Please install git to continue.`);
32
+ }
33
+ const directoryToUse = directory
34
+ ? path_1.default.resolve(process.cwd(), directory)
35
+ : process.cwd();
36
+ (0, snaps_utils_1.logInfo)(`Preparing ${directoryToUse}...`);
37
+ await (0, initUtils_1.prepareWorkingDirectory)(directoryToUse);
38
+ try {
39
+ (0, snaps_utils_1.logInfo)(`Cloning template...`);
40
+ (0, initUtils_1.cloneTemplate)(directoryToUse);
41
+ await fs_1.promises.rm(path_1.default.join(directoryToUse, '.git'), {
42
+ force: true,
43
+ recursive: true,
44
+ });
45
+ }
46
+ catch (error) {
47
+ throw new Error('Init Error: Failed to create template.');
48
+ }
49
+ (0, snaps_utils_1.logInfo)('Installing dependencies...');
50
+ (0, initUtils_1.yarnInstall)(directoryToUse);
51
+ if (!(0, initUtils_1.isInGitRepository)(directoryToUse)) {
52
+ (0, snaps_utils_1.logInfo)('Initializing git repository...');
53
+ (0, initUtils_1.gitInit)(directoryToUse);
54
+ }
55
+ const snapLocation = path_1.default.join(directoryToUse, initUtils_1.SNAP_LOCATION);
56
+ const manifest = (await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.Manifest))).result;
57
+ const validatedManifest = (0, snaps_utils_1.createSnapManifest)(manifest);
58
+ const packageJson = (await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.PackageJson))).result;
59
+ const distPath = validatedManifest.source.location.npm.filePath.split('/');
60
+ return {
61
+ ...argv,
62
+ dist: distPath[0],
63
+ outfileName: distPath[1],
64
+ src: packageJson.main || 'src/index.js',
65
+ snapLocation,
66
+ };
67
+ }
68
+ exports.initHandler = initHandler;
69
+ //# sourceMappingURL=initHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,uDAM+B;AAC/B,2CAIyB;AACzB,2BAAoC;AACpC,gDAA6B;AAG7B,2CAQqB;AAErB,MAAM,iBAAiB,GAAG,MAAqB,CAAC;AAEhD;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE3B,MAAM,kBAAkB,GAAG,IAAA,6BAAqB,EAC9C,OAAO,CAAC,OAAwB,EAChC,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CACb,0DAA0D,OAAO,CAAC,OAAO,4BAA4B,iBAAiB,GAAG,CA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C;IAET,MAAM,iBAAiB,GAAG,IAAA,gCAAkB,EAAC,QAAQ,CAAC,CAAC;IAEvD,MAAM,WAAW,GAAG,CAClB,MAAM,IAAA,0BAAY,EAChB,cAAS,CAAC,IAAI,CAAC,YAAY,EAAE,8BAAgB,CAAC,WAAW,CAAC,CAC3D,CACF,CAAC,MAA4B,CAAC;IAE/B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE3E,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;QACjB,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;QACxB,GAAG,EAAE,WAAW,CAAC,IAAI,IAAI,cAAc;QACvC,YAAY;KACb,CAAC;AACJ,CAAC;AAxED,kCAwEC","sourcesContent":["import {\n NpmSnapFileNames,\n readJsonFile,\n NpmSnapPackageJson,\n createSnapManifest,\n logInfo,\n} from '@metamask/snaps-utils';\nimport {\n satisfiesVersionRange,\n SemVerRange,\n SemVerVersion,\n} from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { YargsArgs } from '../../types/yargs';\nimport {\n cloneTemplate,\n gitInit,\n isGitInstalled,\n isInGitRepository,\n prepareWorkingDirectory,\n SNAP_LOCATION,\n yarnInstall,\n} from './initUtils';\n\nconst SATISFIED_VERSION = '>=16' as SemVerRange;\n\n/**\n * Creates a new snap package, based on one of the provided templates. This\n * creates all the necessary files, like `package.json`, `snap.config.js`, etc.\n * to start developing a snap.\n *\n * @param argv - The Yargs arguments object.\n * @returns The Yargs arguments augmented with the new `dist`, `outfileName` and\n * `src` properties.\n * @throws If initialization of the snap package failed.\n */\nexport async function initHandler(argv: YargsArgs) {\n const { directory } = argv;\n\n const isVersionSupported = satisfiesVersionRange(\n process.version as SemVerVersion,\n SATISFIED_VERSION,\n );\n\n if (!isVersionSupported) {\n throw new Error(\n `Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`,\n );\n }\n\n const gitExists = isGitInstalled();\n if (!gitExists) {\n throw new Error(\n `Init Error: git is not installed. Please install git to continue.`,\n );\n }\n\n const directoryToUse = directory\n ? pathUtils.resolve(process.cwd(), directory)\n : process.cwd();\n\n logInfo(`Preparing ${directoryToUse}...`);\n\n await prepareWorkingDirectory(directoryToUse);\n\n try {\n logInfo(`Cloning template...`);\n cloneTemplate(directoryToUse);\n\n await fs.rm(pathUtils.join(directoryToUse, '.git'), {\n force: true,\n recursive: true,\n });\n } catch (error) {\n throw new Error('Init Error: Failed to create template.');\n }\n\n logInfo('Installing dependencies...');\n yarnInstall(directoryToUse);\n\n if (!isInGitRepository(directoryToUse)) {\n logInfo('Initializing git repository...');\n gitInit(directoryToUse);\n }\n\n const snapLocation = pathUtils.join(directoryToUse, SNAP_LOCATION);\n\n const manifest = (\n await readJsonFile(pathUtils.join(snapLocation, NpmSnapFileNames.Manifest))\n ).result;\n\n const validatedManifest = createSnapManifest(manifest);\n\n const packageJson = (\n await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.PackageJson),\n )\n ).result as NpmSnapPackageJson;\n\n const distPath = validatedManifest.source.location.npm.filePath.split('/');\n\n return {\n ...argv,\n dist: distPath[0],\n outfileName: distPath[1],\n src: packageJson.main || 'src/index.js',\n snapLocation,\n };\n}\n"]}
@@ -0,0 +1,39 @@
1
+ export declare const TEMPLATE_GIT_URL = "https://github.com/MetaMask/template-snap-monorepo.git";
2
+ export declare const SNAP_LOCATION = "packages/snap/";
3
+ /**
4
+ * Checks if the destination folder exists and if it's empty. Otherwise create it.
5
+ *
6
+ * @param directory - The desination folder.
7
+ */
8
+ export declare function prepareWorkingDirectory(directory: string): Promise<void>;
9
+ /**
10
+ * Clones the template in a directory.
11
+ *
12
+ * @param directory - The directory to clone the template in.
13
+ */
14
+ export declare function cloneTemplate(directory: string): void;
15
+ /**
16
+ * Check if git is installed.
17
+ *
18
+ * @returns True if git is installed, or false otherwise.
19
+ */
20
+ export declare function isGitInstalled(): boolean;
21
+ /**
22
+ * Check if the actual working dir is a git repository.
23
+ *
24
+ * @param directory - The directory to check.
25
+ * @returns True if it's a git repository otherwise false.
26
+ */
27
+ export declare function isInGitRepository(directory: string): boolean;
28
+ /**
29
+ * Init a git repository.
30
+ *
31
+ * @param directory - The directory to init.
32
+ */
33
+ export declare function gitInit(directory: string): void;
34
+ /**
35
+ * Install dependencies in a yarn project.
36
+ *
37
+ * @param directory - The directory containing the project.
38
+ */
39
+ export declare function yarnInstall(directory: string): void;
@@ -0,0 +1,122 @@
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.yarnInstall = exports.gitInit = exports.isInGitRepository = exports.isGitInstalled = exports.cloneTemplate = exports.prepareWorkingDirectory = exports.SNAP_LOCATION = exports.TEMPLATE_GIT_URL = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const fs_1 = require("fs");
9
+ const path_1 = __importDefault(require("path"));
10
+ exports.TEMPLATE_GIT_URL = 'https://github.com/MetaMask/template-snap-monorepo.git';
11
+ exports.SNAP_LOCATION = 'packages/snap/';
12
+ /**
13
+ * Checks if the destination folder exists and if it's empty. Otherwise create it.
14
+ *
15
+ * @param directory - The desination folder.
16
+ */
17
+ async function prepareWorkingDirectory(directory) {
18
+ try {
19
+ const isCurrentDirectory = directory === process.cwd();
20
+ if (!isCurrentDirectory) {
21
+ try {
22
+ await fs_1.promises.mkdir(directory, { recursive: true });
23
+ }
24
+ catch (error) {
25
+ throw new Error('Init Error: Failed to create new directory.');
26
+ }
27
+ }
28
+ const existingFiles = await fs_1.promises.readdir(directory);
29
+ if (existingFiles.length > 0) {
30
+ throw new Error(`Directory ${directory} not empty.`);
31
+ }
32
+ }
33
+ catch (error) {
34
+ throw new Error(`Init Error: Failed to prepare working directory with message: ${error.message}`);
35
+ }
36
+ }
37
+ exports.prepareWorkingDirectory = prepareWorkingDirectory;
38
+ /**
39
+ * Clones the template in a directory.
40
+ *
41
+ * @param directory - The directory to clone the template in.
42
+ */
43
+ function cloneTemplate(directory) {
44
+ try {
45
+ (0, child_process_1.execSync)(`git clone --depth=1 ${exports.TEMPLATE_GIT_URL} ${directory}`, {
46
+ stdio: [2],
47
+ });
48
+ }
49
+ catch (error) {
50
+ throw new Error('Init Error: Failed to clone the template.');
51
+ }
52
+ }
53
+ exports.cloneTemplate = cloneTemplate;
54
+ /**
55
+ * Check if git is installed.
56
+ *
57
+ * @returns True if git is installed, or false otherwise.
58
+ */
59
+ function isGitInstalled() {
60
+ try {
61
+ (0, child_process_1.execSync)('git --version', { stdio: 'ignore' });
62
+ return true;
63
+ }
64
+ catch (error) {
65
+ return false;
66
+ }
67
+ }
68
+ exports.isGitInstalled = isGitInstalled;
69
+ /**
70
+ * Check if the actual working dir is a git repository.
71
+ *
72
+ * @param directory - The directory to check.
73
+ * @returns True if it's a git repository otherwise false.
74
+ */
75
+ function isInGitRepository(directory) {
76
+ try {
77
+ (0, child_process_1.execSync)('git rev-parse --is-inside-work-tree', {
78
+ stdio: 'ignore',
79
+ cwd: path_1.default.resolve(__dirname, directory),
80
+ });
81
+ return true;
82
+ }
83
+ catch (error) {
84
+ return false;
85
+ }
86
+ }
87
+ exports.isInGitRepository = isInGitRepository;
88
+ /**
89
+ * Init a git repository.
90
+ *
91
+ * @param directory - The directory to init.
92
+ */
93
+ function gitInit(directory) {
94
+ try {
95
+ (0, child_process_1.execSync)('git init', {
96
+ stdio: 'ignore',
97
+ cwd: path_1.default.resolve(__dirname, directory),
98
+ });
99
+ }
100
+ catch (error) {
101
+ throw new Error('Init Error: Failed to init a new git repository.');
102
+ }
103
+ }
104
+ exports.gitInit = gitInit;
105
+ /**
106
+ * Install dependencies in a yarn project.
107
+ *
108
+ * @param directory - The directory containing the project.
109
+ */
110
+ function yarnInstall(directory) {
111
+ try {
112
+ (0, child_process_1.execSync)('yarn install', {
113
+ stdio: [0, 1, 2],
114
+ cwd: directory,
115
+ });
116
+ }
117
+ catch (error) {
118
+ throw new Error('Init Error: Failed to install dependencies.');
119
+ }
120
+ }
121
+ exports.yarnInstall = yarnInstall;
122
+ //# sourceMappingURL=initUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initUtils.js","sourceRoot":"","sources":["../../../src/cmds/init/initUtils.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAyC;AACzC,2BAAoC;AACpC,gDAA6B;AAEhB,QAAA,gBAAgB,GAC3B,wDAAwD,CAAC;AAE9C,QAAA,aAAa,GAAG,gBAAgB,CAAC;AAE9C;;;;GAIG;AACI,KAAK,UAAU,uBAAuB,CAC3C,SAAiB;IAEjB,IAAI;QACF,MAAM,kBAAkB,GAAG,SAAS,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC;QAEvD,IAAI,CAAC,kBAAkB,EAAE;YACvB,IAAI;gBACF,MAAM,aAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;aAChD;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;aAChE;SACF;QAED,MAAM,aAAa,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,aAAa,SAAS,aAAa,CAAC,CAAC;SACtD;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CACb,iEAAiE,KAAK,CAAC,OAAO,EAAE,CACjF,CAAC;KACH;AACH,CAAC;AAxBD,0DAwBC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,SAAiB;IAC7C,IAAI;QACF,IAAA,wBAAQ,EAAC,uBAAuB,wBAAgB,IA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AC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAChE;AACH,CAAC;AATD,kCASC","sourcesContent":["import { execSync } from 'child_process';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nexport const TEMPLATE_GIT_URL =\n 'https://github.com/MetaMask/template-snap-monorepo.git';\n\nexport const SNAP_LOCATION = 'packages/snap/';\n\n/**\n * Checks if the destination folder exists and if it's empty. Otherwise create it.\n *\n * @param directory - The desination folder.\n */\nexport async function prepareWorkingDirectory(\n directory: string,\n): Promise<void> {\n try {\n const isCurrentDirectory = directory === process.cwd();\n\n if (!isCurrentDirectory) {\n try {\n await fs.mkdir(directory, { recursive: true });\n } catch (error) {\n throw new Error('Init Error: Failed to create new directory.');\n }\n }\n\n const existingFiles = await fs.readdir(directory);\n\n if (existingFiles.length > 0) {\n throw new Error(`Directory ${directory} not empty.`);\n }\n } catch (error) {\n throw new Error(\n `Init Error: Failed to prepare working directory with message: ${error.message}`,\n );\n }\n}\n\n/**\n * Clones the template in a directory.\n *\n * @param directory - The directory to clone the template in.\n */\nexport function cloneTemplate(directory: string) {\n try {\n execSync(`git clone --depth=1 ${TEMPLATE_GIT_URL} ${directory}`, {\n stdio: [2],\n });\n } catch (error) {\n throw new Error('Init Error: Failed to clone the template.');\n }\n}\n\n/**\n * Check if git is installed.\n *\n * @returns True if git is installed, or false otherwise.\n */\nexport function isGitInstalled() {\n try {\n execSync('git --version', { stdio: 'ignore' });\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Check if the actual working dir is a git repository.\n *\n * @param directory - The directory to check.\n * @returns True if it's a git repository otherwise false.\n */\nexport function isInGitRepository(directory: string) {\n try {\n execSync('git rev-parse --is-inside-work-tree', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Init a git repository.\n *\n * @param directory - The directory to init.\n */\nexport function gitInit(directory: string) {\n try {\n execSync('git init', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n } catch (error) {\n throw new Error('Init Error: Failed to init a new git repository.');\n }\n}\n\n/**\n * Install dependencies in a yarn project.\n *\n * @param directory - The directory containing the project.\n */\nexport function yarnInstall(directory: string) {\n try {\n execSync('yarn install', {\n stdio: [0, 1, 2],\n cwd: directory,\n });\n } catch (error) {\n throw new Error('Init Error: Failed to install dependencies.');\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import yargs from 'yargs';
2
2
  import { YargsArgs } from '../../types/yargs';
3
- declare const command: {
3
+ declare const _default: {
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 command;
9
+ export = _default;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const builders_1 = __importDefault(require("../../builders"));
6
+ const utils_1 = require("../../utils");
7
+ const manifestHandler_1 = require("./manifestHandler");
8
+ module.exports = {
9
+ command: ['manifest', 'm'],
10
+ desc: 'Validate the snap.manifest.json file',
11
+ builder: (yarg) => {
12
+ yarg.option('writeManifest', { ...builders_1.default.writeManifest, alias: ['fix'] });
13
+ },
14
+ handler: async (argv) => {
15
+ try {
16
+ await (0, manifestHandler_1.manifestHandler)(argv);
17
+ }
18
+ catch (error) {
19
+ (0, utils_1.logError)(error.message, error);
20
+ throw error;
21
+ }
22
+ },
23
+ };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/manifest/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,uCAAuC;AACvC,uDAAoD;AAEpD,iBAAS;IACP,OAAO,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC;IAC1B,IAAI,EAAE,sCAAsC;IAC5C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,GAAG,kBAAQ,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE;QACjC,IAAI;YACF,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;SAC7B;QAAC,OAAO,KAAK,EAAE;YACd,IAAA,gBAAQ,EAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\nimport { manifestHandler } from './manifestHandler';\n\nexport = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n yarg.option('writeManifest', { ...builders.writeManifest, alias: ['fix'] });\n },\n handler: async (argv: YargsArgs) => {\n try {\n await manifestHandler(argv);\n } catch (error) {\n logError(error.message, error);\n throw error;\n }\n },\n};\n"]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.manifestHandler = void 0;
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
5
+ const ERROR_PREFIX = 'Manifest Error: ';
6
+ /**
7
+ * Validates a snap.manifest.json file. Attempts to fix the manifest and write
8
+ * the fixed version to disk if `writeManifest` is true. Throws if validation
9
+ * fails.
10
+ *
11
+ * @param argv - The Yargs `argv` object.
12
+ * @param argv.writeManifest - Whether to write the fixed manifest to disk.
13
+ */
14
+ async function manifestHandler({ writeManifest }) {
15
+ try {
16
+ const { warnings, errors } = await (0, snaps_utils_1.checkManifest)(process.cwd(), Boolean(writeManifest));
17
+ if (!writeManifest && errors.length > 0) {
18
+ (0, snaps_utils_1.logError)(`${ERROR_PREFIX}The manifest is invalid.`);
19
+ errors.forEach(logManifestError);
20
+ process.exit(1);
21
+ }
22
+ if (warnings.length > 0) {
23
+ (0, snaps_utils_1.logWarning)('Manifest Warning: Validation of snap.manifest.json completed with warnings.');
24
+ warnings.forEach(logManifestWarning);
25
+ }
26
+ }
27
+ catch (error) {
28
+ throw new Error(`${ERROR_PREFIX}${error}`);
29
+ }
30
+ }
31
+ exports.manifestHandler = manifestHandler;
32
+ /**
33
+ * Logs a manifest warning, if `suppressWarnings` is not enabled.
34
+ *
35
+ * @param message - The message to log.
36
+ */
37
+ function logManifestWarning(message) {
38
+ if (!global.snaps.suppressWarnings) {
39
+ (0, snaps_utils_1.logWarning)(`Manifest Warning: ${message}`);
40
+ }
41
+ }
42
+ /**
43
+ * Logs a manifest error.
44
+ *
45
+ * @param message - The message to log.
46
+ */
47
+ function logManifestError(message) {
48
+ (0, snaps_utils_1.logError)(`${ERROR_PREFIX}${message}`);
49
+ }
50
+ //# sourceMappingURL=manifestHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../../src/cmds/manifest/manifestHandler.ts"],"names":[],"mappings":";;;AAAA,uDAA4E;AAI5E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CAAC,EAAE,aAAa,EAAa;IAChE,IAAI;QACF,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,2BAAa,EAC9C,OAAO,CAAC,GAAG,EAAE,EACb,OAAO,CAAC,aAAa,CAAC,CACvB,CAAC;QAEF,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,IAAA,sBAAQ,EAAC,GAAG,YAAY,0BAA0B,CAAC,CAAC;YACpD,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;YAEjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,IAAA,wBAAU,EACR,6EAA6E,CAC9E,CAAC;YACF,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;SACtC;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,GAAG,KAAK,EAAE,CAAC,CAAC;KAC5C;AACH,CAAC;AAvBD,0CAuBC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,OAAe;IACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE;QAClC,IAAA,wBAAU,EAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;KAC5C;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,OAAe;IACvC,IAAA,sBAAQ,EAAC,GAAG,YAAY,GAAG,OAAO,EAAE,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { checkManifest, logError, logWarning } from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\n\nconst ERROR_PREFIX = 'Manifest Error: ';\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param argv - The Yargs `argv` object.\n * @param argv.writeManifest - Whether to write the fixed manifest to disk.\n */\nexport async function manifestHandler({ writeManifest }: YargsArgs) {\n try {\n const { warnings, errors } = await checkManifest(\n process.cwd(),\n Boolean(writeManifest),\n );\n\n if (!writeManifest && errors.length > 0) {\n logError(`${ERROR_PREFIX}The manifest is invalid.`);\n errors.forEach(logManifestError);\n\n process.exit(1);\n }\n\n if (warnings.length > 0) {\n logWarning(\n 'Manifest Warning: Validation of snap.manifest.json completed with warnings.',\n );\n warnings.forEach(logManifestWarning);\n }\n } catch (error) {\n throw new Error(`${ERROR_PREFIX}${error}`);\n }\n}\n\n/**\n * Logs a manifest warning, if `suppressWarnings` is not enabled.\n *\n * @param message - The message to log.\n */\nfunction logManifestWarning(message: string) {\n if (!global.snaps.suppressWarnings) {\n logWarning(`Manifest Warning: ${message}`);\n }\n}\n\n/**\n * Logs a manifest error.\n *\n * @param message - The message to log.\n */\nfunction logManifestError(message: string) {\n logError(`${ERROR_PREFIX}${message}`);\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import yargs from 'yargs';
2
+ import { YargsArgs } from '../../types/yargs';
3
+ declare const _default: {
4
+ command: string[];
5
+ desc: string;
6
+ builder: (yarg: yargs.Argv) => void;
7
+ handler: (argv: YargsArgs) => Promise<void>;
8
+ };
9
+ export = _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const builders_1 = __importDefault(require("../../builders"));
6
+ const serveHandler_1 = require("./serveHandler");
7
+ module.exports = {
8
+ command: ['serve', 's'],
9
+ desc: 'Locally serve Snap file(s) for testing',
10
+ builder: (yarg) => {
11
+ yarg.option('root', builders_1.default.root).option('port', builders_1.default.port);
12
+ },
13
+ handler: async (argv) => (0, serveHandler_1.serve)(argv),
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/serve/index.ts"],"names":[],"mappings":";;;;AAEA,8DAAsC;AAEtC,iDAAuC;AAEvC,iBAAS;IACP,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC;IACvB,IAAI,EAAE,wCAAwC;IAC9C,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAK,EAAC,IAAI,CAAC;CAChD,CAAC","sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { serve } from './serveHandler';\n\nexport = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) => serve(argv),\n};\n"]}
@@ -0,0 +1,59 @@
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.serve = void 0;
7
+ const snaps_utils_1 = require("@metamask/snaps-utils");
8
+ const http_1 = __importDefault(require("http"));
9
+ const serve_handler_1 = __importDefault(require("serve-handler"));
10
+ const serveUtils_1 = require("./serveUtils");
11
+ /**
12
+ * Starts a local, static HTTP server on the given port with the given root
13
+ * directory.
14
+ *
15
+ * @param argv - Arguments as an object generated by Yargs.
16
+ * @param argv.root - The root directory path string.
17
+ * @param argv.port - The server port.
18
+ */
19
+ async function serve(argv) {
20
+ const { port, root: rootDir } = argv;
21
+ await (0, snaps_utils_1.validateDirPath)(rootDir, true);
22
+ (0, snaps_utils_1.logInfo)(`\nStarting server...`);
23
+ const server = http_1.default.createServer((req, res) => {
24
+ (0, serve_handler_1.default)(req, res, {
25
+ public: rootDir,
26
+ headers: [
27
+ {
28
+ source: '**/*',
29
+ headers: [
30
+ {
31
+ key: 'Cache-Control',
32
+ value: 'no-cache',
33
+ },
34
+ {
35
+ key: 'Access-Control-Allow-Origin',
36
+ value: '*',
37
+ },
38
+ ],
39
+ },
40
+ ],
41
+ })?.catch((error) => {
42
+ (0, serveUtils_1.logServerError)(error, argv.port);
43
+ res.statusCode = 500;
44
+ res.end();
45
+ });
46
+ });
47
+ server.listen({ port }, () => (0, serveUtils_1.logServerListening)(port));
48
+ server.on('request', (request) => (0, serveUtils_1.logRequest)(request));
49
+ server.on('error', (error) => {
50
+ (0, serveUtils_1.logServerError)(error, argv.port);
51
+ process.exitCode = 1;
52
+ });
53
+ server.on('close', () => {
54
+ (0, snaps_utils_1.logInfo)('Server closed');
55
+ process.exitCode = 1;
56
+ });
57
+ }
58
+ exports.serve = serve;
59
+ //# sourceMappingURL=serveHandler.js.map