@metamask/snaps-cli 0.34.0-flask.1 → 0.35.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 +13 -1
- package/dist/cjs/builders.js +149 -0
- package/dist/{builders.js.map → cjs/builders.js.map} +1 -1
- package/dist/cjs/cli.js +35 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/cmds/build/buildHandler.js +36 -0
- package/dist/cjs/cmds/build/buildHandler.js.map +1 -0
- package/dist/cjs/cmds/build/bundle.js +83 -0
- package/dist/{cmds → cjs/cmds}/build/bundle.js.map +1 -1
- package/dist/cjs/cmds/build/index.js +32 -0
- package/dist/cjs/cmds/build/index.js.map +1 -0
- package/dist/cjs/cmds/build/utils.js +79 -0
- package/dist/cjs/cmds/build/utils.js.map +1 -0
- package/dist/cjs/cmds/eval/evalHandler.js +24 -0
- package/dist/cjs/cmds/eval/evalHandler.js.map +1 -0
- package/dist/cjs/cmds/eval/index.js +31 -0
- package/dist/cjs/cmds/eval/index.js.map +1 -0
- package/dist/cjs/cmds/index.js +30 -0
- package/dist/cjs/cmds/index.js.map +1 -0
- package/dist/cjs/cmds/manifest/index.js +44 -0
- package/dist/cjs/cmds/manifest/index.js.map +1 -0
- package/dist/cjs/cmds/manifest/manifestHandler.js +46 -0
- package/dist/cjs/cmds/manifest/manifestHandler.js.map +1 -0
- package/dist/cjs/cmds/serve/index.js +31 -0
- package/dist/cjs/cmds/serve/index.js.map +1 -0
- package/dist/cjs/cmds/serve/serveHandler.js +62 -0
- package/dist/cjs/cmds/serve/serveHandler.js.map +1 -0
- package/dist/cjs/cmds/serve/serveUtils.js +37 -0
- package/dist/cjs/cmds/serve/serveUtils.js.map +1 -0
- package/dist/cjs/cmds/watch/index.js +32 -0
- package/dist/cjs/cmds/watch/index.js.map +1 -0
- package/dist/cjs/cmds/watch/watchHandler.js +91 -0
- package/dist/cjs/cmds/watch/watchHandler.js.map +1 -0
- package/dist/cjs/index.js +52 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/main.js +20 -0
- package/dist/cjs/main.js.map +1 -0
- package/dist/cjs/utils/index.js +21 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/misc.js +141 -0
- package/dist/cjs/utils/misc.js.map +1 -0
- package/dist/cjs/utils/snap-config.js +101 -0
- package/dist/cjs/utils/snap-config.js.map +1 -0
- package/dist/{builders.js → esm/builders.js} +27 -29
- package/dist/esm/builders.js.map +1 -0
- package/dist/esm/cli.js +26 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/esm/cmds/build/buildHandler.js +36 -0
- package/dist/esm/cmds/build/buildHandler.js.map +1 -0
- package/dist/{cmds → esm/cmds}/build/bundle.js +40 -39
- package/dist/esm/cmds/build/bundle.js.map +1 -0
- package/dist/esm/cmds/build/index.js +17 -0
- package/dist/esm/cmds/build/index.js.map +1 -0
- package/dist/{cmds → esm/cmds}/build/utils.js +22 -34
- package/dist/esm/cmds/build/utils.js.map +1 -0
- package/dist/esm/cmds/eval/evalHandler.js +20 -0
- package/dist/esm/cmds/eval/evalHandler.js.map +1 -0
- package/dist/esm/cmds/eval/index.js +16 -0
- package/dist/esm/cmds/eval/index.js.map +1 -0
- package/dist/esm/cmds/index.js +15 -0
- package/dist/esm/cmds/index.js.map +1 -0
- package/dist/esm/cmds/manifest/index.js +29 -0
- package/dist/esm/cmds/manifest/index.js.map +1 -0
- package/dist/esm/cmds/manifest/manifestHandler.js +43 -0
- package/dist/esm/cmds/manifest/manifestHandler.js.map +1 -0
- package/dist/esm/cmds/serve/index.js +16 -0
- package/dist/esm/cmds/serve/index.js.map +1 -0
- package/dist/esm/cmds/serve/serveHandler.js +54 -0
- package/dist/esm/cmds/serve/serveHandler.js.map +1 -0
- package/dist/esm/cmds/serve/serveUtils.js +30 -0
- package/dist/esm/cmds/serve/serveUtils.js.map +1 -0
- package/dist/esm/cmds/watch/index.js +17 -0
- package/dist/esm/cmds/watch/index.js.map +1 -0
- package/dist/esm/cmds/watch/watchHandler.js +87 -0
- package/dist/esm/cmds/watch/watchHandler.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/main.js +11 -0
- package/dist/esm/main.js.map +1 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/{utils → esm/utils}/misc.js +32 -50
- package/dist/esm/utils/misc.js.map +1 -0
- package/dist/{utils → esm/utils}/snap-config.js +26 -39
- package/dist/esm/utils/snap-config.js.map +1 -0
- package/dist/{cmds → types/cmds}/build/bundle.d.ts +0 -1
- package/dist/{cmds/serve → types/cmds/build}/index.d.ts +2 -2
- package/dist/{cmds/build → types/cmds/eval}/index.d.ts +2 -2
- package/dist/{cmds → types/cmds}/manifest/index.d.ts +2 -2
- package/dist/{cmds/eval → types/cmds/serve}/index.d.ts +2 -2
- package/dist/types/cmds/watch/index.d.ts +9 -0
- package/dist/{utils → types/utils}/snap-config.d.ts +0 -1
- package/package.json +56 -18
- package/dist/cli.js +0 -51
- package/dist/cli.js.map +0 -1
- package/dist/cmds/build/buildHandler.js +0 -37
- package/dist/cmds/build/buildHandler.js.map +0 -1
- package/dist/cmds/build/index.js +0 -29
- package/dist/cmds/build/index.js.map +0 -1
- package/dist/cmds/build/utils.js.map +0 -1
- package/dist/cmds/eval/evalHandler.js +0 -25
- package/dist/cmds/eval/evalHandler.js.map +0 -1
- package/dist/cmds/eval/index.js +0 -15
- package/dist/cmds/eval/index.js.map +0 -1
- package/dist/cmds/index.js +0 -13
- package/dist/cmds/index.js.map +0 -1
- package/dist/cmds/manifest/index.js +0 -24
- package/dist/cmds/manifest/index.js.map +0 -1
- package/dist/cmds/manifest/manifestHandler.js +0 -50
- package/dist/cmds/manifest/manifestHandler.js.map +0 -1
- package/dist/cmds/serve/index.js +0 -15
- package/dist/cmds/serve/index.js.map +0 -1
- package/dist/cmds/serve/serveHandler.js +0 -59
- package/dist/cmds/serve/serveHandler.js.map +0 -1
- package/dist/cmds/serve/serveUtils.js +0 -39
- package/dist/cmds/serve/serveUtils.js.map +0 -1
- package/dist/cmds/watch/index.d.ts +0 -9
- package/dist/cmds/watch/index.js +0 -32
- package/dist/cmds/watch/index.js.map +0 -1
- package/dist/cmds/watch/watchHandler.js +0 -99
- package/dist/cmds/watch/watchHandler.js.map +0 -1
- package/dist/index.js +0 -28
- package/dist/index.js.map +0 -1
- package/dist/main.js +0 -15
- package/dist/main.js.map +0 -1
- package/dist/utils/index.js +0 -19
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/misc.js.map +0 -1
- package/dist/utils/snap-config.js.map +0 -1
- /package/dist/{builders.d.ts → types/builders.d.ts} +0 -0
- /package/dist/{cli.d.ts → types/cli.d.ts} +0 -0
- /package/dist/{cmds → types/cmds}/build/buildHandler.d.ts +0 -0
- /package/dist/{cmds → types/cmds}/build/utils.d.ts +0 -0
- /package/dist/{cmds → types/cmds}/eval/evalHandler.d.ts +0 -0
- /package/dist/{cmds → types/cmds}/index.d.ts +0 -0
- /package/dist/{cmds → types/cmds}/manifest/manifestHandler.d.ts +0 -0
- /package/dist/{cmds → types/cmds}/serve/serveHandler.d.ts +0 -0
- /package/dist/{cmds → types/cmds}/serve/serveUtils.d.ts +0 -0
- /package/dist/{cmds → types/cmds}/watch/watchHandler.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{main.d.ts → types/main.d.ts} +0 -0
- /package/dist/{utils → types/utils}/index.d.ts +0 -0
- /package/dist/{utils → types/utils}/misc.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/misc.ts"],"sourcesContent":["import { logError as logErrorUtil } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { promises as filesystem } from 'fs';\nimport path from 'path';\nimport { Arguments } from 'yargs';\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.js';\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\n * 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 (hasProperty(argv, 'verboseErrors')) {\n global.snaps.verboseErrors = booleanStringToBoolean(argv.verboseErrors);\n }\n\n if (hasProperty(argv, 'suppressWarnings')) {\n global.snaps.suppressWarnings = booleanStringToBoolean(\n argv.suppressWarnings,\n );\n }\n}\n\n/**\n * Attempts to convert a string to a boolean and throws if the value is invalid.\n *\n * @param value - The value to convert to a boolean.\n * @returns `true` if the value is the string `\"true\"`, `false` if it is the\n * string `\"false\"`, the value if it is already a boolean, or an error\n * otherwise.\n */\nexport function booleanStringToBoolean(value: unknown): boolean {\n if (typeof value === 'boolean') {\n return value;\n } else if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n throw new Error(\n `Expected a boolean or the strings \"true\" or \"false\". Received: \"${String(\n value,\n )}\"`,\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 message - The error message.\n * @param error - The original error.\n */\nexport function logError(message: string | null, error?: Error): void {\n if (message !== null) {\n logErrorUtil(message);\n }\n\n if (error && global.snaps.verboseErrors) {\n logErrorUtil(error);\n }\n\n if (message === null && (!error || (error && !global.snaps.verboseErrors))) {\n logErrorUtil('Unknown error.');\n }\n}\n\n/**\n * Logs an error, attempts to unlink the destination file, and kills the\n * process.\n *\n * @param prefix - The message prefix.\n * @param message - The error message.\n * @param error - The original error.\n * @param destFilePath - The output file path.\n */\nexport async function writeError(\n prefix: string,\n message: string,\n error: Error,\n destFilePath?: string,\n): Promise<void> {\n let processedPrefix = prefix;\n if (!prefix.endsWith(' ')) {\n processedPrefix += ' ';\n }\n\n logError(processedPrefix + message, error);\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 // TODO(ritave): Remove process exit and change into collapse of functions\n // https://github.com/MetaMask/snaps-monorepo/issues/81\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"],"names":["permRequestKeys","CONFIG_FILE","setSnapGlobals","booleanStringToBoolean","sanitizeInputs","logError","writeError","trimPathString","pathArguments","Set","argv","includes","_","global","snaps","isWatching","hasProperty","verboseErrors","suppressWarnings","value","Error","String","Object","keys","forEach","key","has","path","normalize","message","error","logErrorUtil","prefix","destFilePath","processedPrefix","endsWith","filesystem","unlink","unlinkError","process","exit","pathString","replace"],"mappings":";;;;;;;;;;;IAMaA,eAAe;eAAfA;;IAUAC,WAAW;eAAXA;;IAqBGC,cAAc;eAAdA;;IA0BAC,sBAAsB;eAAtBA;;IAsBAC,cAAc;eAAdA;;IAsBAC,QAAQ;eAARA;;IAuBMC,UAAU;eAAVA;;IAmCNC,cAAc;eAAdA;;;4BArKyB;uBACb;oBACW;6DACtB;;;;;;AAGV,MAAMP,kBAAkB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAEM,MAAMC,cAAc;AAE3B,4CAA4C;AAC5C,MAAMO,gBAAgB,IAAIC,IAAI;IAC5B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AASM,SAASP,eAAeQ,IAAe;IAC5C,IAAI;QAAC;QAAK;KAAQ,CAACC,QAAQ,CAACD,KAAKE,CAAC,CAAC,EAAE,GAAa;QAChDC,OAAOC,KAAK,CAACC,UAAU,GAAG;IAC5B,OAAO;QACLF,OAAOC,KAAK,CAACC,UAAU,GAAG;IAC5B;IAEA,IAAIC,IAAAA,kBAAW,EAACN,MAAM,kBAAkB;QACtCG,OAAOC,KAAK,CAACG,aAAa,GAAGd,uBAAuBO,KAAKO,aAAa;IACxE;IAEA,IAAID,IAAAA,kBAAW,EAACN,MAAM,qBAAqB;QACzCG,OAAOC,KAAK,CAACI,gBAAgB,GAAGf,uBAC9BO,KAAKQ,gBAAgB;IAEzB;AACF;AAUO,SAASf,uBAAuBgB,KAAc;IACnD,IAAI,OAAOA,UAAU,WAAW;QAC9B,OAAOA;IACT,OAAO,IAAIA,UAAU,QAAQ;QAC3B,OAAO;IACT,OAAO,IAAIA,UAAU,SAAS;QAC5B,OAAO;IACT;IAEA,MAAM,IAAIC,MACR,CAAC,gEAAgE,EAAEC,OACjEF,OACA,CAAC,CAAC;AAER;AAQO,SAASf,eAAeM,IAAe;IAC5CY,OAAOC,IAAI,CAACb,MAAMc,OAAO,CAAC,CAACC;QACzB,IAAI,OAAOf,IAAI,CAACe,IAAI,KAAK,UAAU;YACjC,2CAA2C;YAC3C,IAAIf,IAAI,CAACe,IAAI,KAAK,MAAM;gBACtBf,IAAI,CAACe,IAAI,GAAG;YACd;YAEA,IAAIjB,cAAckB,GAAG,CAACD,MAAM;gBAC1Bf,IAAI,CAACe,IAAI,GAAGE,aAAI,CAACC,SAAS,CAAClB,IAAI,CAACe,IAAI;YACtC;QACF;IACF;AACF;AASO,SAASpB,SAASwB,OAAsB,EAAEC,KAAa;IAC5D,IAAID,YAAY,MAAM;QACpBE,IAAAA,oBAAY,EAACF;IACf;IAEA,IAAIC,SAASjB,OAAOC,KAAK,CAACG,aAAa,EAAE;QACvCc,IAAAA,oBAAY,EAACD;IACf;IAEA,IAAID,YAAY,QAAS,CAAA,CAACC,SAAUA,SAAS,CAACjB,OAAOC,KAAK,CAACG,aAAa,GAAI;QAC1Ec,IAAAA,oBAAY,EAAC;IACf;AACF;AAWO,eAAezB,WACpB0B,MAAc,EACdH,OAAe,EACfC,KAAY,EACZG,YAAqB;IAErB,IAAIC,kBAAkBF;IACtB,IAAI,CAACA,OAAOG,QAAQ,CAAC,MAAM;QACzBD,mBAAmB;IACrB;IAEA7B,SAAS6B,kBAAkBL,SAASC;IACpC,IAAI;QACF,IAAIG,cAAc;YAChB,MAAMG,YAAU,CAACC,MAAM,CAACJ;QAC1B;IACF,EAAE,OAAOK,aAAa;QACpBjC,SAAS,CAAC,EAAE6B,gBAAgB,8BAA8B,CAAC,EAAEI;IAC/D;IAEA,qCAAqC;IACrC,IAAI,CAACzB,OAAOC,KAAK,CAACC,UAAU,EAAE;QAC5B,0EAA0E;QAC1E,qEAAqE;QACrEwB,QAAQC,IAAI,CAAC;IACf;AACF;AASO,SAASjC,eAAekC,UAAkB;IAC/C,OAAOA,WAAWC,OAAO,CAAC,mBAAmB;AAC/C"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
SnapConfigStruct: function() {
|
|
13
|
+
return SnapConfigStruct;
|
|
14
|
+
},
|
|
15
|
+
isSnapConfig: function() {
|
|
16
|
+
return isSnapConfig;
|
|
17
|
+
},
|
|
18
|
+
loadConfig: function() {
|
|
19
|
+
return loadConfig;
|
|
20
|
+
},
|
|
21
|
+
applyConfig: function() {
|
|
22
|
+
return applyConfig;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _utils = require("@metamask/utils");
|
|
26
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
27
|
+
const _superstruct = require("superstruct");
|
|
28
|
+
const _yargsparser = /*#__PURE__*/ _interop_require_default(require("yargs-parser"));
|
|
29
|
+
const _builders = /*#__PURE__*/ _interop_require_default(require("../builders"));
|
|
30
|
+
const _misc = require("./misc");
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const SnapConfigStruct = (0, _superstruct.object)({
|
|
37
|
+
cliOptions: (0, _superstruct.optional)((0, _superstruct.object)()),
|
|
38
|
+
bundlerCustomizer: (0, _superstruct.optional)((0, _superstruct.func)())
|
|
39
|
+
});
|
|
40
|
+
function isSnapConfig(value) {
|
|
41
|
+
return (0, _superstruct.is)(value, SnapConfigStruct);
|
|
42
|
+
}
|
|
43
|
+
let snapConfigCache;
|
|
44
|
+
function loadConfig(cached = true) {
|
|
45
|
+
if (snapConfigCache !== undefined && cached) {
|
|
46
|
+
return snapConfigCache;
|
|
47
|
+
}
|
|
48
|
+
let config;
|
|
49
|
+
try {
|
|
50
|
+
// eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports
|
|
51
|
+
config = require(_path.default.resolve(process.cwd(), _misc.CONFIG_FILE));
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
54
|
+
snapConfigCache = {};
|
|
55
|
+
return snapConfigCache;
|
|
56
|
+
}
|
|
57
|
+
(0, _misc.logError)(`Error during parsing of ${_misc.CONFIG_FILE}`, error);
|
|
58
|
+
return process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
if (!isSnapConfig(config)) {
|
|
61
|
+
(0, _misc.logError)(`Can't validate ${_misc.CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`);
|
|
62
|
+
return process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
snapConfigCache = config;
|
|
65
|
+
return config;
|
|
66
|
+
}
|
|
67
|
+
function applyConfig(snapConfig, processArgv, yargsArgv, yargsInstance) {
|
|
68
|
+
// Instances of yargs has a number of undocumented functions, including
|
|
69
|
+
// getOptions. This function returns an object with properties "key" and
|
|
70
|
+
// "alias", which specify the options associated with the current command and
|
|
71
|
+
// their aliases, respectively.
|
|
72
|
+
//
|
|
73
|
+
// We leverage this to ensure that the config is only applied to args that are
|
|
74
|
+
// valid for the current command, and that weren't specified by the user on
|
|
75
|
+
// the command line.
|
|
76
|
+
//
|
|
77
|
+
// If we set args that aren't valid for the current command, yargs will error
|
|
78
|
+
// during validation.
|
|
79
|
+
const { alias: aliases, key: options } = yargsInstance.getOptions();
|
|
80
|
+
const parsedProcessArgv = (0, _yargsparser.default)(processArgv, {
|
|
81
|
+
alias: aliases
|
|
82
|
+
});
|
|
83
|
+
delete parsedProcessArgv._; // irrelevant yargs parser artifact
|
|
84
|
+
const commandOptions = new Set(Object.keys(options));
|
|
85
|
+
const shouldSetArg = (key)=>{
|
|
86
|
+
return commandOptions.has(key) && !(0, _utils.hasProperty)(parsedProcessArgv, key);
|
|
87
|
+
};
|
|
88
|
+
const config = snapConfig.cliOptions ?? {};
|
|
89
|
+
for (const key of Object.keys(config)){
|
|
90
|
+
if ((0, _utils.hasProperty)(_builders.default, key)) {
|
|
91
|
+
if (shouldSetArg(key)) {
|
|
92
|
+
yargsArgv[key] = config[key];
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
(0, _misc.logError)(`Error: Encountered unrecognized config property "options.${key}" in config file "${_misc.CONFIG_FILE}". Remove the property and try again.`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=snap-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/snap-config.ts"],"sourcesContent":["import { hasProperty } from '@metamask/utils';\nimport type browserify from 'browserify';\nimport path from 'path';\nimport { object, optional, func, Infer, is } from 'superstruct';\nimport { Arguments } from 'yargs';\nimport yargsParse from 'yargs-parser';\nimport yargs from 'yargs/yargs';\n\nimport builders from '../builders';\nimport { CONFIG_FILE, logError } from './misc';\n\nexport type BundleCustomizer = (bundler: browserify.BrowserifyObject) => void;\n\nexport const SnapConfigStruct = object({\n cliOptions: optional(object()),\n bundlerCustomizer: optional(func()),\n});\n\nexport type SnapConfig = Omit<\n Infer<typeof SnapConfigStruct>,\n 'bundlerCustomizer'\n> & {\n bundlerCustomizer?: BundleCustomizer;\n};\n\n/**\n * Check if the given value is a {@link SnapConfig} object. Note that this\n * function does not check the validity of the `bundleCustomizer` property, as\n * it is not possible to check the validity of a function in JavaScript.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a valid {@link SnapConfig} object, `false`\n * otherwise.\n */\nexport function isSnapConfig(value: unknown): value is SnapConfig {\n return is(value, SnapConfigStruct);\n}\n\nlet snapConfigCache: SnapConfig | undefined;\n\n/**\n * Attempt to load the snap config file (`snap.config.js`). By default will use\n * the cached config, if it was loaded before, and `cached` is `true`. If the\n * config file is not found, or the config is invalid, this function will kill\n * the process.\n *\n * @param cached - Whether to use the cached config. Defaults to `true`.\n * @returns The snap config.\n */\nexport function loadConfig(cached = true): SnapConfig {\n if (snapConfigCache !== undefined && cached) {\n return snapConfigCache;\n }\n\n let config: any;\n try {\n // eslint-disable-next-line node/global-require, import/no-dynamic-require, @typescript-eslint/no-require-imports\n config = require(path.resolve(process.cwd(), CONFIG_FILE));\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n snapConfigCache = {};\n return snapConfigCache;\n }\n logError(`Error during parsing of ${CONFIG_FILE}`, error);\n return process.exit(1);\n }\n\n if (!isSnapConfig(config)) {\n logError(\n `Can't validate ${CONFIG_FILE}. Ensure it's a proper javascript file and abides with the structure of a snap configuration file`,\n );\n return process.exit(1);\n }\n snapConfigCache = config;\n return config;\n}\n\n// Note that the below function is necessary because yargs' .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 *\n * @param snapConfig - The snap config.\n * @param processArgv - The command line arguments, i.e., `process.argv`.\n * @param yargsArgv - The processed `yargs` arguments.\n * @param yargsInstance - An instance of `yargs`.\n */\nexport function applyConfig(\n snapConfig: SnapConfig,\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 commandOptions.has(key) && !hasProperty(parsedProcessArgv, key);\n };\n\n const config: Record<string, unknown> = snapConfig.cliOptions ?? {};\n for (const key of Object.keys(config)) {\n if (hasProperty(builders, key)) {\n if (shouldSetArg(key)) {\n yargsArgv[key] = config[key];\n }\n } else {\n logError(\n `Error: Encountered unrecognized config property \"options.${key}\" in config file \"${CONFIG_FILE}\". Remove the property and try again.`,\n );\n process.exit(1);\n }\n }\n}\n"],"names":["SnapConfigStruct","isSnapConfig","loadConfig","applyConfig","object","cliOptions","optional","bundlerCustomizer","func","value","is","snapConfigCache","cached","undefined","config","require","path","resolve","process","cwd","CONFIG_FILE","error","code","logError","exit","snapConfig","processArgv","yargsArgv","yargsInstance","alias","aliases","key","options","getOptions","parsedProcessArgv","yargsParse","_","commandOptions","Set","Object","keys","shouldSetArg","has","hasProperty","builders"],"mappings":";;;;;;;;;;;IAaaA,gBAAgB;eAAhBA;;IAqBGC,YAAY;eAAZA;;IAeAC,UAAU;eAAVA;;IA8CAC,WAAW;eAAXA;;;uBA/FY;6DAEX;6BACiC;oEAE3B;iEAGF;sBACiB;;;;;;AAI/B,MAAMH,mBAAmBI,IAAAA,mBAAM,EAAC;IACrCC,YAAYC,IAAAA,qBAAQ,EAACF,IAAAA,mBAAM;IAC3BG,mBAAmBD,IAAAA,qBAAQ,EAACE,IAAAA,iBAAI;AAClC;AAkBO,SAASP,aAAaQ,KAAc;IACzC,OAAOC,IAAAA,eAAE,EAACD,OAAOT;AACnB;AAEA,IAAIW;AAWG,SAAST,WAAWU,SAAS,IAAI;IACtC,IAAID,oBAAoBE,aAAaD,QAAQ;QAC3C,OAAOD;IACT;IAEA,IAAIG;IACJ,IAAI;QACF,iHAAiH;QACjHA,SAASC,QAAQC,aAAI,CAACC,OAAO,CAACC,QAAQC,GAAG,IAAIC,iBAAW;IAC1D,EAAE,OAAOC,OAAY;QACnB,IAAIA,MAAMC,IAAI,KAAK,oBAAoB;YACrCX,kBAAkB,CAAC;YACnB,OAAOA;QACT;QACAY,IAAAA,cAAQ,EAAC,CAAC,wBAAwB,EAAEH,iBAAW,CAAC,CAAC,EAAEC;QACnD,OAAOH,QAAQM,IAAI,CAAC;IACtB;IAEA,IAAI,CAACvB,aAAaa,SAAS;QACzBS,IAAAA,cAAQ,EACN,CAAC,eAAe,EAAEH,iBAAW,CAAC,iGAAiG,CAAC;QAElI,OAAOF,QAAQM,IAAI,CAAC;IACtB;IACAb,kBAAkBG;IAClB,OAAOA;AACT;AAoBO,SAASX,YACdsB,UAAsB,EACtBC,WAAqB,EACrBC,SAAoB,EACpBC,aAA2B;IAE3B,uEAAuE;IACvE,wEAAwE;IACxE,6EAA6E;IAC7E,+BAA+B;IAC/B,EAAE;IACF,8EAA8E;IAC9E,2EAA2E;IAC3E,oBAAoB;IACpB,EAAE;IACF,6EAA6E;IAC7E,qBAAqB;IACrB,MAAM,EAAEC,OAAOC,OAAO,EAAEC,KAAKC,OAAO,EAAE,GAAG,AACvCJ,cACAK,UAAU;IAKZ,MAAMC,oBAAoBC,IAAAA,oBAAU,EAACT,aAAa;QAChDG,OAAOC;IACT;IACA,OAAOI,kBAAkBE,CAAC,EAAE,mCAAmC;IAE/D,MAAMC,iBAAiB,IAAIC,IAAIC,OAAOC,IAAI,CAACR;IAE3C,MAAMS,eAAe,CAACV;QACpB,OAAOM,eAAeK,GAAG,CAACX,QAAQ,CAACY,IAAAA,kBAAW,EAACT,mBAAmBH;IACpE;IAEA,MAAMjB,SAAkCW,WAAWpB,UAAU,IAAI,CAAC;IAClE,KAAK,MAAM0B,OAAOQ,OAAOC,IAAI,CAAC1B,QAAS;QACrC,IAAI6B,IAAAA,kBAAW,EAACC,iBAAQ,EAAEb,MAAM;YAC9B,IAAIU,aAAaV,MAAM;gBACrBJ,SAAS,CAACI,IAAI,GAAGjB,MAAM,CAACiB,IAAI;YAC9B;QACF,OAAO;YACLR,IAAAA,cAAQ,EACN,CAAC,yDAAyD,EAAEQ,IAAI,kBAAkB,EAAEX,iBAAW,CAAC,qCAAqC,CAAC;YAExIF,QAAQM,IAAI,CAAC;QACf;IACF;AACF"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
TranspilationModes["LocalOnly"] = "localOnly";
|
|
8
|
-
TranspilationModes["None"] = "none";
|
|
9
|
-
})(TranspilationModes = exports.TranspilationModes || (exports.TranspilationModes = {}));
|
|
1
|
+
export var TranspilationModes;
|
|
2
|
+
(function(TranspilationModes) {
|
|
3
|
+
TranspilationModes["LocalAndDeps"] = 'localAndDeps';
|
|
4
|
+
TranspilationModes["LocalOnly"] = 'localOnly';
|
|
5
|
+
TranspilationModes["None"] = 'none';
|
|
6
|
+
})(TranspilationModes || (TranspilationModes = {}));
|
|
10
7
|
const builders = {
|
|
11
8
|
bundle: {
|
|
12
9
|
alias: 'b',
|
|
@@ -14,7 +11,7 @@ const builders = {
|
|
|
14
11
|
type: 'string',
|
|
15
12
|
demandOption: true,
|
|
16
13
|
normalize: true,
|
|
17
|
-
default: 'dist/bundle.js'
|
|
14
|
+
default: 'dist/bundle.js'
|
|
18
15
|
},
|
|
19
16
|
dist: {
|
|
20
17
|
alias: 'd',
|
|
@@ -22,21 +19,21 @@ const builders = {
|
|
|
22
19
|
type: 'string',
|
|
23
20
|
demandOption: true,
|
|
24
21
|
normalize: true,
|
|
25
|
-
default: 'dist'
|
|
22
|
+
default: 'dist'
|
|
26
23
|
},
|
|
27
24
|
eval: {
|
|
28
25
|
alias: 'e',
|
|
29
26
|
describe: 'Attempt to evaluate Snap bundle in SES',
|
|
30
27
|
type: 'boolean',
|
|
31
28
|
demandOption: false,
|
|
32
|
-
default: true
|
|
29
|
+
default: true
|
|
33
30
|
},
|
|
34
31
|
manifest: {
|
|
35
32
|
alias: 'm',
|
|
36
33
|
describe: 'Validate snap.manifest.json',
|
|
37
34
|
type: 'boolean',
|
|
38
35
|
demandOption: false,
|
|
39
|
-
default: true
|
|
36
|
+
default: true
|
|
40
37
|
},
|
|
41
38
|
port: {
|
|
42
39
|
alias: 'p',
|
|
@@ -44,20 +41,20 @@ const builders = {
|
|
|
44
41
|
type: 'number',
|
|
45
42
|
demandOption: true,
|
|
46
43
|
default: 8081,
|
|
47
|
-
coerce: (arg)
|
|
44
|
+
coerce: (arg)=>{
|
|
48
45
|
const port = Number.parseInt(String(arg), 10);
|
|
49
46
|
if (Number.isNaN(port)) {
|
|
50
47
|
throw new Error(`Invalid port: ${String(arg)}`);
|
|
51
48
|
}
|
|
52
49
|
return port;
|
|
53
|
-
}
|
|
50
|
+
}
|
|
54
51
|
},
|
|
55
52
|
outfileName: {
|
|
56
53
|
alias: 'n',
|
|
57
54
|
describe: 'Output file name',
|
|
58
55
|
type: 'string',
|
|
59
56
|
demandOption: false,
|
|
60
|
-
default: 'bundle.js'
|
|
57
|
+
default: 'bundle.js'
|
|
61
58
|
},
|
|
62
59
|
root: {
|
|
63
60
|
alias: 'r',
|
|
@@ -65,13 +62,13 @@ const builders = {
|
|
|
65
62
|
type: 'string',
|
|
66
63
|
demandOption: true,
|
|
67
64
|
normalize: true,
|
|
68
|
-
default: '.'
|
|
65
|
+
default: '.'
|
|
69
66
|
},
|
|
70
67
|
sourceMaps: {
|
|
71
68
|
describe: 'Whether builds include sourcemaps',
|
|
72
69
|
type: 'boolean',
|
|
73
70
|
demandOption: false,
|
|
74
|
-
default: false
|
|
71
|
+
default: false
|
|
75
72
|
},
|
|
76
73
|
src: {
|
|
77
74
|
alias: 's',
|
|
@@ -79,55 +76,56 @@ const builders = {
|
|
|
79
76
|
type: 'string',
|
|
80
77
|
demandOption: true,
|
|
81
78
|
normalize: true,
|
|
82
|
-
default: 'src/index.js'
|
|
79
|
+
default: 'src/index.js'
|
|
83
80
|
},
|
|
84
81
|
stripComments: {
|
|
85
82
|
alias: 'strip',
|
|
86
83
|
describe: 'Whether to remove code comments from the build output',
|
|
87
84
|
type: 'boolean',
|
|
88
85
|
demandOption: false,
|
|
89
|
-
default: true
|
|
86
|
+
default: true
|
|
90
87
|
},
|
|
91
88
|
suppressWarnings: {
|
|
92
89
|
type: 'boolean',
|
|
93
90
|
describe: 'Whether to suppress warnings',
|
|
94
91
|
demandOption: false,
|
|
95
|
-
default: false
|
|
92
|
+
default: false
|
|
96
93
|
},
|
|
97
94
|
transpilationMode: {
|
|
98
95
|
type: 'string',
|
|
99
96
|
describe: 'Whether to use Babel to transpile all source code (including dependencies), local source code only, or nothing.',
|
|
100
97
|
demandOption: false,
|
|
101
98
|
default: TranspilationModes.LocalOnly,
|
|
102
|
-
choices: Object.values(TranspilationModes)
|
|
99
|
+
choices: Object.values(TranspilationModes)
|
|
103
100
|
},
|
|
104
101
|
depsToTranspile: {
|
|
105
102
|
type: 'array',
|
|
106
103
|
describe: 'Transpile only the listed dependencies.',
|
|
107
|
-
demandOption: false
|
|
104
|
+
demandOption: false
|
|
108
105
|
},
|
|
109
106
|
verboseErrors: {
|
|
110
107
|
type: 'boolean',
|
|
111
108
|
describe: 'Display original errors',
|
|
112
109
|
demandOption: false,
|
|
113
|
-
default: true
|
|
110
|
+
default: true
|
|
114
111
|
},
|
|
115
112
|
writeManifest: {
|
|
116
113
|
describe: 'Make necessary changes to the Snap manifest file',
|
|
117
114
|
type: 'boolean',
|
|
118
115
|
demandOption: false,
|
|
119
|
-
default: true
|
|
116
|
+
default: true
|
|
120
117
|
},
|
|
121
118
|
serve: {
|
|
122
119
|
describe: 'Serve Snap file(s) locally for testing',
|
|
123
120
|
type: 'boolean',
|
|
124
121
|
demandOption: false,
|
|
125
|
-
default: true
|
|
122
|
+
default: true
|
|
126
123
|
},
|
|
127
124
|
directory: {
|
|
128
125
|
describe: 'the directory to use',
|
|
129
|
-
type: 'string'
|
|
130
|
-
}
|
|
126
|
+
type: 'string'
|
|
127
|
+
}
|
|
131
128
|
};
|
|
132
|
-
|
|
129
|
+
export default builders;
|
|
130
|
+
|
|
133
131
|
//# sourceMappingURL=builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/builders.ts"],"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: ${String(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"],"names":["TranspilationModes","LocalAndDeps","LocalOnly","None","builders","bundle","alias","describe","type","demandOption","normalize","default","dist","eval","manifest","port","coerce","arg","Number","parseInt","String","isNaN","Error","outfileName","root","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","choices","Object","values","depsToTranspile","verboseErrors","writeManifest","serve","directory"],"mappings":"WAsBO;UAAKA,kBAAkB;IAAlBA,mBACVC,kBAAe;IADLD,mBAEVE,eAAY;IAFFF,mBAGVG,UAAO;GAHGH,uBAAAA;AAMZ,MAAMI,WAA6B;IACjCC,QAAQ;QACNC,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAC,MAAM;QACJN,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAE,MAAM;QACJP,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAG,UAAU;QACRR,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAI,MAAM;QACJT,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;QACTK,QAAQ,CAACC;YACP,MAAMF,OAAOG,OAAOC,QAAQ,CAACC,OAAOH,MAAM;YAC1C,IAAIC,OAAOG,KAAK,CAACN,OAAO;gBACtB,MAAM,IAAIO,MAAM,CAAC,cAAc,EAAEF,OAAOH,KAAK,CAAC;YAChD;YACA,OAAOF;QACT;IACF;IAEAQ,aAAa;QACXjB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAa,MAAM;QACJlB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAc,YAAY;QACVlB,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAe,KAAK;QACHpB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdC,WAAW;QACXC,SAAS;IACX;IAEAgB,eAAe;QACbrB,OAAO;QACPC,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAiB,kBAAkB;QAChBpB,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAkB,mBAAmB;QACjBrB,MAAM;QACND,UACE;QACFE,cAAc;QACdE,SAASX,mBAAmBE,SAAS;QACrC4B,SAASC,OAAOC,MAAM,CAAChC;IACzB;IAEAiC,iBAAiB;QACfzB,MAAM;QACND,UAAU;QACVE,cAAc;IAChB;IAEAyB,eAAe;QACb1B,MAAM;QACND,UAAU;QACVE,cAAc;QACdE,SAAS;IACX;IAEAwB,eAAe;QACb5B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEAyB,OAAO;QACL7B,UAAU;QACVC,MAAM;QACNC,cAAc;QACdE,SAAS;IACX;IAEA0B,WAAW;QACT9B,UAAU;QACVC,MAAM;IACR;AACF;AAEA,eAAeJ,SAAS"}
|
package/dist/esm/cli.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import builders from './builders';
|
|
3
|
+
import { applyConfig, loadConfig, sanitizeInputs, setSnapGlobals, logError } from './utils';
|
|
4
|
+
/**
|
|
5
|
+
* The main CLI entry point function. This processes the command line args, and
|
|
6
|
+
* runs the appropriate function.
|
|
7
|
+
*
|
|
8
|
+
* @param argv - The raw command line arguments, i.e., `process.argv`.
|
|
9
|
+
* @param commands - The list of commands to use.
|
|
10
|
+
*/ export function cli(argv, commands) {
|
|
11
|
+
const rawArgv = argv.slice(2);
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-floating-promises
|
|
13
|
+
yargs(rawArgv).scriptName('mm-snap').usage('Usage: $0 <command> [options]').example('$0 init', `\tInitialize a snap project in the current directory`).example('$0 init my-snap', `\tInitialize a snap project in the 'my-snap' directory`).example('$0 build -s src/index.js -d out', `\tBuild 'src/index.js' as './out/bundle.js'`).example('$0 build -s src/index.js -d out -n snap.js', `\tBuild 'src/index.js' as './out/snap.js'`).example('$0 serve -r out', `\tServe files in './out' on port 8080`).example('$0 serve -r out -p 9000', `\tServe files in './out' on port 9000`).example('$0 watch -s src/index.js -d out', `\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`).command(commands).option('verboseErrors', builders.verboseErrors).option('suppressWarnings', builders.suppressWarnings).strict()// Typecast: The @types/yargs type for .middleware is incorrect.
|
|
14
|
+
// yargs middleware functions receive the yargs instance as a second parameter.
|
|
15
|
+
// ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation
|
|
16
|
+
.middleware((yargsArgv, yargsInstance)=>{
|
|
17
|
+
applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);
|
|
18
|
+
setSnapGlobals(yargsArgv);
|
|
19
|
+
sanitizeInputs(yargsArgv);
|
|
20
|
+
}, true).fail((message, error, _yargs)=>{
|
|
21
|
+
logError(message, error);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}).demandCommand(1, 'You must specify at least one command.').help().alias('help', 'h').argv;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import yargs, { Arguments } from 'yargs';\nimport yargsType from 'yargs/yargs';\n\nimport builders from './builders';\nimport {\n applyConfig,\n loadConfig,\n sanitizeInputs,\n setSnapGlobals,\n logError,\n} from './utils';\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport function cli(argv: string[], commands: any): void {\n const rawArgv = argv.slice(2);\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-floating-promises\n yargs(rawArgv)\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 init', `\\tInitialize a snap project in the current directory`)\n .example(\n '$0 init my-snap',\n `\\tInitialize a snap project in the 'my-snap' directory`,\n )\n .example(\n '$0 build -s src/index.js -d out',\n `\\tBuild 'src/index.js' as './out/bundle.js'`,\n )\n .example(\n '$0 build -s src/index.js -d out -n snap.js',\n `\\tBuild 'src/index.js' as './out/snap.js'`,\n )\n .example('$0 serve -r out', `\\tServe files in './out' on port 8080`)\n .example('$0 serve -r out -p 9000', `\\tServe files in './out' on port 9000`)\n .example(\n '$0 watch -s src/index.js -d out',\n `\\tRebuild './out/bundle.js' on changes to files in 'src/index.js' parent and child directories`,\n )\n\n .command(commands)\n\n .option('verboseErrors', builders.verboseErrors)\n\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n // Typecast: The @types/yargs type for .middleware is incorrect.\n // yargs middleware functions receive the yargs instance as a second parameter.\n // ref: https://yargs.js.org/docs/#api-reference-middlewarecallbacks-applybeforevalidation\n .middleware(\n ((yargsArgv: Arguments, yargsInstance: typeof yargsType) => {\n applyConfig(loadConfig(), rawArgv, yargsArgv, yargsInstance);\n setSnapGlobals(yargsArgv);\n sanitizeInputs(yargsArgv);\n }) as any,\n true,\n )\n\n .fail((message: string, error: Error, _yargs) => {\n logError(message, error);\n process.exitCode = 1;\n })\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .help()\n .alias('help', 'h').argv;\n}\n"],"names":["yargs","builders","applyConfig","loadConfig","sanitizeInputs","setSnapGlobals","logError","cli","argv","commands","rawArgv","slice","scriptName","usage","example","command","option","verboseErrors","suppressWarnings","strict","middleware","yargsArgv","yargsInstance","fail","message","error","_yargs","process","exitCode","demandCommand","help","alias"],"mappings":"AAAA,OAAOA,WAA0B,QAAQ;AAGzC,OAAOC,cAAc,aAAa;AAClC,SACEC,WAAW,EACXC,UAAU,EACVC,cAAc,EACdC,cAAc,EACdC,QAAQ,QACH,UAAU;AAEjB;;;;;;CAMC,GACD,OAAO,SAASC,IAAIC,IAAc,EAAEC,QAAa;IAC/C,MAAMC,UAAUF,KAAKG,KAAK,CAAC;IAC3B,6GAA6G;IAC7GX,MAAMU,SACHE,UAAU,CAAC,WACXC,KAAK,CAAC,iCAENC,OAAO,CAAC,WAAW,CAAC,oDAAoD,CAAC,EACzEA,OAAO,CACN,mBACA,CAAC,sDAAsD,CAAC,EAEzDA,OAAO,CACN,mCACA,CAAC,2CAA2C,CAAC,EAE9CA,OAAO,CACN,8CACA,CAAC,yCAAyC,CAAC,EAE5CA,OAAO,CAAC,mBAAmB,CAAC,qCAAqC,CAAC,EAClEA,OAAO,CAAC,2BAA2B,CAAC,qCAAqC,CAAC,EAC1EA,OAAO,CACN,mCACA,CAAC,8FAA8F,CAAC,EAGjGC,OAAO,CAACN,UAERO,MAAM,CAAC,iBAAiBf,SAASgB,aAAa,EAE9CD,MAAM,CAAC,oBAAoBf,SAASiB,gBAAgB,EAEpDC,MAAM,EAEP,gEAAgE;IAChE,+EAA+E;IAC/E,0FAA0F;KACzFC,UAAU,CACR,CAACC,WAAsBC;QACtBpB,YAAYC,cAAcO,SAASW,WAAWC;QAC9CjB,eAAegB;QACfjB,eAAeiB;IACjB,GACA,MAGDE,IAAI,CAAC,CAACC,SAAiBC,OAAcC;QACpCpB,SAASkB,SAASC;QAClBE,QAAQC,QAAQ,GAAG;IACrB,GAECC,aAAa,CAAC,GAAG,0CAEjBC,IAAI,GACJC,KAAK,CAAC,QAAQ,KAAKvB,IAAI;AAC5B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getOutfilePath, validateDirPath, validateFilePath, validateOutfileName } from '@metamask/snaps-utils';
|
|
2
|
+
import { loadConfig } from '../../utils';
|
|
3
|
+
import { evalHandler } from '../eval/evalHandler';
|
|
4
|
+
import { manifestHandler } from '../manifest/manifestHandler';
|
|
5
|
+
import { bundle } from './bundle';
|
|
6
|
+
/**
|
|
7
|
+
* Builds all files in the given source directory to the given destination
|
|
8
|
+
* directory.
|
|
9
|
+
*
|
|
10
|
+
* Creates destination directory if it doesn't exist.
|
|
11
|
+
*
|
|
12
|
+
* @param argv - Argv from Yargs.
|
|
13
|
+
* @param argv.src - The source file path.
|
|
14
|
+
* @param argv.dist - The output directory path.
|
|
15
|
+
* @param argv.outfileName - The output file name.
|
|
16
|
+
*/ export async function build(argv) {
|
|
17
|
+
const { src, dist, outfileName } = argv;
|
|
18
|
+
if (outfileName) {
|
|
19
|
+
validateOutfileName(outfileName);
|
|
20
|
+
}
|
|
21
|
+
await validateFilePath(src);
|
|
22
|
+
await validateDirPath(dist, true);
|
|
23
|
+
const outfilePath = getOutfilePath(dist, outfileName);
|
|
24
|
+
const result = await bundle(src, outfilePath, argv, loadConfig().bundlerCustomizer);
|
|
25
|
+
if (result && argv.eval) {
|
|
26
|
+
await evalHandler({
|
|
27
|
+
...argv,
|
|
28
|
+
bundle: outfilePath
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (argv.manifest) {
|
|
32
|
+
await manifestHandler(argv);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=buildHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/cmds/build/buildHandler.ts"],"sourcesContent":["import {\n getOutfilePath,\n validateDirPath,\n validateFilePath,\n validateOutfileName,\n} from '@metamask/snaps-utils';\n\nimport { YargsArgs } from '../../types/yargs';\nimport { loadConfig } from '../../utils';\nimport { evalHandler } from '../eval/evalHandler';\nimport { manifestHandler } from '../manifest/manifestHandler';\nimport { bundle } from './bundle';\n\n/**\n * Builds all files in the given source directory to the given destination\n * directory.\n *\n * Creates destination directory if it doesn't exist.\n *\n * @param argv - Argv from Yargs.\n * @param argv.src - The source file path.\n * @param argv.dist - The output directory path.\n * @param argv.outfileName - The output file name.\n */\nexport async function build(argv: YargsArgs): Promise<void> {\n const { src, dist, outfileName } = argv;\n if (outfileName) {\n validateOutfileName(outfileName);\n }\n await validateFilePath(src);\n await validateDirPath(dist, true);\n\n const outfilePath = getOutfilePath(dist, outfileName);\n const result = await bundle(\n src,\n outfilePath,\n argv,\n loadConfig().bundlerCustomizer,\n );\n if (result && argv.eval) {\n await evalHandler({ ...argv, bundle: outfilePath });\n }\n\n if (argv.manifest) {\n await manifestHandler(argv);\n }\n}\n"],"names":["getOutfilePath","validateDirPath","validateFilePath","validateOutfileName","loadConfig","evalHandler","manifestHandler","bundle","build","argv","src","dist","outfileName","outfilePath","result","bundlerCustomizer","eval","manifest"],"mappings":"AAAA,SACEA,cAAc,EACdC,eAAe,EACfC,gBAAgB,EAChBC,mBAAmB,QACd,wBAAwB;AAG/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,WAAW,QAAQ,sBAAsB;AAClD,SAASC,eAAe,QAAQ,8BAA8B;AAC9D,SAASC,MAAM,QAAQ,WAAW;AAElC;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,MAAMC,IAAe;IACzC,MAAM,EAAEC,GAAG,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH;IACnC,IAAIG,aAAa;QACfT,oBAAoBS;IACtB;IACA,MAAMV,iBAAiBQ;IACvB,MAAMT,gBAAgBU,MAAM;IAE5B,MAAME,cAAcb,eAAeW,MAAMC;IACzC,MAAME,SAAS,MAAMP,OACnBG,KACAG,aACAJ,MACAL,aAAaW,iBAAiB;IAEhC,IAAID,UAAUL,KAAKO,IAAI,EAAE;QACvB,MAAMX,YAAY;YAAE,GAAGI,IAAI;YAAEF,QAAQM;QAAY;IACnD;IAEA,IAAIJ,KAAKQ,QAAQ,EAAE;QACjB,MAAMX,gBAAgBG;IACxB;AACF"}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.bundle = void 0;
|
|
7
|
-
const snaps_browserify_plugin_1 = __importDefault(require("@metamask/snaps-browserify-plugin"));
|
|
8
|
-
const browserify_1 = __importDefault(require("browserify"));
|
|
9
|
-
const builders_1 = require("../../builders");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import plugin from '@metamask/snaps-browserify-plugin';
|
|
2
|
+
import browserify from 'browserify';
|
|
3
|
+
import { TranspilationModes } from '../../builders';
|
|
4
|
+
import { processDependencies, writeBundleFile } from './utils';
|
|
11
5
|
// We need to statically import all Browserify transforms and all Babel presets
|
|
12
6
|
// and plugins, and calling `require` is the sanest way to do that.
|
|
13
|
-
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */
|
|
14
|
-
/**
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */ /**
|
|
15
8
|
* Builds a Snap bundle JS file from its JavaScript source.
|
|
16
9
|
*
|
|
17
10
|
* @param src - The source file path.
|
|
@@ -22,59 +15,67 @@ const utils_1 = require("./utils");
|
|
|
22
15
|
* @param argv.transpilationMode - The Babel transpilation mode.
|
|
23
16
|
* @param bundlerTransform - An optional function which can be used to transform
|
|
24
17
|
* the Browserify instance, e.g., adding a custom transform or plugin.
|
|
25
|
-
*/
|
|
26
|
-
async function bundle(src, dest, argv, bundlerTransform) {
|
|
18
|
+
*/ export async function bundle(src, dest, argv, bundlerTransform) {
|
|
27
19
|
const { sourceMaps: debug, transpilationMode } = argv;
|
|
28
|
-
const babelifyOptions =
|
|
29
|
-
return new Promise((resolve, _reject)
|
|
30
|
-
const bundler = (
|
|
20
|
+
const babelifyOptions = processDependencies(argv);
|
|
21
|
+
return new Promise((resolve, _reject)=>{
|
|
22
|
+
const bundler = browserify(src, {
|
|
31
23
|
debug,
|
|
32
|
-
extensions: [
|
|
24
|
+
extensions: [
|
|
25
|
+
'.js',
|
|
26
|
+
'.ts'
|
|
27
|
+
],
|
|
33
28
|
// Standalone is required to properly support Snaps using module.exports
|
|
34
|
-
standalone: '<snap>'
|
|
29
|
+
standalone: '<snap>'
|
|
35
30
|
});
|
|
36
|
-
if (transpilationMode !==
|
|
31
|
+
if (transpilationMode !== TranspilationModes.None) {
|
|
37
32
|
bundler.transform(require('babelify'), {
|
|
38
|
-
global: transpilationMode ===
|
|
39
|
-
extensions: [
|
|
33
|
+
global: transpilationMode === TranspilationModes.LocalAndDeps,
|
|
34
|
+
extensions: [
|
|
35
|
+
'.js',
|
|
36
|
+
'.ts'
|
|
37
|
+
],
|
|
40
38
|
presets: [
|
|
41
39
|
require('@babel/preset-typescript'),
|
|
42
40
|
[
|
|
43
41
|
require('@babel/preset-env'),
|
|
44
42
|
{
|
|
45
43
|
targets: {
|
|
46
|
-
browsers: [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
browsers: [
|
|
45
|
+
'chrome >= 90',
|
|
46
|
+
'firefox >= 91'
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
50
51
|
],
|
|
51
52
|
plugins: [
|
|
52
53
|
require('@babel/plugin-transform-runtime'),
|
|
53
54
|
require('@babel/plugin-proposal-class-properties'),
|
|
54
55
|
require('@babel/plugin-proposal-private-methods'),
|
|
55
56
|
require('@babel/plugin-proposal-class-static-block'),
|
|
56
|
-
require('@babel/plugin-proposal-private-property-in-object')
|
|
57
|
+
require('@babel/plugin-proposal-private-property-in-object')
|
|
57
58
|
],
|
|
58
59
|
parserOpts: {
|
|
59
|
-
attachComment: !argv.stripComments
|
|
60
|
+
attachComment: !argv.stripComments
|
|
60
61
|
},
|
|
61
|
-
...babelifyOptions
|
|
62
|
+
...babelifyOptions
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
bundlerTransform?.(bundler);
|
|
65
|
-
bundler.plugin(
|
|
66
|
+
bundler.plugin(plugin, {
|
|
66
67
|
stripComments: argv.stripComments,
|
|
67
68
|
manifestPath: undefined,
|
|
68
|
-
eval: false
|
|
69
|
+
eval: false
|
|
69
70
|
});
|
|
70
|
-
bundler.bundle(async (bundleError, bundleBuffer)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
bundler.bundle(async (bundleError, bundleBuffer)=>await writeBundleFile({
|
|
72
|
+
bundleError,
|
|
73
|
+
bundleBuffer,
|
|
74
|
+
src,
|
|
75
|
+
dest,
|
|
76
|
+
resolve
|
|
77
|
+
}));
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
+
|
|
80
81
|
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/cmds/build/bundle.ts"],"sourcesContent":["import plugin, { Options } from '@metamask/snaps-browserify-plugin';\nimport browserify, { BrowserifyObject } from 'browserify';\n\nimport { TranspilationModes } from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { processDependencies, writeBundleFile } from './utils';\n\n// We need to statically import all Browserify transforms and all Babel presets\n// and plugins, and calling `require` is the sanest way to do that.\n/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, node/global-require */\n\n/**\n * Builds a Snap bundle JS file from its JavaScript source.\n *\n * @param src - The source file path.\n * @param dest - The destination file path.\n * @param argv - Arguments as an object generated by `yargs`.\n * @param argv.sourceMaps - Whether to output sourcemaps.\n * @param argv.stripComments - Whether to remove comments from code.\n * @param argv.transpilationMode - The Babel transpilation mode.\n * @param bundlerTransform - An optional function which can be used to transform\n * the Browserify instance, e.g., adding a custom transform or plugin.\n */\nexport async function bundle(\n src: string,\n dest: string,\n argv: YargsArgs,\n bundlerTransform?: (bundler: BrowserifyObject) => void,\n): Promise<boolean> {\n const { sourceMaps: debug, transpilationMode } = argv;\n const babelifyOptions = processDependencies(argv as any);\n return new Promise((resolve, _reject) => {\n const bundler = browserify(src, {\n debug,\n extensions: ['.js', '.ts'],\n // Standalone is required to properly support Snaps using module.exports\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: ['chrome >= 90', 'firefox >= 91'],\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-proposal-class-properties'),\n require('@babel/plugin-proposal-private-methods'),\n require('@babel/plugin-proposal-class-static-block'),\n require('@babel/plugin-proposal-private-property-in-object'),\n ],\n parserOpts: {\n attachComment: !argv.stripComments,\n },\n ...(babelifyOptions as any),\n });\n }\n\n bundlerTransform?.(bundler);\n\n bundler.plugin<Options>(plugin, {\n stripComments: argv.stripComments,\n manifestPath: undefined,\n eval: false,\n });\n\n bundler.bundle(\n async (bundleError, bundleBuffer: Buffer) =>\n await writeBundleFile({\n bundleError,\n bundleBuffer,\n src,\n dest,\n resolve,\n }),\n );\n });\n}\n"],"names":["plugin","browserify","TranspilationModes","processDependencies","writeBundleFile","bundle","src","dest","argv","bundlerTransform","sourceMaps","debug","transpilationMode","babelifyOptions","Promise","resolve","_reject","bundler","extensions","standalone","None","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","parserOpts","attachComment","stripComments","manifestPath","undefined","eval","bundleError","bundleBuffer"],"mappings":"AAAA,OAAOA,YAAyB,oCAAoC;AACpE,OAAOC,gBAAsC,aAAa;AAE1D,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,mBAAmB,EAAEC,eAAe,QAAQ,UAAU;AAE/D,+EAA+E;AAC/E,mEAAmE;AACnE,iHAAiH,GAEjH;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,OACpBC,GAAW,EACXC,IAAY,EACZC,IAAe,EACfC,gBAAsD;IAEtD,MAAM,EAAEC,YAAYC,KAAK,EAAEC,iBAAiB,EAAE,GAAGJ;IACjD,MAAMK,kBAAkBV,oBAAoBK;IAC5C,OAAO,IAAIM,QAAQ,CAACC,SAASC;QAC3B,MAAMC,UAAUhB,WAAWK,KAAK;YAC9BK;YACAO,YAAY;gBAAC;gBAAO;aAAM;YAC1B,wEAAwE;YACxEC,YAAY;QACd;QAEA,IAAIP,sBAAsBV,mBAAmBkB,IAAI,EAAE;YACjDH,QAAQI,SAAS,CAACC,QAAQ,aAAa;gBACrCC,QAAQX,sBAAsBV,mBAAmBsB,YAAY;gBAC7DN,YAAY;oBAAC;oBAAO;iBAAM;gBAC1BO,SAAS;oBACPH,QAAQ;oBACR;wBACEA,QAAQ;wBACR;4BACEI,SAAS;gCACPC,UAAU;oCAAC;oCAAgB;iCAAgB;4BAC7C;wBACF;qBACD;iBACF;gBACDC,SAAS;oBACPN,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;oBACRA,QAAQ;iBACT;gBACDO,YAAY;oBACVC,eAAe,CAACtB,KAAKuB,aAAa;gBACpC;gBACA,GAAIlB,eAAe;YACrB;QACF;QAEAJ,mBAAmBQ;QAEnBA,QAAQjB,MAAM,CAAUA,QAAQ;YAC9B+B,eAAevB,KAAKuB,aAAa;YACjCC,cAAcC;YACdC,MAAM;QACR;QAEAjB,QAAQZ,MAAM,CACZ,OAAO8B,aAAaC,eAClB,MAAMhC,gBAAgB;gBACpB+B;gBACAC;gBACA9B;gBACAC;gBACAQ;YACF;IAEN;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import builders from '../../builders';
|
|
2
|
+
import { build } from './buildHandler';
|
|
3
|
+
import { processInvalidTranspilation } from './utils';
|
|
4
|
+
const command = {
|
|
5
|
+
command: [
|
|
6
|
+
'build',
|
|
7
|
+
'b'
|
|
8
|
+
],
|
|
9
|
+
desc: 'Build Snap from source',
|
|
10
|
+
builder: (yarg)=>{
|
|
11
|
+
yarg.option('dist', builders.dist).option('eval', builders.eval).option('manifest', builders.manifest).option('outfileName', builders.outfileName).option('sourceMaps', builders.sourceMaps).option('src', builders.src).option('stripComments', builders.stripComments).option('transpilationMode', builders.transpilationMode).option('depsToTranspile', builders.depsToTranspile).option('writeManifest', builders.writeManifest).implies('writeManifest', 'manifest').implies('depsToTranspile', 'transpilationMode').middleware((argv)=>processInvalidTranspilation(argv));
|
|
12
|
+
},
|
|
13
|
+
handler: async (argv)=>build(argv)
|
|
14
|
+
};
|
|
15
|
+
export default command;
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/cmds/build/index.ts"],"sourcesContent":["import yargs from 'yargs';\n\nimport builders from '../../builders';\nimport { YargsArgs } from '../../types/yargs';\nimport { build } from './buildHandler';\nimport { processInvalidTranspilation } from './utils';\n\nconst command = {\n command: ['build', 'b'],\n desc: 'Build Snap from source',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('dist', builders.dist)\n .option('eval', builders.eval)\n .option('manifest', builders.manifest)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('src', builders.src)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('writeManifest', builders.writeManifest)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode')\n .middleware((argv) => processInvalidTranspilation(argv as any));\n },\n handler: async (argv: YargsArgs) => build(argv),\n};\n\nexport default command;\n"],"names":["builders","build","processInvalidTranspilation","command","desc","builder","yarg","option","dist","eval","manifest","outfileName","sourceMaps","src","stripComments","transpilationMode","depsToTranspile","writeManifest","implies","middleware","argv","handler"],"mappings":"AAEA,OAAOA,cAAc,iBAAiB;AAEtC,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,2BAA2B,QAAQ,UAAU;AAEtD,MAAMC,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,QAAQP,SAASQ,IAAI,EAC5BD,MAAM,CAAC,QAAQP,SAASS,IAAI,EAC5BF,MAAM,CAAC,YAAYP,SAASU,QAAQ,EACpCH,MAAM,CAAC,eAAeP,SAASW,WAAW,EAC1CJ,MAAM,CAAC,cAAcP,SAASY,UAAU,EACxCL,MAAM,CAAC,OAAOP,SAASa,GAAG,EAC1BN,MAAM,CAAC,iBAAiBP,SAASc,aAAa,EAC9CP,MAAM,CAAC,qBAAqBP,SAASe,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBP,SAASgB,eAAe,EAClDT,MAAM,CAAC,iBAAiBP,SAASiB,aAAa,EAC9CC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB,qBAC3BC,UAAU,CAAC,CAACC,OAASlB,4BAA4BkB;IACtD;IACAC,SAAS,OAAOD,OAAoBnB,MAAMmB;AAC5C;AAEA,eAAejB,QAAQ"}
|