@metamask-previews/messenger-cli 0.2.0-preview-b13d916 → 0.2.0-preview-4f4c98e
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 +1 -0
- package/dist/{check.d.mts → check.d.ts} +3 -3
- package/dist/check.d.ts.map +1 -0
- package/dist/{check.mjs → check.js} +4 -4
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/{cli.mjs → cli.js} +5 -5
- package/dist/cli.js.map +1 -0
- package/dist/{fix.d.cts → fix.d.ts} +3 -3
- package/dist/fix.d.ts.map +1 -0
- package/dist/{fix.mjs → fix.js} +4 -4
- package/dist/fix.js.map +1 -0
- package/dist/{generate-content.d.cts → generate-content.d.ts} +3 -3
- package/dist/generate-content.d.ts.map +1 -0
- package/dist/{generate-content.mjs → generate-content.js} +5 -5
- package/dist/generate-content.js.map +1 -0
- package/dist/{parse-source.d.cts → parse-source.d.ts} +1 -1
- package/dist/parse-source.d.ts.map +1 -0
- package/dist/{parse-source.mjs → parse-source.js} +8 -6
- package/dist/parse-source.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +1 -1
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +12 -7
- package/dist/check.cjs +0 -87
- package/dist/check.cjs.map +0 -1
- package/dist/check.d.cts +0 -13
- package/dist/check.d.cts.map +0 -1
- package/dist/check.d.mts.map +0 -1
- package/dist/check.mjs.map +0 -1
- package/dist/cli.cjs +0 -91
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -3
- package/dist/cli.d.cts.map +0 -1
- package/dist/cli.d.mts +0 -3
- package/dist/cli.d.mts.map +0 -1
- package/dist/cli.mjs.map +0 -1
- package/dist/fix.cjs +0 -51
- package/dist/fix.cjs.map +0 -1
- package/dist/fix.d.cts.map +0 -1
- package/dist/fix.d.mts +0 -13
- package/dist/fix.d.mts.map +0 -1
- package/dist/fix.mjs.map +0 -1
- package/dist/generate-content.cjs +0 -148
- package/dist/generate-content.cjs.map +0 -1
- package/dist/generate-content.d.cts.map +0 -1
- package/dist/generate-content.d.mts +0 -13
- package/dist/generate-content.d.mts.map +0 -1
- package/dist/generate-content.mjs.map +0 -1
- package/dist/parse-source.cjs +0 -324
- package/dist/parse-source.cjs.map +0 -1
- package/dist/parse-source.d.cts.map +0 -1
- package/dist/parse-source.d.mts +0 -25
- package/dist/parse-source.d.mts.map +0 -1
- package/dist/parse-source.mjs.map +0 -1
- package/dist/types.cjs +0 -3
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -5
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs +0 -2
- package/dist/types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
14
14
|
|
|
15
15
|
### Changed
|
|
16
16
|
|
|
17
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
17
18
|
- Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
|
|
18
19
|
|
|
19
20
|
## [0.2.0]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SourceInfo } from
|
|
2
|
-
import { Formatter } from
|
|
1
|
+
import type { SourceInfo } from './parse-source.js';
|
|
2
|
+
import { Formatter } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Checks if generated action types files are up to date.
|
|
5
5
|
*
|
|
@@ -10,4 +10,4 @@ import { Formatter } from "./types.mjs";
|
|
|
10
10
|
* @returns Whether all files are up to date.
|
|
11
11
|
*/
|
|
12
12
|
export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter, esm?: boolean): Promise<boolean>;
|
|
13
|
-
//# sourceMappingURL=check.d.
|
|
13
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,EACpB,GAAG,UAAQ,GACV,OAAO,CAAC,OAAO,CAAC,CAuElB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
3
|
-
import { generateActionTypesContent } from
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { generateActionTypesContent } from './generate-content.js';
|
|
4
4
|
/**
|
|
5
5
|
* Checks if generated action types files are up to date.
|
|
6
6
|
*
|
|
@@ -57,4 +57,4 @@ export async function checkActionTypesFiles(sources, formatter, esm = false) {
|
|
|
57
57
|
console.log('\n🎉 All action type files are up to date!');
|
|
58
58
|
return true;
|
|
59
59
|
}
|
|
60
|
-
//# sourceMappingURL=check.
|
|
60
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAInE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,SAAoB,EACpB,GAAG,GAAG,KAAK;IAEX,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAA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G,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","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { generateActionTypesContent } from './generate-content.js';\nimport type { SourceInfo } from './parse-source.js';\nimport { Formatter } from './types.js';\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 * @param esm - Whether to add `.js` extensions to import paths for ESM\n * compatibility.\n * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n esm = false,\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(\n source,\n formatter,\n esm,\n );\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.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/{cli.mjs → cli.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import yargs from
|
|
3
|
-
import { checkActionTypesFiles } from
|
|
4
|
-
import { generateAllActionTypesFiles } from
|
|
5
|
-
import { findSourcesWithExposedMethods } from
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
import { checkActionTypesFiles } from './check.js';
|
|
4
|
+
import { generateAllActionTypesFiles } from './fix.js';
|
|
5
|
+
import { findSourcesWithExposedMethods } from './parse-source.js';
|
|
6
6
|
/**
|
|
7
7
|
* Parses the given CLI arguments.
|
|
8
8
|
*
|
|
@@ -83,4 +83,4 @@ main().catch((error) => {
|
|
|
83
83
|
// eslint-disable-next-line no-restricted-globals
|
|
84
84
|
process.exitCode = 1;
|
|
85
85
|
});
|
|
86
|
-
//# sourceMappingURL=cli.
|
|
86
|
+
//# sourceMappingURL=cli.js.map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ACH,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.js';\nimport { generateAllActionTypesFiles } from './fix.js';\nimport { findSourcesWithExposedMethods } from './parse-source.js';\nimport { Formatter } from './types.js';\n\ntype CommandLineArguments = {\n check: boolean;\n generate: boolean;\n formatter: Formatter;\n sourcePath: string;\n esm: boolean;\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 esm,\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 .option('esm', {\n type: 'boolean',\n description: 'Add .js extensions to import paths for ESM compatibility',\n default: false,\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 esm,\n };\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { generate, sourcePath, formatter, esm } =\n await parseCommandLineArguments(globalThis.process.argv.slice(2));\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, esm);\n console.log('\\n🎉 All action types generated successfully!');\n } else {\n const success = await checkActionTypesFiles(sources, formatter, esm);\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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SourceInfo } from
|
|
2
|
-
import type { Formatter } from
|
|
1
|
+
import type { SourceInfo } from './parse-source.js';
|
|
2
|
+
import type { Formatter } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generates action types files for all controllers/services.
|
|
5
5
|
*
|
|
@@ -10,4 +10,4 @@ import type { Formatter } from "./types.cjs";
|
|
|
10
10
|
* @returns Whether all files were generated successfully.
|
|
11
11
|
*/
|
|
12
12
|
export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter, esm?: boolean): Promise<void>;
|
|
13
|
-
//# sourceMappingURL=fix.d.
|
|
13
|
+
//# sourceMappingURL=fix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix.d.ts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;GAQG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,EACpB,GAAG,UAAQ,GACV,OAAO,CAAC,IAAI,CAAC,CAmBf"}
|
package/dist/{fix.mjs → fix.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
3
|
-
import { generateActionTypesContent } from
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { generateActionTypesContent } from './generate-content.js';
|
|
4
4
|
/**
|
|
5
5
|
* Generates action types files for all controllers/services.
|
|
6
6
|
*
|
|
@@ -21,4 +21,4 @@ export async function generateAllActionTypesFiles(sources, formatter, esm = fals
|
|
|
21
21
|
console.log(`✅ Generated action types for ${source.name}`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
//# sourceMappingURL=fix.
|
|
24
|
+
//# sourceMappingURL=fix.js.map
|
package/dist/fix.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix.js","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAInE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,SAAoB,EACpB,GAAG,GAAG,KAAK;IAEX,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,EACT,GAAG,CACJ,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.js';\nimport type { SourceInfo } from './parse-source.js';\nimport type { Formatter } from './types.js';\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 * @param esm - Whether to add `.js` extensions to import paths for ESM\n * compatibility.\n * @returns Whether all files were generated successfully.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n esm = false,\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 esm,\n );\n\n await fs.promises.writeFile(outputFile, generatedContent, 'utf8');\n console.log(`✅ Generated action types for ${source.name}`);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SourceInfo } from
|
|
2
|
-
import { Formatter } from
|
|
1
|
+
import type { SourceInfo } from './parse-source.js';
|
|
2
|
+
import { Formatter } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generates the content for the action types file.
|
|
5
5
|
*
|
|
@@ -10,4 +10,4 @@ import { Formatter } from "./types.cjs";
|
|
|
10
10
|
* @returns The content for the action types file.
|
|
11
11
|
*/
|
|
12
12
|
export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter, esm?: boolean): Promise<string>;
|
|
13
|
-
//# sourceMappingURL=generate-content.d.
|
|
13
|
+
//# sourceMappingURL=generate-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-content.d.ts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA0FvC;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,EACpB,GAAG,UAAQ,GACV,OAAO,CAAC,MAAM,CAAC,CA2CjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { assertExhaustive, getErrorMessage } from
|
|
2
|
-
import * as path from
|
|
1
|
+
import { assertExhaustive, getErrorMessage } from '@metamask/utils';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
3
|
/**
|
|
4
4
|
* The default options used by Oxfmt and Prettier when formatting the generated
|
|
5
5
|
* content. In the case of Prettier, these options will be used if the user does
|
|
@@ -23,7 +23,7 @@ const DEFAULT_FORMATTING_OPTIONS = {
|
|
|
23
23
|
*/
|
|
24
24
|
async function prettier(contents, filePath) {
|
|
25
25
|
try {
|
|
26
|
-
const { format, resolveConfig } = await import(
|
|
26
|
+
const { format, resolveConfig } = await import('prettier');
|
|
27
27
|
const config = (await resolveConfig(filePath)) ?? DEFAULT_FORMATTING_OPTIONS;
|
|
28
28
|
return await format(contents, {
|
|
29
29
|
...config,
|
|
@@ -48,7 +48,7 @@ async function prettier(contents, filePath) {
|
|
|
48
48
|
*/
|
|
49
49
|
async function oxfmt(contents, filePath) {
|
|
50
50
|
try {
|
|
51
|
-
const { format } = await import(
|
|
51
|
+
const { format } = await import('oxfmt');
|
|
52
52
|
const result = await format(filePath, contents, DEFAULT_FORMATTING_OPTIONS);
|
|
53
53
|
return result.code;
|
|
54
54
|
}
|
|
@@ -118,4 +118,4 @@ export type ${unionTypeName} = ${actionTypeNames.join(' | ')};\n`;
|
|
|
118
118
|
const formatterFunction = getFormatter(formatter);
|
|
119
119
|
return await formatterFunction(content, source.filePath);
|
|
120
120
|
}
|
|
121
|
-
//# sourceMappingURL=generate-content.
|
|
121
|
+
//# sourceMappingURL=generate-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-content.js","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;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,CAAC,UAAU,CAAC,CAAC;QAE3D,MAAM,MAAM,GACV,CAAC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,0BAA0B,CAAC;QAEhE,OAAO,MAAM,MAAM,CAAC,QAAQ,EAAE;YAC5B,GAAG,MAAM;YACT,MAAM,EAAE,YAAY;SACrB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,yEAAyE,OAAO,EAAE,CACnF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAA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AAC,WAAW,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7D,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,IAAI,GAAG,eAAe,QAAQ,CAAC;QAChE,MAAM,YAAY,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAErD,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAErC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,IAAI,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;QACjC,CAAC;QAED,OAAO,IAAI,eAAe,cAAc;YAChC,YAAY;aACX,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;OACjC,CAAC;IACN,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC;QACpD,OAAO,IAAI;kBACG,MAAM,CAAC,IAAI;;cAEf,aAAa,MAAM,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,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.js';\nimport { Formatter } from './types.js';\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 * @param esm - Whether to add `.js` extensions to import paths for ESM\n * compatibility.\n * @returns The content for the action types file.\n */\nexport async function generateActionTypesContent(\n source: SourceInfo,\n formatter: Formatter,\n esm = false,\n): Promise<string> {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}${esm ? '.js' : ''}`;\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"]}
|
|
@@ -22,4 +22,4 @@ export declare function parseSourceFile(filePath: string): Promise<SourceInfo |
|
|
|
22
22
|
* @returns A list of source information objects.
|
|
23
23
|
*/
|
|
24
24
|
export declare function findSourcesWithExposedMethods(sourcePath: string): Promise<SourceInfo[]>;
|
|
25
|
-
//# sourceMappingURL=parse-source.d.
|
|
25
|
+
//# sourceMappingURL=parse-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-source.d.ts","sourceRoot":"","sources":["../src/parse-source.ts"],"names":[],"mappings":"AAoCA,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AAsPF;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA4E5B;AAgCD;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC,CA0BvB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { assert, hasProperty, isObject } from
|
|
2
|
-
import * as fs from
|
|
3
|
-
import * as path from
|
|
4
|
-
import
|
|
5
|
-
|
|
1
|
+
import { assert, hasProperty, isObject } from '@metamask/utils';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import typescript from 'typescript';
|
|
5
|
+
// Older versions of TypeScript break when importing directly in ESM. This is a
|
|
6
|
+
// temporary workaround
|
|
7
|
+
const { ScriptTarget, createProgram, createSourceFile, findConfigFile, forEachChild, getJSDocCommentsAndTags, isArrayLiteralExpression, isAsExpression, isClassDeclaration, isIdentifier, isJSDoc, isMethodDeclaration, isStringLiteral, isVariableStatement, parseJsonConfigFileContent, readConfigFile, sys, } = typescript;
|
|
6
8
|
/**
|
|
7
9
|
* Extracts JSDoc comment from a method declaration.
|
|
8
10
|
*
|
|
@@ -294,4 +296,4 @@ export async function findSourcesWithExposedMethods(sourcePath) {
|
|
|
294
296
|
}
|
|
295
297
|
return sources;
|
|
296
298
|
}
|
|
297
|
-
//# sourceMappingURL=parse-source.
|
|
299
|
+
//# sourceMappingURL=parse-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-source.js","sourceRoot":"","sources":["../src/parse-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAA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,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;YAC/C,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport type {\n ArrayLiteralExpression,\n ClassDeclaration,\n MethodDeclaration,\n Node as TSNode,\n Program,\n SourceFile,\n Type,\n} from 'typescript';\nimport typescript from 'typescript';\n\n// Older versions of TypeScript break when importing directly in ESM. This is a\n// temporary workaround\nconst {\n ScriptTarget,\n createProgram,\n createSourceFile,\n findConfigFile,\n forEachChild,\n getJSDocCommentsAndTags,\n isArrayLiteralExpression,\n isAsExpression,\n isClassDeclaration,\n isIdentifier,\n isJSDoc,\n isMethodDeclaration,\n isStringLiteral,\n isVariableStatement,\n parseJsonConfigFileContent,\n readConfigFile,\n sys,\n} = typescript;\n\nexport type MethodInfo = {\n name: string;\n jsDoc: string;\n};\n\nexport type SourceInfo = {\n name: string;\n filePath: string;\n methods: MethodInfo[];\n};\n\ntype VisitorContext = {\n exposedMethods: string[];\n className: string;\n methods: MethodInfo[];\n sourceFile: SourceFile;\n};\n\n/**\n * Extracts JSDoc comment from a method declaration.\n *\n * @param node - The method declaration node.\n * @param source - The source file.\n * @returns The JSDoc comment.\n */\nfunction extractJSDoc(node: MethodDeclaration, source: SourceFile): string {\n const jsDocTags = getJSDocCommentsAndTags(node);\n if (jsDocTags.length === 0) {\n return '';\n }\n\n const jsDoc = jsDocTags[0];\n if (isJSDoc(jsDoc)) {\n const fullText = source.getFullText();\n const start = jsDoc.getFullStart();\n const end = jsDoc.getEnd();\n const rawJsDoc = fullText.substring(start, end).trim();\n return formatJSDoc(rawJsDoc);\n }\n\n // istanbul ignore next: defensive check — getJSDocCommentsAndTags always returns JSDoc nodes\n return '';\n}\n\n/**\n * Formats JSDoc comments to have consistent indentation for the generated file.\n *\n * @param rawJsDoc - The raw JSDoc comment from the source.\n * @returns The formatted JSDoc comment.\n */\nfunction formatJSDoc(rawJsDoc: string): string {\n const lines = rawJsDoc.split('\\n');\n const formattedLines: string[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (i === 0) {\n formattedLines.push('/**');\n } else if (i === lines.length - 1) {\n formattedLines.push(' */');\n } else {\n const trimmed = line.trim();\n if (trimmed.startsWith('*')) {\n const content = trimmed.substring(1).trim();\n formattedLines.push(content ? ` * ${content}` : ' *');\n } else {\n formattedLines.push(trimmed ? ` * ${trimmed}` : ' *');\n }\n }\n }\n\n return formattedLines.join('\\n');\n}\n\n/**\n * Visits AST nodes to find exposed methods and controller/service class.\n *\n * @param context - The visitor context.\n * @returns A function to visit nodes.\n */\nfunction createASTVisitor(context: VisitorContext): (node: TSNode) => void {\n function visitNode(node: TSNode): void {\n if (isVariableStatement(node)) {\n const declaration = node.declarationList.declarations[0];\n if (\n isIdentifier(declaration.name) &&\n declaration.name.text === 'MESSENGER_EXPOSED_METHODS'\n ) {\n if (declaration.initializer) {\n let arrayExpression: ArrayLiteralExpression | undefined;\n\n if (isArrayLiteralExpression(declaration.initializer)) {\n arrayExpression = declaration.initializer;\n } else if (\n isAsExpression(declaration.initializer) &&\n isArrayLiteralExpression(declaration.initializer.expression)\n ) {\n arrayExpression = declaration.initializer.expression;\n }\n\n if (arrayExpression) {\n context.exposedMethods = arrayExpression.elements\n .filter(isStringLiteral)\n .map((element) => element.text);\n }\n }\n }\n }\n\n if (isClassDeclaration(node) && node.name) {\n const classText = node.name.text;\n if (classText.includes('Controller') || classText.includes('Service')) {\n context.className = classText;\n\n const seenMethods = new Set<string>();\n for (const member of node.members) {\n if (\n isMethodDeclaration(member) &&\n member.name &&\n isIdentifier(member.name)\n ) {\n const methodName = member.name.text;\n if (\n context.exposedMethods.includes(methodName) &&\n !seenMethods.has(methodName)\n ) {\n seenMethods.add(methodName);\n const jsDoc = extractJSDoc(member, context.sourceFile);\n context.methods.push({\n name: methodName,\n jsDoc,\n });\n }\n }\n }\n }\n }\n\n forEachChild(node, visitNode);\n }\n\n return visitNode;\n}\n\n/**\n * Create a TypeScript program for the given file by locating the nearest\n * tsconfig.json.\n *\n * @param filePath - Absolute path to the source file.\n * @returns A TypeScript program, or null if no tsconfig was found.\n */\nfunction createProgramForFile(filePath: string): Program | null {\n const configPath = findConfigFile(\n path.dirname(filePath),\n sys.fileExists.bind(sys),\n 'tsconfig.json',\n );\n if (!configPath) {\n return null;\n }\n\n const { config, error } = readConfigFile(configPath, sys.readFile.bind(sys));\n\n if (error) {\n return null;\n }\n\n const parsedConfig = parseJsonConfigFileContent(\n config,\n sys,\n path.dirname(configPath),\n );\n\n return createProgram({\n rootNames: parsedConfig.fileNames,\n options: parsedConfig.options,\n });\n}\n\n/**\n * Find a class declaration with the given name in a source file.\n *\n * @param source - The source file to search.\n * @param className - The class name to look for.\n * @returns The class declaration node, or null if not found.\n */\nfunction findClassInSourceFile(\n source: SourceFile,\n className: string,\n): ClassDeclaration | null {\n return (\n source.statements.find(\n (node): node is ClassDeclaration =>\n isClassDeclaration(node) && node.name?.text === className,\n ) ?? // istanbul ignore next: class is always found when called from parseSourceFile\n null\n );\n}\n\n/**\n * Search through the class hierarchy of a TypeScript type to find the\n * declaration of a method with the given name.\n *\n * @param classType - The class type to search.\n * @param methodName - The method name to look for.\n * @returns The method declaration node, or null if not found.\n */\nfunction findMethodInHierarchy(\n classType: Type,\n methodName: string,\n): MethodDeclaration | null {\n const symbol = classType.getProperty(methodName);\n if (!symbol) {\n return null;\n }\n\n const declarations = symbol.getDeclarations();\n // istanbul ignore next: defensive check — symbols from getProperty always have declarations\n if (!declarations) {\n return null;\n }\n\n for (const declaration of declarations) {\n if (isMethodDeclaration(declaration)) {\n return declaration;\n }\n }\n\n // istanbul ignore next: defensive fallback — property found but not a method declaration\n return null;\n}\n\n/**\n * Check if a path is a directory.\n *\n * @param pathValue - The path to check.\n * @returns True if the path is a directory, false otherwise.\n */\nasync function isDirectory(pathValue: string): Promise<boolean> {\n try {\n const stats = await fs.promises.stat(pathValue);\n return stats.isDirectory();\n } catch (error) {\n if (\n isObject(error) &&\n hasProperty(error, 'code') &&\n error.code === 'ENOENT'\n ) {\n return false;\n }\n\n throw error;\n }\n}\n\n/**\n * Parses a source file to extract exposed methods and their metadata.\n *\n * @param filePath - Path to the controller/service file to parse.\n * @returns Source information or null if parsing fails.\n */\nexport async function parseSourceFile(\n filePath: string,\n): Promise<SourceInfo | null> {\n try {\n const content = await fs.promises.readFile(filePath, 'utf8');\n const source = createSourceFile(\n filePath,\n content,\n ScriptTarget.Latest,\n true,\n );\n\n const context: VisitorContext = {\n exposedMethods: [],\n className: '',\n methods: [],\n sourceFile: source,\n };\n\n createASTVisitor(context)(source);\n\n if (context.exposedMethods.length === 0 || !context.className) {\n return null;\n }\n\n const foundMethodNames = new Set(\n context.methods.map((method) => method.name),\n );\n\n const inheritedMethodNames = context.exposedMethods.filter(\n (name) => !foundMethodNames.has(name),\n );\n\n if (inheritedMethodNames.length > 0) {\n const program = createProgramForFile(filePath);\n const checker = program?.getTypeChecker();\n const programSourceFile = program?.getSourceFile(filePath);\n\n assert(\n checker,\n `Type checker could not be created for \"${filePath}\". Ensure a valid tsconfig.json is present.`,\n );\n\n assert(\n programSourceFile,\n `Source file \"${filePath}\" not found in program.`,\n );\n\n const classNode = findClassInSourceFile(\n programSourceFile,\n context.className,\n );\n\n assert(\n classNode,\n `Class \"${context.className}\" not found in \"${filePath}\".`,\n );\n\n const classType = checker.getTypeAtLocation(classNode);\n for (const methodName of inheritedMethodNames) {\n const methodDeclaration = findMethodInHierarchy(classType, methodName);\n\n const jsDoc = methodDeclaration\n ? extractJSDoc(methodDeclaration, methodDeclaration.getSourceFile())\n : '';\n context.methods.push({ name: methodName, jsDoc });\n }\n }\n\n return {\n name: context.className,\n filePath,\n methods: context.methods,\n };\n } catch (error) {\n console.error(`Error parsing ${filePath}:`, error);\n return null;\n }\n}\n\n/**\n * Recursively get all files in a directory and its subdirectories.\n *\n * @param directory - The directory to search.\n * @returns An array of file paths.\n */\nconst EXCLUDED_DIRECTORIES = new Set([\n 'node_modules',\n 'dist',\n '.git',\n 'coverage',\n]);\n\nasync function getFiles(directory: string): Promise<string[]> {\n const entries = await fs.promises.readdir(directory, { withFileTypes: true });\n const files = await Promise.all(\n entries.map(async (entry) => {\n const fullPath = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n return EXCLUDED_DIRECTORIES.has(entry.name)\n ? []\n : await getFiles(fullPath);\n }\n return fullPath;\n }),\n );\n\n return files.flat();\n}\n\n/**\n * Finds all source files that have MESSENGER_EXPOSED_METHODS constants.\n * Searches recursively through subdirectories.\n *\n * @param sourcePath - Path to the folder where controllers/services are located.\n * @returns A list of source information objects.\n */\nexport async function findSourcesWithExposedMethods(\n sourcePath: string,\n): Promise<SourceInfo[]> {\n const srcPath = path.resolve(globalThis.process.cwd(), sourcePath);\n const sources: SourceInfo[] = [];\n\n if (!(await isDirectory(srcPath))) {\n throw new Error(`The specified path is not a directory: ${srcPath}`);\n }\n\n const srcFiles = await getFiles(srcPath);\n\n for (const file of srcFiles) {\n if (!file.endsWith('.ts') || file.endsWith('.test.ts')) {\n continue;\n }\n\n const content = await fs.promises.readFile(file, 'utf8');\n\n if (content.includes('MESSENGER_EXPOSED_METHODS')) {\n const sourceInfo = await parseSourceFile(file);\n if (sourceInfo) {\n sources.push(sourceInfo);\n }\n }\n }\n\n return sources;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The formatting tool to use for formatting the source code.\n */\nexport type Formatter = 'oxfmt' | 'prettier';\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-4f4c98e",
|
|
4
4
|
"description": "CLI tools for the MetaMask messenger system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -16,19 +16,22 @@
|
|
|
16
16
|
"url": "https://github.com/MetaMask/core.git"
|
|
17
17
|
},
|
|
18
18
|
"bin": {
|
|
19
|
-
"messenger-action-types": "./dist/cli.
|
|
19
|
+
"messenger-action-types": "./dist/cli.js"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist/"
|
|
23
23
|
],
|
|
24
|
+
"type": "module",
|
|
24
25
|
"sideEffects": false,
|
|
25
26
|
"publishConfig": {
|
|
26
27
|
"access": "public",
|
|
27
28
|
"registry": "https://registry.npmjs.org/"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
|
-
"build": "
|
|
31
|
-
"build:all": "
|
|
31
|
+
"build": "tsc --project tsconfig.build.json",
|
|
32
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
33
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
34
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
32
35
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/messenger-cli",
|
|
33
36
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/messenger-cli",
|
|
34
37
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -44,18 +47,20 @@
|
|
|
44
47
|
"yargs": "^17.7.2"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
50
|
+
"@jest/globals": "^30.4.1",
|
|
47
51
|
"@metamask/auto-changelog": "^6.1.0",
|
|
48
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
49
52
|
"@types/jest": "^30.0.0",
|
|
50
53
|
"@types/yargs": "^17.0.32",
|
|
54
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
51
55
|
"deepmerge": "^4.2.2",
|
|
52
56
|
"execa": "^5.0.0",
|
|
53
57
|
"jest": "^30.4.2",
|
|
54
58
|
"oxfmt": "^0.44.0",
|
|
55
59
|
"prettier": "^3.3.3",
|
|
60
|
+
"rimraf": "^5.0.5",
|
|
56
61
|
"ts-jest": "^29.4.11",
|
|
57
62
|
"tsx": "^4.20.5",
|
|
58
|
-
"typescript": "
|
|
63
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
59
64
|
},
|
|
60
65
|
"peerDependencies": {
|
|
61
66
|
"oxfmt": "^0.44.0",
|
|
@@ -71,6 +76,6 @@
|
|
|
71
76
|
}
|
|
72
77
|
},
|
|
73
78
|
"engines": {
|
|
74
|
-
"node": "^
|
|
79
|
+
"node": "^22.14.0 || ^24"
|
|
75
80
|
}
|
|
76
81
|
}
|
package/dist/check.cjs
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.checkActionTypesFiles = void 0;
|
|
27
|
-
const fs = __importStar(require("node:fs"));
|
|
28
|
-
const path = __importStar(require("node:path"));
|
|
29
|
-
const generate_content_js_1 = require("./generate-content.cjs");
|
|
30
|
-
/**
|
|
31
|
-
* Checks if generated action types files are up to date.
|
|
32
|
-
*
|
|
33
|
-
* @param sources - Array of source information objects.
|
|
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
|
-
* @returns Whether all files are up to date.
|
|
38
|
-
*/
|
|
39
|
-
async function checkActionTypesFiles(sources, formatter, esm = false) {
|
|
40
|
-
let hasErrors = false;
|
|
41
|
-
const fileComparisonJobs = [];
|
|
42
|
-
for (const source of sources) {
|
|
43
|
-
console.log(`\n🔧 Checking ${source.name}...`);
|
|
44
|
-
const outputDir = path.dirname(source.filePath);
|
|
45
|
-
const baseFileName = path.basename(source.filePath, '.ts');
|
|
46
|
-
const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
47
|
-
const expectedContent = await (0, generate_content_js_1.generateActionTypesContent)(source, formatter, esm);
|
|
48
|
-
try {
|
|
49
|
-
await fs.promises.access(actualFile);
|
|
50
|
-
fileComparisonJobs.push({
|
|
51
|
-
expectedContent,
|
|
52
|
-
actualFile,
|
|
53
|
-
baseFileName,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
if (error.code === 'ENOENT') {
|
|
58
|
-
console.error(`❌ ${baseFileName}-method-action-types.ts does not exist`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
console.error(`❌ Error reading ${baseFileName}-method-action-types.ts:`, error);
|
|
62
|
-
}
|
|
63
|
-
hasErrors = true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (fileComparisonJobs.length > 0) {
|
|
67
|
-
for (const job of fileComparisonJobs) {
|
|
68
|
-
const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');
|
|
69
|
-
if (job.expectedContent === actualContent) {
|
|
70
|
-
console.log(`✅ ${job.baseFileName}-method-action-types.ts is up to date`);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
console.error(`❌ ${job.baseFileName}-method-action-types.ts is out of date`);
|
|
74
|
-
hasErrors = true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (hasErrors) {
|
|
79
|
-
console.error('\n💥 Some action type files are out of date or missing.');
|
|
80
|
-
console.error('Run `messenger-action-types --generate` to update them.');
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
console.log('\n🎉 All action type files are up to date!');
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
exports.checkActionTypesFiles = checkActionTypesFiles;
|
|
87
|
-
//# sourceMappingURL=check.cjs.map
|
package/dist/check.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check.cjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,gEAAmE;AAInE;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,SAAoB,EACpB,GAAG,GAAG,KAAK;IAEX,IAA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U,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;AA3ED,sDA2EC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { generateActionTypesContent } from './generate-content.js';\nimport type { SourceInfo } from './parse-source.js';\nimport { Formatter } from './types.js';\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 * @param esm - Whether to add `.js` extensions to import paths for ESM\n * compatibility.\n * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n esm = false,\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(\n source,\n formatter,\n esm,\n );\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
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { SourceInfo } from "./parse-source.cjs";
|
|
2
|
-
import { Formatter } from "./types.cjs";
|
|
3
|
-
/**
|
|
4
|
-
* Checks if generated action types files are up to date.
|
|
5
|
-
*
|
|
6
|
-
* @param sources - Array of source information objects.
|
|
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
|
-
* @returns Whether all files are up to date.
|
|
11
|
-
*/
|
|
12
|
-
export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter, esm?: boolean): Promise<boolean>;
|
|
13
|
-
//# sourceMappingURL=check.d.cts.map
|
package/dist/check.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.cts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAA0B;AACpD,OAAO,EAAE,SAAS,EAAE,oBAAmB;AAEvC;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,EACpB,GAAG,UAAQ,GACV,OAAO,CAAC,OAAO,CAAC,CAuElB"}
|
package/dist/check.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.mts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAA0B;AACpD,OAAO,EAAE,SAAS,EAAE,oBAAmB;AAEvC;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,EACpB,GAAG,UAAQ,GACV,OAAO,CAAC,OAAO,CAAC,CAuElB"}
|
package/dist/check.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,+BAA8B;AAInE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,SAAoB,EACpB,GAAG,GAAG,KAAK;IAEX,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,kBAAkB,GAIlB,EAAE,CAAC;IAET,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,K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ACd,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.js';\nimport type { SourceInfo } from './parse-source.js';\nimport { Formatter } from './types.js';\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 * @param esm - Whether to add `.js` extensions to import paths for ESM\n * compatibility.\n * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\n esm = false,\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(\n source,\n formatter,\n esm,\n );\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
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
-
const check_js_1 = require("./check.cjs");
|
|
9
|
-
const fix_js_1 = require("./fix.cjs");
|
|
10
|
-
const parse_source_js_1 = require("./parse-source.cjs");
|
|
11
|
-
/**
|
|
12
|
-
* Parses the given CLI arguments.
|
|
13
|
-
*
|
|
14
|
-
* @param args - The arguments to parse.
|
|
15
|
-
* @returns The parsed command line arguments.
|
|
16
|
-
*/
|
|
17
|
-
async function parseCommandLineArguments(args) {
|
|
18
|
-
const { check, generate, formatter, esm, path: sourcePath, } = await (0, yargs_1.default)(args)
|
|
19
|
-
.command('$0 [path]', 'Generate method action types for controller and service messengers', (yargsInstance) => {
|
|
20
|
-
yargsInstance.positional('path', {
|
|
21
|
-
type: 'string',
|
|
22
|
-
description: 'Path to the folder where controllers/services are located',
|
|
23
|
-
default: 'src',
|
|
24
|
-
});
|
|
25
|
-
})
|
|
26
|
-
.option('check', {
|
|
27
|
-
type: 'boolean',
|
|
28
|
-
description: 'Check if generated action type files are up to date',
|
|
29
|
-
default: false,
|
|
30
|
-
})
|
|
31
|
-
.option('generate', {
|
|
32
|
-
type: 'boolean',
|
|
33
|
-
description: 'Generate/update action type files',
|
|
34
|
-
default: false,
|
|
35
|
-
})
|
|
36
|
-
.option('formatter', {
|
|
37
|
-
type: 'string',
|
|
38
|
-
description: 'The formatter to use for formatting generated files',
|
|
39
|
-
choices: ['oxfmt', 'prettier'],
|
|
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
|
-
})
|
|
47
|
-
.help()
|
|
48
|
-
.check((argv) => {
|
|
49
|
-
if (!argv.check && !argv.generate) {
|
|
50
|
-
throw new Error('Either --check or --generate must be provided.\n');
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}).argv;
|
|
54
|
-
return {
|
|
55
|
-
check,
|
|
56
|
-
generate,
|
|
57
|
-
formatter: formatter,
|
|
58
|
-
sourcePath: sourcePath,
|
|
59
|
-
esm,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Main entry point for the CLI.
|
|
64
|
-
*/
|
|
65
|
-
async function main() {
|
|
66
|
-
const { generate, sourcePath, formatter, esm } = await parseCommandLineArguments(globalThis.process.argv.slice(2));
|
|
67
|
-
console.log('🔍 Searching for controllers/services with MESSENGER_EXPOSED_METHODS...');
|
|
68
|
-
const sources = await (0, parse_source_js_1.findSourcesWithExposedMethods)(sourcePath);
|
|
69
|
-
if (sources.length === 0) {
|
|
70
|
-
console.log('⚠️ No controllers/services found with MESSENGER_EXPOSED_METHODS');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
console.log(`📦 Found ${sources.length} controller(s)/service(s) with exposed methods`);
|
|
74
|
-
if (generate) {
|
|
75
|
-
await (0, fix_js_1.generateAllActionTypesFiles)(sources, formatter, esm);
|
|
76
|
-
console.log('\n🎉 All action types generated successfully!');
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const success = await (0, check_js_1.checkActionTypesFiles)(sources, formatter, esm);
|
|
80
|
-
if (!success) {
|
|
81
|
-
// eslint-disable-next-line no-restricted-globals
|
|
82
|
-
process.exitCode = 1;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
main().catch((error) => {
|
|
87
|
-
console.error('❌ Script failed:', error);
|
|
88
|
-
// eslint-disable-next-line no-restricted-globals
|
|
89
|
-
process.exitCode = 1;
|
|
90
|
-
});
|
|
91
|
-
//# sourceMappingURL=cli.cjs.map
|