@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 +6 -6
- package/dist/__mocks__/fs.d.ts +2 -0
- package/dist/__mocks__/fs.js +4 -0
- package/dist/__mocks__/fs.js.map +1 -0
- package/dist/builders.d.ts +2 -6
- package/dist/builders.js +3 -12
- package/dist/builders.js.map +1 -1
- package/dist/cmds/init/index.js +3 -12
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/initHandler.d.ts +5 -9
- package/dist/cmds/init/initHandler.js +34 -89
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +25 -32
- package/dist/cmds/init/initUtils.js +85 -249
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/test-utils/fs.d.ts +5 -0
- package/dist/test-utils/fs.js +18 -0
- package/dist/test-utils/fs.js.map +1 -0
- package/dist/test-utils/index.d.ts +1 -0
- package/dist/test-utils/index.js +18 -0
- package/dist/test-utils/index.js.map +1 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/snap-config.d.ts +21 -4
- package/dist/utils/snap-config.js +20 -3
- package/dist/utils/snap-config.js.map +1 -1
- package/package.json +11 -18
- package/dist/cmds/init/init-template.json +0 -8
- package/dist/tsconfig.json +0 -8
- package/dist/utils/readline.d.ts +0 -37
- package/dist/utils/readline.js +0 -75
- package/dist/utils/readline.js.map +0 -1
- package/dist/utils/snap-config.__GENERATED__.d.ts +0 -2
- package/dist/utils/snap-config.__GENERATED__.js +0 -18
- 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
|
|
22
|
-
mm-snap eval
|
|
23
|
-
mm-snap init
|
|
24
|
-
mm-snap manifest
|
|
25
|
-
mm-snap serve
|
|
26
|
-
mm-snap watch
|
|
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 @@
|
|
|
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"]}
|
package/dist/builders.d.ts
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
-
|
|
133
|
-
|
|
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;
|
package/dist/builders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":";;;AAsBA,IAAY,kBAIX;AAJD,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B,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"]}
|
package/dist/cmds/init/index.js
CHANGED
|
@@ -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,+
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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)(
|
|
49
|
+
(0, utils_1.logError)('Init Error: Failed to create template, cleaning...');
|
|
65
50
|
throw err;
|
|
66
51
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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,
|
|
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,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C,CAAC;QAC9C,MAAM,IAAA,mBAAO,EAAC,cAAc,CAAC,CAAC;KAC/B;IAED,MAAM,YAAY,GAAG,cAAS,CAAC,IAAI,CAAC,cAAc,EAAE,yBAAa,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
|
-
|
|
2
|
-
|
|
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
|
-
*
|
|
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
|
|
11
|
-
* @returns The contents of the `package.json` file.
|
|
6
|
+
* @param directory - The desination folder.
|
|
12
7
|
*/
|
|
13
|
-
export declare function
|
|
8
|
+
export declare function prepareWorkingDirectory(directory: string): Promise<void>;
|
|
14
9
|
/**
|
|
15
|
-
*
|
|
10
|
+
* Clones the template in a directory.
|
|
16
11
|
*
|
|
17
|
-
* @param
|
|
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
|
|
23
|
-
dist: string;
|
|
24
|
-
outfileName: string;
|
|
25
|
-
src: string;
|
|
26
|
-
}]>;
|
|
14
|
+
export declare function cloneTemplate(directory: string): Promise<void>;
|
|
27
15
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
|
27
|
+
export declare function isInGitRepository(directory: string): boolean;
|
|
32
28
|
/**
|
|
33
|
-
*
|
|
34
|
-
* will be updated if previous was not correct.
|
|
29
|
+
* Init a git repository.
|
|
35
30
|
*
|
|
36
|
-
* @param
|
|
37
|
-
* @returns Modified Yargs arguments object.
|
|
31
|
+
* @param directory - The directory to init.
|
|
38
32
|
*/
|
|
39
|
-
export declare function
|
|
33
|
+
export declare function gitInit(directory: string): Promise<void>;
|
|
40
34
|
/**
|
|
41
|
-
*
|
|
35
|
+
* Install dependencies in a yarn project.
|
|
42
36
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @returns True or false.
|
|
37
|
+
* @param directory - The directory containing the project.
|
|
45
38
|
*/
|
|
46
|
-
export declare function
|
|
39
|
+
export declare function yarnInstall(directory: string): Promise<void>;
|