@metamask/snaps-cli 0.22.2 → 0.23.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.
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]
@@ -0,0 +1,2 @@
1
+ declare const _default: import("memfs/lib/volume").Volume;
2
+ export = _default;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const memfs_1 = require("memfs");
3
+ module.exports = new memfs_1.Volume();
4
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/__mocks__/fs.ts"],"names":[],"mappings":";AAAA,iCAA+B;AAG/B,iBAAS,IAAI,cAAM,EAAE,CAAC","sourcesContent":["import { Volume } from 'memfs';\n\n// Note: `Volume` implements most of the `fs` API, but not all.\nexport = new Volume();\n"]}
@@ -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;AAJ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AAE,OAAO;QACb,QAAQ,EAAE,yCAAyC;QACnD,YAAY,EAAE,KAAK;KACpB;IAED,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,yBAAyB;QACnC,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,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;AAJD,WAAY,kBAAkB;IAC5B,mDAA6B,CAAA;IAC7B,6CAAuB,CAAA;IACvB,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B;AAED,MAAM,QAAQ,GAAqB;IACjC,MAAM,EAAE;QACN,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,gBAAgB;KAC1B;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,MAAM;KAChB;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,wCAAwC;QAClD,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,QAAQ,EAAE;QACR,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,6BAA6B;QACvC,IAAI,EAAE,SAAS;QACf,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,IAAI;KACd;IAED,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QAC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QACnB,OAAO,EAAE,KAAK;KACf;IAED,iBAAiB,EAAE;QACjB,IAAI,EAAE,QAAQ;QACd,QAAQ,EACN,iHAAiH;QACnH,YAAY,EAAE,KAAK;QACnB,OAAO,EAAE,kBAAkB,CAAC,SAAS;QACrC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;KAC3C;IAED,eAAe,EAAE;QACf,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,yCAAyC;QACnD,YAAY,EAAE,KAAK;KACpB;IAED,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,yBAAyB;QACnC,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"]}
@@ -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
@@ -16,23 +15,15 @@ const initUtils_1 = require("./initUtils");
16
15
  async function init(argv) {
17
16
  console.log();
18
17
  const newArgs = await (0, initHandler_1.initHandler)(argv);
18
+ process.chdir(newArgs.snapLocation);
19
19
  await (0, buildHandler_1.build)(Object.assign(Object.assign({}, newArgs), { manifest: false, eval: true }));
20
- await (0, initHandler_1.updateManifestShasum)();
21
20
  console.log('\nSnap project successfully initiated!');
22
21
  }
23
22
  module.exports = {
24
- command: ['init', 'i'],
23
+ command: ['init [directory]', 'i [directory]'],
25
24
  desc: 'Initialize Snap package',
26
25
  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);
26
+ yarg.positional('directory', builders_1.default.directory);
36
27
  },
37
28
  handler: (argv) => init(argv),
38
29
  };
@@ -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,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,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;AA7BD,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 console.log();\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,13 @@ 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"));
8
+ const fs_1 = require("fs");
9
9
  const snap_utils_1 = require("@metamask/snap-utils");
10
- const mkdirp_1 = __importDefault(require("mkdirp"));
11
10
  const utils_1 = require("../../utils");
12
- const init_template_json_1 = __importDefault(require("./init-template.json"));
13
11
  const initUtils_1 = require("./initUtils");
12
+ const SATISFIED_VERSION = '>=16';
14
13
  /**
15
14
  * Creates a new snap package, based on one of the provided templates. This
16
15
  * creates all the necessary files, like `package.json`, `snap.config.js`, etc.
@@ -22,99 +21,45 @@ const initUtils_1 = require("./initUtils");
22
21
  * @throws If initialization of the snap package failed.
23
22
  */
24
23
  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;
24
+ const { directory } = argv;
25
+ const isVersionSupported = (0, snap_utils_1.satisfiesVersionRange)(process.version, SATISFIED_VERSION);
26
+ if (!isVersionSupported) {
27
+ (0, utils_1.logError)(`Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`);
28
+ throw new Error('Outdated node version.');
43
29
  }
44
- console.log(`\nInit: Created '${snap_utils_1.NpmSnapFileNames.Manifest}'.`);
45
- // Write main .js entry file
46
- const { src } = newArgs;
47
- 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}'.`);
53
- }
54
- catch (err) {
55
- (0, utils_1.logError)(`Init Error: Failed to write '${src}'.`, err);
56
- throw err;
30
+ const gitExists = (0, initUtils_1.isGitInstalled)();
31
+ if (!gitExists) {
32
+ (0, utils_1.logError)(`Init Error: git is not installed. Please install git to continue.`);
33
+ throw new Error('Git is not installed.');
57
34
  }
58
- // Write index.html
35
+ const directoryToUse = directory
36
+ ? path_1.default.join(process.cwd(), directory)
37
+ : process.cwd();
38
+ console.log(`Preparing ${directoryToUse}...`);
39
+ await (0, initUtils_1.prepareWorkingDirectory)(directoryToUse);
59
40
  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'.`);
41
+ console.log(`Cloning template...`);
42
+ await (0, initUtils_1.cloneTemplate)(directoryToUse);
43
+ fs_1.promises.rm(path_1.default.join(directoryToUse, '.git'), {
44
+ force: true,
45
+ recursive: true,
46
+ });
62
47
  }
63
48
  catch (err) {
64
- (0, utils_1.logError)(`Init Error: Failed to write 'index.html'.`, err);
49
+ (0, utils_1.logError)('Init Error: Failed to create template, cleaning...');
65
50
  throw err;
66
51
  }
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`);
52
+ console.log('Installing dependencies...');
53
+ await (0, initUtils_1.yarnInstall)(directoryToUse);
54
+ if (!(0, initUtils_1.isInGitRepository)(directoryToUse)) {
55
+ console.log('Initializing git repository...');
56
+ await (0, initUtils_1.gitInit)(directoryToUse);
87
57
  }
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);
58
+ const snapLocation = path_1.default.join(directoryToUse, initUtils_1.SNAP_LOCATION);
59
+ const manifest = await (0, snap_utils_1.readJsonFile)(path_1.default.join(snapLocation, snap_utils_1.NpmSnapFileNames.Manifest));
60
+ const packageJson = await (0, snap_utils_1.readJsonFile)(path_1.default.join(snapLocation, snap_utils_1.NpmSnapFileNames.PackageJson));
61
+ const distPath = manifest.source.location.npm.filePath.split('/');
62
+ return Object.assign(Object.assign({}, argv), { dist: distPath[0], outfileName: distPath[1], src: packageJson.main || 'src/index.js', snapLocation });
107
63
  }
108
64
  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
65
  //# 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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AQ,IAAI,CAAC,CAAC;KAC7C;IAAC,OAAO,GAAG,EAAE;QACZ,IAAA,gBAAQ,EAAC,gCAAgC,QAAQ,IAAI,EAAE,GAAG,CAAC,CAAC;QAC5D,MAAM,GAAG,CAAC;KACX;IAED,IAAA,mBAAW,GAAE,CAAC;IACd,uCAAY,IAAI,GAAK,OAAO,EAAG;AACjC,CAAC;AA/GD,kCA+GC;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,qDAM8B;AAE9B,uCAAuC;AACvC,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,kCAAqB,EAC9C,OAAO,CAAC,OAAO,EACf,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,IAAA,gBAAQ,EACN,0DAA0D,OAAO,CAAC,OAAO,4BAA4B,iBAAiB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,CAAC,CAAC;IAEnE,MAAM,QAAQ,GAAiB,MAAM,IAAA,yBAAY,EAC/C,cAAS,CAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,QAAQ,CAAC,CACxD,CAAC;IACF,MAAM,WAAW,GAAuB,MAAM,IAAA,yBAAY,EACxD,cAAS,CAAC,IAAI,CAAC,YAAY,EAAE,6BAAgB,CAAC,WAAW,CAAC,CAC3D,CAAC;IAEF,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,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;AAtED,kCAsEC","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/snap-utils';\nimport { YargsArgs } from '../../types/yargs';\nimport { logError } from '../../utils';\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 logError(\n `Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`,\n );\n throw new Error('Outdated node version.');\n }\n\n const gitExists = isGitInstalled();\n if (!gitExists) {\n logError(\n `Init Error: git is not installed. Please install git to continue.`,\n );\n throw new Error('Git is not installed.');\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 logError('Init Error: Failed to create template, cleaning...');\n throw err;\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>;