@metamask-previews/messenger-cli 0.1.0-preview-71e106795 → 0.1.0-preview-d363b2d74

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 CHANGED
@@ -7,6 +7,14 @@ 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
+ - **BREAKING:** Add support for formatting the generated method action type files with Prettier or Oxfmt ([#8486](https://github.com/MetaMask/core/pull/8486))
13
+ - This adds a `--formatter` option to the CLI, which accepts either `oxfmt` or
14
+ `prettier` (default).
15
+ - ESLint is no longer used to format the generated files, and is no longer a
16
+ (peer) dependency of this package.
17
+
10
18
  ## [0.1.0]
11
19
 
12
20
  ### Added
package/README.md CHANGED
@@ -10,6 +10,12 @@ or
10
10
 
11
11
  `npm install @metamask/messenger-cli`
12
12
 
13
+ Either Prettier (default) or Oxfmt (when using `--formatter oxfmt`) must also be
14
+ installed:
15
+
16
+ - Prettier: `yarn add --dev prettier` or `npm install --save-dev prettier`.
17
+ - Oxfmt: `yarn add --dev oxfmt` or `npm install --save-dev oxfmt`.
18
+
13
19
  ## Contributing
14
20
 
15
21
  This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
package/dist/check.cjs CHANGED
@@ -31,65 +31,45 @@ const generate_content_1 = require("./generate-content.cjs");
31
31
  * Checks if generated action types files are up to date.
32
32
  *
33
33
  * @param sources - Array of source information objects.
34
- * @param eslint - Optional ESLint instance and static methods for formatting.
34
+ * @param formatter - The formatter to use for formatting the generated content.
35
35
  * @returns Whether all files are up to date.
36
36
  */
37
- async function checkActionTypesFiles(sources, eslint) {
37
+ async function checkActionTypesFiles(sources, formatter) {
38
38
  let hasErrors = false;
39
39
  const fileComparisonJobs = [];
40
- try {
41
- for (const source of sources) {
42
- console.log(`\nšŸ”§ Checking ${source.name}...`);
43
- const outputDir = path.dirname(source.filePath);
44
- const baseFileName = path.basename(source.filePath, '.ts');
45
- const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
46
- const expectedContent = (0, generate_content_1.generateActionTypesContent)(source);
47
- const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');
48
- try {
49
- await fs.promises.access(actualFile);
50
- await fs.promises.writeFile(expectedTempFile, expectedContent, 'utf8');
51
- fileComparisonJobs.push({
52
- expectedTempFile,
53
- actualFile,
54
- baseFileName,
55
- });
56
- }
57
- catch (error) {
58
- if (error.code === 'ENOENT') {
59
- console.error(`āŒ ${baseFileName}-method-action-types.ts does not exist`);
60
- }
61
- else {
62
- console.error(`āŒ Error reading ${baseFileName}-method-action-types.ts:`, error);
63
- }
64
- hasErrors = true;
65
- }
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 = await (0, generate_content_1.generateActionTypesContent)(source, formatter);
46
+ try {
47
+ await fs.promises.access(actualFile);
48
+ fileComparisonJobs.push({
49
+ expectedContent,
50
+ actualFile,
51
+ baseFileName,
52
+ });
66
53
  }
67
- if (fileComparisonJobs.length > 0) {
68
- if (eslint) {
69
- console.log('\nšŸ“ Running ESLint to compare files...');
70
- const results = await eslint.instance.lintFiles(fileComparisonJobs.map((job) => job.expectedTempFile));
71
- await eslint.eslintClass.outputFixes(results);
54
+ catch (error) {
55
+ if (error.code === 'ENOENT') {
56
+ console.error(`āŒ ${baseFileName}-method-action-types.ts does not exist`);
72
57
  }
73
- for (const job of fileComparisonJobs) {
74
- const expectedContent = await fs.promises.readFile(job.expectedTempFile, 'utf8');
75
- const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');
76
- if (expectedContent === actualContent) {
77
- console.log(`āœ… ${job.baseFileName}-method-action-types.ts is up to date`);
78
- }
79
- else {
80
- console.error(`āŒ ${job.baseFileName}-method-action-types.ts is out of date`);
81
- hasErrors = true;
82
- }
58
+ else {
59
+ console.error(`āŒ Error reading ${baseFileName}-method-action-types.ts:`, error);
83
60
  }
61
+ hasErrors = true;
84
62
  }
85
63
  }
86
- finally {
64
+ if (fileComparisonJobs.length > 0) {
87
65
  for (const job of fileComparisonJobs) {
88
- try {
89
- await fs.promises.unlink(job.expectedTempFile);
66
+ const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');
67
+ if (job.expectedContent === actualContent) {
68
+ console.log(`āœ… ${job.baseFileName}-method-action-types.ts is up to date`);
90
69
  }
91
- catch {
92
- // Ignore cleanup errors
70
+ else {
71
+ console.error(`āŒ ${job.baseFileName}-method-action-types.ts is out of date`);
72
+ hasErrors = true;
93
73
  }
94
74
  }
95
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"check.cjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;;GAMG;AACI,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,MAAqB;IAErB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,kBAAkB,GAIlB,EAAE,CAAC;IAET,IAAI,CAAC;QACH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;YAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,SAAS,EACT,GAAG,YAAY,yBAAyB,CACzC,CAAC;YAEF,MAAM,eAAe,GAA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CAAC,gBAAgB,EACpB,MAAM,CACP,CAAC;gBACF,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAC9C,GAAG,CAAC,UAAU,EACd,MAAM,CACP,CAAC;gBAEF,IAAI,eAAe,KAAK,aAAa,EAAE,CAAC;oBACtC,OAAO,CAAC,GAAG,CACT,KAAK,GAAG,CAAC,YAAY,uCAAuC,CAC7D,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAK,CACX,KAAK,GAAG,CAAC,YAAY,wCAAwC,CAC9D,CAAC;oBACF,SAAS,GAAG,IAAI,CAAC;gBACnB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;YACjD,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC;AApGD,sDAoGC","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 * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<boolean> {\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.eslintClass.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('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
+ {"version":3,"file":"check.cjs","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;;GAMG;AACI,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,SAAoB;IAEpB,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,IAAA,6CAA0B,EAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE5E,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;AAtED,sDAsEC","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 { Formatter } 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 formatter - The formatter to use for formatting the generated content.\n * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\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(source, formatter);\n\n try {\n await fs.promises.access(actualFile);\n fileComparisonJobs.push({\n expectedContent,\n actualFile,\n baseFileName,\n });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n console.error(\n `āŒ ${baseFileName}-method-action-types.ts does not exist`,\n );\n } else {\n console.error(\n `āŒ Error reading ${baseFileName}-method-action-types.ts:`,\n error,\n );\n }\n hasErrors = true;\n }\n }\n\n if (fileComparisonJobs.length > 0) {\n for (const job of fileComparisonJobs) {\n const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');\n\n if (job.expectedContent === actualContent) {\n console.log(\n `āœ… ${job.baseFileName}-method-action-types.ts is up to date`,\n );\n } else {\n console.error(\n `āŒ ${job.baseFileName}-method-action-types.ts is out of date`,\n );\n hasErrors = true;\n }\n }\n }\n\n if (hasErrors) {\n console.error('\\nšŸ’„ Some action type files are out of date or missing.');\n console.error('Run `messenger-action-types --generate` to update them.');\n return false;\n }\n\n console.log('\\nšŸŽ‰ All action type files are up to date!');\n return true;\n}\n"]}
package/dist/check.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { SourceInfo } from "./parse-source.cjs";
2
- import type { ESLint } from "./types.cjs";
2
+ import { Formatter } from "./types.cjs";
3
3
  /**
4
4
  * Checks if generated action types files are up to date.
5
5
  *
6
6
  * @param sources - Array of source information objects.
7
- * @param eslint - Optional ESLint instance and static methods for formatting.
7
+ * @param formatter - The formatter to use for formatting the generated content.
8
8
  * @returns Whether all files are up to date.
9
9
  */
10
- export declare function checkActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<boolean>;
10
+ export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<boolean>;
11
11
  //# sourceMappingURL=check.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.cts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,OAAO,CAAC,CAiGlB"}
1
+ {"version":3,"file":"check.d.cts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAEpC;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,OAAO,CAAC,CAmElB"}
package/dist/check.d.mts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { SourceInfo } from "./parse-source.mjs";
2
- import type { ESLint } from "./types.mjs";
2
+ import { Formatter } from "./types.mjs";
3
3
  /**
4
4
  * Checks if generated action types files are up to date.
5
5
  *
6
6
  * @param sources - Array of source information objects.
7
- * @param eslint - Optional ESLint instance and static methods for formatting.
7
+ * @param formatter - The formatter to use for formatting the generated content.
8
8
  * @returns Whether all files are up to date.
9
9
  */
10
- export declare function checkActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<boolean>;
10
+ export declare function checkActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<boolean>;
11
11
  //# sourceMappingURL=check.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.mts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,OAAO,CAAC,CAiGlB"}
1
+ {"version":3,"file":"check.d.mts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAEpC;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,OAAO,CAAC,CAmElB"}
package/dist/check.mjs CHANGED
@@ -5,65 +5,45 @@ import { generateActionTypesContent } from "./generate-content.mjs";
5
5
  * Checks if generated action types files are up to date.
6
6
  *
7
7
  * @param sources - Array of source information objects.
8
- * @param eslint - Optional ESLint instance and static methods for formatting.
8
+ * @param formatter - The formatter to use for formatting the generated content.
9
9
  * @returns Whether all files are up to date.
10
10
  */
11
- export async function checkActionTypesFiles(sources, eslint) {
11
+ export async function checkActionTypesFiles(sources, formatter) {
12
12
  let hasErrors = false;
13
13
  const fileComparisonJobs = [];
14
- try {
15
- for (const source of sources) {
16
- console.log(`\nšŸ”§ Checking ${source.name}...`);
17
- const outputDir = path.dirname(source.filePath);
18
- const baseFileName = path.basename(source.filePath, '.ts');
19
- const actualFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
20
- const expectedContent = generateActionTypesContent(source);
21
- const expectedTempFile = actualFile.replace('.ts', '.tmp.ts');
22
- try {
23
- await fs.promises.access(actualFile);
24
- await fs.promises.writeFile(expectedTempFile, expectedContent, 'utf8');
25
- fileComparisonJobs.push({
26
- expectedTempFile,
27
- actualFile,
28
- baseFileName,
29
- });
30
- }
31
- catch (error) {
32
- if (error.code === 'ENOENT') {
33
- console.error(`āŒ ${baseFileName}-method-action-types.ts does not exist`);
34
- }
35
- else {
36
- console.error(`āŒ Error reading ${baseFileName}-method-action-types.ts:`, error);
37
- }
38
- hasErrors = true;
39
- }
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 = await generateActionTypesContent(source, formatter);
20
+ try {
21
+ await fs.promises.access(actualFile);
22
+ fileComparisonJobs.push({
23
+ expectedContent,
24
+ actualFile,
25
+ baseFileName,
26
+ });
40
27
  }
41
- if (fileComparisonJobs.length > 0) {
42
- if (eslint) {
43
- console.log('\nšŸ“ Running ESLint to compare files...');
44
- const results = await eslint.instance.lintFiles(fileComparisonJobs.map((job) => job.expectedTempFile));
45
- await eslint.eslintClass.outputFixes(results);
28
+ catch (error) {
29
+ if (error.code === 'ENOENT') {
30
+ console.error(`āŒ ${baseFileName}-method-action-types.ts does not exist`);
46
31
  }
47
- for (const job of fileComparisonJobs) {
48
- const expectedContent = await fs.promises.readFile(job.expectedTempFile, 'utf8');
49
- const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');
50
- if (expectedContent === actualContent) {
51
- console.log(`āœ… ${job.baseFileName}-method-action-types.ts is up to date`);
52
- }
53
- else {
54
- console.error(`āŒ ${job.baseFileName}-method-action-types.ts is out of date`);
55
- hasErrors = true;
56
- }
32
+ else {
33
+ console.error(`āŒ Error reading ${baseFileName}-method-action-types.ts:`, error);
57
34
  }
35
+ hasErrors = true;
58
36
  }
59
37
  }
60
- finally {
38
+ if (fileComparisonJobs.length > 0) {
61
39
  for (const job of fileComparisonJobs) {
62
- try {
63
- await fs.promises.unlink(job.expectedTempFile);
40
+ const actualContent = await fs.promises.readFile(job.actualFile, 'utf8');
41
+ if (job.expectedContent === actualContent) {
42
+ console.log(`āœ… ${job.baseFileName}-method-action-types.ts is up to date`);
64
43
  }
65
- catch {
66
- // Ignore cleanup errors
44
+ else {
45
+ console.error(`āŒ ${job.baseFileName}-method-action-types.ts is out of date`);
46
+ hasErrors = true;
67
47
  }
68
48
  }
69
49
  }
@@ -1 +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,+BAA2B;AAIhE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,MAAqB;IAErB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,kBAAkB,GAIlB,EAAE,CAAC;IAET,IAAI,CAAC;QACH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;YAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,SAAS,EACT,GAAG,YAAY,yBAAyB,CACzC,CAAC;YAEF,MAAM,eAAe,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;YAC3D,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAE9D,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAErC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,gBAAgB,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;gBAEvE,kBAAkB,CAAC,IAAI,CAAC;oBACtB,gBAAgB;oBAChB,UAAU;oBACV,YAAY;iBACb,CAAC,CAAC;YACL,CAAC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C;YACH,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;YACjD,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO,CAAC,KAAK,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';\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 * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<boolean> {\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.eslintClass.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('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
+ {"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,+BAA2B;AAIhE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqB,EACrB,SAAoB;IAEpB,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,kBAAkB,GAIlB,EAAE,CAAC;IAET,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAA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AAC,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';\nimport type { SourceInfo } from './parse-source';\nimport { Formatter } 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 formatter - The formatter to use for formatting the generated content.\n * @returns Whether all files are up to date.\n */\nexport async function checkActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\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(source, formatter);\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 CHANGED
@@ -15,7 +15,7 @@ const parse_source_1 = require("./parse-source.cjs");
15
15
  * @returns The parsed command line arguments.
16
16
  */
17
17
  async function parseCommandLineArguments(args) {
18
- const { check, generate, path: sourcePath, } = await (0, yargs_1.default)(args)
18
+ const { check, generate, formatter, path: sourcePath, } = await (0, yargs_1.default)(args)
19
19
  .command('$0 [path]', 'Generate method action types for controller and service messengers', (yargsInstance) => {
20
20
  yargsInstance.positional('path', {
21
21
  type: 'string',
@@ -32,6 +32,12 @@ async function parseCommandLineArguments(args) {
32
32
  type: 'boolean',
33
33
  description: 'Generate/update action type files',
34
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',
35
41
  })
36
42
  .help()
37
43
  .check((argv) => {
@@ -43,36 +49,15 @@ async function parseCommandLineArguments(args) {
43
49
  return {
44
50
  check,
45
51
  generate,
52
+ formatter: formatter,
46
53
  sourcePath: sourcePath,
47
54
  };
48
55
  }
49
- /**
50
- * Attempt to load ESLint from the current project. Returns null if unavailable.
51
- *
52
- * @returns An ESLint object with instance and static methods, or null if unavailable.
53
- */
54
- async function loadESLint() {
55
- try {
56
- const { ESLint: ESLintClass } = await import("eslint");
57
- const instance = new ESLintClass({
58
- fix: true,
59
- errorOnUnmatchedPattern: false,
60
- });
61
- return {
62
- instance,
63
- eslintClass: ESLintClass,
64
- };
65
- }
66
- catch {
67
- console.warn('āš ļø ESLint could not be loaded. Generated files will not be formatted.');
68
- return null;
69
- }
70
- }
71
56
  /**
72
57
  * Main entry point for the CLI.
73
58
  */
74
59
  async function main() {
75
- const { generate, sourcePath } = await parseCommandLineArguments(globalThis.process.argv.slice(2));
60
+ const { generate, sourcePath, formatter } = await parseCommandLineArguments(globalThis.process.argv.slice(2));
76
61
  console.log('šŸ” Searching for controllers/services with MESSENGER_EXPOSED_METHODS...');
77
62
  const sources = await (0, parse_source_1.findSourcesWithExposedMethods)(sourcePath);
78
63
  if (sources.length === 0) {
@@ -80,19 +65,12 @@ async function main() {
80
65
  return;
81
66
  }
82
67
  console.log(`šŸ“¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
83
- const eslint = await loadESLint();
84
68
  if (generate) {
85
- const success = await (0, fix_1.generateAllActionTypesFiles)(sources, eslint);
86
- if (success) {
87
- console.log('\nšŸŽ‰ All action types generated successfully!');
88
- }
89
- else {
90
- // eslint-disable-next-line no-restricted-globals
91
- process.exitCode = 1;
92
- }
69
+ await (0, fix_1.generateAllActionTypesFiles)(sources, formatter);
70
+ console.log('\nšŸŽ‰ All action types generated successfully!');
93
71
  }
94
72
  else {
95
- const success = await (0, check_1.checkActionTypesFiles)(sources, eslint);
73
+ const success = await (0, check_1.checkActionTypesFiles)(sources, formatter);
96
74
  if (!success) {
97
75
  // eslint-disable-next-line no-restricted-globals
98
76
  process.exitCode = 1;
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B,uCAAgD;AAChD,mCAAoD;AACpD,qDAA+D;AAS/D;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CACtC,IAAc;IAEd,MAAM,EACJ,KAAK,EACL,QAAQ,EAC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;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';\nimport { generateAllActionTypesFiles } from './fix';\nimport { findSourcesWithExposedMethods } from './parse-source';\nimport type { ESLint } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n generate: boolean;\n sourcePath: string;\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 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 .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 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 eslintClass: ESLintClass,\n };\n } catch {\n console.warn(\n 'āš ļø ESLint could not be loaded. Generated files will not be formatted.',\n );\n return null;\n }\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { generate, sourcePath } = await parseCommandLineArguments(\n globalThis.process.argv.slice(2),\n );\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 (generate) {\n const success = await generateAllActionTypesFiles(sources, eslint);\n if (success) {\n console.log('\\nšŸŽ‰ All action types generated successfully!');\n } else {\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n }\n } else {\n const success = await checkActionTypesFiles(sources, eslint);\n if (!success) {\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n }\n }\n}\n\nmain().catch((error) => {\n console.error('āŒ Script failed:', error);\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n});\n"]}
1
+ {"version":3,"file":"cli.cjs","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,kDAA0B;AAE1B,uCAAgD;AAChD,mCAAoD;AACpD,qDAA+D;AAU/D;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CACtC,IAAc;IAEd,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,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;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,WA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;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,MAAM,IAAA,6BAAqB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAChE,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';\nimport { generateAllActionTypesFiles } from './fix';\nimport { findSourcesWithExposedMethods } from './parse-source';\nimport { Formatter } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n generate: boolean;\n formatter: Formatter;\n sourcePath: string;\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 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 .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 };\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { generate, sourcePath, formatter } = await parseCommandLineArguments(\n globalThis.process.argv.slice(2),\n );\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);\n console.log('\\nšŸŽ‰ All action types generated successfully!');\n } else {\n const success = await checkActionTypesFiles(sources, formatter);\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.mjs CHANGED
@@ -10,7 +10,7 @@ import { findSourcesWithExposedMethods } from "./parse-source.mjs";
10
10
  * @returns The parsed command line arguments.
11
11
  */
12
12
  async function parseCommandLineArguments(args) {
13
- const { check, generate, path: sourcePath, } = await yargs(args)
13
+ const { check, generate, formatter, path: sourcePath, } = await yargs(args)
14
14
  .command('$0 [path]', 'Generate method action types for controller and service messengers', (yargsInstance) => {
15
15
  yargsInstance.positional('path', {
16
16
  type: 'string',
@@ -27,6 +27,12 @@ async function parseCommandLineArguments(args) {
27
27
  type: 'boolean',
28
28
  description: 'Generate/update action type files',
29
29
  default: false,
30
+ })
31
+ .option('formatter', {
32
+ type: 'string',
33
+ description: 'The formatter to use for formatting generated files',
34
+ choices: ['oxfmt', 'prettier'],
35
+ default: 'prettier',
30
36
  })
31
37
  .help()
32
38
  .check((argv) => {
@@ -38,36 +44,15 @@ async function parseCommandLineArguments(args) {
38
44
  return {
39
45
  check,
40
46
  generate,
47
+ formatter: formatter,
41
48
  sourcePath: sourcePath,
42
49
  };
43
50
  }
44
- /**
45
- * Attempt to load ESLint from the current project. Returns null if unavailable.
46
- *
47
- * @returns An ESLint object with instance and static methods, or null if unavailable.
48
- */
49
- async function loadESLint() {
50
- try {
51
- const { ESLint: ESLintClass } = await import("eslint");
52
- const instance = new ESLintClass({
53
- fix: true,
54
- errorOnUnmatchedPattern: false,
55
- });
56
- return {
57
- instance,
58
- eslintClass: ESLintClass,
59
- };
60
- }
61
- catch {
62
- console.warn('āš ļø ESLint could not be loaded. Generated files will not be formatted.');
63
- return null;
64
- }
65
- }
66
51
  /**
67
52
  * Main entry point for the CLI.
68
53
  */
69
54
  async function main() {
70
- const { generate, sourcePath } = await parseCommandLineArguments(globalThis.process.argv.slice(2));
55
+ const { generate, sourcePath, formatter } = await parseCommandLineArguments(globalThis.process.argv.slice(2));
71
56
  console.log('šŸ” Searching for controllers/services with MESSENGER_EXPOSED_METHODS...');
72
57
  const sources = await findSourcesWithExposedMethods(sourcePath);
73
58
  if (sources.length === 0) {
@@ -75,19 +60,12 @@ async function main() {
75
60
  return;
76
61
  }
77
62
  console.log(`šŸ“¦ Found ${sources.length} controller(s)/service(s) with exposed methods`);
78
- const eslint = await loadESLint();
79
63
  if (generate) {
80
- const success = await generateAllActionTypesFiles(sources, eslint);
81
- if (success) {
82
- console.log('\nšŸŽ‰ All action types generated successfully!');
83
- }
84
- else {
85
- // eslint-disable-next-line no-restricted-globals
86
- process.exitCode = 1;
87
- }
64
+ await generateAllActionTypesFiles(sources, formatter);
65
+ console.log('\nšŸŽ‰ All action types generated successfully!');
88
66
  }
89
67
  else {
90
- const success = await checkActionTypesFiles(sources, eslint);
68
+ const success = await checkActionTypesFiles(sources, formatter);
91
69
  if (!success) {
92
70
  // eslint-disable-next-line no-restricted-globals
93
71
  process.exitCode = 1;
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","sour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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';\nimport { generateAllActionTypesFiles } from './fix';\nimport { findSourcesWithExposedMethods } from './parse-source';\nimport type { ESLint } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n generate: boolean;\n sourcePath: string;\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 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 .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 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 eslintClass: ESLintClass,\n };\n } catch {\n console.warn(\n 'āš ļø ESLint could not be loaded. Generated files will not be formatted.',\n );\n return null;\n }\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { generate, sourcePath } = await parseCommandLineArguments(\n globalThis.process.argv.slice(2),\n );\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 (generate) {\n const success = await generateAllActionTypesFiles(sources, eslint);\n if (success) {\n console.log('\\nšŸŽ‰ All action types generated successfully!');\n } else {\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n }\n } else {\n const success = await checkActionTypesFiles(sources, eslint);\n if (!success) {\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n }\n }\n}\n\nmain().catch((error) => {\n console.error('āŒ Script failed:', error);\n // eslint-disable-next-line no-restricted-globals\n process.exitCode = 1;\n});\n"]}
1
+ {"version":3,"file":"cli.mjs","sourceRoot":"","sources":["../src/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;AAU/D;;;;;GAKG;AACH,KAAK,UAAU,yBAAyB,CACtC,IAAc;IAEd,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EAAE,UAAU,GACjB,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;SAClB,OAAO,CACN,WAAW,EACX,oEAAoE,EACpE,CAAC,aAAa,EAA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O,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,2BAA2B,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACN,MAAM,OAAO,GAAG,MAAM,qBAAqB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAChE,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';\nimport { generateAllActionTypesFiles } from './fix';\nimport { findSourcesWithExposedMethods } from './parse-source';\nimport { Formatter } from './types';\n\ntype CommandLineArguments = {\n check: boolean;\n generate: boolean;\n formatter: Formatter;\n sourcePath: string;\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 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 .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 };\n}\n\n/**\n * Main entry point for the CLI.\n */\nasync function main(): Promise<void> {\n const { generate, sourcePath, formatter } = await parseCommandLineArguments(\n globalThis.process.argv.slice(2),\n );\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);\n console.log('\\nšŸŽ‰ All action types generated successfully!');\n } else {\n const success = await checkActionTypesFiles(sources, formatter);\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 CHANGED
@@ -31,33 +31,19 @@ const generate_content_1 = require("./generate-content.cjs");
31
31
  * Generates action types files for all controllers/services.
32
32
  *
33
33
  * @param sources - Array of source information objects.
34
- * @param eslint - Optional ESLint instance and static methods for formatting.
34
+ * @param formatter - The formatter to use for formatting the generated content.
35
35
  * @returns Whether all files were generated successfully.
36
36
  */
37
- async function generateAllActionTypesFiles(sources, eslint) {
38
- const outputFiles = [];
37
+ async function generateAllActionTypesFiles(sources, formatter) {
39
38
  for (const source of sources) {
40
39
  console.log(`\nšŸ”§ Processing ${source.name}...`);
41
40
  const outputDir = path.dirname(source.filePath);
42
41
  const baseFileName = path.basename(source.filePath, '.ts');
43
42
  const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
44
- const generatedContent = (0, generate_content_1.generateActionTypesContent)(source);
43
+ const generatedContent = await (0, generate_content_1.generateActionTypesContent)(source, formatter);
45
44
  await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
46
- outputFiles.push(outputFile);
47
45
  console.log(`āœ… Generated action types for ${source.name}`);
48
46
  }
49
- if (outputFiles.length > 0 && eslint) {
50
- console.log('\nšŸ“ Running ESLint on generated files...');
51
- const results = await eslint.instance.lintFiles(outputFiles);
52
- await eslint.eslintClass.outputFixes(results);
53
- const errors = eslint.eslintClass.getErrorResults(results);
54
- if (errors.length > 0) {
55
- console.error('āŒ ESLint errors:', errors);
56
- return false;
57
- }
58
- console.log('āœ… ESLint formatting applied');
59
- }
60
- return true;
61
47
  }
62
48
  exports.generateAllActionTypesFiles = generateAllActionTypesFiles;
63
49
  //# sourceMappingURL=fix.cjs.map
package/dist/fix.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fix.cjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;;GAMG;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,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;YAC1C,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAnCD,kEAmCC","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 * @returns Whether all files were generated successfully.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<boolean> {\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.eslintClass.outputFixes(results);\n const errors = eslint.eslintClass.getErrorResults(results);\n if (errors.length > 0) {\n console.error('āŒ ESLint errors:', errors);\n return false;\n }\n console.log('āœ… ESLint formatting applied');\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"fix.cjs","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAElC,6DAAgE;AAIhE;;;;;;GAMG;AACI,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,SAAoB;IAEpB,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,6CAA0B,EACvD,MAAM,EACN,SAAS,CACV,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;AArBD,kEAqBC","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 { Formatter } from './types';\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 * @returns Whether all files were generated successfully.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\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 );\n\n await fs.promises.writeFile(outputFile, generatedContent, 'utf8');\n console.log(`āœ… Generated action types for ${source.name}`);\n }\n}\n"]}
package/dist/fix.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { SourceInfo } from "./parse-source.cjs";
2
- import type { ESLint } from "./types.cjs";
2
+ import type { Formatter } from "./types.cjs";
3
3
  /**
4
4
  * Generates action types files for all controllers/services.
5
5
  *
6
6
  * @param sources - Array of source information objects.
7
- * @param eslint - Optional ESLint instance and static methods for formatting.
7
+ * @param formatter - The formatter to use for formatting the generated content.
8
8
  * @returns Whether all files were generated successfully.
9
9
  */
10
- export declare function generateAllActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<boolean>;
10
+ export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<void>;
11
11
  //# sourceMappingURL=fix.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fix.d.cts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,OAAO,CAAC,CAgClB"}
1
+ {"version":3,"file":"fix.d.cts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAgB;AAEzC;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAkBf"}
package/dist/fix.d.mts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { SourceInfo } from "./parse-source.mjs";
2
- import type { ESLint } from "./types.mjs";
2
+ import type { Formatter } from "./types.mjs";
3
3
  /**
4
4
  * Generates action types files for all controllers/services.
5
5
  *
6
6
  * @param sources - Array of source information objects.
7
- * @param eslint - Optional ESLint instance and static methods for formatting.
7
+ * @param formatter - The formatter to use for formatting the generated content.
8
8
  * @returns Whether all files were generated successfully.
9
9
  */
10
- export declare function generateAllActionTypesFiles(sources: SourceInfo[], eslint: ESLint | null): Promise<boolean>;
10
+ export declare function generateAllActionTypesFiles(sources: SourceInfo[], formatter: Formatter): Promise<void>;
11
11
  //# sourceMappingURL=fix.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fix.d.mts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAEtC;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,OAAO,CAAC,CAgClB"}
1
+ {"version":3,"file":"fix.d.mts","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAgB;AAEzC;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,UAAU,EAAE,EACrB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAkBf"}
package/dist/fix.mjs CHANGED
@@ -5,32 +5,18 @@ import { generateActionTypesContent } from "./generate-content.mjs";
5
5
  * Generates action types files for all controllers/services.
6
6
  *
7
7
  * @param sources - Array of source information objects.
8
- * @param eslint - Optional ESLint instance and static methods for formatting.
8
+ * @param formatter - The formatter to use for formatting the generated content.
9
9
  * @returns Whether all files were generated successfully.
10
10
  */
11
- export async function generateAllActionTypesFiles(sources, eslint) {
12
- const outputFiles = [];
11
+ export async function generateAllActionTypesFiles(sources, formatter) {
13
12
  for (const source of sources) {
14
13
  console.log(`\nšŸ”§ Processing ${source.name}...`);
15
14
  const outputDir = path.dirname(source.filePath);
16
15
  const baseFileName = path.basename(source.filePath, '.ts');
17
16
  const outputFile = path.join(outputDir, `${baseFileName}-method-action-types.ts`);
18
- const generatedContent = generateActionTypesContent(source);
17
+ const generatedContent = await generateActionTypesContent(source, formatter);
19
18
  await fs.promises.writeFile(outputFile, generatedContent, 'utf8');
20
- outputFiles.push(outputFile);
21
19
  console.log(`āœ… Generated action types for ${source.name}`);
22
20
  }
23
- if (outputFiles.length > 0 && eslint) {
24
- console.log('\nšŸ“ Running ESLint on generated files...');
25
- const results = await eslint.instance.lintFiles(outputFiles);
26
- await eslint.eslintClass.outputFixes(results);
27
- const errors = eslint.eslintClass.getErrorResults(results);
28
- if (errors.length > 0) {
29
- console.error('āŒ ESLint errors:', errors);
30
- return false;
31
- }
32
- console.log('āœ… ESLint formatting applied');
33
- }
34
- return true;
35
21
  }
36
22
  //# sourceMappingURL=fix.mjs.map
package/dist/fix.mjs.map CHANGED
@@ -1 +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,+BAA2B;AAIhE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,MAAqB;IAErB,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAC1B,SAAS,EACT,GAAG,YAAY,yBAAyB,CACzC,CAAC;QAEF,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAClE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,gCAAgC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QAEzD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7D,MAAM,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;YAC1C,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { generateActionTypesContent } from './generate-content';\nimport type { SourceInfo } from './parse-source';\nimport type { ESLint } from './types';\n\n/**\n * Generates action types files for all controllers/services.\n *\n * @param sources - Array of source information objects.\n * @param eslint - Optional ESLint instance and static methods for formatting.\n * @returns Whether all files were generated successfully.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n eslint: ESLint | null,\n): Promise<boolean> {\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.eslintClass.outputFixes(results);\n const errors = eslint.eslintClass.getErrorResults(results);\n if (errors.length > 0) {\n console.error('āŒ ESLint errors:', errors);\n return false;\n }\n console.log('āœ… ESLint formatting applied');\n }\n\n return true;\n}\n"]}
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,+BAA2B;AAIhE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAqB,EACrB,SAAoB;IAEpB,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,CACV,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';\nimport type { SourceInfo } from './parse-source';\nimport type { Formatter } from './types';\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 * @returns Whether all files were generated successfully.\n */\nexport async function generateAllActionTypesFiles(\n sources: SourceInfo[],\n formatter: Formatter,\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 );\n\n await fs.promises.writeFile(outputFile, generatedContent, 'utf8');\n console.log(`āœ… Generated action types for ${source.name}`);\n }\n}\n"]}
@@ -24,14 +24,90 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.generateActionTypesContent = void 0;
27
+ const utils_1 = require("@metamask/utils");
27
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
+ }
28
103
  /**
29
104
  * Generates the content for the action types file.
30
105
  *
31
106
  * @param source - The source information object (controller or service).
107
+ * @param formatter - The formatter to use for formatting the generated content.
32
108
  * @returns The content for the action types file.
33
109
  */
34
- function generateActionTypesContent(source) {
110
+ async function generateActionTypesContent(source, formatter) {
35
111
  const baseFileName = path.basename(source.filePath, '.ts');
36
112
  const sourceImportPath = `./${baseFileName}`;
37
113
  let content = `/**
@@ -63,7 +139,8 @@ import type { ${source.name} } from '${sourceImportPath}';
63
139
  */
64
140
  export type ${unionTypeName} = ${actionTypeNames.join(' | ')};\n`;
65
141
  }
66
- return `${content.trimEnd()}\n`;
142
+ const formatterFunction = getFormatter(formatter);
143
+ return await formatterFunction(content, source.filePath);
67
144
  }
68
145
  exports.generateActionTypesContent = generateActionTypesContent;
69
146
  //# sourceMappingURL=generate-content.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-content.cjs","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAIlC;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,MAAkB;IAC3D,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC3D,MAAM,gBAAgB,GAAG,KAAK,YAAY,EAAE,CAAC;IAE7C,IAAI,OAAO,GAAG;;;;;gBAKA,MAAM,CAAC,IAAI,YAAY,gBAAgB;;CAEtD,CAAC;IAEA,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpC,MAAM,eAAe,GACnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7D,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,IAAI,GAAG,eAAe,QAAQ,CAAC;QAChE,MAAM,YAAY,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAErD,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAErC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,IAAI,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;QACjC,CAAC;QAED,OAAO,IAAI,eAAe,cAAc;YAChC,YAAY;aACX,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;OACjC,CAAC;IACN,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,GAAG,MAAM,CAAC,IAAI,eAAe,CAAC;QACpD,OAAO,IAAI;kBACG,MAAM,CAAC,IAAI;;cAEf,aAAa,MAAM,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAChE,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;AAClC,CAAC;AA1CD,gEA0CC","sourcesContent":["import * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\n\n/**\n * Generates the content for the action types file.\n *\n * @param source - The source information object (controller or service).\n * @returns The content for the action types file.\n */\nexport function generateActionTypesContent(source: SourceInfo): string {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\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 return `${content.trimEnd()}\\n`;\n}\n"]}
1
+ {"version":3,"file":"generate-content.cjs","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;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;QACpD,OAAO,IAAI;kBACG,MAAM,CAAC,IAAI;;cAEf,aAAa,MAAM,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAChE,CAAC;IAED,MAAM,iBAAiB,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAClD,OAAO,MAAM,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC3D,CAAC;AA9CD,gEA8CC","sourcesContent":["import { assertExhaustive, getErrorMessage } from '@metamask/utils';\nimport * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\nimport { Formatter } from './types';\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 * @returns The content for the action types file.\n */\nexport async function generateActionTypesContent(\n source: SourceInfo,\n formatter: Formatter,\n): Promise<string> {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\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,9 +1,11 @@
1
1
  import type { SourceInfo } from "./parse-source.cjs";
2
+ import { Formatter } from "./types.cjs";
2
3
  /**
3
4
  * Generates the content for the action types file.
4
5
  *
5
6
  * @param source - The source information object (controller or service).
7
+ * @param formatter - The formatter to use for formatting the generated content.
6
8
  * @returns The content for the action types file.
7
9
  */
8
- export declare function generateActionTypesContent(source: SourceInfo): string;
10
+ export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter): Promise<string>;
9
11
  //# sourceMappingURL=generate-content.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-content.d.cts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AAEjD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CA0CrE"}
1
+ {"version":3,"file":"generate-content.d.cts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AA0FpC;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,MAAM,CAAC,CA2CjB"}
@@ -1,9 +1,11 @@
1
1
  import type { SourceInfo } from "./parse-source.mjs";
2
+ import { Formatter } from "./types.mjs";
2
3
  /**
3
4
  * Generates the content for the action types file.
4
5
  *
5
6
  * @param source - The source information object (controller or service).
7
+ * @param formatter - The formatter to use for formatting the generated content.
6
8
  * @returns The content for the action types file.
7
9
  */
8
- export declare function generateActionTypesContent(source: SourceInfo): string;
10
+ export declare function generateActionTypesContent(source: SourceInfo, formatter: Formatter): Promise<string>;
9
11
  //# sourceMappingURL=generate-content.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-content.d.mts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AAEjD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CA0CrE"}
1
+ {"version":3,"file":"generate-content.d.mts","sourceRoot":"","sources":["../src/generate-content.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AACjD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AA0FpC;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,MAAM,CAAC,CA2CjB"}
@@ -1,11 +1,87 @@
1
+ import { assertExhaustive, getErrorMessage } from "@metamask/utils";
1
2
  import * as path from "node:path";
3
+ /**
4
+ * The default options used by Oxfmt and Prettier when formatting the generated
5
+ * content. In the case of Prettier, these options will be used if the user does
6
+ * not have a Prettier configuration file in their project. Oxfmt doesn't have a
7
+ * `resolveConfig` function like Prettier, so it will always use these options
8
+ * when formatting.
9
+ */
10
+ const DEFAULT_FORMATTING_OPTIONS = {
11
+ printWidth: 80,
12
+ singleQuote: true,
13
+ };
14
+ /**
15
+ * Safely format a TypeScript file with Prettier. If Prettier is not installed,
16
+ * it will throw an error with a clear message. This allows us to use Prettier
17
+ * for formatting when available, without making it a hard dependency of the
18
+ * project.
19
+ *
20
+ * @param contents - The source code to format.
21
+ * @param filePath - The file path to use for resolving Prettier configuration.
22
+ * @returns The formatted source code.
23
+ */
24
+ async function prettier(contents, filePath) {
25
+ try {
26
+ const { format, resolveConfig } = await import("prettier");
27
+ const config = (await resolveConfig(filePath)) ?? DEFAULT_FORMATTING_OPTIONS;
28
+ return await format(contents, {
29
+ ...config,
30
+ parser: 'typescript',
31
+ });
32
+ }
33
+ catch (error) {
34
+ const message = getErrorMessage(error);
35
+ throw new Error(`Failed to format source code with Prettier. Is Prettier installed?\n\n${message}`);
36
+ }
37
+ }
38
+ /**
39
+ * Safely format a TypeScript file with Oxfmt. If Oxfmt is not installed, it
40
+ * will throw an error with a clear message. This allows us to use Oxfmt for
41
+ * formatting when available, without making it a hard dependency of the
42
+ * project.
43
+ *
44
+ * @param contents - The source code to format.
45
+ * @param filePath - The file path to use for resolving Oxfmt configuration. Not
46
+ * currently used, but included for future extensibility.
47
+ * @returns The formatted source code.
48
+ */
49
+ async function oxfmt(contents, filePath) {
50
+ try {
51
+ const { format } = await import("oxfmt");
52
+ const result = await format(filePath, contents, DEFAULT_FORMATTING_OPTIONS);
53
+ return result.code;
54
+ }
55
+ catch (error) {
56
+ const message = getErrorMessage(error);
57
+ throw new Error(`Failed to format source code with Oxfmt. Is Oxfmt installed?\n\n${message}`);
58
+ }
59
+ }
60
+ /**
61
+ * Get the appropriate formatter function based on the specified formatter.
62
+ *
63
+ * @param formatter - The formatter to use.
64
+ * @returns A function that takes source code as input and returns the formatted
65
+ * source code.
66
+ */
67
+ function getFormatter(formatter) {
68
+ switch (formatter) {
69
+ case 'prettier':
70
+ return prettier;
71
+ case 'oxfmt':
72
+ return oxfmt;
73
+ default:
74
+ return assertExhaustive(formatter);
75
+ }
76
+ }
2
77
  /**
3
78
  * Generates the content for the action types file.
4
79
  *
5
80
  * @param source - The source information object (controller or service).
81
+ * @param formatter - The formatter to use for formatting the generated content.
6
82
  * @returns The content for the action types file.
7
83
  */
8
- export function generateActionTypesContent(source) {
84
+ export async function generateActionTypesContent(source, formatter) {
9
85
  const baseFileName = path.basename(source.filePath, '.ts');
10
86
  const sourceImportPath = `./${baseFileName}`;
11
87
  let content = `/**
@@ -37,6 +113,7 @@ import type { ${source.name} } from '${sourceImportPath}';
37
113
  */
38
114
  export type ${unionTypeName} = ${actionTypeNames.join(' | ')};\n`;
39
115
  }
40
- return `${content.trimEnd()}\n`;
116
+ const formatterFunction = getFormatter(formatter);
117
+ return await formatterFunction(content, source.filePath);
41
118
  }
42
119
  //# sourceMappingURL=generate-content.mjs.map
@@ -1 +1 @@
1
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M,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAChE,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;AAClC,CAAC","sourcesContent":["import * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\n\n/**\n * Generates the content for the action types file.\n *\n * @param source - The source information object (controller or service).\n * @returns The content for the action types file.\n */\nexport function generateActionTypesContent(source: SourceInfo): string {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\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 return `${content.trimEnd()}\\n`;\n}\n"]}
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;Q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AQ,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { assertExhaustive, getErrorMessage } from '@metamask/utils';\nimport * as path from 'node:path';\n\nimport type { SourceInfo } from './parse-source';\nimport { Formatter } from './types';\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 * @returns The content for the action types file.\n */\nexport async function generateActionTypesContent(\n source: SourceInfo,\n formatter: Formatter,\n): Promise<string> {\n const baseFileName = path.basename(source.filePath, '.ts');\n const sourceImportPath = `./${baseFileName}`;\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 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ESLint as eslintClass } from 'eslint';\n\nexport type ESLint = {\n instance: eslintClass;\n eslintClass: typeof eslintClass;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The formatting tool to use for formatting the source code.\n */\nexport type Formatter = 'oxfmt' | 'prettier';\n"]}
package/dist/types.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import type { ESLint as eslintClass } from "eslint";
2
- export type ESLint = {
3
- instance: eslintClass;
4
- eslintClass: typeof eslintClass;
5
- };
1
+ /**
2
+ * The formatting tool to use for formatting the source code.
3
+ */
4
+ export type Formatter = 'oxfmt' | 'prettier';
6
5
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,eAAe;AAEpD,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,WAAW,CAAC;IACtB,WAAW,EAAE,OAAO,WAAW,CAAC;CACjC,CAAC"}
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC"}
package/dist/types.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import type { ESLint as eslintClass } from "eslint";
2
- export type ESLint = {
3
- instance: eslintClass;
4
- eslintClass: typeof eslintClass;
5
- };
1
+ /**
2
+ * The formatting tool to use for formatting the source code.
3
+ */
4
+ export type Formatter = 'oxfmt' | 'prettier';
6
5
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,WAAW,EAAE,eAAe;AAEpD,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,WAAW,CAAC;IACtB,WAAW,EAAE,OAAO,WAAW,CAAC;CACjC,CAAC"}
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ESLint as eslintClass } from 'eslint';\n\nexport type ESLint = {\n instance: eslintClass;\n eslintClass: typeof eslintClass;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The formatting tool to use for formatting the source code.\n */\nexport type Formatter = 'oxfmt' | 'prettier';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/messenger-cli",
3
- "version": "0.1.0-preview-71e106795",
3
+ "version": "0.1.0-preview-d363b2d74",
4
4
  "description": "CLI tools for the MetaMask messenger system",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -50,15 +50,21 @@
50
50
  "eslint": "^9.39.1",
51
51
  "execa": "^5.0.0",
52
52
  "jest": "^29.7.0",
53
+ "oxfmt": "^0.44.0",
54
+ "prettier": "^3.3.3",
53
55
  "ts-jest": "^29.2.5",
54
56
  "typescript": "~5.3.3"
55
57
  },
56
58
  "peerDependencies": {
57
- "eslint": ">=8",
59
+ "oxfmt": "^0.44.0",
60
+ "prettier": "^3.0.0",
58
61
  "typescript": ">=5.0.0"
59
62
  },
60
63
  "peerDependenciesMeta": {
61
- "eslint": {
64
+ "oxfmt": {
65
+ "optional": true
66
+ },
67
+ "prettier": {
62
68
  "optional": true
63
69
  }
64
70
  },