@metamask-previews/messenger-cli 0.2.0-preview-ec4680201 ā 0.2.0-preview-40d5fb1e2
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 +0 -5
- package/dist/check.cjs +3 -5
- package/dist/check.cjs.map +1 -1
- package/dist/check.d.cts +1 -3
- package/dist/check.d.cts.map +1 -1
- package/dist/check.d.mts +1 -3
- package/dist/check.d.mts.map +1 -1
- package/dist/check.mjs +2 -4
- package/dist/check.mjs.map +1 -1
- package/dist/cli.cjs +8 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +4 -10
- package/dist/cli.mjs.map +1 -1
- package/dist/fix.cjs +3 -5
- package/dist/fix.cjs.map +1 -1
- package/dist/fix.d.cts +1 -3
- package/dist/fix.d.cts.map +1 -1
- package/dist/fix.d.mts +1 -3
- package/dist/fix.d.mts.map +1 -1
- package/dist/fix.mjs +2 -4
- package/dist/fix.mjs.map +1 -1
- package/dist/generate-content.cjs +2 -4
- package/dist/generate-content.cjs.map +1 -1
- package/dist/generate-content.d.cts +1 -3
- package/dist/generate-content.d.cts.map +1 -1
- package/dist/generate-content.d.mts +1 -3
- package/dist/generate-content.d.mts.map +1 -1
- package/dist/generate-content.mjs +2 -4
- package/dist/generate-content.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add `--esm` flag for ESM-compatible import extensions ([#9572](https://github.com/MetaMask/core/pull/9572))
|
|
13
|
-
- When `--esm` is set, the generated files will have `.js` import extensions.
|
|
14
|
-
|
|
15
10
|
### Changed
|
|
16
11
|
|
|
17
12
|
- Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
|
package/dist/check.cjs
CHANGED
|
@@ -26,17 +26,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.checkActionTypesFiles = void 0;
|
|
27
27
|
const fs = __importStar(require("node:fs"));
|
|
28
28
|
const path = __importStar(require("node:path"));
|
|
29
|
-
const
|
|
29
|
+
const generate_content_1 = require("./generate-content.cjs");
|
|
30
30
|
/**
|
|
31
31
|
* Checks if generated action types files are up to date.
|
|
32
32
|
*
|
|
33
33
|
* @param sources - Array of source information objects.
|
|
34
34
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
35
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
36
|
-
* compatibility.
|
|
37
35
|
* @returns Whether all files are up to date.
|
|
38
36
|
*/
|
|
39
|
-
async function checkActionTypesFiles(sources, formatter
|
|
37
|
+
async function checkActionTypesFiles(sources, formatter) {
|
|
40
38
|
let hasErrors = false;
|
|
41
39
|
const fileComparisonJobs = [];
|
|
42
40
|
for (const source of sources) {
|
|
@@ -44,7 +42,7 @@ async function checkActionTypesFiles(sources, formatter, esm = false) {
|
|
|
44
42
|
const outputDir = path.dirname(source.filePath);
|
|
45
43
|
const baseFileName = path.basename(source.filePath, '.ts');
|
|
46
44
|
const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
47
|
-
const expectedContent = await (0,
|
|
45
|
+
const expectedContent = await (0, generate_content_1.generateActionTypesContent)(source, formatter);
|
|
48
46
|
try {
|
|
49
47
|
await fs.promises.access(actualFile);
|
|
50
48
|
fileComparisonJobs.push({
|
package/dist/check.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.cjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,
|
|
1
|
+
{"version":3,"file":"check.cjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":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C,EAAE,CAAC;QAClC,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAEzE,IAAI,GAAG,CAAC,eAAe,KAAK,aAAa,EAAE,CAAC;gBAC1C,OAAO,CAAC,GAAG,CACT,KAAK,GAAG,CAAC,YAAY,uCAAuC,CAC7D,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CACX,KAAK,GAAG,CAAC,YAAY,wCAAwC,CAC9D,CAAC;gBACF,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC;AAtED,sDAsEC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { generateActionTypesContent } from './generate-content';\nimport type { SourceInfo } from './parse-source';\nimport { Formatter } from './types';\n\n/**\n * Checks if generated action types files are up to date.\n *\n * @param sources - Array of source information objects.\n * @param formatter - The formatter to use for formatting the generated content.\n * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n): Promise<boolean> {\n let hasErrors = false;\n\n const fileComparisonJobs: {\n expectedContent: string;\n actualFile: string;\n baseFileName: string;\n }[] = [];\n\n for (const source of sources) {\n console.log(`\\nš§ Checking ${source.name}...`);\n const outputDir = path.dirname(source.filePath);\n const baseFileName = path.basename(source.filePath, '.ts');\n const actualFile = path.join(\n outputDir,\n `${baseFileName}-method-action-types.ts`,\n );\n\n const expectedContent = await generateActionTypesContent(source, formatter);\n\n try {\n await fs.promises.access(actualFile);\n fileComparisonJobs.push({\n expectedContent,\n actualFile,\n baseFileName,\n });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n console.error(\n `ā ${baseFileName}-method-action-types.ts does not exist`,\n );\n } else {\n console.error(\n `ā Error reading ${baseFileName}-method-action-types.ts:`,\n error,\n );\n }\n hasErrors = true;\n }\n }\n\n if (fileComparisonJobs.length > 0) {\n for (const job of fileComparisonJobs) {\n const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');\n\n if (job.expectedContent === actualContent) {\n console.log(\n `ā
${job.baseFileName}-method-action-types.ts is up to date`,\n );\n } else {\n console.error(\n `ā ${job.baseFileName}-method-action-types.ts is out of date`,\n );\n hasErrors = true;\n }\n }\n }\n\n if (hasErrors) {\n console.error('\\nš„ Some action type files are out of date or missing.');\n console.error('Run `messenger-action-types --generate` to update them.');\n return false;\n }\n\n console.log('\\nš All action type files are up to date!');\n return true;\n}\n"]}
|
package/dist/check.d.cts
CHANGED
|
@@ -5,9 +5,7 @@ import { Formatter } from "./types.cjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param sources - Array of source information objects.
|
|
7
7
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
8
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
9
|
-
* compatibility.
|
|
10
8
|
* @returns Whether all files are up to date.
|
|
11
9
|
*/
|
|
12
|
-
export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter
|
|
10
|
+
export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<boolean>;
|
|
13
11
|
//# sourceMappingURL=check.d.cts.map
|
package/dist/check.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.cts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"check.d.cts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAEpC;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,OAAO,CAAC,CAmElB"}
|
package/dist/check.d.mts
CHANGED
|
@@ -5,9 +5,7 @@ import { Formatter } from "./types.mjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param sources - Array of source information objects.
|
|
7
7
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
8
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
9
|
-
* compatibility.
|
|
10
8
|
* @returns Whether all files are up to date.
|
|
11
9
|
*/
|
|
12
|
-
export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter
|
|
10
|
+
export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<boolean>;
|
|
13
11
|
//# sourceMappingURL=check.d.mts.map
|
package/dist/check.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.mts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"check.d.mts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAEpC;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,OAAO,CAAC,CAmElB"}
|
package/dist/check.mjs
CHANGED
|
@@ -6,11 +6,9 @@ import { generateActionTypesContent } from "./generate-content.mjs";
|
|
|
6
6
|
*
|
|
7
7
|
* @param sources - Array of source information objects.
|
|
8
8
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
9
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
10
|
-
* compatibility.
|
|
11
9
|
* @returns Whether all files are up to date.
|
|
12
10
|
*/
|
|
13
|
-
export async function checkActionTypesFiles(sources, formatter
|
|
11
|
+
export async function checkActionTypesFiles(sources, formatter) {
|
|
14
12
|
let hasErrors = false;
|
|
15
13
|
const fileComparisonJobs = [];
|
|
16
14
|
for (const source of sources) {
|
|
@@ -18,7 +16,7 @@ export async function checkActionTypesFiles(sources, formatter, esm = false) {
|
|
|
18
16
|
const outputDir = path.dirname(source.filePath);
|
|
19
17
|
const baseFileName = path.basename(source.filePath, '.ts');
|
|
20
18
|
const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
21
|
-
const expectedContent = await generateActionTypesContent(source, formatter
|
|
19
|
+
const expectedContent = await generateActionTypesContent(source, formatter);
|
|
22
20
|
try {
|
|
23
21
|
await fs.promises.access(actualFile);
|
|
24
22
|
fileComparisonJobs.push({
|
package/dist/check.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.mjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+
|
|
1
|
+
{"version":3,"file":"check.mjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAIhE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,SAAoB;IAEpB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,kBAAkB,GAI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Aa,EAAE,CAAC;gBAC1C,OAAO,CAAC,GAAG,CACT,KAAK,GAAG,CAAC,YAAY,uCAAuC,CAC7D,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CACX,KAAK,GAAG,CAAC,YAAY,wCAAwC,CAC9D,CAAC;gBACF,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { generateActionTypesContent } from './generate-content';\nimport type { SourceInfo } from './parse-source';\nimport { Formatter } from './types';\n\n/**\n * Checks if generated action types files are up to date.\n *\n * @param sources - Array of source information objects.\n * @param formatter - The formatter to use for formatting the generated content.\n * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n): Promise<boolean> {\n let hasErrors = false;\n\n const fileComparisonJobs: {\n expectedContent: string;\n actualFile: string;\n baseFileName: string;\n }[] = [];\n\n for (const source of sources) {\n console.log(`\\nš§ Checking ${source.name}...`);\n const outputDir = path.dirname(source.filePath);\n const baseFileName = path.basename(source.filePath, '.ts');\n const actualFile = path.join(\n outputDir,\n `${baseFileName}-method-action-types.ts`,\n );\n\n const expectedContent = await generateActionTypesContent(source, formatter);\n\n try {\n await fs.promises.access(actualFile);\n fileComparisonJobs.push({\n expectedContent,\n actualFile,\n baseFileName,\n });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n console.error(\n `ā ${baseFileName}-method-action-types.ts does not exist`,\n );\n } else {\n console.error(\n `ā Error reading ${baseFileName}-method-action-types.ts:`,\n error,\n );\n }\n hasErrors = true;\n }\n }\n\n if (fileComparisonJobs.length > 0) {\n for (const job of fileComparisonJobs) {\n const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');\n\n if (job.expectedContent === actualContent) {\n console.log(\n `ā
${job.baseFileName}-method-action-types.ts is up to date`,\n );\n } else {\n console.error(\n `ā ${job.baseFileName}-method-action-types.ts is out of date`,\n );\n hasErrors = true;\n }\n }\n }\n\n if (hasErrors) {\n console.error('\\nš„ Some action type files are out of date or missing.');\n console.error('Run `messenger-action-types --generate` to update them.');\n return false;\n }\n\n console.log('\\nš All action type files are up to date!');\n return true;\n}\n"]}
|
package/dist/cli.cjs
CHANGED
|
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
8
|
+
const check_1 = require("./check.cjs");
|
|
9
|
+
const fix_1 = require("./fix.cjs");
|
|
10
|
+
const parse_source_1 = require("./parse-source.cjs");
|
|
11
11
|
/**
|
|
12
12
|
* Parses the given CLI arguments.
|
|
13
13
|
*
|
|
@@ -15,7 +15,7 @@ const parse_source_js_1 = require("./parse-source.cjs");
|
|
|
15
15
|
* @returns The parsed command line arguments.
|
|
16
16
|
*/
|
|
17
17
|
async function parseCommandLineArguments(args) {
|
|
18
|
-
const { check, generate, formatter,
|
|
18
|
+
const { check, generate, formatter, path: sourcePath, } = await (0, yargs_1.default)(args)
|
|
19
19
|
.command('$0 [path]', 'Generate method action types for controller and service messengers', (yargsInstance) => {
|
|
20
20
|
yargsInstance.positional('path', {
|
|
21
21
|
type: 'string',
|
|
@@ -38,11 +38,6 @@ async function parseCommandLineArguments(args) {
|
|
|
38
38
|
description: 'The formatter to use for formatting generated files',
|
|
39
39
|
choices: ['oxfmt', 'prettier'],
|
|
40
40
|
default: 'prettier',
|
|
41
|
-
})
|
|
42
|
-
.option('esm', {
|
|
43
|
-
type: 'boolean',
|
|
44
|
-
description: 'Add .js extensions to import paths for ESM compatibility',
|
|
45
|
-
default: false,
|
|
46
41
|
})
|
|
47
42
|
.help()
|
|
48
43
|
.check((argv) => {
|
|
@@ -56,27 +51,26 @@ async function parseCommandLineArguments(args) {
|
|
|
56
51
|
generate,
|
|
57
52
|
formatter: formatter,
|
|
58
53
|
sourcePath: sourcePath,
|
|
59
|
-
esm,
|
|
60
54
|
};
|
|
61
55
|
}
|
|
62
56
|
/**
|
|
63
57
|
* Main entry point for the CLI.
|
|
64
58
|
*/
|
|
65
59
|
async function main() {
|
|
66
|
-
const { generate, sourcePath, formatter
|
|
60
|
+
const { generate, sourcePath, formatter } = await parseCommandLineArguments(globalThis.process.argv.slice(2));
|
|
67
61
|
console.log('š Searching for controllers/services with MESSENGER_EXPOSED_METHODS...');
|
|
68
|
-
const sources = await (0,
|
|
62
|
+
const sources = await (0, parse_source_1.findSourcesWithExposedMethods)(sourcePath);
|
|
69
63
|
if (sources.length === 0) {
|
|
70
64
|
console.log('ā ļø No controllers/services found with MESSENGER_EXPOSED_METHODS');
|
|
71
65
|
return;
|
|
72
66
|
}
|
|
73
67
|
console.log(`š¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
|
|
74
68
|
if (generate) {
|
|
75
|
-
await (0,
|
|
69
|
+
await (0, fix_1.generateAllActionTypesFiles)(sources, formatter);
|
|
76
70
|
console.log('\nš All action types generated successfully!');
|
|
77
71
|
}
|
|
78
72
|
else {
|
|
79
|
-
const success = await (0,
|
|
73
|
+
const success = await (0, check_1.checkActionTypesFiles)(sources, formatter);
|
|
80
74
|
if (!success) {
|
|
81
75
|
// eslint-disable-next-line no-restricted-globals
|
|
82
76
|
process.exitCode = 1;
|
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B,
|
|
1
|
+
{"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B,uCAAgD;AAChD,mCAAoD;AACpD,qDAA+D;AAU/D;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CACtC,IAAc;IAEd,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EAAE,UAAU,GACjB,GAAG,MAAM,IAAA,eAAK,EAAC,IAAI,CAAC;SAClB,OAAO,CACN,WAAW,EACX,oEAAoE,EACpE,CAAC,aAAa,EAAE,EAAE;QAChB,aAAa,CAAC,UAAU,CAAC,MAAM,EAAE;YAC/B,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,2DAA2D;YAC7D,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;IACL,CAAC,CACF;SACA,MAAM,CAAC,OAAO,EAAE;QACf,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,qDAAqD;QAClE,OAAO,EAAE,KAAK;KACf,CAAC;SACD,MAAM,CAAC,UAAU,EAAE;QAClB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,mCAAmC;QAChD,OAAO,EAAE,KAAK;KACf,CAAC;SACD,MAAM,CAAC,WAAW,EAAE;QACnB,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,qDAAqD;QAClE,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;QAC9B,OAAO,EAAE,UAAU;KACpB,CAAC;SACD,IAAI,EAAE;SACN,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC,IAAI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args from 'yargs';\n\nimport { checkActionTypesFiles } from './check';\nimport { generateAllActionTypesFiles } from './fix';\nimport { findSourcesWithExposedMethods } from './parse-source';\nimport { Formatter } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n generate: boolean;\n formatter: Formatter;\n sourcePath: string;\n};\n\n/**\n * Parses the given CLI arguments.\n *\n * @param args - The arguments to parse.\n * @returns The parsed command line arguments.\n */\nasync function parseCommandLineArguments(\n args: string[],\n): Promise<CommandLineArguments> {\n const {\n check,\n generate,\n formatter,\n path: sourcePath,\n } = await yargs(args)\n .command(\n '$0 [path]',\n 'Generate method action types for controller and service messengers',\n (yargsInstance) => {\n yargsInstance.positional('path', {\n type: 'string',\n description:\n 'Path to the folder where controllers/services are located',\n default: 'src',\n });\n },\n )\n .option('check', {\n type: 'boolean',\n description: 'Check if generated action type files are up to date',\n default: false,\n })\n .option('generate', {\n type: 'boolean',\n description: 'Generate/update action type files',\n default: false,\n })\n .option('formatter', {\n type: 'string',\n description: 'The formatter to use for formatting generated files',\n choices: ['oxfmt', 'prettier'],\n default: 'prettier',\n })\n .help()\n .check((argv) => {\n if (!argv.check && !argv.generate) {\n throw new Error('Either --check or --generate must be provided.\\n');\n }\n return true;\n }).argv;\n\n return {\n check,\n generate,\n formatter: formatter as Formatter,\n sourcePath: sourcePath as string,\n };\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { generate, sourcePath, formatter } = await parseCommandLineArguments(\n globalThis.process.argv.slice(2),\n );\n\n console.log(\n 'š Searching for controllers/services with MESSENGER_EXPOSED_METHODS...',\n );\n\n const sources = await findSourcesWithExposedMethods(sourcePath);\n\n if (sources.length === 0) {\n console.log(\n 'ā ļø No controllers/services found with MESSENGER_EXPOSED_METHODS',\n );\n return;\n }\n\n console.log(\n `š¦ Found ${sources.length} controller(s)/service(s) with exposed methods`,\n );\n\n if (generate) {\n await generateAllActionTypesFiles(sources, formatter);\n console.log('\\nš All action types generated successfully!');\n } else {\n const success = await checkActionTypesFiles(sources, formatter);\n if (!success) {\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n }\n }\n}\n\nmain().catch((error) => {\n console.error('ā Script failed:', error);\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n});\n"]}
|
package/dist/cli.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { findSourcesWithExposedMethods } from "./parse-source.mjs";
|
|
|
10
10
|
* @returns The parsed command line arguments.
|
|
11
11
|
*/
|
|
12
12
|
async function parseCommandLineArguments(args) {
|
|
13
|
-
const { check, generate, formatter,
|
|
13
|
+
const { check, generate, formatter, path: sourcePath, } = await yargs(args)
|
|
14
14
|
.command('$0 [path]', 'Generate method action types for controller and service messengers', (yargsInstance) => {
|
|
15
15
|
yargsInstance.positional('path', {
|
|
16
16
|
type: 'string',
|
|
@@ -33,11 +33,6 @@ async function parseCommandLineArguments(args) {
|
|
|
33
33
|
description: 'The formatter to use for formatting generated files',
|
|
34
34
|
choices: ['oxfmt', 'prettier'],
|
|
35
35
|
default: 'prettier',
|
|
36
|
-
})
|
|
37
|
-
.option('esm', {
|
|
38
|
-
type: 'boolean',
|
|
39
|
-
description: 'Add .js extensions to import paths for ESM compatibility',
|
|
40
|
-
default: false,
|
|
41
36
|
})
|
|
42
37
|
.help()
|
|
43
38
|
.check((argv) => {
|
|
@@ -51,14 +46,13 @@ async function parseCommandLineArguments(args) {
|
|
|
51
46
|
generate,
|
|
52
47
|
formatter: formatter,
|
|
53
48
|
sourcePath: sourcePath,
|
|
54
|
-
esm,
|
|
55
49
|
};
|
|
56
50
|
}
|
|
57
51
|
/**
|
|
58
52
|
* Main entry point for the CLI.
|
|
59
53
|
*/
|
|
60
54
|
async function main() {
|
|
61
|
-
const { generate, sourcePath, formatter
|
|
55
|
+
const { generate, sourcePath, formatter } = await parseCommandLineArguments(globalThis.process.argv.slice(2));
|
|
62
56
|
console.log('š Searching for controllers/services with MESSENGER_EXPOSED_METHODS...');
|
|
63
57
|
const sources = await findSourcesWithExposedMethods(sourcePath);
|
|
64
58
|
if (sources.length === 0) {
|
|
@@ -67,11 +61,11 @@ async function main() {
|
|
|
67
61
|
}
|
|
68
62
|
console.log(`š¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
|
|
69
63
|
if (generate) {
|
|
70
|
-
await generateAllActionTypesFiles(sources, formatter
|
|
64
|
+
await generateAllActionTypesFiles(sources, formatter);
|
|
71
65
|
console.log('\nš All action types generated successfully!');
|
|
72
66
|
}
|
|
73
67
|
else {
|
|
74
|
-
const success = await checkActionTypesFiles(sources, formatter
|
|
68
|
+
const success = await checkActionTypesFiles(sources, formatter);
|
|
75
69
|
if (!success) {
|
|
76
70
|
// eslint-disable-next-line no-restricted-globals
|
|
77
71
|
process.exitCode = 1;
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,cAAc;AAE1B,OAAO,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,cAAc;AAE1B,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,6BAA6B,EAAE,2BAAuB;AAU/D;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CACtC,IAAc;IAEd,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EAAE,UAAU,GACjB,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;SAClB,OAAO,CACN,WAAW,EACX,oEAAoE,EACpE,CAAC,aAAa,EAAE,EAAE;QAChB,aAAa,CAAC,UAAU,CAAC,MAAM,EAAE;YAC/B,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,2DAA2D;YAC7D,OAAO,EAAE,KAAK;SACf,CAAC,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YAAY,OAAO,CAAC,MAAM,gDAAgD,CAC3E,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,2BAA2B,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,MAAM,qBAAqB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAChE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,iDAAiD;YACjD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,iDAAiD;IACjD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport yargs from 'yargs';\n\nimport { checkActionTypesFiles } from './check';\nimport { generateAllActionTypesFiles } from './fix';\nimport { findSourcesWithExposedMethods } from './parse-source';\nimport { Formatter } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n generate: boolean;\n formatter: Formatter;\n sourcePath: string;\n};\n\n/**\n * Parses the given CLI arguments.\n *\n * @param args - The arguments to parse.\n * @returns The parsed command line arguments.\n */\nasync function parseCommandLineArguments(\n args: string[],\n): Promise<CommandLineArguments> {\n const {\n check,\n generate,\n formatter,\n path: sourcePath,\n } = await yargs(args)\n .command(\n '$0 [path]',\n 'Generate method action types for controller and service messengers',\n (yargsInstance) => {\n yargsInstance.positional('path', {\n type: 'string',\n description:\n 'Path to the folder where controllers/services are located',\n default: 'src',\n });\n },\n )\n .option('check', {\n type: 'boolean',\n description: 'Check if generated action type files are up to date',\n default: false,\n })\n .option('generate', {\n type: 'boolean',\n description: 'Generate/update action type files',\n default: false,\n })\n .option('formatter', {\n type: 'string',\n description: 'The formatter to use for formatting generated files',\n choices: ['oxfmt', 'prettier'],\n default: 'prettier',\n })\n .help()\n .check((argv) => {\n if (!argv.check && !argv.generate) {\n throw new Error('Either --check or --generate must be provided.\\n');\n }\n return true;\n }).argv;\n\n return {\n check,\n generate,\n formatter: formatter as Formatter,\n sourcePath: sourcePath as string,\n };\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { generate, sourcePath, formatter } = await parseCommandLineArguments(\n globalThis.process.argv.slice(2),\n );\n\n console.log(\n 'š Searching for controllers/services with MESSENGER_EXPOSED_METHODS...',\n );\n\n const sources = await findSourcesWithExposedMethods(sourcePath);\n\n if (sources.length === 0) {\n console.log(\n 'ā ļø No controllers/services found with MESSENGER_EXPOSED_METHODS',\n );\n return;\n }\n\n console.log(\n `š¦ Found ${sources.length} controller(s)/service(s) with exposed methods`,\n );\n\n if (generate) {\n await generateAllActionTypesFiles(sources, formatter);\n console.log('\\nš All action types generated successfully!');\n } else {\n const success = await checkActionTypesFiles(sources, formatter);\n if (!success) {\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n }\n }\n}\n\nmain().catch((error) => {\n console.error('ā Script failed:', error);\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n});\n"]}
|
package/dist/fix.cjs
CHANGED
|
@@ -26,23 +26,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.generateAllActionTypesFiles = void 0;
|
|
27
27
|
const fs = __importStar(require("node:fs"));
|
|
28
28
|
const path = __importStar(require("node:path"));
|
|
29
|
-
const
|
|
29
|
+
const generate_content_1 = require("./generate-content.cjs");
|
|
30
30
|
/**
|
|
31
31
|
* Generates action types files for all controllers/services.
|
|
32
32
|
*
|
|
33
33
|
* @param sources - Array of source information objects.
|
|
34
34
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
35
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
36
|
-
* compatibility.
|
|
37
35
|
* @returns Whether all files were generated successfully.
|
|
38
36
|
*/
|
|
39
|
-
async function generateAllActionTypesFiles(sources, formatter
|
|
37
|
+
async function generateAllActionTypesFiles(sources, formatter) {
|
|
40
38
|
for (const source of sources) {
|
|
41
39
|
console.log(`\nš§ Processing ${source.name}...`);
|
|
42
40
|
const outputDir = path.dirname(source.filePath);
|
|
43
41
|
const baseFileName = path.basename(source.filePath, '.ts');
|
|
44
42
|
const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
45
|
-
const generatedContent = await (0,
|
|
43
|
+
const generatedContent = await (0, generate_content_1.generateActionTypesContent)(source, formatter);
|
|
46
44
|
await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
|
|
47
45
|
console.log(`ā
Generated action types for ${source.name}`);
|
|
48
46
|
}
|
package/dist/fix.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.cjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,
|
|
1
|
+
{"version":3,"file":"fix.cjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;;GAMG;AACI,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,SAAoB;IAEpB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,SAAS,EACT,GAAG,YAAY,yBAAyB,CACzC,CAAC;QAEF,MAAM,gBAAgB,GAAG,MAAM,IAAA,6CAA0B,EACvD,MAAM,EACN,SAAS,CACV,CAAC;QAEF,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC,gCAAgC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AArBD,kEAqBC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { generateActionTypesContent } from './generate-content';\nimport type { SourceInfo } from './parse-source';\nimport type { Formatter } from './types';\n\n/**\n * Generates action types files for all controllers/services.\n *\n * @param sources - Array of source information objects.\n * @param formatter - The formatter to use for formatting the generated content.\n * @returns Whether all files were generated successfully.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n): Promise<void> {\n for (const source of sources) {\n console.log(`\\nš§ Processing ${source.name}...`);\n const outputDir = path.dirname(source.filePath);\n const baseFileName = path.basename(source.filePath, '.ts');\n const outputFile = path.join(\n outputDir,\n `${baseFileName}-method-action-types.ts`,\n );\n\n const generatedContent = await generateActionTypesContent(\n source,\n formatter,\n );\n\n await fs.promises.writeFile(outputFile, generatedContent, 'utf8');\n console.log(`ā
Generated action types for ${source.name}`);\n }\n}\n"]}
|
package/dist/fix.d.cts
CHANGED
|
@@ -5,9 +5,7 @@ import type { Formatter } from "./types.cjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param sources - Array of source information objects.
|
|
7
7
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
8
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
9
|
-
* compatibility.
|
|
10
8
|
* @returns Whether all files were generated successfully.
|
|
11
9
|
*/
|
|
12
|
-
export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter
|
|
10
|
+
export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<void>;
|
|
13
11
|
//# sourceMappingURL=fix.d.cts.map
|
package/dist/fix.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.d.cts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"fix.d.cts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAgB;AAEzC;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
package/dist/fix.d.mts
CHANGED
|
@@ -5,9 +5,7 @@ import type { Formatter } from "./types.mjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param sources - Array of source information objects.
|
|
7
7
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
8
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
9
|
-
* compatibility.
|
|
10
8
|
* @returns Whether all files were generated successfully.
|
|
11
9
|
*/
|
|
12
|
-
export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter
|
|
10
|
+
export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<void>;
|
|
13
11
|
//# sourceMappingURL=fix.d.mts.map
|
package/dist/fix.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.d.mts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"fix.d.mts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAgB;AAEzC;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
package/dist/fix.mjs
CHANGED
|
@@ -6,17 +6,15 @@ import { generateActionTypesContent } from "./generate-content.mjs";
|
|
|
6
6
|
*
|
|
7
7
|
* @param sources - Array of source information objects.
|
|
8
8
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
9
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
10
|
-
* compatibility.
|
|
11
9
|
* @returns Whether all files were generated successfully.
|
|
12
10
|
*/
|
|
13
|
-
export async function generateAllActionTypesFiles(sources, formatter
|
|
11
|
+
export async function generateAllActionTypesFiles(sources, formatter) {
|
|
14
12
|
for (const source of sources) {
|
|
15
13
|
console.log(`\nš§ Processing ${source.name}...`);
|
|
16
14
|
const outputDir = path.dirname(source.filePath);
|
|
17
15
|
const baseFileName = path.basename(source.filePath, '.ts');
|
|
18
16
|
const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
19
|
-
const generatedContent = await generateActionTypesContent(source, formatter
|
|
17
|
+
const generatedContent = await generateActionTypesContent(source, formatter);
|
|
20
18
|
await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
|
|
21
19
|
console.log(`ā
Generated action types for ${source.name}`);
|
|
22
20
|
}
|
package/dist/fix.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.mjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+
|
|
1
|
+
{"version":3,"file":"fix.mjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAIhE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,SAAoB;IAEpB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,SAAS,EACT,GAAG,YAAY,yBAAyB,CACzC,CAAC;QAEF,MAAM,gBAAgB,GAAG,MAAM,0BAA0B,CACvD,MAAM,EACN,SAAS,CACV,CAAC;QAEF,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC,gCAAgC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { generateActionTypesContent } from './generate-content';\nimport type { SourceInfo } from './parse-source';\nimport type { Formatter } from './types';\n\n/**\n * Generates action types files for all controllers/services.\n *\n * @param sources - Array of source information objects.\n * @param formatter - The formatter to use for formatting the generated content.\n * @returns Whether all files were generated successfully.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n): Promise<void> {\n for (const source of sources) {\n console.log(`\\nš§ Processing ${source.name}...`);\n const outputDir = path.dirname(source.filePath);\n const baseFileName = path.basename(source.filePath, '.ts');\n const outputFile = path.join(\n outputDir,\n `${baseFileName}-method-action-types.ts`,\n );\n\n const generatedContent = await generateActionTypesContent(\n source,\n formatter,\n );\n\n await fs.promises.writeFile(outputFile, generatedContent, 'utf8');\n console.log(`ā
Generated action types for ${source.name}`);\n }\n}\n"]}
|
|
@@ -105,13 +105,11 @@ function getFormatter(formatter) {
|
|
|
105
105
|
*
|
|
106
106
|
* @param source - The source information object (controller or service).
|
|
107
107
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
108
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
109
|
-
* compatibility.
|
|
110
108
|
* @returns The content for the action types file.
|
|
111
109
|
*/
|
|
112
|
-
async function generateActionTypesContent(source, formatter
|
|
110
|
+
async function generateActionTypesContent(source, formatter) {
|
|
113
111
|
const baseFileName = path.basename(source.filePath, '.ts');
|
|
114
|
-
const sourceImportPath = `./${baseFileName}
|
|
112
|
+
const sourceImportPath = `./${baseFileName}`;
|
|
115
113
|
let content = `/**
|
|
116
114
|
* This file is auto generated.
|
|
117
115
|
* Do not edit manually.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.cjs","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAoE;AACpE,gDAAkC;AAKlC;;;;;;GAMG;AACH,MAAM,0BAA0B,GAAG;IACjC,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,QAAgB;IACxD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,YAAY,CAAC;QAE3D,MAAM,MAAM,GACV,CAAC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,0BAA0B,CAAC;QAEhE,OAAO,MAAM,MAAM,CAAC,QAA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AAC,CAAC;IAClD,OAAO,MAAM,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC3D,CAAC;AA9CD,gEA8CC","sourcesContent":["import { assertExhaustive, getErrorMessage } from '@metamask/utils';\nimport * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\nimport { Formatter } from './types';\n\n/**\n * The default options used by Oxfmt and Prettier when formatting the generated\n * content. In the case of Prettier, these options will be used if the user does\n * not have a Prettier configuration file in their project. Oxfmt doesn't have a\n * `resolveConfig` function like Prettier, so it will always use these options\n * when formatting.\n */\nconst DEFAULT_FORMATTING_OPTIONS = {\n printWidth: 80,\n singleQuote: true,\n};\n\n/**\n * Safely format a TypeScript file with Prettier. If Prettier is not installed,\n * it will throw an error with a clear message. This allows us to use Prettier\n * for formatting when available, without making it a hard dependency of the\n * project.\n *\n * @param contents - The source code to format.\n * @param filePath - The file path to use for resolving Prettier configuration.\n * @returns The formatted source code.\n */\nasync function prettier(contents: string, filePath: string): Promise<string> {\n try {\n const { format, resolveConfig } = await import('prettier');\n\n const config =\n (await resolveConfig(filePath)) ?? DEFAULT_FORMATTING_OPTIONS;\n\n return await format(contents, {\n ...config,\n parser: 'typescript',\n });\n } catch (error) {\n const message = getErrorMessage(error);\n throw new Error(\n `Failed to format source code with Prettier. Is Prettier installed?\\n\\n${message}`,\n );\n }\n}\n\n/**\n * Safely format a TypeScript file with Oxfmt. If Oxfmt is not installed, it\n * will throw an error with a clear message. This allows us to use Oxfmt for\n * formatting when available, without making it a hard dependency of the\n * project.\n *\n * @param contents - The source code to format.\n * @param filePath - The file path to use for resolving Oxfmt configuration. Not\n * currently used, but included for future extensibility.\n * @returns The formatted source code.\n */\nasync function oxfmt(contents: string, filePath: string): Promise<string> {\n try {\n const { format } = await import('oxfmt');\n const result = await format(filePath, contents, DEFAULT_FORMATTING_OPTIONS);\n\n return result.code;\n } catch (error) {\n const message = getErrorMessage(error);\n throw new Error(\n `Failed to format source code with Oxfmt. Is Oxfmt installed?\\n\\n${message}`,\n );\n }\n}\n\n/**\n * Get the appropriate formatter function based on the specified formatter.\n *\n * @param formatter - The formatter to use.\n * @returns A function that takes source code as input and returns the formatted\n * source code.\n */\nfunction getFormatter(\n formatter: Formatter,\n): (contents: string, filePath: string) => Promise<string> {\n switch (formatter) {\n case 'prettier':\n return prettier;\n\n case 'oxfmt':\n return oxfmt;\n\n default:\n return assertExhaustive(formatter);\n }\n}\n\n/**\n * Generates the content for the action types file.\n *\n * @param source - The source information object (controller or service).\n * @param formatter - The formatter to use for formatting the generated content.\n * @returns The content for the action types file.\n */\nexport async function generateActionTypesContent(\n source: SourceInfo,\n formatter: Formatter,\n): Promise<string> {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\n\n let content = `/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ${source.name} } from '${sourceImportPath}';\n\n`;\n\n const actionTypeNames: string[] = [];\n\n for (const method of source.methods) {\n const capitalizedName =\n method.name.charAt(0).toUpperCase() + method.name.slice(1);\n const actionTypeName = `${source.name}${capitalizedName}Action`;\n const actionString = `${source.name}:${method.name}`;\n\n actionTypeNames.push(actionTypeName);\n\n if (method.jsDoc) {\n content += `${method.jsDoc}\\n`;\n }\n\n content += `export type ${actionTypeName} = {\n type: \\`${actionString}\\`;\n handler: ${source.name}['${method.name}'];\n};\\n\\n`;\n }\n\n if (actionTypeNames.length > 0) {\n const unionTypeName = `${source.name}MethodActions`;\n content += `/**\n * Union of all ${source.name} action types.\n */\nexport type ${unionTypeName} = ${actionTypeNames.join(' | ')};\\n`;\n }\n\n const formatterFunction = getFormatter(formatter);\n return await formatterFunction(content, source.filePath);\n}\n"]}
|
|
@@ -5,9 +5,7 @@ import { Formatter } from "./types.cjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param source - The source information object (controller or service).
|
|
7
7
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
8
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
9
|
-
* compatibility.
|
|
10
8
|
* @returns The content for the action types file.
|
|
11
9
|
*/
|
|
12
|
-
export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter
|
|
10
|
+
export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter): Promise<string>;
|
|
13
11
|
//# sourceMappingURL=generate-content.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.d.cts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"generate-content.d.cts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AA0FpC;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,MAAM,CAAC,CA2CjB"}
|
|
@@ -5,9 +5,7 @@ import { Formatter } from "./types.mjs";
|
|
|
5
5
|
*
|
|
6
6
|
* @param source - The source information object (controller or service).
|
|
7
7
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
8
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
9
|
-
* compatibility.
|
|
10
8
|
* @returns The content for the action types file.
|
|
11
9
|
*/
|
|
12
|
-
export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter
|
|
10
|
+
export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter): Promise<string>;
|
|
13
11
|
//# sourceMappingURL=generate-content.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.d.mts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"generate-content.d.mts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AA0FpC;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,MAAM,CAAC,CA2CjB"}
|
|
@@ -79,13 +79,11 @@ function getFormatter(formatter) {
|
|
|
79
79
|
*
|
|
80
80
|
* @param source - The source information object (controller or service).
|
|
81
81
|
* @param formatter - The formatter to use for formatting the generated content.
|
|
82
|
-
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
83
|
-
* compatibility.
|
|
84
82
|
* @returns The content for the action types file.
|
|
85
83
|
*/
|
|
86
|
-
export async function generateActionTypesContent(source, formatter
|
|
84
|
+
export async function generateActionTypesContent(source, formatter) {
|
|
87
85
|
const baseFileName = path.basename(source.filePath, '.ts');
|
|
88
|
-
const sourceImportPath = `./${baseFileName}
|
|
86
|
+
const sourceImportPath = `./${baseFileName}`;
|
|
89
87
|
let content = `/**
|
|
90
88
|
* This file is auto generated.
|
|
91
89
|
* Do not edit manually.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-content.mjs","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,wBAAwB;AACpE,OAAO,KAAK,IAAI,kBAAkB;AAKlC;;;;;;GAMG;AACH,MAAM,0BAA0B,GAAG;IACjC,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,QAAgB;IACxD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,YAAY,CAAC;QAE3D,MAAM,MAAM,GACV,CAAC,MAAM,aAAa,CAAC,QA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,KAAK,CAAC;IAChE,CAAC;IAED,MAAM,iBAAiB,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAClD,OAAO,MAAM,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { assertExhaustive, getErrorMessage } from '@metamask/utils';\nimport * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\nimport { Formatter } from './types';\n\n/**\n * The default options used by Oxfmt and Prettier when formatting the generated\n * content. In the case of Prettier, these options will be used if the user does\n * not have a Prettier configuration file in their project. Oxfmt doesn't have a\n * `resolveConfig` function like Prettier, so it will always use these options\n * when formatting.\n */\nconst DEFAULT_FORMATTING_OPTIONS = {\n printWidth: 80,\n singleQuote: true,\n};\n\n/**\n * Safely format a TypeScript file with Prettier. If Prettier is not installed,\n * it will throw an error with a clear message. This allows us to use Prettier\n * for formatting when available, without making it a hard dependency of the\n * project.\n *\n * @param contents - The source code to format.\n * @param filePath - The file path to use for resolving Prettier configuration.\n * @returns The formatted source code.\n */\nasync function prettier(contents: string, filePath: string): Promise<string> {\n try {\n const { format, resolveConfig } = await import('prettier');\n\n const config =\n (await resolveConfig(filePath)) ?? DEFAULT_FORMATTING_OPTIONS;\n\n return await format(contents, {\n ...config,\n parser: 'typescript',\n });\n } catch (error) {\n const message = getErrorMessage(error);\n throw new Error(\n `Failed to format source code with Prettier. Is Prettier installed?\\n\\n${message}`,\n );\n }\n}\n\n/**\n * Safely format a TypeScript file with Oxfmt. If Oxfmt is not installed, it\n * will throw an error with a clear message. This allows us to use Oxfmt for\n * formatting when available, without making it a hard dependency of the\n * project.\n *\n * @param contents - The source code to format.\n * @param filePath - The file path to use for resolving Oxfmt configuration. Not\n * currently used, but included for future extensibility.\n * @returns The formatted source code.\n */\nasync function oxfmt(contents: string, filePath: string): Promise<string> {\n try {\n const { format } = await import('oxfmt');\n const result = await format(filePath, contents, DEFAULT_FORMATTING_OPTIONS);\n\n return result.code;\n } catch (error) {\n const message = getErrorMessage(error);\n throw new Error(\n `Failed to format source code with Oxfmt. Is Oxfmt installed?\\n\\n${message}`,\n );\n }\n}\n\n/**\n * Get the appropriate formatter function based on the specified formatter.\n *\n * @param formatter - The formatter to use.\n * @returns A function that takes source code as input and returns the formatted\n * source code.\n */\nfunction getFormatter(\n formatter: Formatter,\n): (contents: string, filePath: string) => Promise<string> {\n switch (formatter) {\n case 'prettier':\n return prettier;\n\n case 'oxfmt':\n return oxfmt;\n\n default:\n return assertExhaustive(formatter);\n }\n}\n\n/**\n * Generates the content for the action types file.\n *\n * @param source - The source information object (controller or service).\n * @param formatter - The formatter to use for formatting the generated content.\n * @returns The content for the action types file.\n */\nexport async function generateActionTypesContent(\n source: SourceInfo,\n formatter: Formatter,\n): Promise<string> {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\n\n let content = `/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ${source.name} } from '${sourceImportPath}';\n\n`;\n\n const actionTypeNames: string[] = [];\n\n for (const method of source.methods) {\n const capitalizedName =\n method.name.charAt(0).toUpperCase() + method.name.slice(1);\n const actionTypeName = `${source.name}${capitalizedName}Action`;\n const actionString = `${source.name}:${method.name}`;\n\n actionTypeNames.push(actionTypeName);\n\n if (method.jsDoc) {\n content += `${method.jsDoc}\\n`;\n }\n\n content += `export type ${actionTypeName} = {\n type: \\`${actionString}\\`;\n handler: ${source.name}['${method.name}'];\n};\\n\\n`;\n }\n\n if (actionTypeNames.length > 0) {\n const unionTypeName = `${source.name}MethodActions`;\n content += `/**\n * Union of all ${source.name} action types.\n */\nexport type ${unionTypeName} = ${actionTypeNames.join(' | ')};\\n`;\n }\n\n const formatterFunction = getFormatter(formatter);\n return await formatterFunction(content, source.filePath);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/messenger-cli",
|
|
3
|
-
"version": "0.2.0-preview-
|
|
3
|
+
"version": "0.2.0-preview-40d5fb1e2",
|
|
4
4
|
"description": "CLI tools for the MetaMask messenger system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@metamask/auto-changelog": "^6.1.0",
|
|
48
48
|
"@ts-bridge/cli": "^0.6.4",
|
|
49
|
-
"@types/jest": "^
|
|
49
|
+
"@types/jest": "^29.5.14",
|
|
50
50
|
"@types/yargs": "^17.0.32",
|
|
51
51
|
"deepmerge": "^4.2.2",
|
|
52
52
|
"execa": "^5.0.0",
|
|
53
|
-
"jest": "^
|
|
53
|
+
"jest": "^29.7.0",
|
|
54
54
|
"oxfmt": "^0.44.0",
|
|
55
55
|
"prettier": "^3.3.3",
|
|
56
|
-
"ts-jest": "^29.
|
|
56
|
+
"ts-jest": "^29.2.5",
|
|
57
57
|
"tsx": "^4.20.5",
|
|
58
58
|
"typescript": "~5.3.3"
|
|
59
59
|
},
|