@metamask/snaps-cli 0.22.3 → 0.24.0

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 (40) hide show
  1. package/README.md +6 -6
  2. package/dist/builders.d.ts +2 -6
  3. package/dist/builders.js +3 -12
  4. package/dist/builders.js.map +1 -1
  5. package/dist/cmds/build/buildHandler.js +5 -5
  6. package/dist/cmds/build/buildHandler.js.map +1 -1
  7. package/dist/cmds/eval/evalHandler.js +3 -5
  8. package/dist/cmds/eval/evalHandler.js.map +1 -1
  9. package/dist/cmds/init/index.js +3 -13
  10. package/dist/cmds/init/index.js.map +1 -1
  11. package/dist/cmds/init/initHandler.d.ts +5 -9
  12. package/dist/cmds/init/initHandler.js +37 -96
  13. package/dist/cmds/init/initHandler.js.map +1 -1
  14. package/dist/cmds/init/initUtils.d.ts +25 -32
  15. package/dist/cmds/init/initUtils.js +80 -250
  16. package/dist/cmds/init/initUtils.js.map +1 -1
  17. package/dist/cmds/manifest/manifestHandler.js +2 -2
  18. package/dist/cmds/manifest/manifestHandler.js.map +1 -1
  19. package/dist/cmds/serve/serveHandler.js +2 -2
  20. package/dist/cmds/serve/serveHandler.js.map +1 -1
  21. package/dist/cmds/watch/watchHandler.js +5 -5
  22. package/dist/cmds/watch/watchHandler.js.map +1 -1
  23. package/dist/utils/index.d.ts +0 -1
  24. package/dist/utils/index.js +0 -1
  25. package/dist/utils/index.js.map +1 -1
  26. package/dist/utils/misc.d.ts +1 -1
  27. package/dist/utils/misc.js +6 -1
  28. package/dist/utils/misc.js.map +1 -1
  29. package/dist/utils/snap-config.d.ts +21 -4
  30. package/dist/utils/snap-config.js +20 -3
  31. package/dist/utils/snap-config.js.map +1 -1
  32. package/package.json +13 -19
  33. package/dist/cmds/init/init-template.json +0 -8
  34. package/dist/tsconfig.json +0 -8
  35. package/dist/utils/readline.d.ts +0 -37
  36. package/dist/utils/readline.js +0 -75
  37. package/dist/utils/readline.js.map +0 -1
  38. package/dist/utils/snap-config.__GENERATED__.d.ts +0 -2
  39. package/dist/utils/snap-config.__GENERATED__.js +0 -18
  40. package/dist/utils/snap-config.__GENERATED__.js.map +0 -1
package/README.md CHANGED
@@ -18,12 +18,12 @@ Install a dev dependency in your snap project or globally using `yarn` or `npm`:
18
18
  Usage: mm-snap <command> [options]
19
19
 
20
20
  Commands:
21
- mm-snap build Build Snap from source [aliases: b]
22
- mm-snap eval Attempt to evaluate Snap bundle in SES [aliases: e]
23
- mm-snap init Initialize Snap package [aliases: i]
24
- mm-snap manifest Validate the snap.manifest.json file [aliases: m]
25
- mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
26
- mm-snap watch Build Snap on change [aliases: w]
21
+ mm-snap build Build Snap from source [aliases: b]
22
+ mm-snap eval Attempt to evaluate Snap bundle in SES [aliases: e]
23
+ mm-snap init [directory] Initialize Snap package [aliases: i]
24
+ mm-snap manifest Validate the snap.manifest.json file [aliases: m]
25
+ mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
26
+ mm-snap watch Build Snap on change [aliases: w]
27
27
 
28
28
  Options:
29
29
  --version Show version number [boolean]
@@ -1,4 +1,4 @@
1
- import { Options } from 'yargs';
1
+ import { Options, PositionalOptions } from 'yargs';
2
2
  export declare type SnapsCliBuilders = {
3
3
  readonly bundle: Readonly<Options>;
4
4
  readonly dist: Readonly<Options>;
@@ -16,16 +16,12 @@ export declare type SnapsCliBuilders = {
16
16
  readonly verboseErrors: Readonly<Options>;
17
17
  readonly writeManifest: Readonly<Options>;
18
18
  readonly serve: Readonly<Options>;
19
- readonly template: Readonly<Options>;
19
+ readonly directory: Readonly<PositionalOptions>;
20
20
  };
21
21
  export declare enum TranspilationModes {
22
22
  localAndDeps = "localAndDeps",
23
23
  localOnly = "localOnly",
24
24
  none = "none"
25
25
  }
26
- export declare enum TemplateType {
27
- TypeScript = "typescript",
28
- JavaScript = "javascript"
29
- }
30
26
  declare const builders: SnapsCliBuilders;
31
27
  export default builders;
package/dist/builders.js CHANGED
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemplateType = exports.TranspilationModes = void 0;
3
+ exports.TranspilationModes = void 0;
4
4
  var TranspilationModes;
5
5
  (function (TranspilationModes) {
6
6
  TranspilationModes["localAndDeps"] = "localAndDeps";
7
7
  TranspilationModes["localOnly"] = "localOnly";
8
8
  TranspilationModes["none"] = "none";
9
9
  })(TranspilationModes = exports.TranspilationModes || (exports.TranspilationModes = {}));
10
- var TemplateType;
11
- (function (TemplateType) {
12
- TemplateType["TypeScript"] = "typescript";
13
- TemplateType["JavaScript"] = "javascript";
14
- })(TemplateType = exports.TemplateType || (exports.TemplateType = {}));
15
10
  const builders = {
16
11
  bundle: {
17
12
  alias: 'b',
@@ -129,13 +124,9 @@ const builders = {
129
124
  demandOption: false,
130
125
  default: true,
131
126
  },
132
- template: {
133
- alias: 't',
134
- describe: 'Specify which template to use (TypeScript or JavaScript)',
127
+ directory: {
128
+ describe: 'the directory to use',
135
129
  type: 'string',
136
- demandOption: false,
137
- default: TemplateType.TypeScript,
138
- choices: Object.values(TemplateType),
139
130
  },
140
131
  };
141
132
  exports.default = builders;
@@ -1 +1 @@
1
- {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;AAsBA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,mDAA6B,CAAA;IAC7B,6CAAuB,CAAA;IACvB,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAED,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,yCAAyB,CAAA;AAC3B,CAAC,EAHW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAGvB;AAED,MAAM,QAAQ,GAAqB;IACjC,MAAM,EAAE;QACN,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE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KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,QAAQ,EAAE;QACR,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,0DAA0D;QACpE,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,YAAY,CAAC,UAAU;QAChC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;KACrC;CACF,CAAC;AAEF,kBAAe,QAAQ,CAAC","sourcesContent":["import { Options } from 'yargs';\n\nexport type SnapsCliBuilders = {\n readonly bundle: Readonly<Options>;\n readonly dist: Readonly<Options>;\n readonly eval: Readonly<Options>;\n readonly manifest: Readonly<Options>;\n readonly outfileName: Readonly<Options>;\n readonly port: Readonly<Options>;\n readonly root: Readonly<Options>;\n readonly sourceMaps: Readonly<Options>;\n readonly src: Readonly<Options>;\n readonly stripComments: Readonly<Options>;\n readonly suppressWarnings: Readonly<Options>;\n readonly transpilationMode: Readonly<Options>;\n readonly depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly template: Readonly<Options>;\n};\n\nexport enum TranspilationModes {\n localAndDeps = 'localAndDeps',\n localOnly = 'localOnly',\n none = 'none',\n}\n\nexport enum TemplateType {\n TypeScript = 'typescript',\n JavaScript = 'javascript',\n}\n\nconst builders: SnapsCliBuilders = {\n bundle: {\n alias: 'b',\n describe: 'Snap bundle file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist/bundle.js',\n },\n\n dist: {\n alias: 'd',\n describe: 'Output directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist',\n },\n\n eval: {\n alias: 'e',\n describe: 'Attempt to evaluate Snap bundle in SES',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n manifest: {\n alias: 'm',\n describe: 'Validate snap.manifest.json',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n port: {\n alias: 'p',\n describe: 'Local server port for testing',\n type: 'number',\n demandOption: true,\n default: 8081,\n coerce: (arg: unknown) => {\n const port = Number.parseInt(String(arg), 10);\n if (Number.isNaN(port)) {\n throw new Error(`Invalid port: ${arg}`);\n }\n return port;\n },\n },\n\n outfileName: {\n alias: 'n',\n describe: 'Output file name',\n type: 'string',\n demandOption: false,\n default: 'bundle.js',\n },\n\n root: {\n alias: 'r',\n describe: 'Server root directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: '.',\n },\n\n sourceMaps: {\n describe: 'Whether builds include sourcemaps',\n type: 'boolean',\n demandOption: false,\n default: false,\n },\n\n src: {\n alias: 's',\n describe: 'Source file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'src/index.js',\n },\n\n stripComments: {\n alias: 'strip',\n describe: 'Whether to remove code comments from the build output',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n suppressWarnings: {\n type: 'boolean',\n describe: 'Whether to suppress warnings',\n demandOption: false,\n default: false,\n },\n\n transpilationMode: {\n type: 'string',\n describe:\n 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',\n demandOption: false,\n default: TranspilationModes.localOnly,\n choices: Object.values(TranspilationModes),\n },\n\n depsToTranspile: {\n type: 'array',\n describe: 'Transpile only the listed dependencies.',\n demandOption: false,\n },\n\n verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: true,\n },\n\n writeManifest: {\n describe: 'Make necessary changes to the Snap manifest file',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n serve: {\n describe: 'Serve Snap file(s) locally for testing',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n template: {\n alias: 't',\n describe: 'Specify which template to use (TypeScript or JavaScript)',\n type: 'string',\n demandOption: false,\n default: TemplateType.TypeScript,\n choices: Object.values(TemplateType),\n },\n};\n\nexport default builders;\n"]}
1
+ {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;AAsBA,IAAY,kBAIX;AAJ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C,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,aAAa,EAAE;QACb,QAAQ,EAAE,kDAAkD;QAC5D,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,KAAK,EAAE;QACL,QAAQ,EAAE,wCAAwC;QAClD,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,SAAS,EAAE;QACT,QAAQ,EAAE,sBAAsB;QAChC,IAAI,EAAE,QAAQ;KACf;CACF,CAAC;AAEF,kBAAe,QAAQ,CAAC","sourcesContent":["import { Options, PositionalOptions } from 'yargs';\n\nexport type SnapsCliBuilders = {\n readonly bundle: Readonly<Options>;\n readonly dist: Readonly<Options>;\n readonly eval: Readonly<Options>;\n readonly manifest: Readonly<Options>;\n readonly outfileName: Readonly<Options>;\n readonly port: Readonly<Options>;\n readonly root: Readonly<Options>;\n readonly sourceMaps: Readonly<Options>;\n readonly src: Readonly<Options>;\n readonly stripComments: Readonly<Options>;\n readonly suppressWarnings: Readonly<Options>;\n readonly transpilationMode: Readonly<Options>;\n readonly depsToTranspile: Readonly<Options>;\n readonly verboseErrors: Readonly<Options>;\n readonly writeManifest: Readonly<Options>;\n readonly serve: Readonly<Options>;\n readonly directory: Readonly<PositionalOptions>;\n};\n\nexport enum TranspilationModes {\n localAndDeps = 'localAndDeps',\n localOnly = 'localOnly',\n none = 'none',\n}\n\nconst builders: SnapsCliBuilders = {\n bundle: {\n alias: 'b',\n describe: 'Snap bundle file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist/bundle.js',\n },\n\n dist: {\n alias: 'd',\n describe: 'Output directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'dist',\n },\n\n eval: {\n alias: 'e',\n describe: 'Attempt to evaluate Snap bundle in SES',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n manifest: {\n alias: 'm',\n describe: 'Validate snap.manifest.json',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n port: {\n alias: 'p',\n describe: 'Local server port for testing',\n type: 'number',\n demandOption: true,\n default: 8081,\n coerce: (arg: unknown) => {\n const port = Number.parseInt(String(arg), 10);\n if (Number.isNaN(port)) {\n throw new Error(`Invalid port: ${arg}`);\n }\n return port;\n },\n },\n\n outfileName: {\n alias: 'n',\n describe: 'Output file name',\n type: 'string',\n demandOption: false,\n default: 'bundle.js',\n },\n\n root: {\n alias: 'r',\n describe: 'Server root directory',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: '.',\n },\n\n sourceMaps: {\n describe: 'Whether builds include sourcemaps',\n type: 'boolean',\n demandOption: false,\n default: false,\n },\n\n src: {\n alias: 's',\n describe: 'Source file',\n type: 'string',\n demandOption: true,\n normalize: true,\n default: 'src/index.js',\n },\n\n stripComments: {\n alias: 'strip',\n describe: 'Whether to remove code comments from the build output',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n suppressWarnings: {\n type: 'boolean',\n describe: 'Whether to suppress warnings',\n demandOption: false,\n default: false,\n },\n\n transpilationMode: {\n type: 'string',\n describe:\n 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',\n demandOption: false,\n default: TranspilationModes.localOnly,\n choices: Object.values(TranspilationModes),\n },\n\n depsToTranspile: {\n type: 'array',\n describe: 'Transpile only the listed dependencies.',\n demandOption: false,\n },\n\n verboseErrors: {\n type: 'boolean',\n describe: 'Display original errors',\n demandOption: false,\n default: true,\n },\n\n writeManifest: {\n describe: 'Make necessary changes to the Snap manifest file',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n serve: {\n describe: 'Serve Snap file(s) locally for testing',\n type: 'boolean',\n demandOption: false,\n default: true,\n },\n\n directory: {\n describe: 'the directory to use',\n type: 'string',\n },\n};\n\nexport default builders;\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = void 0;
4
- const snap_utils_1 = require("@metamask/snap-utils");
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
5
5
  const utils_1 = require("../../utils");
6
6
  const manifestHandler_1 = require("../manifest/manifestHandler");
7
7
  const evalHandler_1 = require("../eval/evalHandler");
@@ -20,11 +20,11 @@ const bundle_1 = require("./bundle");
20
20
  async function build(argv) {
21
21
  const { src, dist, outfileName } = argv;
22
22
  if (outfileName) {
23
- (0, snap_utils_1.validateOutfileName)(outfileName);
23
+ (0, snaps_utils_1.validateOutfileName)(outfileName);
24
24
  }
25
- await (0, snap_utils_1.validateFilePath)(src);
26
- await (0, snap_utils_1.validateDirPath)(dist, true);
27
- const outfilePath = (0, snap_utils_1.getOutfilePath)(dist, outfileName);
25
+ await (0, snaps_utils_1.validateFilePath)(src);
26
+ await (0, snaps_utils_1.validateDirPath)(dist, true);
27
+ const outfilePath = (0, snaps_utils_1.getOutfilePath)(dist, outfileName);
28
28
  const result = await (0, bundle_1.bundle)(src, outfilePath, argv, (0, utils_1.loadConfig)().bundlerCustomizer);
29
29
  if (result && argv.eval) {
30
30
  await (0, evalHandler_1.evalHandler)(Object.assign(Object.assign({}, argv), { bundle: outfilePath }));
@@ -1 +1 @@
1
- {"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,qDAK8B;AAE9B,uCAAyC;AACzC,iEAA8D;AAC9D,qDAAkD;AAClD,qCAAkC;AAElC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACxC,IAAI,WAAW,EAAE;QACf,IAAA,gCAAmB,EAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,IAAA,6BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,4BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,IAAA,2BAAc,EAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,IAAA,eAAM,EACzB,GAAG,EACH,WAAW,EACX,IAAI,EACJ,IAAA,kBAAU,GAAE,CAAC,iBAAiB,CAC/B,CAAC;IACF,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;QACvB,MAAM,IAAA,yBAAW,kCAAM,IAAI,KAAE,MAAM,EAAE,WAAW,IAAG,CAAC;KACrD;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,sBAsBC","sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snap-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { evalHandler } from '../eval/evalHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Argv from Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.outfileName - The output file name.\n */\nexport async function build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName as string);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName as string);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
1
+ {"version":3,"file":"buildHandler.js","sourceRoot":"","sources":["../../../src/cmds/build/buildHandler.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAE/B,uCAAyC;AACzC,iEAA8D;AAC9D,qDAAkD;AAClD,qCAAkC;AAElC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAC,IAAe;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACxC,IAAI,WAAW,EAAE;QACf,IAAA,iCAAmB,EAAC,WAAqB,CAAC,CAAC;KAC5C;IACD,MAAM,IAAA,8BAAgB,EAAC,GAAG,CAAC,CAAC;IAC5B,MAAM,IAAA,6BAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAElC,MAAM,WAAW,GAAG,IAAA,4BAAc,EAAC,IAAI,EAAE,WAAqB,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,MAAM,IAAA,eAAM,EACzB,GAAG,EACH,WAAW,EACX,IAAI,EACJ,IAAA,kBAAU,GAAE,CAAC,iBAAiB,CAC/B,CAAC;IACF,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;QACvB,MAAM,IAAA,yBAAW,kCAAM,IAAI,KAAE,MAAM,EAAE,WAAW,IAAG,CAAC;KACrD;IAED,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,sBAsBC","sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { evalHandler } from '../eval/evalHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Argv from Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.outfileName - The output file name.\n */\nexport async function build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName as string);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName as string);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"]}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evalHandler = void 0;
4
- const snap_utils_1 = require("@metamask/snap-utils");
5
- const utils_1 = require("../../utils");
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
6
5
  /**
7
6
  * Runs the snap in a worker, to ensure SES compatibility.
8
7
  *
@@ -13,12 +12,11 @@ const utils_1 = require("../../utils");
13
12
  async function evalHandler(argv) {
14
13
  const { bundle: bundlePath } = argv;
15
14
  try {
16
- await (0, snap_utils_1.evalBundle)(bundlePath);
15
+ await (0, snaps_utils_1.evalBundle)(bundlePath);
17
16
  console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);
18
17
  }
19
18
  catch (error) {
20
- (0, utils_1.logError)(`Snap evaluation error: ${error.message}`, error);
21
- throw error;
19
+ throw new Error(`Snap evaluation error: ${error.message}`);
22
20
  }
23
21
  }
24
22
  exports.evalHandler = evalHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAElD,uCAAuC;AAEvC;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEpC,IAAI;QACF,MAAM,IAAA,uBAAU,EAAC,UAAoB,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,4BAA4B,UAAU,WAAW,CAAC,CAAC;KAChE;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,gBAAQ,EAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAVD,kCAUC","sourcesContent":["import { evalBundle } from '@metamask/snap-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\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 try {\n await evalBundle(bundlePath as string);\n console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n logError(`Snap evaluation error: ${error.message}`, error);\n throw error;\n }\n}\n"]}
1
+ {"version":3,"file":"evalHandler.js","sourceRoot":"","sources":["../../../src/cmds/eval/evalHandler.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAGnD;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAEpC,IAAI;QACF,MAAM,IAAA,wBAAU,EAAC,UAAoB,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,4BAA4B,UAAU,WAAW,CAAC,CAAC;KAChE;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5D;AACH,CAAC;AATD,kCASC","sourcesContent":["import { evalBundle } from '@metamask/snaps-utils';\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 try {\n await evalBundle(bundlePath as string);\n console.log(`Eval Success: evaluated '${bundlePath}' in SES!`);\n } catch (error) {\n throw new Error(`Snap evaluation error: ${error.message}`);\n }\n}\n"]}
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  const builders_1 = __importDefault(require("../../builders"));
6
6
  const buildHandler_1 = require("../build/buildHandler");
7
7
  const initHandler_1 = require("./initHandler");
8
- const initUtils_1 = require("./initUtils");
9
8
  /**
10
9
  * The main entrypoint for the init command. This calls the init handler to
11
10
  * initialize the snap package, builds the snap, and then updates the manifest
@@ -14,25 +13,16 @@ const initUtils_1 = require("./initUtils");
14
13
  * @param argv - The Yargs arguments object.
15
14
  */
16
15
  async function init(argv) {
17
- console.log();
18
16
  const newArgs = await (0, initHandler_1.initHandler)(argv);
17
+ process.chdir(newArgs.snapLocation);
19
18
  await (0, buildHandler_1.build)(Object.assign(Object.assign({}, newArgs), { manifest: false, eval: true }));
20
- await (0, initHandler_1.updateManifestShasum)();
21
19
  console.log('\nSnap project successfully initiated!');
22
20
  }
23
21
  module.exports = {
24
- command: ['init', 'i'],
22
+ command: ['init [directory]', 'i [directory]'],
25
23
  desc: 'Initialize Snap package',
26
24
  builder: (yarg) => {
27
- yarg
28
- .option('src', builders_1.default.src)
29
- .option('dist', builders_1.default.dist)
30
- .option('port', builders_1.default.port)
31
- .option('outfileName', builders_1.default.outfileName)
32
- .option('template', builders_1.default.template)
33
- .middleware(((yargsArgv) => {
34
- (0, initUtils_1.correctDefaultArgs)(yargsArgv);
35
- }), true);
25
+ yarg.positional('directory', builders_1.default.directory);
36
26
  },
37
27
  handler: (argv) => init(argv),
38
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAAkE;AAClE,2CAAiD;AAsBjD;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC;IAExC,MAAM,IAAA,oBAAK,kCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,MAAM,IAAA,kCAAoB,GAAE,CAAC;IAE7B,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC;AAxCD,iBAAS;IACP,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC;IACtB,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI;aACD,MAAM,CAAC,KAAK,EAAE,kBAAQ,CAAC,GAAG,CAAC;aAC3B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,MAAM,EAAE,kBAAQ,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,aAAa,EAAE,kBAAQ,CAAC,WAAW,CAAC;aAC3C,MAAM,CAAC,UAAU,EAAE,kBAAQ,CAAC,QAAQ,CAAC;aACrC,UAAU,CACT,CAAC,CAAC,SAAoB,EAAE,EAAE;YACxB,IAAA,8BAAkB,EAAC,SAAS,CAAC,CAAC;QAChC,CAAC,CAAQ,EACT,IAAI,CACL,CAAC;IACN,CAAC;IACD,OAAO,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler, updateManifestShasum } from './initHandler';\nimport { correctDefaultArgs } from './initUtils';\n\nexport = {\n command: ['init', 'i'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('dist', builders.dist)\n .option('port', builders.port)\n .option('outfileName', builders.outfileName)\n .option('template', builders.template)\n .middleware(\n ((yargsArgv: Arguments) => {\n correctDefaultArgs(yargsArgv);\n }) as any,\n true,\n );\n },\n handler: (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 console.log();\n const newArgs = await initHandler(argv);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n await updateManifestShasum();\n\n console.log('\\nSnap project successfully initiated!');\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AACA,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,kCACN,OAAO,KACV,QAAQ,EAAE,KAAK,EACf,IAAI,EAAE,IAAI,IACV,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,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,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CACzC,CAAC","sourcesContent":["import yargs from 'yargs';\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: (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 console.log('\\nSnap project successfully initiated!');\n}\n"]}
@@ -10,21 +10,17 @@ import { YargsArgs } from '../../types/yargs';
10
10
  * @throws If initialization of the snap package failed.
11
11
  */
12
12
  export declare function initHandler(argv: YargsArgs): Promise<{
13
- [x: string]: unknown;
13
+ dist: string;
14
+ outfileName: string;
15
+ src: string;
16
+ snapLocation: string;
14
17
  sourceMaps: boolean;
15
18
  stripComments: boolean;
16
19
  transformHtmlComments: boolean;
17
20
  port: number;
18
- dist: string;
19
- src: string;
20
21
  eval: boolean;
21
- outfileName: string;
22
22
  serve: boolean;
23
+ directory?: string | undefined;
23
24
  _?: (string | number)[] | undefined;
24
25
  $0?: string | undefined;
25
26
  }>;
26
- /**
27
- * This updates the Snap shasum value of the manifest after building the Snap
28
- * during the init command.
29
- */
30
- export declare function updateManifestShasum(): Promise<void>;
@@ -3,14 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.updateManifestShasum = exports.initHandler = void 0;
7
- const fs_1 = require("fs");
6
+ exports.initHandler = void 0;
8
7
  const path_1 = __importDefault(require("path"));
9
- const snap_utils_1 = require("@metamask/snap-utils");
10
- const mkdirp_1 = __importDefault(require("mkdirp"));
11
- const utils_1 = require("../../utils");
12
- const init_template_json_1 = __importDefault(require("./init-template.json"));
8
+ const fs_1 = require("fs");
9
+ const snaps_utils_1 = require("@metamask/snaps-utils");
13
10
  const initUtils_1 = require("./initUtils");
11
+ const SATISFIED_VERSION = '>=16';
14
12
  /**
15
13
  * Creates a new snap package, based on one of the provided templates. This
16
14
  * creates all the necessary files, like `package.json`, `snap.config.js`, etc.
@@ -22,99 +20,42 @@ const initUtils_1 = require("./initUtils");
22
20
  * @throws If initialization of the snap package failed.
23
21
  */
24
22
  async function initHandler(argv) {
25
- console.log(`MetaMask Snaps: Initialize\n`);
26
- const packageJson = await (0, initUtils_1.asyncPackageInit)(argv);
27
- await (0, initUtils_1.prepareWorkingDirectory)();
28
- console.log(`\nInit: Building '${snap_utils_1.NpmSnapFileNames.Manifest}'...\n`);
29
- const [snapManifest, _newArgs] = await (0, initUtils_1.buildSnapManifest)(argv, packageJson);
30
- const newArgs = Object.keys(_newArgs)
31
- .sort()
32
- .reduce((sorted, key) => {
33
- sorted[key] = _newArgs[key];
34
- return sorted;
35
- }, {});
36
- const isTypeScript = (0, initUtils_1.isTemplateTypescript)(argv.template);
37
- try {
38
- await fs_1.promises.writeFile(snap_utils_1.NpmSnapFileNames.Manifest, `${JSON.stringify(snapManifest, null, 2)}\n`);
39
- }
40
- catch (err) {
41
- (0, utils_1.logError)(`Init Error: Failed to write '${snap_utils_1.NpmSnapFileNames.Manifest}'.`, err);
42
- throw err;
43
- }
44
- console.log(`\nInit: Created '${snap_utils_1.NpmSnapFileNames.Manifest}'.`);
45
- // Write main .js entry file
46
- const { src } = newArgs;
23
+ const { directory } = argv;
24
+ const isVersionSupported = (0, snaps_utils_1.satisfiesVersionRange)(process.version, SATISFIED_VERSION);
25
+ if (!isVersionSupported) {
26
+ throw new Error(`Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`);
27
+ }
28
+ const gitExists = (0, initUtils_1.isGitInstalled)();
29
+ if (!gitExists) {
30
+ throw new Error(`Init Error: git is not installed. Please install git to continue.`);
31
+ }
32
+ const directoryToUse = directory
33
+ ? path_1.default.join(process.cwd(), directory)
34
+ : process.cwd();
35
+ console.log(`Preparing ${directoryToUse}...`);
36
+ await (0, initUtils_1.prepareWorkingDirectory)(directoryToUse);
47
37
  try {
48
- if (path_1.default.basename(src) !== src) {
49
- await (0, mkdirp_1.default)(path_1.default.dirname(src));
50
- }
51
- await fs_1.promises.writeFile(src, isTypeScript ? init_template_json_1.default.typescriptSource : init_template_json_1.default.source);
52
- console.log(`Init: Created '${src}'.`);
38
+ console.log(`Cloning template...`);
39
+ await (0, initUtils_1.cloneTemplate)(directoryToUse);
40
+ fs_1.promises.rm(path_1.default.join(directoryToUse, '.git'), {
41
+ force: true,
42
+ recursive: true,
43
+ });
53
44
  }
54
45
  catch (err) {
55
- (0, utils_1.logError)(`Init Error: Failed to write '${src}'.`, err);
56
- throw err;
57
- }
58
- // Write index.html
59
- try {
60
- await fs_1.promises.writeFile('index.html', isTypeScript ? init_template_json_1.default.typescriptHtml : init_template_json_1.default.html);
61
- console.log(`Init: Created 'index.html'.`);
62
- }
63
- catch (err) {
64
- (0, utils_1.logError)(`Init Error: Failed to write 'index.html'.`, err);
65
- throw err;
66
- }
67
- // Write tsconfig.json
68
- if (isTypeScript) {
69
- try {
70
- await fs_1.promises.writeFile('tsconfig.json', init_template_json_1.default.typescriptConfig);
71
- console.log(`Init: Created 'tsconfig.json'.`);
72
- }
73
- catch (err) {
74
- (0, utils_1.logError)(`Init Error: Failed to write 'tsconfig.json'.`, err);
75
- throw err;
76
- }
77
- }
78
- // Write config file
79
- try {
80
- const defaultConfig = {
81
- cliOptions: newArgs,
82
- };
83
- const defaultConfigFile = `module.exports = ${JSON.stringify(defaultConfig, null, 2)}
84
- `;
85
- await fs_1.promises.writeFile(utils_1.CONFIG_FILE, defaultConfigFile);
86
- console.log(`Init: Wrote '${utils_1.CONFIG_FILE}' config file`);
87
- }
88
- catch (err) {
89
- (0, utils_1.logError)(`Init Error: Failed to write '${utils_1.CONFIG_FILE}'.`, err);
90
- throw err;
91
- }
92
- // Write icon
93
- const iconPath = 'images/icon.svg';
94
- try {
95
- if (path_1.default.basename(iconPath) !== iconPath) {
96
- await (0, mkdirp_1.default)(path_1.default.dirname(iconPath));
97
- }
98
- await fs_1.promises.writeFile(iconPath, init_template_json_1.default.icon);
99
- console.log(`Init: Created '${iconPath}'.`);
100
- }
101
- catch (err) {
102
- (0, utils_1.logError)(`Init Error: Failed to write '${iconPath}'.`, err);
103
- throw err;
104
- }
105
- (0, utils_1.closePrompt)();
106
- return Object.assign(Object.assign({}, argv), newArgs);
46
+ throw new Error('Init Error: Failed to create template.');
47
+ }
48
+ console.log('Installing dependencies...');
49
+ await (0, initUtils_1.yarnInstall)(directoryToUse);
50
+ if (!(0, initUtils_1.isInGitRepository)(directoryToUse)) {
51
+ console.log('Initializing git repository...');
52
+ await (0, initUtils_1.gitInit)(directoryToUse);
53
+ }
54
+ const snapLocation = path_1.default.join(directoryToUse, initUtils_1.SNAP_LOCATION);
55
+ const manifest = await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.Manifest));
56
+ const packageJson = await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.PackageJson));
57
+ const distPath = manifest.source.location.npm.filePath.split('/');
58
+ return Object.assign(Object.assign({}, argv), { dist: distPath[0], outfileName: distPath[1], src: packageJson.main || 'src/index.js', snapLocation });
107
59
  }
108
60
  exports.initHandler = initHandler;
109
- /**
110
- * This updates the Snap shasum value of the manifest after building the Snap
111
- * during the init command.
112
- */
113
- async function updateManifestShasum() {
114
- const manifest = await (0, snap_utils_1.readJsonFile)(snap_utils_1.NpmSnapFileNames.Manifest);
115
- const bundleContents = await fs_1.promises.readFile(manifest.source.location.npm.filePath, 'utf8');
116
- manifest.source.shasum = (0, snap_utils_1.getSnapSourceShasum)(bundleContents);
117
- await fs_1.promises.writeFile(snap_utils_1.NpmSnapFileNames.Manifest, JSON.stringify((0, snap_utils_1.getWritableManifest)(manifest), null, 2));
118
- }
119
- exports.updateManifestShasum = updateManifestShasum;
120
61
  //# sourceMappingURL=initHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAoC;AACpC,gDAA6B;AAC7B,qDAM8B;AAC9B,oDAA4B;AAE5B,uCAA6E;AAE7E,8EAA4C;AAC5C,2CAKqB;AAErB;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAE5C,MAAM,WAAW,GAAG,MAAM,IAAA,4BAAgB,EAAC,IAAI,CAAC,CAAC;IAEjD,MAAM,IAAA,mCAAuB,GAAE,CAAC;IAEhC,OAAO,CAAC,GAAG,CAAC,qBAAqB,6BAAgB,CAAC,QAAQ,QAAQ,CAAC,CAAC;IAEpE,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,MAAM,IAAA,6BAAiB,EAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAE5E,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;SAClC,IAAI,EAAE;SACN,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAA4B,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAe,CAAC,CAAC;IAEtB,MAAM,YAAY,GAAG,IAAA,gCAAoB,EAAC,IAAI,CAAC,QAAwB,CAAC,CAAC;IACzE,IAAI;QACF,MAAM,aAAE,CAAC,SAAS,CAChB,6BAAgB,CAAC,QAAQ,EACzB,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAC7C,CAAC;KACH;IAAC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C;AAED;;;GAGG;AACI,KAAK,UAAU,oBAAoB;IACxC,MAAM,QAAQ,GAAG,MAAM,IAAA,yBAAY,EAAe,6BAAgB,CAAC,QAAQ,CAAC,CAAC;IAE7E,MAAM,cAAc,GAAG,MAAM,aAAE,CAAC,QAAQ,CACtC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EACrC,MAAM,CACP,CAAC;IAEF,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,IAAA,gCAAmB,EAAC,cAAc,CAAC,CAAC;IAC7D,MAAM,aAAE,CAAC,SAAS,CAChB,6BAAgB,CAAC,QAAQ,EACzB,IAAI,CAAC,SAAS,CAAC,IAAA,gCAAmB,EAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CACvD,CAAC;AACJ,CAAC;AAbD,oDAaC","sourcesContent":["import { promises as fs } from 'fs';\nimport pathUtils from 'path';\nimport {\n NpmSnapFileNames,\n SnapManifest,\n getSnapSourceShasum,\n getWritableManifest,\n readJsonFile,\n} from '@metamask/snap-utils';\nimport mkdirp from 'mkdirp';\nimport { YargsArgs } from '../../types/yargs';\nimport { closePrompt, CONFIG_FILE, logError, SnapConfig } from '../../utils';\nimport { TemplateType } from '../../builders';\nimport template from './init-template.json';\nimport {\n asyncPackageInit,\n buildSnapManifest,\n isTemplateTypescript,\n prepareWorkingDirectory,\n} from './initUtils';\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 console.log(`MetaMask Snaps: Initialize\\n`);\n\n const packageJson = await asyncPackageInit(argv);\n\n await prepareWorkingDirectory();\n\n console.log(`\\nInit: Building '${NpmSnapFileNames.Manifest}'...\\n`);\n\n const [snapManifest, _newArgs] = await buildSnapManifest(argv, packageJson);\n\n const newArgs = Object.keys(_newArgs)\n .sort()\n .reduce((sorted, key) => {\n sorted[key] = _newArgs[key as keyof typeof _newArgs];\n return sorted;\n }, {} as YargsArgs);\n\n const isTypeScript = isTemplateTypescript(argv.template as TemplateType);\n try {\n await fs.writeFile(\n NpmSnapFileNames.Manifest,\n `${JSON.stringify(snapManifest, null, 2)}\\n`,\n );\n } catch (err) {\n logError(\n `Init Error: Failed to write '${NpmSnapFileNames.Manifest}'.`,\n err,\n );\n throw err;\n }\n\n console.log(`\\nInit: Created '${NpmSnapFileNames.Manifest}'.`);\n\n // Write main .js entry file\n const { src } = newArgs;\n\n try {\n if (pathUtils.basename(src) !== src) {\n await mkdirp(pathUtils.dirname(src));\n }\n\n await fs.writeFile(\n src,\n isTypeScript ? template.typescriptSource : template.source,\n );\n\n console.log(`Init: Created '${src}'.`);\n } catch (err) {\n logError(`Init Error: Failed to write '${src}'.`, err);\n throw err;\n }\n\n // Write index.html\n try {\n await fs.writeFile(\n 'index.html',\n isTypeScript ? template.typescriptHtml : template.html,\n );\n\n console.log(`Init: Created 'index.html'.`);\n } catch (err) {\n logError(`Init Error: Failed to write 'index.html'.`, err);\n throw err;\n }\n\n // Write tsconfig.json\n if (isTypeScript) {\n try {\n await fs.writeFile('tsconfig.json', template.typescriptConfig);\n console.log(`Init: Created 'tsconfig.json'.`);\n } catch (err) {\n logError(`Init Error: Failed to write 'tsconfig.json'.`, err);\n throw err;\n }\n }\n\n // Write config file\n try {\n const defaultConfig: SnapConfig = {\n cliOptions: newArgs,\n };\n const defaultConfigFile = `module.exports = ${JSON.stringify(\n defaultConfig,\n null,\n 2,\n )}\n `;\n await fs.writeFile(CONFIG_FILE, defaultConfigFile);\n console.log(`Init: Wrote '${CONFIG_FILE}' config file`);\n } catch (err) {\n logError(`Init Error: Failed to write '${CONFIG_FILE}'.`, err);\n throw err;\n }\n\n // Write icon\n const iconPath = 'images/icon.svg';\n try {\n if (pathUtils.basename(iconPath) !== iconPath) {\n await mkdirp(pathUtils.dirname(iconPath));\n }\n await fs.writeFile(iconPath, template.icon);\n\n console.log(`Init: Created '${iconPath}'.`);\n } catch (err) {\n logError(`Init Error: Failed to write '${iconPath}'.`, err);\n throw err;\n }\n\n closePrompt();\n return { ...argv, ...newArgs };\n}\n\n/**\n * This updates the Snap shasum value of the manifest after building the Snap\n * during the init command.\n */\nexport async function updateManifestShasum() {\n const manifest = await readJsonFile<SnapManifest>(NpmSnapFileNames.Manifest);\n\n const bundleContents = await fs.readFile(\n manifest.source.location.npm.filePath,\n 'utf8',\n );\n\n manifest.source.shasum = getSnapSourceShasum(bundleContents);\n await fs.writeFile(\n NpmSnapFileNames.Manifest,\n JSON.stringify(getWritableManifest(manifest), null, 2),\n );\n}\n"]}
1
+ {"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,2BAAoC;AACpC,uDAM+B;AAE/B,2CAQqB;AAErB,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE3B,MAAM,kBAAkB,GAAG,IAAA,mCAAqB,EAC9C,OAAO,CAAC,OAAO,EACf,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CACb,0DAA0D,OAAO,CAAC,OAAO,4BAA4B,iBAAiB,GAAG,CAC1H,CAAC;KACH;IAED,MAAM,SAAS,GAAG,IAAA,0BAAc,GAAE,CAAC;IACnC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;KACH;IAED,MAAM,cAAc,GAAG,SAAS;QAC9B,CAAC,CAAC,cAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,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AC,CAAC;IAElE,uCACK,IAAI,KACP,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,EACxB,GAAG,EAAE,WAAW,CAAC,IAAI,IAAI,cAAc,EACvC,YAAY,IACZ;AACJ,CAAC;AAnED,kCAmEC","sourcesContent":["import pathUtils from 'path';\nimport { promises as fs } from 'fs';\nimport {\n NpmSnapFileNames,\n SnapManifest,\n readJsonFile,\n satisfiesVersionRange,\n NpmSnapPackageJson,\n} from '@metamask/snaps-utils';\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';\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,\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.join(process.cwd(), directory)\n : process.cwd();\n\n console.log(`Preparing ${directoryToUse}...`);\n\n await prepareWorkingDirectory(directoryToUse);\n\n try {\n console.log(`Cloning template...`);\n await cloneTemplate(directoryToUse);\n\n fs.rm(pathUtils.join(directoryToUse, '.git'), {\n force: true,\n recursive: true,\n });\n } catch (err) {\n throw new Error('Init Error: Failed to create template.');\n }\n\n console.log('Installing dependencies...');\n await yarnInstall(directoryToUse);\n\n if (!isInGitRepository(directoryToUse)) {\n console.log('Initializing git repository...');\n await gitInit(directoryToUse);\n }\n\n const snapLocation = pathUtils.join(directoryToUse, SNAP_LOCATION);\n\n const manifest: SnapManifest = await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.Manifest),\n );\n const packageJson: NpmSnapPackageJson = await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.PackageJson),\n );\n\n const distPath = manifest.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"]}
@@ -1,46 +1,39 @@
1
- import { SnapManifest, NpmSnapPackageJson } from '@metamask/snap-utils';
2
- import { Arguments } from 'yargs';
3
- import { YargsArgs } from '../../types/yargs';
4
- import { TemplateType } from '../../builders';
1
+ export declare const TEMPLATE_GIT_URL = "https://github.com/MetaMask/template-snap-monorepo.git";
2
+ export declare const SNAP_LOCATION = "packages/snap/";
5
3
  /**
6
- * Initializes a `package.json` file for a Snap project. Will attempt to read
7
- * and parse the existing file if it already exists, otherwise will intialize
8
- * a brand new one.
4
+ * Checks if the destination folder exists and if it's empty. Otherwise create it.
9
5
  *
10
- * @param argv - Yargs arguments object.
11
- * @returns The contents of the `package.json` file.
6
+ * @param directory - The desination folder.
12
7
  */
13
- export declare function asyncPackageInit(argv: YargsArgs): Promise<Readonly<NpmSnapPackageJson>>;
8
+ export declare function prepareWorkingDirectory(directory: string): Promise<void>;
14
9
  /**
15
- * Interactively constructs a Snap manifest file by prompting the user.
10
+ * Clones the template in a directory.
16
11
  *
17
- * @param argv - The `yargs` `argv` object.
18
- * @param packageJson - The `package.json` object.
19
- * @returns A tuple of the resulting Snap manifest object and a new `argv`
20
- * object with properties to match the manifest.
12
+ * @param directory - The directory to clone the template in.
21
13
  */
22
- export declare function buildSnapManifest(argv: YargsArgs, packageJson: NpmSnapPackageJson): Promise<[SnapManifest, {
23
- dist: string;
24
- outfileName: string;
25
- src: string;
26
- }]>;
14
+ export declare function cloneTemplate(directory: string): Promise<void>;
27
15
  /**
28
- * Checks whether any files in the current working directory will be overwritten
29
- * by the initialization process, and asks the user whether to continue if so.
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.
30
26
  */
31
- export declare function prepareWorkingDirectory(): Promise<void>;
27
+ export declare function isInGitRepository(directory: string): boolean;
32
28
  /**
33
- * In case when TypeScript version is used, default source file
34
- * will be updated if previous was not correct.
29
+ * Init a git repository.
35
30
  *
36
- * @param yargsArgv - The Yargs arguments object.
37
- * @returns Modified Yargs arguments object.
31
+ * @param directory - The directory to init.
38
32
  */
39
- export declare function correctDefaultArgs(yargsArgv: Arguments): Arguments;
33
+ export declare function gitInit(directory: string): Promise<void>;
40
34
  /**
41
- * Check if template argument is TemplateType.TypeScript.
35
+ * Install dependencies in a yarn project.
42
36
  *
43
- * @param templateType - TemplateType value of the template argument passed from CLI.
44
- * @returns True or false.
37
+ * @param directory - The directory containing the project.
45
38
  */
46
- export declare function isTemplateTypescript(templateType: TemplateType): boolean;
39
+ export declare function yarnInstall(directory: string): Promise<void>;