@metamask-previews/messenger 0.3.0-preview-74da211 → 0.3.0-preview-3047a7f

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/package.json +2 -39
  3. package/dist/generate-action-types/check.cjs +0 -105
  4. package/dist/generate-action-types/check.cjs.map +0 -1
  5. package/dist/generate-action-types/check.d.cts +0 -10
  6. package/dist/generate-action-types/check.d.cts.map +0 -1
  7. package/dist/generate-action-types/check.d.mts +0 -10
  8. package/dist/generate-action-types/check.d.mts.map +0 -1
  9. package/dist/generate-action-types/check.mjs +0 -78
  10. package/dist/generate-action-types/check.mjs.map +0 -1
  11. package/dist/generate-action-types/cli.cjs +0 -95
  12. package/dist/generate-action-types/cli.cjs.map +0 -1
  13. package/dist/generate-action-types/cli.d.cts +0 -3
  14. package/dist/generate-action-types/cli.d.cts.map +0 -1
  15. package/dist/generate-action-types/cli.d.mts +0 -3
  16. package/dist/generate-action-types/cli.d.mts.map +0 -1
  17. package/dist/generate-action-types/cli.mjs +0 -90
  18. package/dist/generate-action-types/cli.mjs.map +0 -1
  19. package/dist/generate-action-types/fix.cjs +0 -63
  20. package/dist/generate-action-types/fix.cjs.map +0 -1
  21. package/dist/generate-action-types/fix.d.cts +0 -10
  22. package/dist/generate-action-types/fix.d.cts.map +0 -1
  23. package/dist/generate-action-types/fix.d.mts +0 -10
  24. package/dist/generate-action-types/fix.d.mts.map +0 -1
  25. package/dist/generate-action-types/fix.mjs +0 -36
  26. package/dist/generate-action-types/fix.mjs.map +0 -1
  27. package/dist/generate-action-types/generate-content.cjs +0 -69
  28. package/dist/generate-action-types/generate-content.cjs.map +0 -1
  29. package/dist/generate-action-types/generate-content.d.cts +0 -9
  30. package/dist/generate-action-types/generate-content.d.cts.map +0 -1
  31. package/dist/generate-action-types/generate-content.d.mts +0 -9
  32. package/dist/generate-action-types/generate-content.d.mts.map +0 -1
  33. package/dist/generate-action-types/generate-content.mjs +0 -42
  34. package/dist/generate-action-types/generate-content.mjs.map +0 -1
  35. package/dist/generate-action-types/index.cjs +0 -13
  36. package/dist/generate-action-types/index.cjs.map +0 -1
  37. package/dist/generate-action-types/index.d.cts +0 -7
  38. package/dist/generate-action-types/index.d.cts.map +0 -1
  39. package/dist/generate-action-types/index.d.mts +0 -7
  40. package/dist/generate-action-types/index.d.mts.map +0 -1
  41. package/dist/generate-action-types/index.mjs +0 -5
  42. package/dist/generate-action-types/index.mjs.map +0 -1
  43. package/dist/generate-action-types/parse-source.cjs +0 -299
  44. package/dist/generate-action-types/parse-source.cjs.map +0 -1
  45. package/dist/generate-action-types/parse-source.d.cts +0 -24
  46. package/dist/generate-action-types/parse-source.d.cts.map +0 -1
  47. package/dist/generate-action-types/parse-source.d.mts +0 -24
  48. package/dist/generate-action-types/parse-source.d.mts.map +0 -1
  49. package/dist/generate-action-types/parse-source.mjs +0 -272
  50. package/dist/generate-action-types/parse-source.mjs.map +0 -1
  51. package/dist/generate-action-types/types.cjs +0 -3
  52. package/dist/generate-action-types/types.cjs.map +0 -1
  53. package/dist/generate-action-types/types.d.cts +0 -7
  54. package/dist/generate-action-types/types.d.cts.map +0 -1
  55. package/dist/generate-action-types/types.d.mts +0 -7
  56. package/dist/generate-action-types/types.d.mts.map +0 -1
  57. package/dist/generate-action-types/types.mjs +0 -2
  58. package/dist/generate-action-types/types.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,13 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Add `generate-action-types` CLI tool and subpath export ([#8264](https://github.com/MetaMask/core/pull/8264))
13
- - Generates TypeScript action type files for controllers and services that define `MESSENGER_EXPOSED_METHODS`.
14
- - Available as a CLI binary (`messenger-generate-action-types`) and as a programmatic API via `@metamask/messenger/generate-action-types`.
15
- - `typescript`, `yargs`, and `eslint` are optional peer dependencies, only required when using the codegen tool.
16
-
17
10
  ## [0.3.0]
18
11
 
19
12
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/messenger",
3
- "version": "0.3.0-preview-74da211",
3
+ "version": "0.3.0-preview-3047a7f",
4
4
  "description": "A type-safe message bus library",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -27,23 +27,10 @@
27
27
  "default": "./dist/index.cjs"
28
28
  }
29
29
  },
30
- "./generate-action-types": {
31
- "import": {
32
- "types": "./dist/generate-action-types/index.d.mts",
33
- "default": "./dist/generate-action-types/index.mjs"
34
- },
35
- "require": {
36
- "types": "./dist/generate-action-types/index.d.cts",
37
- "default": "./dist/generate-action-types/index.cjs"
38
- }
39
- },
40
30
  "./package.json": "./package.json"
41
31
  },
42
32
  "main": "./dist/index.cjs",
43
33
  "types": "./dist/index.d.cts",
44
- "bin": {
45
- "messenger-generate-action-types": "./dist/generate-action-types/cli.mjs"
46
- },
47
34
  "files": [
48
35
  "dist/"
49
36
  ],
@@ -61,39 +48,15 @@
61
48
  },
62
49
  "devDependencies": {
63
50
  "@metamask/auto-changelog": "^3.4.4",
64
- "@metamask/utils": "^11.9.0",
65
51
  "@ts-bridge/cli": "^0.6.4",
66
52
  "@types/jest": "^29.5.14",
67
- "@types/yargs": "^17.0.32",
68
53
  "deepmerge": "^4.2.2",
69
- "eslint": "^9.39.1",
70
54
  "immer": "^9.0.6",
71
55
  "jest": "^29.7.0",
72
56
  "ts-jest": "^29.2.5",
73
57
  "typedoc": "^0.25.13",
74
58
  "typedoc-plugin-missing-exports": "^2.0.0",
75
- "typescript": "~5.3.3",
76
- "yargs": "^17.7.2"
77
- },
78
- "peerDependencies": {
79
- "@metamask/utils": "^11.9.0",
80
- "eslint": ">=8",
81
- "typescript": "~5.3.3",
82
- "yargs": "^17.7.2"
83
- },
84
- "peerDependenciesMeta": {
85
- "@metamask/utils": {
86
- "optional": true
87
- },
88
- "eslint": {
89
- "optional": true
90
- },
91
- "typescript": {
92
- "optional": true
93
- },
94
- "yargs": {
95
- "optional": true
96
- }
59
+ "typescript": "~5.3.3"
97
60
  },
98
61
  "engines": {
99
62
  "node": "^18.18 || >=20"
@@ -1,105 +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_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 eslint - Optional ESLint instance and static methods for formatting.
35
- */
36
- async function checkActionTypesFiles(sources, eslint) {
37
- let hasErrors = false;
38
- const fileComparisonJobs = [];
39
- try {
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
- const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
45
- const expectedContent = (0, generate_content_1.generateActionTypesContent)(source);
46
- const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');
47
- try {
48
- await fs.promises.access(actualFile);
49
- await fs.promises.writeFile(expectedTempFile, expectedContent, 'utf8');
50
- fileComparisonJobs.push({
51
- expectedTempFile,
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
- if (eslint) {
68
- console.log('\nšŸ“ Running ESLint to compare files...');
69
- const results = await eslint.instance.lintFiles(fileComparisonJobs.map((job) => job.expectedTempFile));
70
- await eslint.outputFixes(results);
71
- }
72
- for (const job of fileComparisonJobs) {
73
- const expectedContent = await fs.promises.readFile(job.expectedTempFile, 'utf8');
74
- const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');
75
- if (expectedContent === actualContent) {
76
- console.log(`āœ… ${job.baseFileName}-method-action-types.ts is up to date`);
77
- }
78
- else {
79
- console.error(`āŒ ${job.baseFileName}-method-action-types.ts is out of date`);
80
- hasErrors = true;
81
- }
82
- }
83
- }
84
- }
85
- finally {
86
- for (const job of fileComparisonJobs) {
87
- try {
88
- await fs.promises.unlink(job.expectedTempFile);
89
- }
90
- catch {
91
- // Ignore cleanup errors
92
- }
93
- }
94
- }
95
- if (hasErrors) {
96
- console.error('\nšŸ’„ Some action type files are out of date or missing.');
97
- console.error('Run `yarn generate-method-action-types --fix` to update them.');
98
- globalThis.process.exitCode = 1;
99
- }
100
- else {
101
- console.log('\nšŸŽ‰ All action type files are up to date!');
102
- }
103
- }
104
- exports.checkActionTypesFiles = checkActionTypesFiles;
105
- //# sourceMappingURL=check.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.cjs","sourceRoot":"","sources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,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 +0,0 @@
1
- import type { SourceInfo } from "./parse-source.cjs";
2
- import type { ESLint } 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 eslint - Optional ESLint instance and static methods for formatting.
8
- */
9
- export declare function checkActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<void>;
10
- //# sourceMappingURL=check.d.cts.map
@@ -1 +0,0 @@
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 +0,0 @@
1
- import type { SourceInfo } from "./parse-source.mjs";
2
- import type { ESLint } from "./types.mjs";
3
- /**
4
- * Checks if generated action types files are up to date.
5
- *
6
- * @param sources - Array of source information objects.
7
- * @param eslint - Optional ESLint instance and static methods for formatting.
8
- */
9
- export declare function checkActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<void>;
10
- //# sourceMappingURL=check.d.mts.map
@@ -1 +0,0 @@
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"}
@@ -1,78 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { generateActionTypesContent } from "./generate-content.mjs";
4
- /**
5
- * Checks if generated action types files are up to date.
6
- *
7
- * @param sources - Array of source information objects.
8
- * @param eslint - Optional ESLint instance and static methods for formatting.
9
- */
10
- export async function checkActionTypesFiles(sources, eslint) {
11
- let hasErrors = false;
12
- const fileComparisonJobs = [];
13
- try {
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
- const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
19
- const expectedContent = generateActionTypesContent(source);
20
- const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');
21
- try {
22
- await fs.promises.access(actualFile);
23
- await fs.promises.writeFile(expectedTempFile, expectedContent, 'utf8');
24
- fileComparisonJobs.push({
25
- expectedTempFile,
26
- actualFile,
27
- baseFileName,
28
- });
29
- }
30
- catch (error) {
31
- if (error.code === 'ENOENT') {
32
- console.error(`āŒ ${baseFileName}-method-action-types.ts does not exist`);
33
- }
34
- else {
35
- console.error(`āŒ Error reading ${baseFileName}-method-action-types.ts:`, error);
36
- }
37
- hasErrors = true;
38
- }
39
- }
40
- if (fileComparisonJobs.length > 0) {
41
- if (eslint) {
42
- console.log('\nšŸ“ Running ESLint to compare files...');
43
- const results = await eslint.instance.lintFiles(fileComparisonJobs.map((job) => job.expectedTempFile));
44
- await eslint.outputFixes(results);
45
- }
46
- for (const job of fileComparisonJobs) {
47
- const expectedContent = await fs.promises.readFile(job.expectedTempFile, 'utf8');
48
- const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');
49
- if (expectedContent === actualContent) {
50
- console.log(`āœ… ${job.baseFileName}-method-action-types.ts is up to date`);
51
- }
52
- else {
53
- console.error(`āŒ ${job.baseFileName}-method-action-types.ts is out of date`);
54
- hasErrors = true;
55
- }
56
- }
57
- }
58
- }
59
- finally {
60
- for (const job of fileComparisonJobs) {
61
- try {
62
- await fs.promises.unlink(job.expectedTempFile);
63
- }
64
- catch {
65
- // Ignore cleanup errors
66
- }
67
- }
68
- }
69
- if (hasErrors) {
70
- console.error('\nšŸ’„ Some action type files are out of date or missing.');
71
- console.error('Run `yarn generate-method-action-types --fix` to update them.');
72
- globalThis.process.exitCode = 1;
73
- }
74
- else {
75
- console.log('\nšŸŽ‰ All action type files are up to date!');
76
- }
77
- }
78
- //# sourceMappingURL=check.mjs.map
@@ -1 +0,0 @@
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,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S,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","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,95 +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_1 = require("./check.cjs");
9
- const fix_1 = require("./fix.cjs");
10
- const parse_source_1 = require("./parse-source.cjs");
11
- /**
12
- * Uses `yargs` to parse the arguments given to the script.
13
- *
14
- * @returns The command line arguments.
15
- */
16
- async function parseCommandLineArguments() {
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
- yargsInstance.positional('path', {
20
- type: 'string',
21
- description: 'Path to the folder where controllers/services are located',
22
- default: 'src',
23
- });
24
- })
25
- .option('check', {
26
- type: 'boolean',
27
- description: 'Check if generated action type files are up to date',
28
- default: false,
29
- })
30
- .option('fix', {
31
- type: 'boolean',
32
- description: 'Generate/update action type files',
33
- default: false,
34
- })
35
- .help()
36
- .check((argv) => {
37
- if (!argv.check && !argv.fix) {
38
- throw new Error('Either --check or --fix must be provided.\n');
39
- }
40
- return true;
41
- }).argv;
42
- return {
43
- check,
44
- fix,
45
- sourcePath: sourcePath,
46
- };
47
- }
48
- /**
49
- * Attempt to load ESLint from the current project. Returns null if unavailable.
50
- *
51
- * @returns An ESLint object with instance and static methods, or null if unavailable.
52
- */
53
- async function loadESLint() {
54
- try {
55
- const { ESLint: ESLintClass } = await import("eslint");
56
- const instance = new ESLintClass({
57
- fix: true,
58
- errorOnUnmatchedPattern: false,
59
- });
60
- return {
61
- instance,
62
- outputFixes: ESLintClass.outputFixes.bind(ESLintClass),
63
- getErrorResults: ESLintClass.getErrorResults.bind(ESLintClass),
64
- };
65
- }
66
- catch {
67
- return null;
68
- }
69
- }
70
- /**
71
- * Main entry point for the CLI.
72
- */
73
- async function main() {
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');
79
- return;
80
- }
81
- console.log(`šŸ“¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
82
- const eslint = await loadESLint();
83
- if (fix) {
84
- await (0, fix_1.generateAllActionTypesFiles)(sources, eslint);
85
- console.log('\nšŸŽ‰ All action types generated successfully!');
86
- }
87
- else {
88
- await (0, check_1.checkActionTypesFiles)(sources, eslint);
89
- }
90
- }
91
- main().catch((error) => {
92
- console.error('āŒ Script failed:', error);
93
- globalThis.process.exitCode = 1;
94
- });
95
- //# sourceMappingURL=cli.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../../src/generate-action-types/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B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args 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.bind(ESLintClass),\n getErrorResults: ESLintClass.getErrorResults.bind(ESLintClass),\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"]}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.cts","sourceRoot":"","sources":["../../src/generate-action-types/cli.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.mts","sourceRoot":"","sources":["../../src/generate-action-types/cli.ts"],"names":[],"mappings":""}
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env node
2
- import yargs from "yargs";
3
- import { checkActionTypesFiles } from "./check.mjs";
4
- import { generateAllActionTypesFiles } from "./fix.mjs";
5
- import { findSourcesWithExposedMethods } from "./parse-source.mjs";
6
- /**
7
- * Uses `yargs` to parse the arguments given to the script.
8
- *
9
- * @returns The command line arguments.
10
- */
11
- async function parseCommandLineArguments() {
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
- yargsInstance.positional('path', {
15
- type: 'string',
16
- description: 'Path to the folder where controllers/services are located',
17
- default: 'src',
18
- });
19
- })
20
- .option('check', {
21
- type: 'boolean',
22
- description: 'Check if generated action type files are up to date',
23
- default: false,
24
- })
25
- .option('fix', {
26
- type: 'boolean',
27
- description: 'Generate/update action type files',
28
- default: false,
29
- })
30
- .help()
31
- .check((argv) => {
32
- if (!argv.check && !argv.fix) {
33
- throw new Error('Either --check or --fix must be provided.\n');
34
- }
35
- return true;
36
- }).argv;
37
- return {
38
- check,
39
- fix,
40
- sourcePath: sourcePath,
41
- };
42
- }
43
- /**
44
- * Attempt to load ESLint from the current project. Returns null if unavailable.
45
- *
46
- * @returns An ESLint object with instance and static methods, or null if unavailable.
47
- */
48
- async function loadESLint() {
49
- try {
50
- const { ESLint: ESLintClass } = await import("eslint");
51
- const instance = new ESLintClass({
52
- fix: true,
53
- errorOnUnmatchedPattern: false,
54
- });
55
- return {
56
- instance,
57
- outputFixes: ESLintClass.outputFixes.bind(ESLintClass),
58
- getErrorResults: ESLintClass.getErrorResults.bind(ESLintClass),
59
- };
60
- }
61
- catch {
62
- return null;
63
- }
64
- }
65
- /**
66
- * Main entry point for the CLI.
67
- */
68
- async function main() {
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');
74
- return;
75
- }
76
- console.log(`šŸ“¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
77
- const eslint = await loadESLint();
78
- if (fix) {
79
- await generateAllActionTypesFiles(sources, eslint);
80
- console.log('\nšŸŽ‰ All action types generated successfully!');
81
- }
82
- else {
83
- await checkActionTypesFiles(sources, eslint);
84
- }
85
- }
86
- main().catch((error) => {
87
- console.error('āŒ Script failed:', error);
88
- globalThis.process.exitCode = 1;
89
- });
90
- //# sourceMappingURL=cli.mjs.map
@@ -1 +0,0 @@
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;AA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Q;YACR,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC;YACtD,eAAe,EAAE,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC;SAC/D,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,MAAM,yBAAyB,EAAE,CAAC;IAE9D,OAAO,CAAC,GAAG,CACT,yEAAyE,CAC1E,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAEhE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CACT,kEAAkE,CACnE,CAAC;QACF,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CACT,YAAY,OAAO,CAAC,MAAM,gDAAgD,CAC3E,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAElC,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,2BAA2B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;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.bind(ESLintClass),\n getErrorResults: ESLintClass.getErrorResults.bind(ESLintClass),\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"]}
@@ -1,63 +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.generateAllActionTypesFiles = void 0;
27
- const fs = __importStar(require("node:fs"));
28
- const path = __importStar(require("node:path"));
29
- const generate_content_1 = require("./generate-content.cjs");
30
- /**
31
- * Generates action types files for all controllers/services.
32
- *
33
- * @param sources - Array of source information objects.
34
- * @param eslint - Optional ESLint instance and static methods for formatting.
35
- */
36
- async function generateAllActionTypesFiles(sources, eslint) {
37
- const outputFiles = [];
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
- const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
43
- const generatedContent = (0, generate_content_1.generateActionTypesContent)(source);
44
- await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
45
- outputFiles.push(outputFile);
46
- console.log(`āœ… Generated action types for ${source.name}`);
47
- }
48
- if (outputFiles.length > 0 && eslint) {
49
- console.log('\nšŸ“ Running ESLint on generated files...');
50
- const results = await eslint.instance.lintFiles(outputFiles);
51
- await eslint.outputFixes(results);
52
- const errors = eslint.getErrorResults(results);
53
- if (errors.length > 0) {
54
- console.error('āŒ ESLint errors:', errors);
55
- globalThis.process.exitCode = 1;
56
- }
57
- else {
58
- console.log('āœ… ESLint formatting applied');
59
- }
60
- }
61
- }
62
- exports.generateAllActionTypesFiles = generateAllActionTypesFiles;
63
- //# sourceMappingURL=fix.cjs.map
@@ -1 +0,0 @@
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 +0,0 @@
1
- import type { SourceInfo } from "./parse-source.cjs";
2
- import type { ESLint } from "./types.cjs";
3
- /**
4
- * Generates action types files for all controllers/services.
5
- *
6
- * @param sources - Array of source information objects.
7
- * @param eslint - Optional ESLint instance and static methods for formatting.
8
- */
9
- export declare function generateAllActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<void>;
10
- //# sourceMappingURL=fix.d.cts.map
@@ -1 +0,0 @@
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"}