@metamask/snaps-cli 0.5.0 → 0.6.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/CHANGELOG.md +13 -1
- package/README.md +65 -104
- package/dist/builders.d.ts +17 -2
- package/dist/builders.js +4 -6
- package/dist/builders.js.map +1 -1
- package/dist/cli.d.ts +0 -7
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/cmds/build/buildHandler.js +1 -1
- package/dist/cmds/build/buildHandler.js.map +1 -1
- package/dist/cmds/build/index.js +2 -3
- package/dist/cmds/build/index.js.map +1 -1
- package/dist/cmds/eval/eval-worker.js +4 -1
- package/dist/cmds/eval/eval-worker.js.map +1 -1
- package/dist/cmds/init/index.js +3 -2
- package/dist/cmds/init/index.js.map +1 -1
- package/dist/cmds/init/init-template.json +2 -2
- package/dist/cmds/init/initHandler.d.ts +6 -1
- package/dist/cmds/init/initHandler.js +50 -33
- package/dist/cmds/init/initHandler.js.map +1 -1
- package/dist/cmds/init/initUtils.d.ts +28 -11
- package/dist/cmds/init/initUtils.js +158 -91
- package/dist/cmds/init/initUtils.js.map +1 -1
- package/dist/cmds/manifest/index.js +3 -6
- package/dist/cmds/manifest/index.js.map +1 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +15 -3
- package/dist/cmds/manifest/manifestHandler.js +180 -147
- package/dist/cmds/manifest/manifestHandler.js.map +1 -1
- package/dist/cmds/watch/watchHandler.js +2 -0
- package/dist/cmds/watch/watchHandler.js.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/tsconfig.json +3 -0
- package/dist/utils/fs.d.ts +10 -2
- package/dist/utils/fs.js +16 -3
- package/dist/utils/fs.js.map +1 -1
- package/dist/utils/misc.d.ts +4 -3
- package/dist/utils/misc.js +6 -4
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/snap-config.js +12 -17
- package/dist/utils/snap-config.js.map +1 -1
- package/dist/utils/validate-fs.d.ts +1 -1
- package/dist/utils/validate-fs.js +1 -1
- package/dist/utils/validate-fs.js.map +1 -1
- package/package.json +10 -2
package/dist/utils/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AAGX,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA4C;AAC5C,gDAAwB;AACxB,gDAAwB;AAGX,QAAA,SAAS,GAAG,cAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAEnD,QAAA,eAAe,GAAG;IAC7B,UAAU;IACV,IAAI;IACJ,kBAAkB;IAClB,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;CACR,CAAC;AAEW,QAAA,WAAW,GAAG,kBAAkB,CAAC;AAE9C,4CAA4C;AAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK;IACL,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ;IACR,GAAG;IACH,MAAM;IACN,GAAG;CACJ,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,IAAe;IAC5C,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC,EAAE;QAChD,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;KAChC;SAAM;QACL,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;KACjC;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,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AC,gBAAgB,EAAE;QACzC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClB,IAAI,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE;YACvC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACtB;KACF;AACH,CAAC;AAPD,gCAOC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,GAAW,EACX,GAAU,EACV,YAAqB;IAErB,IAAI,eAAe,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACzB,eAAe,IAAI,GAAG,CAAC;KACxB;IAED,QAAQ,CAAC,eAAe,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,IAAI;QACF,IAAI,YAAY,EAAE;YAChB,MAAM,aAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SACvC;KACF;IAAC,OAAO,WAAW,EAAE;QACpB,QAAQ,CAAC,GAAG,eAAe,gCAAgC,EAAE,WAAW,CAAC,CAAC;KAC3E;IAED,qCAAqC;IACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE;QAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AAxBD,gCAwBC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,UAAkB;IAC/C,OAAO,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import { promises as filesystem } from 'fs';\nimport path from 'path';\nimport rfdc from 'rfdc';\nimport { Arguments } from 'yargs';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n\nexport const permRequestKeys = [\n '@context',\n 'id',\n 'parentCapability',\n 'invoker',\n 'date',\n 'caveats',\n 'proof',\n];\n\nexport const CONFIG_FILE = 'snap.config.json';\n\n// CLI arguments whose values are file paths\nconst pathArguments = new Set([\n 'src',\n 's',\n 'dist',\n 'd',\n 'bundle',\n 'b',\n 'root',\n 'r',\n]);\n\n/**\n * Sets global variable snaps which tracks user settings:\n * watch mode activation, verbose errors messages, and whether to suppress warnings.\n *\n * @param argv - arguments as an object generated by yargs\n */\nexport function setSnapGlobals(argv: Arguments) {\n if (['w', 'watch'].includes(argv._[0] as string)) {\n global.snaps.isWatching = true;\n } else {\n global.snaps.isWatching = false;\n }\n\n if (Object.prototype.hasOwnProperty.call(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = Boolean(argv.verboseErrors);\n }\n\n if (Object.prototype.hasOwnProperty.call(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = Boolean(argv.suppressWarnings);\n }\n}\n\n/**\n * Sanitizes inputs. Currently normalizes \"./\" paths to \".\".\n * Yargs handles other path normalization as specified in builders.\n *\n * @param argv - arguments as an object generated by yargs\n */\nexport function sanitizeInputs(argv: Arguments) {\n Object.keys(argv).forEach((key) => {\n if (typeof argv[key] === 'string') {\n // Node's path.normalize() does not do this\n if (argv[key] === './') {\n argv[key] = '.';\n }\n\n if (pathArguments.has(key)) {\n argv[key] = path.normalize(argv[key] as string);\n }\n }\n });\n}\n\n/**\n * Logs an error message to console. Logs original error if it exists and\n * the verboseErrors global is true.\n *\n * @param msg - The error message\n * @param err - The original error\n */\nexport function logError(msg: string, err?: Error): void {\n console.error(msg);\n if (err && global.snaps.verboseErrors) {\n console.error(err);\n }\n}\n\n/**\n * Logs a warning message to console.\n *\n * @param msg - The warning message\n */\nexport function logWarning(msg: string, error?: Error): void {\n if (msg && !global.snaps.suppressWarnings) {\n console.warn(msg);\n if (error && global.snaps.verboseErrors) {\n console.error(error);\n }\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and exits.\n *\n * @param prefix - The message prefix\n * @param msg - The error message\n * @param err - The original error\n * @param destFilePath - The output file path\n */\nexport async function writeError(\n prefix: string,\n msg: string,\n err: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + msg, err);\n try {\n if (destFilePath) {\n await filesystem.unlink(destFilePath);\n }\n } catch (unlinkError) {\n logError(`${processedPrefix}Failed to unlink mangled file.`, unlinkError);\n }\n\n // unless the watcher is active, exit\n if (!global.snaps.isWatching) {\n process.exit(1);\n }\n}\n\n/**\n * Trims leading and trailing periods \".\" and forward slashes \"/\" from the\n * given path string.\n *\n * @param pathString - The path string to trim.\n * @returns - The trimmed path string.\n */\nexport function trimPathString(pathString: string): string {\n return pathString.replace(/^[./]+|[./]+$/gu, '');\n}\n"]}
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.applyConfig = void 0;
|
|
7
|
-
const fs_1 =
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
8
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
9
9
|
const builders_1 = __importDefault(require("../builders"));
|
|
10
10
|
const misc_1 = require("./misc");
|
|
@@ -45,21 +45,16 @@ function applyConfig(processArgv, yargsArgv, yargsInstance) {
|
|
|
45
45
|
};
|
|
46
46
|
// Now, we attempt to read and apply config from the config file, if any.
|
|
47
47
|
let cfg = {};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
catch (err) {
|
|
56
|
-
if (err.code === 'ENOENT') {
|
|
57
|
-
// If there's no config file, we're done here.
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
misc_1.logError(`Error: "${configPath}" exists but could not be parsed. Ensure your config file is valid JSON and try again.`, err);
|
|
61
|
-
process.exit(1);
|
|
48
|
+
try {
|
|
49
|
+
cfg = JSON.parse(fs_1.readFileSync(_1.CONFIG_FILE, 'utf8'));
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (err.code === 'ENOENT') {
|
|
53
|
+
// If there's no config file, we're done here.
|
|
54
|
+
return;
|
|
62
55
|
}
|
|
56
|
+
misc_1.logError(`Error: "${_1.CONFIG_FILE}" exists but could not be parsed. Ensure your config file is valid JSON and try again.`, err);
|
|
57
|
+
process.exit(1);
|
|
63
58
|
}
|
|
64
59
|
if (cfg && typeof cfg === 'object' && !Array.isArray(cfg)) {
|
|
65
60
|
for (const key of Object.keys(cfg)) {
|
|
@@ -69,14 +64,14 @@ function applyConfig(processArgv, yargsArgv, yargsInstance) {
|
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
else {
|
|
72
|
-
misc_1.logError(`Error: Encountered unrecognized config property "${key}" in config file "${
|
|
67
|
+
misc_1.logError(`Error: Encountered unrecognized config property "${key}" in config file "${_1.CONFIG_FILE}". Remove the property and try again.`);
|
|
73
68
|
process.exit(1);
|
|
74
69
|
}
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
else {
|
|
78
73
|
const cfgType = cfg === null ? 'null' : typeof cfg;
|
|
79
|
-
misc_1.logError(`Error: The config file must consist of a top-level JSON object. Received "${cfgType}" from "${
|
|
74
|
+
misc_1.logError(`Error: The config file must consist of a top-level JSON object. Received "${cfgType}" from "${_1.CONFIG_FILE}". Fix your config file and try again.`);
|
|
80
75
|
process.exit(1);
|
|
81
76
|
}
|
|
82
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"snap-config.js","sourceRoot":"","sources":["../../src/utils/snap-config.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAkC;AAGlC,gEAAsC;AACtC,2DAAmC;AACnC,iCAAkC;AAClC,wBAAgC;AAEhC,8EAA8E;AAC9E,6BAA6B;AAC7B,EAAE;AACF,wEAAwE;AACxE,4D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IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACzD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAClC,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,kBAAQ,EAAE,GAAG,CAAC,EAAE;gBAC7C,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;oBACrB,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;iBAC3B;aACF;iBAAM;gBACL,eAAQ,CACN,oDAAoD,GAAG,qBAAqB,cAAW,uCAAuC,CAC/H,CAAC;gBACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;SACF;KACF;SAAM;QACL,MAAM,OAAO,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC;QAEnD,eAAQ,CACN,6EAA6E,OAAO,WAAW,cAAW,wCAAwC,CACnJ,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AA3ED,kCA2EC","sourcesContent":["import { readFileSync } from 'fs';\nimport { Arguments } from 'yargs';\nimport yargs from 'yargs/yargs';\nimport yargsParse from 'yargs-parser';\nimport builders from '../builders';\nimport { logError } from './misc';\nimport { CONFIG_FILE } from '.';\n\n// Note that the below function is necessary because yarg's .config() function\n// leaves much to be desired.\n//\n// In particular, it will set all properties included in the config file\n// regardless of the command, which fails during validation.\n\n/**\n * Attempts to read configuration options for package.json and the config file,\n * and apply them to argv if they weren't already set.\n *\n * Arguments are only set per the snap-cli config file if they were not specified\n * on the command line.\n */\nexport function applyConfig(\n processArgv: string[],\n yargsArgv: Arguments,\n yargsInstance: typeof yargs,\n): void {\n // Instances of yargs has a number of undocumented functions, including\n // getOptions. This function returns an object with properties \"key\" and\n // \"alias\", which specify the options associated with the current command and\n // their aliases, respectively.\n //\n // We leverage this to ensure that the config is only applied to args that are\n // valid for the current command, and that weren't specified by the user on\n // the command line.\n //\n // If we set args that aren't valid for the current command, yargs will error\n // during validation.\n const { alias: aliases, key: options } = (\n yargsInstance as any\n ).getOptions() as {\n alias: Record<string, string[]>;\n key: Record<string, unknown>;\n };\n\n const parsedProcessArgv = yargsParse(processArgv, {\n alias: aliases,\n }) as Record<string, unknown>;\n delete parsedProcessArgv._; // irrelevant yargs parser artifact\n\n const commandOptions = new Set(Object.keys(options));\n\n const shouldSetArg = (key: string): boolean => {\n return (\n commandOptions.has(key) &&\n !Object.prototype.hasOwnProperty.call(parsedProcessArgv, key)\n );\n };\n\n // Now, we attempt to read and apply config from the config file, if any.\n let cfg: Record<string, unknown> = {};\n try {\n cfg = JSON.parse(readFileSync(CONFIG_FILE, 'utf8'));\n } catch (err) {\n if (err.code === 'ENOENT') {\n // If there's no config file, we're done here.\n return;\n }\n\n logError(\n `Error: \"${CONFIG_FILE}\" exists but could not be parsed. Ensure your config file is valid JSON and try again.`,\n err,\n );\n process.exit(1);\n }\n\n if (cfg && typeof cfg === 'object' && !Array.isArray(cfg)) {\n for (const key of Object.keys(cfg)) {\n if (Object.hasOwnProperty.call(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = cfg[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n process.exit(1);\n }\n }\n } else {\n const cfgType = cfg === null ? 'null' : typeof cfg;\n\n logError(\n `Error: The config file must consist of a top-level JSON object. Received \"${cfgType}\" from \"${CONFIG_FILE}\". Fix your config file and try again.`,\n );\n process.exit(1);\n }\n}\n"]}
|
|
@@ -25,7 +25,7 @@ export declare function validateOutfileName(filename: string): boolean;
|
|
|
25
25
|
export declare function validateFilePath(filePath: string): Promise<boolean>;
|
|
26
26
|
/**
|
|
27
27
|
* Validates a directory path.
|
|
28
|
-
* Throws on validation failure
|
|
28
|
+
* Throws on validation failure.
|
|
29
29
|
*
|
|
30
30
|
* @param dirPath - The directory path to validate
|
|
31
31
|
* @param createDir - Whether to create the directory if it doesn't exist
|
|
@@ -51,7 +51,7 @@ async function validateFilePath(filePath) {
|
|
|
51
51
|
exports.validateFilePath = validateFilePath;
|
|
52
52
|
/**
|
|
53
53
|
* Validates a directory path.
|
|
54
|
-
* Throws on validation failure
|
|
54
|
+
* Throws on validation failure.
|
|
55
55
|
*
|
|
56
56
|
* @param dirPath - The directory path to validate
|
|
57
57
|
* @param createDir - Whether to create the directory if it doesn't exist
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-fs.js","sourceRoot":"","sources":["../../src/utils/validate-fs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,6BAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,OAAO,cAAS,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,WAAW,CAAC,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACzB,QAAQ,KAAK,KAAK;QAClB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAC5B;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,sBAAsB,CAAC,CAAC;KAC1E;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AATD,kDASC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,MAAM,MAAM,GAAG,MAAM,WAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,QAAQ,oCAAoC,CACjE,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4CAQC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,gBAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0CAWC","sourcesContent":["import pathUtils from 'path';\nimport { isFile, isDirectory } from './fs';\n\n/**\n * Gets the complete out file path from the source file path and output\n * directory path.\n *\n * @param srcFilePath - The source file path\n * @param outDir - The out file directory\n * @returns - The complete out file path\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a js file name.\n * Throws on validation failure\n *\n * @param filename - The file name to validate\n * @returns - True if validation succeeded\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n filename.indexOf('/') !== -1\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path.\n * Throws on validation failure\n *\n * @param filePath - The file path to validate\n * @returns - True if validation succeeded\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path.\n * Throws on validation failure
|
|
1
|
+
{"version":3,"file":"validate-fs.js","sourceRoot":"","sources":["../../src/utils/validate-fs.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA6B;AAC7B,6BAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAc,EAAE,WAAmB;IAChE,OAAO,cAAS,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,IAAI,WAAW,CAAC,CAAC;AAC5D,CAAC;AAFD,wCAEC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QACzB,QAAQ,KAAK,KAAK;QAClB,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAC5B;QACA,MAAM,IAAI,KAAK,CAAC,yBAAyB,QAAQ,sBAAsB,CAAC,CAAC;KAC1E;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AATD,kDASC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,MAAM,MAAM,GAAG,MAAM,WAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,QAAQ,oCAAoC,CACjE,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4CAQC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,gBAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0CAWC","sourcesContent":["import pathUtils from 'path';\nimport { isFile, isDirectory } from './fs';\n\n/**\n * Gets the complete out file path from the source file path and output\n * directory path.\n *\n * @param srcFilePath - The source file path\n * @param outDir - The out file directory\n * @returns - The complete out file path\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a js file name.\n * Throws on validation failure\n *\n * @param filename - The file name to validate\n * @returns - True if validation succeeded\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n filename.indexOf('/') !== -1\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path.\n * Throws on validation failure\n *\n * @param filePath - The file path to validate\n * @returns - True if validation succeeded\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path.\n * Throws on validation failure.\n *\n * @param dirPath - The directory path to validate\n * @param createDir - Whether to create the directory if it doesn't exist\n * @returns - True if validation succeeded\n */\nexport async function validateDirPath(\n dirName: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirName, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirName}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"setup": "yarn install && yarn allow-scripts",
|
|
18
|
+
"shasum": "node ./scripts/computeSnapShasum.js",
|
|
18
19
|
"build:init-template": "node ./scripts/createInitTemplate.js",
|
|
19
20
|
"build:typescript": "tsc --project ./tsconfig.local.json",
|
|
20
21
|
"build:chmod": "chmod +x ./dist/main.js",
|
|
21
22
|
"build": "yarn build:init-template && yarn build:typescript && yarn build:chmod",
|
|
22
23
|
"build:clean": "yarn clean && yarn build",
|
|
24
|
+
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
|
|
23
25
|
"clean": "rimraf dist/*",
|
|
24
26
|
"test": "jest",
|
|
25
27
|
"test:watch": "jest --watch",
|
|
@@ -33,14 +35,17 @@
|
|
|
33
35
|
"publish:prep": "./scripts/publish-prep.sh"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
38
|
+
"@metamask/snap-controllers": "^0.6.0",
|
|
36
39
|
"browserify": "^17.0.0",
|
|
37
40
|
"chokidar": "^3.0.2",
|
|
38
41
|
"fast-deep-equal": "^2.0.1",
|
|
39
42
|
"init-package-json": "^1.10.3",
|
|
40
43
|
"is-url": "^1.2.4",
|
|
44
|
+
"mkdirp": "^1.0.4",
|
|
41
45
|
"rfdc": "^1.3.0",
|
|
42
46
|
"serve-handler": "^6.1.1",
|
|
43
|
-
"ses": "^0.
|
|
47
|
+
"ses": "^0.15.3",
|
|
48
|
+
"slash": "^3.0.0",
|
|
44
49
|
"strip-comments": "^2.0.1",
|
|
45
50
|
"yargs": "^16.2.0",
|
|
46
51
|
"yargs-parser": "^20.2.2"
|
|
@@ -56,6 +61,7 @@
|
|
|
56
61
|
"@types/init-package-json": "^1.10.0",
|
|
57
62
|
"@types/is-url": "^1.2.28",
|
|
58
63
|
"@types/jest": "^26.0.20",
|
|
64
|
+
"@types/mkdirp": "^1.0.2",
|
|
59
65
|
"@types/node": "^14.14.25",
|
|
60
66
|
"@types/rimraf": "^3.0.0",
|
|
61
67
|
"@types/serve-handler": "^6.1.0",
|
|
@@ -63,6 +69,7 @@
|
|
|
63
69
|
"@types/yargs": "^15.0.12",
|
|
64
70
|
"@typescript-eslint/eslint-plugin": "^4.28.1",
|
|
65
71
|
"@typescript-eslint/parser": "^4.28.1",
|
|
72
|
+
"clipboardy": "^2.3.0",
|
|
66
73
|
"eslint": "^7.30.0",
|
|
67
74
|
"eslint-config-prettier": "^8.3.0",
|
|
68
75
|
"eslint-plugin-import": "^2.23.4",
|
|
@@ -74,6 +81,7 @@
|
|
|
74
81
|
"rimraf": "^3.0.2",
|
|
75
82
|
"ts-jest": "^26.5.6",
|
|
76
83
|
"ts-node": "^9.1.1",
|
|
84
|
+
"tsc-watch": "^4.5.0",
|
|
77
85
|
"typescript": "^4.3.5"
|
|
78
86
|
},
|
|
79
87
|
"engines": {
|