@metamask-previews/messenger-cli 0.2.0-preview-3e34650c2 → 0.2.0-preview-4f4c98e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/{check.d.mts → check.d.ts} +3 -3
  3. package/dist/check.d.ts.map +1 -0
  4. package/dist/{check.mjs → check.js} +4 -4
  5. package/dist/check.js.map +1 -0
  6. package/dist/cli.d.ts +3 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/{cli.mjs → cli.js} +5 -5
  9. package/dist/cli.js.map +1 -0
  10. package/dist/{fix.d.cts → fix.d.ts} +3 -3
  11. package/dist/fix.d.ts.map +1 -0
  12. package/dist/{fix.mjs → fix.js} +4 -4
  13. package/dist/fix.js.map +1 -0
  14. package/dist/{generate-content.d.cts → generate-content.d.ts} +3 -3
  15. package/dist/generate-content.d.ts.map +1 -0
  16. package/dist/{generate-content.mjs → generate-content.js} +5 -5
  17. package/dist/generate-content.js.map +1 -0
  18. package/dist/{parse-source.d.cts → parse-source.d.ts} +1 -1
  19. package/dist/parse-source.d.ts.map +1 -0
  20. package/dist/{parse-source.mjs → parse-source.js} +8 -6
  21. package/dist/parse-source.js.map +1 -0
  22. package/dist/{types.d.cts → types.d.ts} +1 -1
  23. package/dist/types.d.ts.map +1 -0
  24. package/dist/types.js +2 -0
  25. package/dist/types.js.map +1 -0
  26. package/package.json +12 -7
  27. package/dist/check.cjs +0 -87
  28. package/dist/check.cjs.map +0 -1
  29. package/dist/check.d.cts +0 -13
  30. package/dist/check.d.cts.map +0 -1
  31. package/dist/check.d.mts.map +0 -1
  32. package/dist/check.mjs.map +0 -1
  33. package/dist/cli.cjs +0 -91
  34. package/dist/cli.cjs.map +0 -1
  35. package/dist/cli.d.cts +0 -3
  36. package/dist/cli.d.cts.map +0 -1
  37. package/dist/cli.d.mts +0 -3
  38. package/dist/cli.d.mts.map +0 -1
  39. package/dist/cli.mjs.map +0 -1
  40. package/dist/fix.cjs +0 -51
  41. package/dist/fix.cjs.map +0 -1
  42. package/dist/fix.d.cts.map +0 -1
  43. package/dist/fix.d.mts +0 -13
  44. package/dist/fix.d.mts.map +0 -1
  45. package/dist/fix.mjs.map +0 -1
  46. package/dist/generate-content.cjs +0 -148
  47. package/dist/generate-content.cjs.map +0 -1
  48. package/dist/generate-content.d.cts.map +0 -1
  49. package/dist/generate-content.d.mts +0 -13
  50. package/dist/generate-content.d.mts.map +0 -1
  51. package/dist/generate-content.mjs.map +0 -1
  52. package/dist/parse-source.cjs +0 -324
  53. package/dist/parse-source.cjs.map +0 -1
  54. package/dist/parse-source.d.cts.map +0 -1
  55. package/dist/parse-source.d.mts +0 -25
  56. package/dist/parse-source.d.mts.map +0 -1
  57. package/dist/parse-source.mjs.map +0 -1
  58. package/dist/types.cjs +0 -3
  59. package/dist/types.cjs.map +0 -1
  60. package/dist/types.d.cts.map +0 -1
  61. package/dist/types.d.mts +0 -5
  62. package/dist/types.d.mts.map +0 -1
  63. package/dist/types.mjs +0 -2
  64. package/dist/types.mjs.map +0 -1
package/dist/cli.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B,0CAAmD;AACnD,sCAAuD;AACvD,wDAAkE;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,IAAA,eAAK,EAAC,IAAI,CAAC;SAClB,OAAO,CACN,WAAW,EACX,oEAAoE,EACpE,CAAC,aAAa,EAAE,EAAE;QAChB,aAAa,CAAC,UAAU,CAAC,MAAM,EAAE;YAC/B,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,2DAA2D;YAC7D,OAAO,EAAE,KAAK;S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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,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAA,oCAA2B,EAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QAC3D,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,MAAM,IAAA,gCAAqB,EAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QACrE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,iDAAiD;YACjD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,iDAAiD;IACjD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport yargs from 'yargs';\n\nimport { checkActionTypesFiles } from './check.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 DELETED
@@ -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/cli.ts"],"names":[],"mappings":""}
package/dist/cli.d.mts DELETED
@@ -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/cli.ts"],"names":[],"mappings":""}
package/dist/cli.mjs.map DELETED
@@ -1 +0,0 @@
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,C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,OAAO,GAAG,MAAM,qBAAqB,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QACrE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,iDAAiD;YACjD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,iDAAiD;IACjD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport yargs from 'yargs';\n\nimport { checkActionTypesFiles } from './check.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 DELETED
@@ -1,51 +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_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 DELETED
@@ -1 +0,0 @@
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 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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
@@ -1 +0,0 @@
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.mjs.map DELETED
@@ -1 +0,0 @@
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"]}
@@ -1,148 +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.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
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-content.cjs","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAoE;AACpE,gDAAkC;AAKlC;;;;;;GAMG;AACH,MAAM,0BAA0B,GAAG;IACjC,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,QAAgB;IACxD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,YAAY,CAAC;QAE3D,MAAM,MAAM,GACV,CAAC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,0BAA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["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 +0,0 @@
1
- {"version":3,"file":"generate-content.d.cts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAA0B;AACpD,OAAO,EAAE,SAAS,EAAE,oBAAmB;AA0FvC;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,EACpB,GAAG,UAAQ,GACV,OAAO,CAAC,MAAM,CAAC,CA2CjB"}
@@ -1,13 +0,0 @@
1
- import type { SourceInfo } from "./parse-source.mjs";
2
- import { Formatter } from "./types.mjs";
3
- /**
4
- * Generates the content for the action types file.
5
- *
6
- * @param source - The source information object (controller or service).
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 The content for the action types file.
11
- */
12
- export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter, esm?: boolean): Promise<string>;
13
- //# sourceMappingURL=generate-content.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-content.d.mts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAA0B;AACpD,OAAO,EAAE,SAAS,EAAE,oBAAmB;AA0FvC;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,EACpB,GAAG,UAAQ,GACV,OAAO,CAAC,MAAM,CAAC,CA2CjB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-content.mjs","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,wBAAwB;AACpE,OAAO,KAAK,IAAI,kBAAkB;AAKlC;;;;;;GAMG;AACH,MAAM,0BAA0B,GAAG;IACjC,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,QAAgB;IACxD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,YAAY,CAAC;QAE3D,MAAM,MAAM,GACV,CAAC,MAAM,aAAa,CAAC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ourcesContent":["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"]}