@metamask/snaps-cli 0.33.0-flask.1 → 0.34.0-flask.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -59
- package/README.md +5 -6
- package/dist/cmds/index.js +1 -2
- package/dist/cmds/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -5
- package/dist/cmds/init/index.d.ts +0 -9
- package/dist/cmds/init/index.js +0 -34
- package/dist/cmds/init/index.js.map +0 -1
- package/dist/cmds/init/initHandler.d.ts +0 -26
- package/dist/cmds/init/initHandler.js +0 -69
- package/dist/cmds/init/initHandler.js.map +0 -1
- package/dist/cmds/init/initUtils.d.ts +0 -39
- package/dist/cmds/init/initUtils.js +0 -122
- package/dist/cmds/init/initUtils.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.34.0-flask.1]
|
|
10
|
+
### Removed
|
|
11
|
+
- **BREAKING:** Remove `init` command ([#1268](https://github.com/MetaMask/snaps/pull/1268))
|
|
12
|
+
|
|
13
|
+
## [0.33.1-flask.1]
|
|
14
|
+
### Changed
|
|
15
|
+
- No changes this release.
|
|
16
|
+
|
|
9
17
|
## [0.33.0-flask.1]
|
|
10
18
|
### Changed
|
|
11
19
|
- Support ES2022 features ([#1373](https://github.com/MetaMask/snaps-monorepo/pull/1373))
|
|
@@ -326,62 +334,64 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
326
334
|
- Example snaps ([#72](https://github.com/MetaMask/snaps-monorepo/pull/72))
|
|
327
335
|
- The examples now live in their own package, [`@metamask/snap-examples`](https://npmjs.com/package/@metamask/snap-examples).
|
|
328
336
|
|
|
329
|
-
[Unreleased]: https://github.com/MetaMask/snaps
|
|
330
|
-
[0.
|
|
331
|
-
[0.
|
|
332
|
-
[0.
|
|
333
|
-
[0.32.
|
|
334
|
-
[0.
|
|
335
|
-
[0.
|
|
336
|
-
[0.
|
|
337
|
-
[0.
|
|
338
|
-
[0.
|
|
339
|
-
[0.
|
|
340
|
-
[0.
|
|
341
|
-
[0.
|
|
342
|
-
[0.26.
|
|
343
|
-
[0.
|
|
344
|
-
[0.
|
|
345
|
-
[0.
|
|
346
|
-
[0.
|
|
347
|
-
[0.
|
|
348
|
-
[0.
|
|
349
|
-
[0.22.
|
|
350
|
-
[0.22.
|
|
351
|
-
[0.
|
|
352
|
-
[0.
|
|
353
|
-
[0.
|
|
354
|
-
[0.
|
|
355
|
-
[0.
|
|
356
|
-
[0.
|
|
357
|
-
[0.
|
|
358
|
-
[0.
|
|
359
|
-
[0.
|
|
360
|
-
[0.
|
|
361
|
-
[0.
|
|
362
|
-
[0.
|
|
363
|
-
[0.
|
|
364
|
-
[0.
|
|
365
|
-
[0.
|
|
366
|
-
[0.
|
|
367
|
-
[0.10.
|
|
368
|
-
[0.10.
|
|
369
|
-
[0.10.
|
|
370
|
-
[0.10.
|
|
371
|
-
[0.10.
|
|
372
|
-
[0.
|
|
373
|
-
[0.
|
|
374
|
-
[0.
|
|
375
|
-
[0.
|
|
376
|
-
[0.
|
|
377
|
-
[0.6.
|
|
378
|
-
[0.6.
|
|
379
|
-
[0.
|
|
380
|
-
[0.
|
|
381
|
-
[0.
|
|
382
|
-
[0.
|
|
383
|
-
[0.
|
|
384
|
-
[0.
|
|
385
|
-
[0.2.
|
|
386
|
-
[0.
|
|
387
|
-
[0.
|
|
337
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/v0.34.0-flask.1...HEAD
|
|
338
|
+
[0.34.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.1-flask.1...v0.34.0-flask.1
|
|
339
|
+
[0.33.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.0-flask.1...v0.33.1-flask.1
|
|
340
|
+
[0.33.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v0.33.0-flask.1
|
|
341
|
+
[0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
|
|
342
|
+
[0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
|
|
343
|
+
[0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
|
|
344
|
+
[0.31.0]: https://github.com/MetaMask/snaps/compare/v0.30.0...v0.31.0
|
|
345
|
+
[0.30.0]: https://github.com/MetaMask/snaps/compare/v0.29.0...v0.30.0
|
|
346
|
+
[0.29.0]: https://github.com/MetaMask/snaps/compare/v0.28.0...v0.29.0
|
|
347
|
+
[0.28.0]: https://github.com/MetaMask/snaps/compare/v0.27.1...v0.28.0
|
|
348
|
+
[0.27.1]: https://github.com/MetaMask/snaps/compare/v0.27.0...v0.27.1
|
|
349
|
+
[0.27.0]: https://github.com/MetaMask/snaps/compare/v0.26.2...v0.27.0
|
|
350
|
+
[0.26.2]: https://github.com/MetaMask/snaps/compare/v0.26.1...v0.26.2
|
|
351
|
+
[0.26.1]: https://github.com/MetaMask/snaps/compare/v0.26.0...v0.26.1
|
|
352
|
+
[0.26.0]: https://github.com/MetaMask/snaps/compare/v0.25.0...v0.26.0
|
|
353
|
+
[0.25.0]: https://github.com/MetaMask/snaps/compare/v0.24.1...v0.25.0
|
|
354
|
+
[0.24.1]: https://github.com/MetaMask/snaps/compare/v0.24.0...v0.24.1
|
|
355
|
+
[0.24.0]: https://github.com/MetaMask/snaps/compare/v0.23.0...v0.24.0
|
|
356
|
+
[0.23.0]: https://github.com/MetaMask/snaps/compare/v0.22.3...v0.23.0
|
|
357
|
+
[0.22.3]: https://github.com/MetaMask/snaps/compare/v0.22.2...v0.22.3
|
|
358
|
+
[0.22.2]: https://github.com/MetaMask/snaps/compare/v0.22.1...v0.22.2
|
|
359
|
+
[0.22.1]: https://github.com/MetaMask/snaps/compare/v0.22.0...v0.22.1
|
|
360
|
+
[0.22.0]: https://github.com/MetaMask/snaps/compare/v0.21.0...v0.22.0
|
|
361
|
+
[0.21.0]: https://github.com/MetaMask/snaps/compare/v0.20.0...v0.21.0
|
|
362
|
+
[0.20.0]: https://github.com/MetaMask/snaps/compare/v0.19.1...v0.20.0
|
|
363
|
+
[0.19.1]: https://github.com/MetaMask/snaps/compare/v0.19.0...v0.19.1
|
|
364
|
+
[0.19.0]: https://github.com/MetaMask/snaps/compare/v0.18.1...v0.19.0
|
|
365
|
+
[0.18.1]: https://github.com/MetaMask/snaps/compare/v0.18.0...v0.18.1
|
|
366
|
+
[0.18.0]: https://github.com/MetaMask/snaps/compare/v0.17.0...v0.18.0
|
|
367
|
+
[0.17.0]: https://github.com/MetaMask/snaps/compare/v0.16.0...v0.17.0
|
|
368
|
+
[0.16.0]: https://github.com/MetaMask/snaps/compare/v0.15.0...v0.16.0
|
|
369
|
+
[0.15.0]: https://github.com/MetaMask/snaps/compare/v0.14.0...v0.15.0
|
|
370
|
+
[0.14.0]: https://github.com/MetaMask/snaps/compare/v0.13.0...v0.14.0
|
|
371
|
+
[0.13.0]: https://github.com/MetaMask/snaps/compare/v0.12.0...v0.13.0
|
|
372
|
+
[0.12.0]: https://github.com/MetaMask/snaps/compare/v0.11.1...v0.12.0
|
|
373
|
+
[0.11.1]: https://github.com/MetaMask/snaps/compare/v0.11.0...v0.11.1
|
|
374
|
+
[0.11.0]: https://github.com/MetaMask/snaps/compare/v0.10.7...v0.11.0
|
|
375
|
+
[0.10.7]: https://github.com/MetaMask/snaps/compare/v0.10.6...v0.10.7
|
|
376
|
+
[0.10.6]: https://github.com/MetaMask/snaps/compare/v0.10.5...v0.10.6
|
|
377
|
+
[0.10.5]: https://github.com/MetaMask/snaps/compare/v0.10.3...v0.10.5
|
|
378
|
+
[0.10.3]: https://github.com/MetaMask/snaps/compare/v0.10.2...v0.10.3
|
|
379
|
+
[0.10.2]: https://github.com/MetaMask/snaps/compare/v0.10.1...v0.10.2
|
|
380
|
+
[0.10.1]: https://github.com/MetaMask/snaps/compare/v0.10.0...v0.10.1
|
|
381
|
+
[0.10.0]: https://github.com/MetaMask/snaps/compare/v0.9.0...v0.10.0
|
|
382
|
+
[0.9.0]: https://github.com/MetaMask/snaps/compare/v0.8.0...v0.9.0
|
|
383
|
+
[0.8.0]: https://github.com/MetaMask/snaps/compare/v0.7.0...v0.8.0
|
|
384
|
+
[0.7.0]: https://github.com/MetaMask/snaps/compare/v0.6.3...v0.7.0
|
|
385
|
+
[0.6.3]: https://github.com/MetaMask/snaps/compare/v0.6.2...v0.6.3
|
|
386
|
+
[0.6.2]: https://github.com/MetaMask/snaps/compare/v0.6.1...v0.6.2
|
|
387
|
+
[0.6.1]: https://github.com/MetaMask/snaps/compare/v0.6.0...v0.6.1
|
|
388
|
+
[0.6.0]: https://github.com/MetaMask/snaps/compare/v0.5.0...v0.6.0
|
|
389
|
+
[0.5.0]: https://github.com/MetaMask/snaps/compare/v0.4.0...v0.5.0
|
|
390
|
+
[0.4.0]: https://github.com/MetaMask/snaps/compare/v0.3.1...v0.4.0
|
|
391
|
+
[0.3.1]: https://github.com/MetaMask/snaps/compare/v0.3.0...v0.3.1
|
|
392
|
+
[0.3.0]: https://github.com/MetaMask/snaps/compare/v0.2.2...v0.3.0
|
|
393
|
+
[0.2.2]: https://github.com/MetaMask/snaps/compare/v0.2.1...v0.2.2
|
|
394
|
+
[0.2.1]: https://github.com/MetaMask/snaps/compare/v0.2.0...v0.2.1
|
|
395
|
+
[0.2.0]: https://github.com/MetaMask/snaps/compare/v0.1.1...v0.2.0
|
|
396
|
+
[0.1.1]: https://github.com/MetaMask/snaps/compare/v0.1.0...v0.1.1
|
|
397
|
+
[0.1.0]: https://github.com/MetaMask/snaps/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -18,12 +18,11 @@ 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
|
|
24
|
-
mm-snap
|
|
25
|
-
mm-snap
|
|
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 manifest Validate the snap.manifest.json file [aliases: m]
|
|
24
|
+
mm-snap serve Locally serve Snap file(s) for testing [aliases: s]
|
|
25
|
+
mm-snap watch Build Snap on change [aliases: w]
|
|
27
26
|
|
|
28
27
|
Options:
|
|
29
28
|
--version Show version number [boolean]
|
package/dist/cmds/index.js
CHANGED
|
@@ -5,10 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const build_1 = __importDefault(require("./build"));
|
|
7
7
|
const eval_1 = __importDefault(require("./eval"));
|
|
8
|
-
const init_1 = __importDefault(require("./init"));
|
|
9
8
|
const manifest_1 = __importDefault(require("./manifest"));
|
|
10
9
|
const serve_1 = __importDefault(require("./serve"));
|
|
11
10
|
const watch_1 = __importDefault(require("./watch"));
|
|
12
|
-
const commands = [build_1.default, eval_1.default,
|
|
11
|
+
const commands = [build_1.default, eval_1.default, manifest_1.default, serve_1.default, watch_1.default];
|
|
13
12
|
exports.default = commands;
|
|
14
13
|
//# sourceMappingURL=index.js.map
|
package/dist/cmds/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmds/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,kDAA8B;AAC9B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmds/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,kDAA8B;AAC9B,0DAAkC;AAClC,oDAA4B;AAC5B,oDAA4B;AAE5B,MAAM,QAAQ,GAAG,CAAC,eAAK,EAAE,cAAQ,EAAE,kBAAQ,EAAE,eAAK,EAAE,eAAK,CAAC,CAAC;AAC3D,kBAAe,QAAQ,CAAC","sourcesContent":["import build from './build';\nimport evaluate from './eval';\nimport manifest from './manifest';\nimport serve from './serve';\nimport watch from './watch';\n\nconst commands = [build, evaluate, manifest, serve, watch];\nexport default commands;\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as utils from './utils';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.utils = void 0;
|
|
27
|
+
exports.utils = __importStar(require("./utils"));
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAiC","sourcesContent":["export * as utils from './utils';\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0-flask.1",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/MetaMask/snaps
|
|
7
|
+
"url": "https://github.com/MetaMask/snaps.git"
|
|
8
8
|
},
|
|
9
9
|
"license": "ISC",
|
|
10
|
+
"main": "dist/index.js",
|
|
10
11
|
"bin": {
|
|
11
12
|
"mm-snap": "./dist/main.js"
|
|
12
13
|
},
|
|
@@ -44,9 +45,9 @@
|
|
|
44
45
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
45
46
|
"@babel/preset-env": "^7.20.12",
|
|
46
47
|
"@babel/preset-typescript": "^7.20.12",
|
|
47
|
-
"@metamask/snaps-browserify-plugin": "^0.
|
|
48
|
-
"@metamask/snaps-utils": "^0.
|
|
49
|
-
"@metamask/utils": "^
|
|
48
|
+
"@metamask/snaps-browserify-plugin": "^0.34.0-flask.1",
|
|
49
|
+
"@metamask/snaps-utils": "^0.34.0-flask.1",
|
|
50
|
+
"@metamask/utils": "^6.0.0",
|
|
50
51
|
"babelify": "^10.0.0",
|
|
51
52
|
"browserify": "^17.0.0",
|
|
52
53
|
"chokidar": "^3.5.2",
|
package/dist/cmds/init/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
|
-
const builders_1 = __importDefault(require("../../builders"));
|
|
7
|
-
const buildHandler_1 = require("../build/buildHandler");
|
|
8
|
-
const initHandler_1 = require("./initHandler");
|
|
9
|
-
/**
|
|
10
|
-
* The main entrypoint for the init command. This calls the init handler to
|
|
11
|
-
* initialize the snap package, builds the snap, and then updates the manifest
|
|
12
|
-
* with the shasum of the built snap.
|
|
13
|
-
*
|
|
14
|
-
* @param argv - The Yargs arguments object.
|
|
15
|
-
*/
|
|
16
|
-
async function init(argv) {
|
|
17
|
-
const newArgs = await (0, initHandler_1.initHandler)(argv);
|
|
18
|
-
process.chdir(newArgs.snapLocation);
|
|
19
|
-
await (0, buildHandler_1.build)({
|
|
20
|
-
...newArgs,
|
|
21
|
-
manifest: false,
|
|
22
|
-
eval: true,
|
|
23
|
-
});
|
|
24
|
-
(0, snaps_utils_1.logInfo)('\nSnap project successfully initiated!');
|
|
25
|
-
}
|
|
26
|
-
module.exports = {
|
|
27
|
-
command: ['init [directory]', 'i [directory]'],
|
|
28
|
-
desc: 'Initialize Snap package',
|
|
29
|
-
builder: (yarg) => {
|
|
30
|
-
yarg.positional('directory', builders_1.default.directory);
|
|
31
|
-
},
|
|
32
|
-
handler: async (argv) => init(argv),
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cmds/init/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAgD;AAGhD,8DAAsC;AAEtC,wDAA8C;AAC9C,+CAA4C;AAW5C;;;;;;GAMG;AACH,KAAK,UAAU,IAAI,CAAC,IAAe;IACjC,MAAM,OAAO,GAAG,MAAM,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC;IAExC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEpC,MAAM,IAAA,oBAAK,EAAC;QACV,GAAG,OAAO;QACV,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,IAAI;KACX,CAAC,CAAC;IAEH,IAAA,qBAAO,EAAC,wCAAwC,CAAC,CAAC;AACpD,CAAC;AA5BD,iBAAS;IACP,OAAO,EAAE,CAAC,kBAAkB,EAAE,eAAe,CAAC;IAC9C,IAAI,EAAE,yBAAyB;IAC/B,OAAO,EAAE,CAAC,IAAgB,EAAE,EAAE;QAC5B,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,kBAAQ,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;CAC/C,CAAC","sourcesContent":["import { logInfo } from '@metamask/snaps-utils';\nimport yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from '../build/buildHandler';\nimport { initHandler } from './initHandler';\n\nexport = {\n command: ['init [directory]', 'i [directory]'],\n desc: 'Initialize Snap package',\n builder: (yarg: yargs.Argv) => {\n yarg.positional('directory', builders.directory);\n },\n handler: async (argv: YargsArgs) => init(argv),\n};\n\n/**\n * The main entrypoint for the init command. This calls the init handler to\n * initialize the snap package, builds the snap, and then updates the manifest\n * with the shasum of the built snap.\n *\n * @param argv - The Yargs arguments object.\n */\nasync function init(argv: YargsArgs): Promise<void> {\n const newArgs = await initHandler(argv);\n\n process.chdir(newArgs.snapLocation);\n\n await build({\n ...newArgs,\n manifest: false,\n eval: true,\n });\n\n logInfo('\\nSnap project successfully initiated!');\n}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { YargsArgs } from '../../types/yargs';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a new snap package, based on one of the provided templates. This
|
|
4
|
-
* creates all the necessary files, like `package.json`, `snap.config.js`, etc.
|
|
5
|
-
* to start developing a snap.
|
|
6
|
-
*
|
|
7
|
-
* @param argv - The Yargs arguments object.
|
|
8
|
-
* @returns The Yargs arguments augmented with the new `dist`, `outfileName` and
|
|
9
|
-
* `src` properties.
|
|
10
|
-
* @throws If initialization of the snap package failed.
|
|
11
|
-
*/
|
|
12
|
-
export declare function initHandler(argv: YargsArgs): Promise<{
|
|
13
|
-
dist: string;
|
|
14
|
-
outfileName: string;
|
|
15
|
-
src: string;
|
|
16
|
-
snapLocation: string;
|
|
17
|
-
sourceMaps: boolean;
|
|
18
|
-
stripComments: boolean;
|
|
19
|
-
transformHtmlComments: boolean;
|
|
20
|
-
port: number;
|
|
21
|
-
eval: boolean;
|
|
22
|
-
serve: boolean;
|
|
23
|
-
directory?: string | undefined;
|
|
24
|
-
_?: (string | number)[] | undefined;
|
|
25
|
-
$0?: string | undefined;
|
|
26
|
-
}>;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initHandler = void 0;
|
|
7
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
-
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const initUtils_1 = require("./initUtils");
|
|
12
|
-
const SATISFIED_VERSION = '>=16';
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new snap package, based on one of the provided templates. This
|
|
15
|
-
* creates all the necessary files, like `package.json`, `snap.config.js`, etc.
|
|
16
|
-
* to start developing a snap.
|
|
17
|
-
*
|
|
18
|
-
* @param argv - The Yargs arguments object.
|
|
19
|
-
* @returns The Yargs arguments augmented with the new `dist`, `outfileName` and
|
|
20
|
-
* `src` properties.
|
|
21
|
-
* @throws If initialization of the snap package failed.
|
|
22
|
-
*/
|
|
23
|
-
async function initHandler(argv) {
|
|
24
|
-
const { directory } = argv;
|
|
25
|
-
const isVersionSupported = (0, utils_1.satisfiesVersionRange)(process.version, SATISFIED_VERSION);
|
|
26
|
-
if (!isVersionSupported) {
|
|
27
|
-
throw new Error(`Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`);
|
|
28
|
-
}
|
|
29
|
-
const gitExists = (0, initUtils_1.isGitInstalled)();
|
|
30
|
-
if (!gitExists) {
|
|
31
|
-
throw new Error(`Init Error: git is not installed. Please install git to continue.`);
|
|
32
|
-
}
|
|
33
|
-
const directoryToUse = directory
|
|
34
|
-
? path_1.default.resolve(process.cwd(), directory)
|
|
35
|
-
: process.cwd();
|
|
36
|
-
(0, snaps_utils_1.logInfo)(`Preparing ${directoryToUse}...`);
|
|
37
|
-
await (0, initUtils_1.prepareWorkingDirectory)(directoryToUse);
|
|
38
|
-
try {
|
|
39
|
-
(0, snaps_utils_1.logInfo)(`Cloning template...`);
|
|
40
|
-
(0, initUtils_1.cloneTemplate)(directoryToUse);
|
|
41
|
-
await fs_1.promises.rm(path_1.default.join(directoryToUse, '.git'), {
|
|
42
|
-
force: true,
|
|
43
|
-
recursive: true,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
throw new Error('Init Error: Failed to create template.');
|
|
48
|
-
}
|
|
49
|
-
(0, snaps_utils_1.logInfo)('Installing dependencies...');
|
|
50
|
-
(0, initUtils_1.yarnInstall)(directoryToUse);
|
|
51
|
-
if (!(0, initUtils_1.isInGitRepository)(directoryToUse)) {
|
|
52
|
-
(0, snaps_utils_1.logInfo)('Initializing git repository...');
|
|
53
|
-
(0, initUtils_1.gitInit)(directoryToUse);
|
|
54
|
-
}
|
|
55
|
-
const snapLocation = path_1.default.join(directoryToUse, initUtils_1.SNAP_LOCATION);
|
|
56
|
-
const manifest = (await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.Manifest))).result;
|
|
57
|
-
const validatedManifest = (0, snaps_utils_1.createSnapManifest)(manifest);
|
|
58
|
-
const packageJson = (await (0, snaps_utils_1.readJsonFile)(path_1.default.join(snapLocation, snaps_utils_1.NpmSnapFileNames.PackageJson))).result;
|
|
59
|
-
const distPath = validatedManifest.source.location.npm.filePath.split('/');
|
|
60
|
-
return {
|
|
61
|
-
...argv,
|
|
62
|
-
dist: distPath[0],
|
|
63
|
-
outfileName: distPath[1],
|
|
64
|
-
src: packageJson.main || 'src/index.js',
|
|
65
|
-
snapLocation,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
exports.initHandler = initHandler;
|
|
69
|
-
//# sourceMappingURL=initHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initHandler.js","sourceRoot":"","sources":["../../../src/cmds/init/initHandler.ts"],"names":[],"mappings":";;;;;;AAAA,uDAM+B;AAC/B,2CAIyB;AACzB,2BAAoC;AACpC,gDAA6B;AAG7B,2CAQqB;AAErB,MAAM,iBAAiB,GAAG,MAAqB,CAAC;AAEhD;;;;;;;;;GASG;AACI,KAAK,UAAU,WAAW,CAAC,IAAe;IAC/C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAE3B,MAAM,kBAAkB,GAAG,IAAA,6BAAqB,EAC9C,OAAO,CAAC,OAAwB,EAChC,iBAAiB,CAClB,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CACb,0DAA0D,OAAO,CAAC,OAAO,4BAA4B,iBAAiB,GAAG,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,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC;QAC7C,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAElB,IAAA,qBAAO,EAAC,aAAa,cAAc,KAAK,CAAC,CAAC;IAE1C,MAAM,IAAA,mCAAuB,EAAC,cAAc,CAAC,CAAC;IAE9C,IAAI;QACF,IAAA,qBAAO,EAAC,qBAAqB,CAAC,CAAC;QAC/B,IAAA,yBAAa,EAAC,cAAc,CAAC,CAAC;QAE9B,MAAM,aAAE,CAAC,EAAE,CAAC,cAAS,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE;YAClD,KAAK,EAAE,IAAI;YACX,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,IAAA,qBAAO,EAAC,4BAA4B,CAAC,CAAC;IACtC,IAAA,uBAAW,EAAC,cAAc,CAAC,CAAC;IAE5B,IAAI,CAAC,IAAA,6BAAiB,EAAC,cAAc,CAAC,EAAE;QACtC,IAAA,qBAAO,EAAC,gCAAgC,CAAC,CAAC;QAC1C,IAAA,mBAAO,EAAC,cAAc,CAAC,CAAC;KACzB;IAED,MAAM,YAAY,GAAG,cAAS,CAAC,IAAI,CAAC,cAAc,EAAE,yBAAa,CAAC,CAAC;IAEnE,MAAM,QAAQ,GAAG,CACf,MAAM,IAAA,0BAAY,EAAC,cAAS,CAAC,IAAI,CAAC,YAAY,EAAE,8BAAgB,CAAC,QAAQ,CAAC,CAAC,CAC5E,CAAC,MAAM,CAAC;IAET,MAAM,iBAAiB,GAAG,IAAA,gCAAkB,EAAC,QAAQ,CAAC,CAAC;IAEvD,MAAM,WAAW,GAAG,CAClB,MAAM,IAAA,0BAAY,EAChB,cAAS,CAAC,IAAI,CAAC,YAAY,EAAE,8BAAgB,CAAC,WAAW,CAAC,CAC3D,CACF,CAAC,MAA4B,CAAC;IAE/B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE3E,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;QACjB,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;QACxB,GAAG,EAAE,WAAW,CAAC,IAAI,IAAI,cAAc;QACvC,YAAY;KACb,CAAC;AACJ,CAAC;AAxED,kCAwEC","sourcesContent":["import {\n NpmSnapFileNames,\n readJsonFile,\n NpmSnapPackageJson,\n createSnapManifest,\n logInfo,\n} from '@metamask/snaps-utils';\nimport {\n satisfiesVersionRange,\n SemVerRange,\n SemVerVersion,\n} from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { YargsArgs } from '../../types/yargs';\nimport {\n cloneTemplate,\n gitInit,\n isGitInstalled,\n isInGitRepository,\n prepareWorkingDirectory,\n SNAP_LOCATION,\n yarnInstall,\n} from './initUtils';\n\nconst SATISFIED_VERSION = '>=16' as SemVerRange;\n\n/**\n * Creates a new snap package, based on one of the provided templates. This\n * creates all the necessary files, like `package.json`, `snap.config.js`, etc.\n * to start developing a snap.\n *\n * @param argv - The Yargs arguments object.\n * @returns The Yargs arguments augmented with the new `dist`, `outfileName` and\n * `src` properties.\n * @throws If initialization of the snap package failed.\n */\nexport async function initHandler(argv: YargsArgs) {\n const { directory } = argv;\n\n const isVersionSupported = satisfiesVersionRange(\n process.version as SemVerVersion,\n SATISFIED_VERSION,\n );\n\n if (!isVersionSupported) {\n throw new Error(\n `Init Error: You are using an outdated version of Node (${process.version}). Please update to Node ${SATISFIED_VERSION}.`,\n );\n }\n\n const gitExists = isGitInstalled();\n if (!gitExists) {\n throw new Error(\n `Init Error: git is not installed. Please install git to continue.`,\n );\n }\n\n const directoryToUse = directory\n ? pathUtils.resolve(process.cwd(), directory)\n : process.cwd();\n\n logInfo(`Preparing ${directoryToUse}...`);\n\n await prepareWorkingDirectory(directoryToUse);\n\n try {\n logInfo(`Cloning template...`);\n cloneTemplate(directoryToUse);\n\n await fs.rm(pathUtils.join(directoryToUse, '.git'), {\n force: true,\n recursive: true,\n });\n } catch (error) {\n throw new Error('Init Error: Failed to create template.');\n }\n\n logInfo('Installing dependencies...');\n yarnInstall(directoryToUse);\n\n if (!isInGitRepository(directoryToUse)) {\n logInfo('Initializing git repository...');\n gitInit(directoryToUse);\n }\n\n const snapLocation = pathUtils.join(directoryToUse, SNAP_LOCATION);\n\n const manifest = (\n await readJsonFile(pathUtils.join(snapLocation, NpmSnapFileNames.Manifest))\n ).result;\n\n const validatedManifest = createSnapManifest(manifest);\n\n const packageJson = (\n await readJsonFile(\n pathUtils.join(snapLocation, NpmSnapFileNames.PackageJson),\n )\n ).result as NpmSnapPackageJson;\n\n const distPath = validatedManifest.source.location.npm.filePath.split('/');\n\n return {\n ...argv,\n dist: distPath[0],\n outfileName: distPath[1],\n src: packageJson.main || 'src/index.js',\n snapLocation,\n };\n}\n"]}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export declare const TEMPLATE_GIT_URL = "https://github.com/MetaMask/template-snap-monorepo.git";
|
|
2
|
-
export declare const SNAP_LOCATION = "packages/snap/";
|
|
3
|
-
/**
|
|
4
|
-
* Checks if the destination folder exists and if it's empty. Otherwise create it.
|
|
5
|
-
*
|
|
6
|
-
* @param directory - The desination folder.
|
|
7
|
-
*/
|
|
8
|
-
export declare function prepareWorkingDirectory(directory: string): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Clones the template in a directory.
|
|
11
|
-
*
|
|
12
|
-
* @param directory - The directory to clone the template in.
|
|
13
|
-
*/
|
|
14
|
-
export declare function cloneTemplate(directory: string): void;
|
|
15
|
-
/**
|
|
16
|
-
* Check if git is installed.
|
|
17
|
-
*
|
|
18
|
-
* @returns True if git is installed, or false otherwise.
|
|
19
|
-
*/
|
|
20
|
-
export declare function isGitInstalled(): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Check if the actual working dir is a git repository.
|
|
23
|
-
*
|
|
24
|
-
* @param directory - The directory to check.
|
|
25
|
-
* @returns True if it's a git repository otherwise false.
|
|
26
|
-
*/
|
|
27
|
-
export declare function isInGitRepository(directory: string): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Init a git repository.
|
|
30
|
-
*
|
|
31
|
-
* @param directory - The directory to init.
|
|
32
|
-
*/
|
|
33
|
-
export declare function gitInit(directory: string): void;
|
|
34
|
-
/**
|
|
35
|
-
* Install dependencies in a yarn project.
|
|
36
|
-
*
|
|
37
|
-
* @param directory - The directory containing the project.
|
|
38
|
-
*/
|
|
39
|
-
export declare function yarnInstall(directory: string): void;
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.yarnInstall = exports.gitInit = exports.isInGitRepository = exports.isGitInstalled = exports.cloneTemplate = exports.prepareWorkingDirectory = exports.SNAP_LOCATION = exports.TEMPLATE_GIT_URL = void 0;
|
|
7
|
-
const child_process_1 = require("child_process");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
exports.TEMPLATE_GIT_URL = 'https://github.com/MetaMask/template-snap-monorepo.git';
|
|
11
|
-
exports.SNAP_LOCATION = 'packages/snap/';
|
|
12
|
-
/**
|
|
13
|
-
* Checks if the destination folder exists and if it's empty. Otherwise create it.
|
|
14
|
-
*
|
|
15
|
-
* @param directory - The desination folder.
|
|
16
|
-
*/
|
|
17
|
-
async function prepareWorkingDirectory(directory) {
|
|
18
|
-
try {
|
|
19
|
-
const isCurrentDirectory = directory === process.cwd();
|
|
20
|
-
if (!isCurrentDirectory) {
|
|
21
|
-
try {
|
|
22
|
-
await fs_1.promises.mkdir(directory, { recursive: true });
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
throw new Error('Init Error: Failed to create new directory.');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const existingFiles = await fs_1.promises.readdir(directory);
|
|
29
|
-
if (existingFiles.length > 0) {
|
|
30
|
-
throw new Error(`Directory ${directory} not empty.`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
throw new Error(`Init Error: Failed to prepare working directory with message: ${error.message}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.prepareWorkingDirectory = prepareWorkingDirectory;
|
|
38
|
-
/**
|
|
39
|
-
* Clones the template in a directory.
|
|
40
|
-
*
|
|
41
|
-
* @param directory - The directory to clone the template in.
|
|
42
|
-
*/
|
|
43
|
-
function cloneTemplate(directory) {
|
|
44
|
-
try {
|
|
45
|
-
(0, child_process_1.execSync)(`git clone --depth=1 ${exports.TEMPLATE_GIT_URL} ${directory}`, {
|
|
46
|
-
stdio: [2],
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
throw new Error('Init Error: Failed to clone the template.');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.cloneTemplate = cloneTemplate;
|
|
54
|
-
/**
|
|
55
|
-
* Check if git is installed.
|
|
56
|
-
*
|
|
57
|
-
* @returns True if git is installed, or false otherwise.
|
|
58
|
-
*/
|
|
59
|
-
function isGitInstalled() {
|
|
60
|
-
try {
|
|
61
|
-
(0, child_process_1.execSync)('git --version', { stdio: 'ignore' });
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.isGitInstalled = isGitInstalled;
|
|
69
|
-
/**
|
|
70
|
-
* Check if the actual working dir is a git repository.
|
|
71
|
-
*
|
|
72
|
-
* @param directory - The directory to check.
|
|
73
|
-
* @returns True if it's a git repository otherwise false.
|
|
74
|
-
*/
|
|
75
|
-
function isInGitRepository(directory) {
|
|
76
|
-
try {
|
|
77
|
-
(0, child_process_1.execSync)('git rev-parse --is-inside-work-tree', {
|
|
78
|
-
stdio: 'ignore',
|
|
79
|
-
cwd: path_1.default.resolve(__dirname, directory),
|
|
80
|
-
});
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.isInGitRepository = isInGitRepository;
|
|
88
|
-
/**
|
|
89
|
-
* Init a git repository.
|
|
90
|
-
*
|
|
91
|
-
* @param directory - The directory to init.
|
|
92
|
-
*/
|
|
93
|
-
function gitInit(directory) {
|
|
94
|
-
try {
|
|
95
|
-
(0, child_process_1.execSync)('git init', {
|
|
96
|
-
stdio: 'ignore',
|
|
97
|
-
cwd: path_1.default.resolve(__dirname, directory),
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
throw new Error('Init Error: Failed to init a new git repository.');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.gitInit = gitInit;
|
|
105
|
-
/**
|
|
106
|
-
* Install dependencies in a yarn project.
|
|
107
|
-
*
|
|
108
|
-
* @param directory - The directory containing the project.
|
|
109
|
-
*/
|
|
110
|
-
function yarnInstall(directory) {
|
|
111
|
-
try {
|
|
112
|
-
(0, child_process_1.execSync)('yarn install', {
|
|
113
|
-
stdio: [0, 1, 2],
|
|
114
|
-
cwd: directory,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
throw new Error('Init Error: Failed to install dependencies.');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.yarnInstall = yarnInstall;
|
|
122
|
-
//# sourceMappingURL=initUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initUtils.js","sourceRoot":"","sources":["../../../src/cmds/init/initUtils.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAyC;AACzC,2BAAoC;AACpC,gDAA6B;AAEhB,QAAA,gBAAgB,GAC3B,wDAAwD,CAAC;AAE9C,QAAA,aAAa,GAAG,gBAAgB,CAAC;AAE9C;;;;GAIG;AACI,KAAK,UAAU,uBAAuB,CAC3C,SAAiB;IAEjB,IAAI;QACF,MAAM,kBAAkB,GAAG,SAAS,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC;QAEvD,IAAI,CAAC,kBAAkB,EAAE;YACvB,IAAI;gBACF,MAAM,aAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;aAChD;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;aAChE;SACF;QAED,MAAM,aAAa,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,aAAa,SAAS,aAAa,CAAC,CAAC;SACtD;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CACb,iEAAiE,KAAK,CAAC,OAAO,EAAE,CACjF,CAAC;KACH;AACH,CAAC;AAxBD,0DAwBC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,SAAiB;IAC7C,IAAI;QACF,IAAA,wBAAQ,EAAC,uBAAuB,wBAAgB,IAAI,SAAS,EAAE,EAAE;YAC/D,KAAK,EAAE,CAAC,CAAC,CAAC;SACX,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;AACH,CAAC;AARD,sCAQC;AAED;;;;GAIG;AACH,SAAgB,cAAc;IAC5B,IAAI;QACF,IAAA,wBAAQ,EAAC,eAAe,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wCAOC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,SAAiB;IACjD,IAAI;QACF,IAAA,wBAAQ,EAAC,qCAAqC,EAAE;YAC9C,KAAK,EAAE,QAAQ;YACf,GAAG,EAAE,cAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7C,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAVD,8CAUC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,SAAiB;IACvC,IAAI;QACF,IAAA,wBAAQ,EAAC,UAAU,EAAE;YACnB,KAAK,EAAE,QAAQ;YACf,GAAG,EAAE,cAAS,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;SAC7C,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;KACrE;AACH,CAAC;AATD,0BASC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,SAAiB;IAC3C,IAAI;QACF,IAAA,wBAAQ,EAAC,cAAc,EAAE;YACvB,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAChB,GAAG,EAAE,SAAS;SACf,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAChE;AACH,CAAC;AATD,kCASC","sourcesContent":["import { execSync } from 'child_process';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nexport const TEMPLATE_GIT_URL =\n 'https://github.com/MetaMask/template-snap-monorepo.git';\n\nexport const SNAP_LOCATION = 'packages/snap/';\n\n/**\n * Checks if the destination folder exists and if it's empty. Otherwise create it.\n *\n * @param directory - The desination folder.\n */\nexport async function prepareWorkingDirectory(\n directory: string,\n): Promise<void> {\n try {\n const isCurrentDirectory = directory === process.cwd();\n\n if (!isCurrentDirectory) {\n try {\n await fs.mkdir(directory, { recursive: true });\n } catch (error) {\n throw new Error('Init Error: Failed to create new directory.');\n }\n }\n\n const existingFiles = await fs.readdir(directory);\n\n if (existingFiles.length > 0) {\n throw new Error(`Directory ${directory} not empty.`);\n }\n } catch (error) {\n throw new Error(\n `Init Error: Failed to prepare working directory with message: ${error.message}`,\n );\n }\n}\n\n/**\n * Clones the template in a directory.\n *\n * @param directory - The directory to clone the template in.\n */\nexport function cloneTemplate(directory: string) {\n try {\n execSync(`git clone --depth=1 ${TEMPLATE_GIT_URL} ${directory}`, {\n stdio: [2],\n });\n } catch (error) {\n throw new Error('Init Error: Failed to clone the template.');\n }\n}\n\n/**\n * Check if git is installed.\n *\n * @returns True if git is installed, or false otherwise.\n */\nexport function isGitInstalled() {\n try {\n execSync('git --version', { stdio: 'ignore' });\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Check if the actual working dir is a git repository.\n *\n * @param directory - The directory to check.\n * @returns True if it's a git repository otherwise false.\n */\nexport function isInGitRepository(directory: string) {\n try {\n execSync('git rev-parse --is-inside-work-tree', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Init a git repository.\n *\n * @param directory - The directory to init.\n */\nexport function gitInit(directory: string) {\n try {\n execSync('git init', {\n stdio: 'ignore',\n cwd: pathUtils.resolve(__dirname, directory),\n });\n } catch (error) {\n throw new Error('Init Error: Failed to init a new git repository.');\n }\n}\n\n/**\n * Install dependencies in a yarn project.\n *\n * @param directory - The directory containing the project.\n */\nexport function yarnInstall(directory: string) {\n try {\n execSync('yarn install', {\n stdio: [0, 1, 2],\n cwd: directory,\n });\n } catch (error) {\n throw new Error('Init Error: Failed to install dependencies.');\n }\n}\n"]}
|