@metamask-previews/messenger-cli 0.2.0-preview-4f4c98e → 0.2.0-preview-5b293ee50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/check.cjs +87 -0
- package/dist/check.cjs.map +1 -0
- package/dist/{check.d.ts → check.d.cts} +3 -3
- package/dist/check.d.cts.map +1 -0
- package/dist/check.d.mts +13 -0
- package/dist/check.d.mts.map +1 -0
- package/dist/{check.js → check.mjs} +4 -4
- package/dist/check.mjs.map +1 -0
- package/dist/cli.cjs +91 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +3 -0
- package/dist/cli.d.cts.map +1 -0
- package/dist/cli.d.mts +3 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/{cli.js → cli.mjs} +5 -5
- package/dist/cli.mjs.map +1 -0
- package/dist/fix.cjs +51 -0
- package/dist/fix.cjs.map +1 -0
- package/dist/{fix.d.ts → fix.d.cts} +3 -3
- package/dist/fix.d.cts.map +1 -0
- package/dist/fix.d.mts +13 -0
- package/dist/fix.d.mts.map +1 -0
- package/dist/{fix.js → fix.mjs} +4 -4
- package/dist/fix.mjs.map +1 -0
- package/dist/generate-content.cjs +148 -0
- package/dist/generate-content.cjs.map +1 -0
- package/dist/{generate-content.d.ts → generate-content.d.cts} +3 -3
- package/dist/generate-content.d.cts.map +1 -0
- package/dist/generate-content.d.mts +13 -0
- package/dist/generate-content.d.mts.map +1 -0
- package/dist/{generate-content.js → generate-content.mjs} +5 -5
- package/dist/generate-content.mjs.map +1 -0
- package/dist/parse-source.cjs +324 -0
- package/dist/parse-source.cjs.map +1 -0
- package/dist/{parse-source.d.ts → parse-source.d.cts} +1 -1
- package/dist/parse-source.d.cts.map +1 -0
- package/dist/parse-source.d.mts +25 -0
- package/dist/parse-source.d.mts.map +1 -0
- package/dist/{parse-source.js → parse-source.mjs} +6 -8
- package/dist/parse-source.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +1 -1
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +5 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +7 -12
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/fix.d.ts.map +0 -1
- package/dist/fix.js.map +0 -1
- package/dist/generate-content.d.ts.map +0 -1
- package/dist/generate-content.js.map +0 -1
- package/dist/parse-source.d.ts.map +0 -1
- package/dist/parse-source.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -14,7 +14,6 @@ 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))
|
|
18
17
|
- Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
|
|
19
18
|
|
|
20
19
|
## [0.2.0]
|
package/dist/check.cjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.cjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AA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,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAEzE,IAAI,GAAG,CAAC,eAAe,KAAK,aAAa,EAAE,CAAC;gBAC1C,OAAO,CAAC,GAAG,CACT,KAAK,GAAG,CAAC,YAAY,uCAAuC,CAC7D,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CACX,KAAK,GAAG,CAAC,YAAY,wCAAwC,CAC9D,CAAC;gBACF,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC;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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SourceInfo } from
|
|
2
|
-
import { Formatter } from
|
|
1
|
+
import type { SourceInfo } from "./parse-source.cjs";
|
|
2
|
+
import { Formatter } from "./types.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Checks if generated action types files are up to date.
|
|
5
5
|
*
|
|
@@ -10,4 +10,4 @@ import { Formatter } from './types.js';
|
|
|
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.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SourceInfo } from "./parse-source.mjs";
|
|
2
|
+
import { Formatter } 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 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.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -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.mjs";
|
|
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.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.mjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+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,KAAK,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,SAAS,EACT,GAAG,YAAY,yBAAyB,CACzC,CAAC;QAEF,MAAM,eAAe,GAAG,MAAM,0BAA0B,CACtD,MAAM,EACN,SAAS,EACT,GAAG,CACJ,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACrC,kBAAkB,CAAC,IAAI,CAAC;gBACtB,eAAe;gBACf,UAAU;gBACV,YAAY;aACb,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACvD,OAAO,CAAC,KAAK,CACX,KAAK,YAAY,wCAAwC,CAC1D,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CACX,mBAAmB,YAAY,0BAA0B,EACzD,KAAK,CACN,CAAC;YACJ,CAAC;YACD,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC;IACH,CAAC;IAED,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAEzE,IAAI,GAAG,CAAC,eAAe,KAAK,aAAa,EAAE,CAAC;gBAC1C,OAAO,CAAC,GAAG,CACT,KAAK,GAAG,CAAC,YAAY,uCAAuC,CAC7D,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CACX,KAAK,GAAG,CAAC,YAAY,wCAAwC,CAC9D,CAAC;gBACF,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC","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
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
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
|
package/dist/cli.cjs.map
AD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AE,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"]}
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.cts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.mts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/{cli.js → cli.mjs}
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.mjs";
|
|
4
|
+
import { generateAllActionTypesFiles } from "./fix.mjs";
|
|
5
|
+
import { findSourcesWithExposedMethods } from "./parse-source.mjs";
|
|
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.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,cAAc;AAE1B,OAAO,EAAE,qBAAqB,EAAE,oBAAmB;AACnD,OAAO,EAAE,2BAA2B,EAAE,kBAAiB;AACvD,OAAO,EAAE,6BAA6B,EAAE,2BAA0B;AAWlE;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CACtC,IAAc;IAEd,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,GAAG,EACH,IAAI,EAAE,UAAU,GACjB,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;SAClB,OAAO,CACN,WAAW,EACX,oEAAoE,EACpE,CAAC,aAAa,EAAE,EAAE;QAChB,aAAa,CAAC,UAAU,CAAC,MAAM,EAAE;YAC/B,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,2DAA2D;YAC7D,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;IACL,CAAC,CACF;SACA,MAAM,CAAC,OAAO,EAAE;QACf,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,qDAAqD;QAClE,OAAO,EAAE,KAAK;KACf,CAAC;SACD,MAAM,CAAC,UAAU,EAAE;QAClB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,mCAAmC;QAChD,OAAO,EAAE,KAAK;KACf,CAAC;SACD,MAAM,CAAC,WAAW,EAAE;QACnB,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,qDAAqD;QAClE,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC;QAC9B,OAAO,EAAE,UAAU;KACpB,CAAC;SACD,MAAM,CAAC,KAAK,EAAE;QACb,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,0DAA0D;QACvE,OAAO,EAAE,KAAK;KACf,CAAC;SACD,IAAI,EAAE;SACN,KAAK,CAAC,CAAC,IAAI,EAAE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ED,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"]}
|
package/dist/fix.cjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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_js_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 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 were generated successfully.
|
|
38
|
+
*/
|
|
39
|
+
async function generateAllActionTypesFiles(sources, formatter, esm = false) {
|
|
40
|
+
for (const source of sources) {
|
|
41
|
+
console.log(`\n🔧 Processing ${source.name}...`);
|
|
42
|
+
const outputDir = path.dirname(source.filePath);
|
|
43
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
44
|
+
const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
|
|
45
|
+
const generatedContent = await (0, generate_content_js_1.generateActionTypesContent)(source, formatter, esm);
|
|
46
|
+
await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
|
|
47
|
+
console.log(`✅ Generated action types for ${source.name}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.generateAllActionTypesFiles = generateAllActionTypesFiles;
|
|
51
|
+
//# sourceMappingURL=fix.cjs.map
|
package/dist/fix.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix.cjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,gEAAmE;AAInE;;;;;;;;GAQG;AACI,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,IAAA,gDAA0B,EACvD,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;AAvBD,kEAuBC","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 type { Formatter } from
|
|
1
|
+
import type { SourceInfo } from "./parse-source.cjs";
|
|
2
|
+
import type { Formatter } from "./types.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Generates action types files for all controllers/services.
|
|
5
5
|
*
|
|
@@ -10,4 +10,4 @@ import type { Formatter } from './types.js';
|
|
|
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.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix.d.cts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAA0B;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAmB;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.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SourceInfo } from "./parse-source.mjs";
|
|
2
|
+
import type { Formatter } from "./types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Generates action types files for all controllers/services.
|
|
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 were generated successfully.
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter, esm?: boolean): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=fix.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix.d.mts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAA0B;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAmB;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.js → fix.mjs}
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.mjs";
|
|
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.mjs.map
|
package/dist/fix.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix.mjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB;AAC9B,OAAO,KAAK,IAAI,kBAAkB;AAElC,OAAO,EAAE,0BAA0B,EAAE,+BAA8B;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"]}
|
|
@@ -0,0 +1,148 @@
|
|
|
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.generateActionTypesContent = void 0;
|
|
27
|
+
const utils_1 = require("@metamask/utils");
|
|
28
|
+
const path = __importStar(require("node:path"));
|
|
29
|
+
/**
|
|
30
|
+
* The default options used by Oxfmt and Prettier when formatting the generated
|
|
31
|
+
* content. In the case of Prettier, these options will be used if the user does
|
|
32
|
+
* not have a Prettier configuration file in their project. Oxfmt doesn't have a
|
|
33
|
+
* `resolveConfig` function like Prettier, so it will always use these options
|
|
34
|
+
* when formatting.
|
|
35
|
+
*/
|
|
36
|
+
const DEFAULT_FORMATTING_OPTIONS = {
|
|
37
|
+
printWidth: 80,
|
|
38
|
+
singleQuote: true,
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Safely format a TypeScript file with Prettier. If Prettier is not installed,
|
|
42
|
+
* it will throw an error with a clear message. This allows us to use Prettier
|
|
43
|
+
* for formatting when available, without making it a hard dependency of the
|
|
44
|
+
* project.
|
|
45
|
+
*
|
|
46
|
+
* @param contents - The source code to format.
|
|
47
|
+
* @param filePath - The file path to use for resolving Prettier configuration.
|
|
48
|
+
* @returns The formatted source code.
|
|
49
|
+
*/
|
|
50
|
+
async function prettier(contents, filePath) {
|
|
51
|
+
try {
|
|
52
|
+
const { format, resolveConfig } = await import("prettier");
|
|
53
|
+
const config = (await resolveConfig(filePath)) ?? DEFAULT_FORMATTING_OPTIONS;
|
|
54
|
+
return await format(contents, {
|
|
55
|
+
...config,
|
|
56
|
+
parser: 'typescript',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const message = (0, utils_1.getErrorMessage)(error);
|
|
61
|
+
throw new Error(`Failed to format source code with Prettier. Is Prettier installed?\n\n${message}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Safely format a TypeScript file with Oxfmt. If Oxfmt is not installed, it
|
|
66
|
+
* will throw an error with a clear message. This allows us to use Oxfmt for
|
|
67
|
+
* formatting when available, without making it a hard dependency of the
|
|
68
|
+
* project.
|
|
69
|
+
*
|
|
70
|
+
* @param contents - The source code to format.
|
|
71
|
+
* @param filePath - The file path to use for resolving Oxfmt configuration. Not
|
|
72
|
+
* currently used, but included for future extensibility.
|
|
73
|
+
* @returns The formatted source code.
|
|
74
|
+
*/
|
|
75
|
+
async function oxfmt(contents, filePath) {
|
|
76
|
+
try {
|
|
77
|
+
const { format } = await import("oxfmt");
|
|
78
|
+
const result = await format(filePath, contents, DEFAULT_FORMATTING_OPTIONS);
|
|
79
|
+
return result.code;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const message = (0, utils_1.getErrorMessage)(error);
|
|
83
|
+
throw new Error(`Failed to format source code with Oxfmt. Is Oxfmt installed?\n\n${message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the appropriate formatter function based on the specified formatter.
|
|
88
|
+
*
|
|
89
|
+
* @param formatter - The formatter to use.
|
|
90
|
+
* @returns A function that takes source code as input and returns the formatted
|
|
91
|
+
* source code.
|
|
92
|
+
*/
|
|
93
|
+
function getFormatter(formatter) {
|
|
94
|
+
switch (formatter) {
|
|
95
|
+
case 'prettier':
|
|
96
|
+
return prettier;
|
|
97
|
+
case 'oxfmt':
|
|
98
|
+
return oxfmt;
|
|
99
|
+
default:
|
|
100
|
+
return (0, utils_1.assertExhaustive)(formatter);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generates the content for the action types file.
|
|
105
|
+
*
|
|
106
|
+
* @param source - The source information object (controller or service).
|
|
107
|
+
* @param formatter - The formatter to use for formatting the generated content.
|
|
108
|
+
* @param esm - Whether to add `.js` extensions to import paths for ESM
|
|
109
|
+
* compatibility.
|
|
110
|
+
* @returns The content for the action types file.
|
|
111
|
+
*/
|
|
112
|
+
async function generateActionTypesContent(source, formatter, esm = false) {
|
|
113
|
+
const baseFileName = path.basename(source.filePath, '.ts');
|
|
114
|
+
const sourceImportPath = `./${baseFileName}${esm ? '.js' : ''}`;
|
|
115
|
+
let content = `/**
|
|
116
|
+
* This file is auto generated.
|
|
117
|
+
* Do not edit manually.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
import type { ${source.name} } from '${sourceImportPath}';
|
|
121
|
+
|
|
122
|
+
`;
|
|
123
|
+
const actionTypeNames = [];
|
|
124
|
+
for (const method of source.methods) {
|
|
125
|
+
const capitalizedName = method.name.charAt(0).toUpperCase() + method.name.slice(1);
|
|
126
|
+
const actionTypeName = `${source.name}${capitalizedName}Action`;
|
|
127
|
+
const actionString = `${source.name}:${method.name}`;
|
|
128
|
+
actionTypeNames.push(actionTypeName);
|
|
129
|
+
if (method.jsDoc) {
|
|
130
|
+
content += `${method.jsDoc}\n`;
|
|
131
|
+
}
|
|
132
|
+
content += `export type ${actionTypeName} = {
|
|
133
|
+
type: \`${actionString}\`;
|
|
134
|
+
handler: ${source.name}['${method.name}'];
|
|
135
|
+
};\n\n`;
|
|
136
|
+
}
|
|
137
|
+
if (actionTypeNames.length > 0) {
|
|
138
|
+
const unionTypeName = `${source.name}MethodActions`;
|
|
139
|
+
content += `/**
|
|
140
|
+
* Union of all ${source.name} action types.
|
|
141
|
+
*/
|
|
142
|
+
export type ${unionTypeName} = ${actionTypeNames.join(' | ')};\n`;
|
|
143
|
+
}
|
|
144
|
+
const formatterFunction = getFormatter(formatter);
|
|
145
|
+
return await formatterFunction(content, source.filePath);
|
|
146
|
+
}
|
|
147
|
+
exports.generateActionTypesContent = generateActionTypesContent;
|
|
148
|
+
//# sourceMappingURL=generate-content.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-content.cjs","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAoE;AACpE,gDAAkC;AAKlC;;;;;;GAMG;AACH,MAAM,0BAA0B,GAAG;IACjC,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,QAAgB;IACxD,IAAI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BAAiB,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAClD,OAAO,MAAM,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC3D,CAAC;AA/CD,gEA+CC","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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SourceInfo } from
|
|
2
|
-
import { Formatter } from
|
|
1
|
+
import type { SourceInfo } from "./parse-source.cjs";
|
|
2
|
+
import { Formatter } from "./types.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Generates the content for the action types file.
|
|
5
5
|
*
|
|
@@ -10,4 +10,4 @@ import { Formatter } from './types.js';
|
|
|
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.cts.map
|