@metamask-previews/messenger 0.3.0-preview-b9ae764 ā 0.3.0-preview-3f2e0ea
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/dist/generate-action-types/check.cjs +8 -8
- package/dist/generate-action-types/check.cjs.map +1 -1
- package/dist/generate-action-types/check.d.cts +3 -3
- package/dist/generate-action-types/check.d.cts.map +1 -1
- package/dist/generate-action-types/check.d.mts +3 -3
- package/dist/generate-action-types/check.d.mts.map +1 -1
- package/dist/generate-action-types/check.mjs +8 -8
- package/dist/generate-action-types/check.mjs.map +1 -1
- package/dist/generate-action-types/cli.cjs +17 -13
- package/dist/generate-action-types/cli.cjs.map +1 -1
- package/dist/generate-action-types/cli.mjs +18 -14
- package/dist/generate-action-types/cli.mjs.map +1 -1
- package/dist/generate-action-types/fix.cjs +11 -11
- package/dist/generate-action-types/fix.cjs.map +1 -1
- package/dist/generate-action-types/fix.d.cts +4 -4
- package/dist/generate-action-types/fix.d.cts.map +1 -1
- package/dist/generate-action-types/fix.d.mts +4 -4
- package/dist/generate-action-types/fix.d.mts.map +1 -1
- package/dist/generate-action-types/fix.mjs +11 -11
- package/dist/generate-action-types/fix.mjs.map +1 -1
- package/dist/generate-action-types/generate-content.cjs +11 -11
- package/dist/generate-action-types/generate-content.cjs.map +1 -1
- package/dist/generate-action-types/generate-content.d.cts +3 -3
- package/dist/generate-action-types/generate-content.d.cts.map +1 -1
- package/dist/generate-action-types/generate-content.d.mts +3 -3
- package/dist/generate-action-types/generate-content.d.mts.map +1 -1
- package/dist/generate-action-types/generate-content.mjs +11 -11
- package/dist/generate-action-types/generate-content.mjs.map +1 -1
- package/dist/generate-action-types/index.cjs +3 -3
- package/dist/generate-action-types/index.cjs.map +1 -1
- package/dist/generate-action-types/index.d.cts +2 -2
- package/dist/generate-action-types/index.d.cts.map +1 -1
- package/dist/generate-action-types/index.d.mts +2 -2
- package/dist/generate-action-types/index.d.mts.map +1 -1
- package/dist/generate-action-types/index.mjs +1 -1
- package/dist/generate-action-types/index.mjs.map +1 -1
- package/dist/generate-action-types/parse-source.cjs +19 -19
- package/dist/generate-action-types/parse-source.cjs.map +1 -1
- package/dist/generate-action-types/parse-source.d.cts +9 -9
- package/dist/generate-action-types/parse-source.d.cts.map +1 -1
- package/dist/generate-action-types/parse-source.d.mts +9 -9
- package/dist/generate-action-types/parse-source.d.mts.map +1 -1
- package/dist/generate-action-types/parse-source.mjs +16 -16
- package/dist/generate-action-types/parse-source.mjs.map +1 -1
- package/dist/generate-action-types/types.cjs.map +1 -1
- package/dist/generate-action-types/types.d.cts +4 -12
- package/dist/generate-action-types/types.d.cts.map +1 -1
- package/dist/generate-action-types/types.d.mts +4 -12
- package/dist/generate-action-types/types.d.mts.map +1 -1
- package/dist/generate-action-types/types.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -30,19 +30,19 @@ 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
|
-
* @param
|
|
33
|
+
* @param sources - Array of source information objects.
|
|
34
34
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
35
35
|
*/
|
|
36
|
-
async function checkActionTypesFiles(
|
|
36
|
+
async function checkActionTypesFiles(sources, eslint) {
|
|
37
37
|
let hasErrors = false;
|
|
38
38
|
const fileComparisonJobs = [];
|
|
39
39
|
try {
|
|
40
|
-
for (const
|
|
41
|
-
console.log(`\nš§ Checking ${
|
|
42
|
-
const outputDir = path.dirname(
|
|
43
|
-
const baseFileName = path.basename(
|
|
40
|
+
for (const source of sources) {
|
|
41
|
+
console.log(`\nš§ Checking ${source.name}...`);
|
|
42
|
+
const outputDir = path.dirname(source.filePath);
|
|
43
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
44
44
|
const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
45
|
-
const expectedContent = (0, generate_content_1.generateActionTypesContent)(
|
|
45
|
+
const expectedContent = (0, generate_content_1.generateActionTypesContent)(source);
|
|
46
46
|
const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');
|
|
47
47
|
try {
|
|
48
48
|
await fs.promises.access(actualFile);
|
|
@@ -67,7 +67,7 @@ async function checkActionTypesFiles(controllers, eslint) {
|
|
|
67
67
|
if (eslint) {
|
|
68
68
|
console.log('\nš Running ESLint to compare files...');
|
|
69
69
|
const results = await eslint.instance.lintFiles(fileComparisonJobs.map((job) => job.expectedTempFile));
|
|
70
|
-
await eslint.
|
|
70
|
+
await eslint.outputFixes(results);
|
|
71
71
|
}
|
|
72
72
|
for (const job of fileComparisonJobs) {
|
|
73
73
|
const expectedContent = await fs.promises.readFile(job.expectedTempFile, 'utf8');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.cjs","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;GAKG;AACI,KAAK,UAAU,qBAAqB,CACzC,
|
|
1
|
+
{"version":3,"file":"check.cjs","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;GAKG;AACI,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,MAAqB;IAErB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,kBAAkB,GAIlB,EAAE,CAAC;IAET,IAAI,CAAC;QACH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;YAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChD,MAAM,YAAY,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AAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC;YAED,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;gBACrC,MAAM,eAAe,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAChD,GAAG,CAAC,gBAAgB,EACpB,MAAM,CACP,CAAC;gBACF,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAC9C,GAAG,CAAC,UAAU,EACd,MAAM,CACP,CAAC;gBAEF,IAAI,eAAe,KAAK,aAAa,EAAE,CAAC;oBACtC,OAAO,CAAC,GAAG,CACT,KAAK,GAAG,CAAC,YAAY,uCAAuC,CAC7D,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAK,CACX,KAAK,GAAG,CAAC,YAAY,wCAAwC,CAC9D,CAAC;oBACF,SAAS,GAAG,IAAI,CAAC;gBACnB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;YACjD,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,CAAC,KAAK,CACX,+DAA+D,CAChE,CAAC;QACF,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AArGD,sDAqGC","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 { ESLint } 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 eslint - Optional ESLint instance and static methods for formatting.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<void> {\n let hasErrors = false;\n\n const fileComparisonJobs: {\n expectedTempFile: string;\n actualFile: string;\n baseFileName: string;\n }[] = [];\n\n try {\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 = generateActionTypesContent(source);\n const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');\n\n try {\n await fs.promises.access(actualFile);\n\n await fs.promises.writeFile(expectedTempFile, expectedContent, 'utf8');\n\n fileComparisonJobs.push({\n expectedTempFile,\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 if (eslint) {\n console.log('\\nš Running ESLint to compare files...');\n\n const results = await eslint.instance.lintFiles(\n fileComparisonJobs.map((job) => job.expectedTempFile),\n );\n await eslint.outputFixes(results);\n }\n\n for (const job of fileComparisonJobs) {\n const expectedContent = await fs.promises.readFile(\n job.expectedTempFile,\n 'utf8',\n );\n const actualContent = await fs.promises.readFile(\n job.actualFile,\n 'utf8',\n );\n\n if (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 } finally {\n for (const job of fileComparisonJobs) {\n try {\n await fs.promises.unlink(job.expectedTempFile);\n } catch {\n // Ignore cleanup errors\n }\n }\n }\n\n if (hasErrors) {\n console.error('\\nš„ Some action type files are out of date or missing.');\n console.error(\n 'Run `yarn generate-method-action-types --fix` to update them.',\n );\n globalThis.process.exitCode = 1;\n } else {\n console.log('\\nš All action type files are up to date!');\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceInfo } from "./parse-source.cjs";
|
|
2
2
|
import type { ESLint } from "./types.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Checks if generated action types files are up to date.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param sources - Array of source information objects.
|
|
7
7
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
8
8
|
*/
|
|
9
|
-
export declare function checkActionTypesFiles(
|
|
9
|
+
export declare function checkActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<void>;
|
|
10
10
|
//# sourceMappingURL=check.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"check.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC,CAkGf"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceInfo } from "./parse-source.mjs";
|
|
2
2
|
import type { ESLint } from "./types.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Checks if generated action types files are up to date.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param sources - Array of source information objects.
|
|
7
7
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
8
8
|
*/
|
|
9
|
-
export declare function checkActionTypesFiles(
|
|
9
|
+
export declare function checkActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<void>;
|
|
10
10
|
//# sourceMappingURL=check.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"check.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC,CAkGf"}
|
|
@@ -4,19 +4,19 @@ import { generateActionTypesContent } from "./generate-content.mjs";
|
|
|
4
4
|
/**
|
|
5
5
|
* Checks if generated action types files are up to date.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param sources - Array of source information objects.
|
|
8
8
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
9
9
|
*/
|
|
10
|
-
export async function checkActionTypesFiles(
|
|
10
|
+
export async function checkActionTypesFiles(sources, eslint) {
|
|
11
11
|
let hasErrors = false;
|
|
12
12
|
const fileComparisonJobs = [];
|
|
13
13
|
try {
|
|
14
|
-
for (const
|
|
15
|
-
console.log(`\nš§ Checking ${
|
|
16
|
-
const outputDir = path.dirname(
|
|
17
|
-
const baseFileName = path.basename(
|
|
14
|
+
for (const source of sources) {
|
|
15
|
+
console.log(`\nš§ Checking ${source.name}...`);
|
|
16
|
+
const outputDir = path.dirname(source.filePath);
|
|
17
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
18
18
|
const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
19
|
-
const expectedContent = generateActionTypesContent(
|
|
19
|
+
const expectedContent = generateActionTypesContent(source);
|
|
20
20
|
const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');
|
|
21
21
|
try {
|
|
22
22
|
await fs.promises.access(actualFile);
|
|
@@ -41,7 +41,7 @@ export async function checkActionTypesFiles(controllers, eslint) {
|
|
|
41
41
|
if (eslint) {
|
|
42
42
|
console.log('\nš Running ESLint to compare files...');
|
|
43
43
|
const results = await eslint.instance.lintFiles(fileComparisonJobs.map((job) => job.expectedTempFile));
|
|
44
|
-
await eslint.
|
|
44
|
+
await eslint.outputFixes(results);
|
|
45
45
|
}
|
|
46
46
|
for (const job of fileComparisonJobs) {
|
|
47
47
|
const expectedContent = await fs.promises.readFile(job.expectedTempFile, 'utf8');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.mjs","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAIhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,
|
|
1
|
+
{"version":3,"file":"check.mjs","sourceRoot":"","sources":["../../src/generate-action-types/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAIhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,MAAqB;IAErB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,kBAAkB,GAIlB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C;QACF,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC5D,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 { ESLint } 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 eslint - Optional ESLint instance and static methods for formatting.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<void> {\n let hasErrors = false;\n\n const fileComparisonJobs: {\n expectedTempFile: string;\n actualFile: string;\n baseFileName: string;\n }[] = [];\n\n try {\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 = generateActionTypesContent(source);\n const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');\n\n try {\n await fs.promises.access(actualFile);\n\n await fs.promises.writeFile(expectedTempFile, expectedContent, 'utf8');\n\n fileComparisonJobs.push({\n expectedTempFile,\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 if (eslint) {\n console.log('\\nš Running ESLint to compare files...');\n\n const results = await eslint.instance.lintFiles(\n fileComparisonJobs.map((job) => job.expectedTempFile),\n );\n await eslint.outputFixes(results);\n }\n\n for (const job of fileComparisonJobs) {\n const expectedContent = await fs.promises.readFile(\n job.expectedTempFile,\n 'utf8',\n );\n const actualContent = await fs.promises.readFile(\n job.actualFile,\n 'utf8',\n );\n\n if (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 } finally {\n for (const job of fileComparisonJobs) {\n try {\n await fs.promises.unlink(job.expectedTempFile);\n } catch {\n // Ignore cleanup errors\n }\n }\n }\n\n if (hasErrors) {\n console.error('\\nš„ Some action type files are out of date or missing.');\n console.error(\n 'Run `yarn generate-method-action-types --fix` to update them.',\n );\n globalThis.process.exitCode = 1;\n } else {\n console.log('\\nš All action type files are up to date!');\n }\n}\n"]}
|
|
@@ -14,11 +14,11 @@ const parse_source_1 = require("./parse-source.cjs");
|
|
|
14
14
|
* @returns The command line arguments.
|
|
15
15
|
*/
|
|
16
16
|
async function parseCommandLineArguments() {
|
|
17
|
-
const { check, fix, path:
|
|
18
|
-
.command('$0 [path]', 'Generate method action types for
|
|
17
|
+
const { check, fix, path: sourcePath, } = await (0, yargs_1.default)(globalThis.process.argv.slice(2))
|
|
18
|
+
.command('$0 [path]', 'Generate method action types for controller and service messengers', (yargsInstance) => {
|
|
19
19
|
yargsInstance.positional('path', {
|
|
20
20
|
type: 'string',
|
|
21
|
-
description: 'Path to the folder where controllers are located',
|
|
21
|
+
description: 'Path to the folder where controllers/services are located',
|
|
22
22
|
default: 'src',
|
|
23
23
|
});
|
|
24
24
|
})
|
|
@@ -42,7 +42,7 @@ async function parseCommandLineArguments() {
|
|
|
42
42
|
return {
|
|
43
43
|
check,
|
|
44
44
|
fix,
|
|
45
|
-
|
|
45
|
+
sourcePath: sourcePath,
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
@@ -57,7 +57,11 @@ async function loadESLint() {
|
|
|
57
57
|
fix: true,
|
|
58
58
|
errorOnUnmatchedPattern: false,
|
|
59
59
|
});
|
|
60
|
-
return {
|
|
60
|
+
return {
|
|
61
|
+
instance,
|
|
62
|
+
outputFixes: ESLintClass.outputFixes,
|
|
63
|
+
getErrorResults: ESLintClass.getErrorResults,
|
|
64
|
+
};
|
|
61
65
|
}
|
|
62
66
|
catch {
|
|
63
67
|
return null;
|
|
@@ -67,21 +71,21 @@ async function loadESLint() {
|
|
|
67
71
|
* Main entry point for the CLI.
|
|
68
72
|
*/
|
|
69
73
|
async function main() {
|
|
70
|
-
const { fix,
|
|
71
|
-
console.log('š Searching for controllers with MESSENGER_EXPOSED_METHODS...');
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
console.log('ā ļø No controllers found with MESSENGER_EXPOSED_METHODS');
|
|
74
|
+
const { fix, sourcePath } = await parseCommandLineArguments();
|
|
75
|
+
console.log('š Searching for controllers/services with MESSENGER_EXPOSED_METHODS...');
|
|
76
|
+
const sources = await (0, parse_source_1.findSourcesWithExposedMethods)(sourcePath);
|
|
77
|
+
if (sources.length === 0) {
|
|
78
|
+
console.log('ā ļø No controllers/services found with MESSENGER_EXPOSED_METHODS');
|
|
75
79
|
return;
|
|
76
80
|
}
|
|
77
|
-
console.log(`š¦ Found ${
|
|
81
|
+
console.log(`š¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
|
|
78
82
|
const eslint = await loadESLint();
|
|
79
83
|
if (fix) {
|
|
80
|
-
await (0, fix_1.generateAllActionTypesFiles)(
|
|
84
|
+
await (0, fix_1.generateAllActionTypesFiles)(sources, eslint);
|
|
81
85
|
console.log('\nš All action types generated successfully!');
|
|
82
86
|
}
|
|
83
87
|
else {
|
|
84
|
-
await (0, check_1.checkActionTypesFiles)(
|
|
88
|
+
await (0, check_1.checkActionTypesFiles)(sources, eslint);
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
main().catch((error) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../../src/generate-action-types/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B,uCAAgD;AAChD,mCAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../../src/generate-action-types/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B,uCAAgD;AAChD,mCAAoD;AACpD,qDAA+D;AAS/D;;;;GAIG;AACH,KAAK,UAAU,yBAAyB;IACtC,MAAM,EACJ,KAAK,EACL,GAAG,EACH,IAAI,EAAE,UAAU,GACjB,GAAG,MAAM,IAAA,eAAK,EAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC9C,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,KAAK,EAAE;QACb,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,mCAAmC;QAChD,OAAO,EAAE,KAAK;KACf,CAAC;SACD,IAAI,EAAE;SACN,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC,IAAI,CAAC;IAEV,OAAO;QACL,KAAK;QACL,GAAG;QACH,UAAU,EAAE,UAAoB;KACjC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,MAA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,CAAC,QAAQ,GAAG,CAAC,CAAC;AAClC,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 type { ESLint } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n fix: boolean;\n sourcePath: string;\n};\n\n/**\n * Uses `yargs` to parse the arguments given to the script.\n *\n * @returns The command line arguments.\n */\nasync function parseCommandLineArguments(): Promise<CommandLineArguments> {\n const {\n check,\n fix,\n path: sourcePath,\n } = await yargs(globalThis.process.argv.slice(2))\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('fix', {\n type: 'boolean',\n description: 'Generate/update action type files',\n default: false,\n })\n .help()\n .check((argv) => {\n if (!argv.check && !argv.fix) {\n throw new Error('Either --check or --fix must be provided.\\n');\n }\n return true;\n }).argv;\n\n return {\n check,\n fix,\n sourcePath: sourcePath as string,\n };\n}\n\n/**\n * Attempt to load ESLint from the current project. Returns null if unavailable.\n *\n * @returns An ESLint object with instance and static methods, or null if unavailable.\n */\nasync function loadESLint(): Promise<ESLint | null> {\n try {\n const { ESLint: ESLintClass } = await import('eslint');\n const instance = new ESLintClass({\n fix: true,\n errorOnUnmatchedPattern: false,\n });\n return {\n instance,\n outputFixes: ESLintClass.outputFixes,\n getErrorResults: ESLintClass.getErrorResults,\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { fix, sourcePath } = await parseCommandLineArguments();\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 const eslint = await loadESLint();\n\n if (fix) {\n await generateAllActionTypesFiles(sources, eslint);\n console.log('\\nš All action types generated successfully!');\n } else {\n await checkActionTypesFiles(sources, eslint);\n }\n}\n\nmain().catch((error) => {\n console.error('ā Script failed:', error);\n globalThis.process.exitCode = 1;\n});\n"]}
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
import yargs from "yargs";
|
|
3
3
|
import { checkActionTypesFiles } from "./check.mjs";
|
|
4
4
|
import { generateAllActionTypesFiles } from "./fix.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { findSourcesWithExposedMethods } from "./parse-source.mjs";
|
|
6
6
|
/**
|
|
7
7
|
* Uses `yargs` to parse the arguments given to the script.
|
|
8
8
|
*
|
|
9
9
|
* @returns The command line arguments.
|
|
10
10
|
*/
|
|
11
11
|
async function parseCommandLineArguments() {
|
|
12
|
-
const { check, fix, path:
|
|
13
|
-
.command('$0 [path]', 'Generate method action types for
|
|
12
|
+
const { check, fix, path: sourcePath, } = await yargs(globalThis.process.argv.slice(2))
|
|
13
|
+
.command('$0 [path]', 'Generate method action types for controller and service messengers', (yargsInstance) => {
|
|
14
14
|
yargsInstance.positional('path', {
|
|
15
15
|
type: 'string',
|
|
16
|
-
description: 'Path to the folder where controllers are located',
|
|
16
|
+
description: 'Path to the folder where controllers/services are located',
|
|
17
17
|
default: 'src',
|
|
18
18
|
});
|
|
19
19
|
})
|
|
@@ -37,7 +37,7 @@ async function parseCommandLineArguments() {
|
|
|
37
37
|
return {
|
|
38
38
|
check,
|
|
39
39
|
fix,
|
|
40
|
-
|
|
40
|
+
sourcePath: sourcePath,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
@@ -52,7 +52,11 @@ async function loadESLint() {
|
|
|
52
52
|
fix: true,
|
|
53
53
|
errorOnUnmatchedPattern: false,
|
|
54
54
|
});
|
|
55
|
-
return {
|
|
55
|
+
return {
|
|
56
|
+
instance,
|
|
57
|
+
outputFixes: ESLintClass.outputFixes,
|
|
58
|
+
getErrorResults: ESLintClass.getErrorResults,
|
|
59
|
+
};
|
|
56
60
|
}
|
|
57
61
|
catch {
|
|
58
62
|
return null;
|
|
@@ -62,21 +66,21 @@ async function loadESLint() {
|
|
|
62
66
|
* Main entry point for the CLI.
|
|
63
67
|
*/
|
|
64
68
|
async function main() {
|
|
65
|
-
const { fix,
|
|
66
|
-
console.log('š Searching for controllers with MESSENGER_EXPOSED_METHODS...');
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
console.log('ā ļø No controllers found with MESSENGER_EXPOSED_METHODS');
|
|
69
|
+
const { fix, sourcePath } = await parseCommandLineArguments();
|
|
70
|
+
console.log('š Searching for controllers/services with MESSENGER_EXPOSED_METHODS...');
|
|
71
|
+
const sources = await findSourcesWithExposedMethods(sourcePath);
|
|
72
|
+
if (sources.length === 0) {
|
|
73
|
+
console.log('ā ļø No controllers/services found with MESSENGER_EXPOSED_METHODS');
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
|
-
console.log(`š¦ Found ${
|
|
76
|
+
console.log(`š¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
|
|
73
77
|
const eslint = await loadESLint();
|
|
74
78
|
if (fix) {
|
|
75
|
-
await generateAllActionTypesFiles(
|
|
79
|
+
await generateAllActionTypesFiles(sources, eslint);
|
|
76
80
|
console.log('\nš All action types generated successfully!');
|
|
77
81
|
}
|
|
78
82
|
else {
|
|
79
|
-
await checkActionTypesFiles(
|
|
83
|
+
await checkActionTypesFiles(sources, eslint);
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
main().catch((error) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../../src/generate-action-types/cli.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,cAAc;AAE1B,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EAAE,2BAA2B,EAAE,kBAAc;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../../src/generate-action-types/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;AAS/D;;;;GAIG;AACH,KAAK,UAAU,yBAAyB;IACtC,MAAM,EACJ,KAAK,EACL,GAAG,EACH,IAAI,EAAE,UAAU,GACjB,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC9C,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,KAAK,EAAE;QACb,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,mCAAmC;QAChD,OAAO,EAAE,KAAK;KACf,CAAC;SACD,IAAI,EAAE;SACN,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE;QACd,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CA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AAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AAClC,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 type { ESLint } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n fix: boolean;\n sourcePath: string;\n};\n\n/**\n * Uses `yargs` to parse the arguments given to the script.\n *\n * @returns The command line arguments.\n */\nasync function parseCommandLineArguments(): Promise<CommandLineArguments> {\n const {\n check,\n fix,\n path: sourcePath,\n } = await yargs(globalThis.process.argv.slice(2))\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('fix', {\n type: 'boolean',\n description: 'Generate/update action type files',\n default: false,\n })\n .help()\n .check((argv) => {\n if (!argv.check && !argv.fix) {\n throw new Error('Either --check or --fix must be provided.\\n');\n }\n return true;\n }).argv;\n\n return {\n check,\n fix,\n sourcePath: sourcePath as string,\n };\n}\n\n/**\n * Attempt to load ESLint from the current project. Returns null if unavailable.\n *\n * @returns An ESLint object with instance and static methods, or null if unavailable.\n */\nasync function loadESLint(): Promise<ESLint | null> {\n try {\n const { ESLint: ESLintClass } = await import('eslint');\n const instance = new ESLintClass({\n fix: true,\n errorOnUnmatchedPattern: false,\n });\n return {\n instance,\n outputFixes: ESLintClass.outputFixes,\n getErrorResults: ESLintClass.getErrorResults,\n };\n } catch {\n return null;\n }\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { fix, sourcePath } = await parseCommandLineArguments();\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 const eslint = await loadESLint();\n\n if (fix) {\n await generateAllActionTypesFiles(sources, eslint);\n console.log('\\nš All action types generated successfully!');\n } else {\n await checkActionTypesFiles(sources, eslint);\n }\n}\n\nmain().catch((error) => {\n console.error('ā Script failed:', error);\n globalThis.process.exitCode = 1;\n});\n"]}
|
|
@@ -28,28 +28,28 @@ const fs = __importStar(require("node:fs"));
|
|
|
28
28
|
const path = __importStar(require("node:path"));
|
|
29
29
|
const generate_content_1 = require("./generate-content.cjs");
|
|
30
30
|
/**
|
|
31
|
-
* Generates action types files for all controllers.
|
|
31
|
+
* Generates action types files for all controllers/services.
|
|
32
32
|
*
|
|
33
|
-
* @param
|
|
33
|
+
* @param sources - Array of source information objects.
|
|
34
34
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
35
35
|
*/
|
|
36
|
-
async function generateAllActionTypesFiles(
|
|
36
|
+
async function generateAllActionTypesFiles(sources, eslint) {
|
|
37
37
|
const outputFiles = [];
|
|
38
|
-
for (const
|
|
39
|
-
console.log(`\nš§ Processing ${
|
|
40
|
-
const outputDir = path.dirname(
|
|
41
|
-
const baseFileName = path.basename(
|
|
38
|
+
for (const source of sources) {
|
|
39
|
+
console.log(`\nš§ Processing ${source.name}...`);
|
|
40
|
+
const outputDir = path.dirname(source.filePath);
|
|
41
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
42
42
|
const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
43
|
-
const generatedContent = (0, generate_content_1.generateActionTypesContent)(
|
|
43
|
+
const generatedContent = (0, generate_content_1.generateActionTypesContent)(source);
|
|
44
44
|
await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
|
|
45
45
|
outputFiles.push(outputFile);
|
|
46
|
-
console.log(`ā
Generated action types for ${
|
|
46
|
+
console.log(`ā
Generated action types for ${source.name}`);
|
|
47
47
|
}
|
|
48
48
|
if (outputFiles.length > 0 && eslint) {
|
|
49
49
|
console.log('\nš Running ESLint on generated files...');
|
|
50
50
|
const results = await eslint.instance.lintFiles(outputFiles);
|
|
51
|
-
await eslint.
|
|
52
|
-
const errors = eslint.
|
|
51
|
+
await eslint.outputFixes(results);
|
|
52
|
+
const errors = eslint.getErrorResults(results);
|
|
53
53
|
if (errors.length > 0) {
|
|
54
54
|
console.error('ā ESLint errors:', errors);
|
|
55
55
|
globalThis.process.exitCode = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.cjs","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;GAKG;AACI,KAAK,UAAU,2BAA2B,CAC/C,
|
|
1
|
+
{"version":3,"file":"fix.cjs","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;GAKG;AACI,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,MAAqB;IAErB,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,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,IAAA,6CAA0B,EAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAClE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,gCAAgC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QAEzD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7D,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;YAC1C,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;AACH,CAAC;AAlCD,kEAkCC","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 { ESLint } from './types';\n\n/**\n * Generates action types files for all controllers/services.\n *\n * @param sources - Array of source information objects.\n * @param eslint - Optional ESLint instance and static methods for formatting.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<void> {\n const outputFiles: string[] = [];\n\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 = generateActionTypesContent(source);\n await fs.promises.writeFile(outputFile, generatedContent, 'utf8');\n outputFiles.push(outputFile);\n console.log(`ā
Generated action types for ${source.name}`);\n }\n\n if (outputFiles.length > 0 && eslint) {\n console.log('\\nš Running ESLint on generated files...');\n\n const results = await eslint.instance.lintFiles(outputFiles);\n await eslint.outputFixes(results);\n const errors = eslint.getErrorResults(results);\n if (errors.length > 0) {\n console.error('ā ESLint errors:', errors);\n globalThis.process.exitCode = 1;\n } else {\n console.log('ā
ESLint formatting applied');\n }\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceInfo } from "./parse-source.cjs";
|
|
2
2
|
import type { ESLint } from "./types.cjs";
|
|
3
3
|
/**
|
|
4
|
-
* Generates action types files for all controllers.
|
|
4
|
+
* Generates action types files for all controllers/services.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param sources - Array of source information objects.
|
|
7
7
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateAllActionTypesFiles(
|
|
9
|
+
export declare function generateAllActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<void>;
|
|
10
10
|
//# sourceMappingURL=fix.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"fix.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceInfo } from "./parse-source.mjs";
|
|
2
2
|
import type { ESLint } from "./types.mjs";
|
|
3
3
|
/**
|
|
4
|
-
* Generates action types files for all controllers.
|
|
4
|
+
* Generates action types files for all controllers/services.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param sources - Array of source information objects.
|
|
7
7
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateAllActionTypesFiles(
|
|
9
|
+
export declare function generateAllActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<void>;
|
|
10
10
|
//# sourceMappingURL=fix.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"fix.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -2,28 +2,28 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { generateActionTypesContent } from "./generate-content.mjs";
|
|
4
4
|
/**
|
|
5
|
-
* Generates action types files for all controllers.
|
|
5
|
+
* Generates action types files for all controllers/services.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param sources - Array of source information objects.
|
|
8
8
|
* @param eslint - Optional ESLint instance and static methods for formatting.
|
|
9
9
|
*/
|
|
10
|
-
export async function generateAllActionTypesFiles(
|
|
10
|
+
export async function generateAllActionTypesFiles(sources, eslint) {
|
|
11
11
|
const outputFiles = [];
|
|
12
|
-
for (const
|
|
13
|
-
console.log(`\nš§ Processing ${
|
|
14
|
-
const outputDir = path.dirname(
|
|
15
|
-
const baseFileName = path.basename(
|
|
12
|
+
for (const source of sources) {
|
|
13
|
+
console.log(`\nš§ Processing ${source.name}...`);
|
|
14
|
+
const outputDir = path.dirname(source.filePath);
|
|
15
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
16
16
|
const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
17
|
-
const generatedContent = generateActionTypesContent(
|
|
17
|
+
const generatedContent = generateActionTypesContent(source);
|
|
18
18
|
await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
|
|
19
19
|
outputFiles.push(outputFile);
|
|
20
|
-
console.log(`ā
Generated action types for ${
|
|
20
|
+
console.log(`ā
Generated action types for ${source.name}`);
|
|
21
21
|
}
|
|
22
22
|
if (outputFiles.length > 0 && eslint) {
|
|
23
23
|
console.log('\nš Running ESLint on generated files...');
|
|
24
24
|
const results = await eslint.instance.lintFiles(outputFiles);
|
|
25
|
-
await eslint.
|
|
26
|
-
const errors = eslint.
|
|
25
|
+
await eslint.outputFixes(results);
|
|
26
|
+
const errors = eslint.getErrorResults(results);
|
|
27
27
|
if (errors.length > 0) {
|
|
28
28
|
console.error('ā ESLint errors:', errors);
|
|
29
29
|
globalThis.process.exitCode = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.mjs","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAIhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,
|
|
1
|
+
{"version":3,"file":"fix.mjs","sourceRoot":"","sources":["../../src/generate-action-types/fix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+BAA2B;AAIhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,MAAqB;IAErB,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,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,0BAA0B,CAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAClE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,gCAAgC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QAEzD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7D,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;YAC1C,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC7C,CAAC;IACH,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 { ESLint } from './types';\n\n/**\n * Generates action types files for all controllers/services.\n *\n * @param sources - Array of source information objects.\n * @param eslint - Optional ESLint instance and static methods for formatting.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<void> {\n const outputFiles: string[] = [];\n\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 = generateActionTypesContent(source);\n await fs.promises.writeFile(outputFile, generatedContent, 'utf8');\n outputFiles.push(outputFile);\n console.log(`ā
Generated action types for ${source.name}`);\n }\n\n if (outputFiles.length > 0 && eslint) {\n console.log('\\nš Running ESLint on generated files...');\n\n const results = await eslint.instance.lintFiles(outputFiles);\n await eslint.outputFixes(results);\n const errors = eslint.getErrorResults(results);\n if (errors.length > 0) {\n console.error('ā ESLint errors:', errors);\n globalThis.process.exitCode = 1;\n } else {\n console.log('ā
ESLint formatting applied');\n }\n }\n}\n"]}
|
|
@@ -28,38 +28,38 @@ const path = __importStar(require("node:path"));
|
|
|
28
28
|
/**
|
|
29
29
|
* Generates the content for the action types file.
|
|
30
30
|
*
|
|
31
|
-
* @param
|
|
31
|
+
* @param source - The source information object (controller or service).
|
|
32
32
|
* @returns The content for the action types file.
|
|
33
33
|
*/
|
|
34
|
-
function generateActionTypesContent(
|
|
35
|
-
const baseFileName = path.basename(
|
|
36
|
-
const
|
|
34
|
+
function generateActionTypesContent(source) {
|
|
35
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
36
|
+
const sourceImportPath = `./${baseFileName}`;
|
|
37
37
|
let content = `/**
|
|
38
38
|
* This file is auto generated by \`@metamask/messenger/generate-action-types\`.
|
|
39
39
|
* Do not edit manually.
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
|
-
import type { ${
|
|
42
|
+
import type { ${source.name} } from '${sourceImportPath}';
|
|
43
43
|
|
|
44
44
|
`;
|
|
45
45
|
const actionTypeNames = [];
|
|
46
|
-
for (const method of
|
|
46
|
+
for (const method of source.methods) {
|
|
47
47
|
const capitalizedName = method.name.charAt(0).toUpperCase() + method.name.slice(1);
|
|
48
|
-
const actionTypeName = `${
|
|
49
|
-
const actionString = `${
|
|
48
|
+
const actionTypeName = `${source.name}${capitalizedName}Action`;
|
|
49
|
+
const actionString = `${source.name}:${method.name}`;
|
|
50
50
|
actionTypeNames.push(actionTypeName);
|
|
51
51
|
if (method.jsDoc) {
|
|
52
52
|
content += `${method.jsDoc}\n`;
|
|
53
53
|
}
|
|
54
54
|
content += `export type ${actionTypeName} = {
|
|
55
55
|
type: \`${actionString}\`;
|
|
56
|
-
handler: ${
|
|
56
|
+
handler: ${source.name}['${method.name}'];
|
|
57
57
|
};\n\n`;
|
|
58
58
|
}
|
|
59
59
|
if (actionTypeNames.length > 0) {
|
|
60
|
-
const unionTypeName = `${
|
|
60
|
+
const unionTypeName = `${source.name}MethodActions`;
|
|
61
61
|
content += `/**
|
|
62
|
-
* Union of all ${
|
|
62
|
+
* Union of all ${source.name} action types.
|
|
63
63
|
*/
|
|
64
64
|
export type ${unionTypeName} = ${actionTypeNames.join(' | ')};\n`;
|
|
65
65
|
}
|