@l10nmonster/cli 3.0.0-alpha.9 → 3.1.1

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
@@ -1,3 +1,49 @@
1
+ ## @l10nmonster/cli [3.1.1](https://public-github/l10nmonster/l10nmonster/compare/@l10nmonster/cli@3.1.0...@l10nmonster/cli@3.1.1) (2025-12-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Improve type definitions and checks ([826b412](https://public-github/l10nmonster/l10nmonster/commit/826b412f0f7e761d404165a243b0c2b26c416ac1))
7
+
8
+ ## @l10nmonster/cli [3.1.1](https://public-github/l10nmonster/l10nmonster/compare/@l10nmonster/cli@3.1.0...@l10nmonster/cli@3.1.1) (2025-12-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Improve type definitions and checks ([826b412](https://public-github/l10nmonster/l10nmonster/commit/826b412f0f7e761d404165a243b0c2b26c416ac1))
14
+
15
+
16
+
17
+
18
+
19
+ ### Dependencies
20
+
21
+ * **@l10nmonster/core:** upgraded to 3.1.1
22
+
23
+ # @l10nmonster/cli [3.1.0](https://public-github/l10nmonster/l10nmonster/compare/@l10nmonster/cli@3.0.0...@l10nmonster/cli@3.1.0) (2025-12-20)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * **server:** Fix cart cleanup ([9bbcab9](https://public-github/l10nmonster/l10nmonster/commit/9bbcab93e1fd20aeb09f59c828665159f091f37c))
29
+
30
+
31
+ ### Features
32
+
33
+ * **core:** Major refactor ([6992ee4](https://public-github/l10nmonster/l10nmonster/commit/6992ee4d74ad2e25afef6220f92f2e72dfd02457))
34
+
35
+ # @l10nmonster/cli [3.1.0](https://public-github/l10nmonster/l10nmonster/compare/@l10nmonster/cli@3.0.0...@l10nmonster/cli@3.1.0) (2025-12-20)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * **server:** Fix cart cleanup ([9bbcab9](https://public-github/l10nmonster/l10nmonster/commit/9bbcab93e1fd20aeb09f59c828665159f091f37c))
41
+
42
+
43
+ ### Features
44
+
45
+ * **core:** Major refactor ([6992ee4](https://public-github/l10nmonster/l10nmonster/commit/6992ee4d74ad2e25afef6220f92f2e72dfd02457))
46
+
1
47
  # Changelog
2
48
 
3
49
  All notable changes to this project will be documented in this file.
package/index.js CHANGED
@@ -1,11 +1,96 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
2
 
3
3
  import { Command, Argument, Option, InvalidArgumentError } from 'commander';
4
- import { getVerbosity } from '@l10nmonster/core';
5
-
4
+ import { existsSync } from 'fs';
6
5
  import path from 'path';
7
- import { readFileSync } from 'fs';
8
- const cliVersion = JSON.parse(readFileSync(path.join(import.meta.dirname, 'package.json'), 'utf-8')).version;
6
+ import { l10nMonsterVersion } from '@l10nmonster/core';
7
+
8
+ /**
9
+ * Find l10nmonster.config.mjs by walking up the directory tree.
10
+ * @param {string} [startDir] - Directory to start searching from (defaults to cwd)
11
+ * @returns {string|null} - Path to config file or null if not found
12
+ */
13
+ export function findConfigFile(startDir = process.cwd()) {
14
+ let currentDir = path.resolve(startDir);
15
+ const configFileName = 'l10nmonster.config.mjs';
16
+
17
+ while (true) {
18
+ const configPath = path.join(currentDir, configFileName);
19
+ if (existsSync(configPath)) {
20
+ return configPath;
21
+ }
22
+
23
+ const parentDir = path.dirname(currentDir);
24
+ if (parentDir === currentDir) {
25
+ break;
26
+ }
27
+ currentDir = parentDir;
28
+ }
29
+
30
+ return null;
31
+ }
32
+
33
+ /**
34
+ * Run the CLI with automatic config discovery.
35
+ * @param {Object} [options] - Options for running the CLI
36
+ * @param {Array} [options.extraActions] - Additional actions to register
37
+ * @returns {Promise<void>}
38
+ */
39
+ export async function runCLI({ extraActions = [] } = {}) {
40
+ // Global unhandled promise rejection handler
41
+ process.on('unhandledRejection', (reason, promise) => {
42
+ console.error('Unhandled Promise Rejection detected:');
43
+ console.error('Promise:', promise);
44
+ console.error('Reason:', reason);
45
+ if (reason instanceof Error && reason.stack) {
46
+ console.error('Stack trace:', reason.stack);
47
+ }
48
+ console.error('Exiting due to unhandled promise rejection...');
49
+ process.exit(1);
50
+ });
51
+
52
+ // Global uncaught exception handler
53
+ process.on('uncaughtException', (error) => {
54
+ console.error('Uncaught Exception:', error);
55
+ process.exit(1);
56
+ });
57
+
58
+ // Handle --help and --version before requiring config
59
+ const args = process.argv.slice(2);
60
+ if (args.length === 0 || args.includes('--help') || args.includes('-h') || args.includes('--version')) {
61
+ const helpCLI = new Command();
62
+ helpCLI
63
+ .name('l10n')
64
+ .version(l10nMonsterVersion, '--version', 'output the current version number')
65
+ .description('Continuous localization for the rest of us.\n\nRun from a directory containing l10nmonster.config.mjs to see available commands.');
66
+ helpCLI.parse();
67
+ return;
68
+ }
69
+
70
+ try {
71
+ const configPath = findConfigFile();
72
+ if (!configPath) {
73
+ console.error('Error: Could not find l10nmonster.config.mjs in current directory or any parent directory.');
74
+ console.error('Please ensure the config file exists in your project root or current working directory.');
75
+ process.exit(1);
76
+ }
77
+
78
+ const config = await import(configPath);
79
+ let monsterConfig = config.default;
80
+
81
+ // Add any extra actions
82
+ for (const action of extraActions) {
83
+ monsterConfig = monsterConfig.action(action);
84
+ }
85
+
86
+ // eslint-disable-next-line no-use-before-define
87
+ await runMonsterCLI(monsterConfig);
88
+ } catch (error) {
89
+ console.error('Error running l10nmonster CLI:');
90
+ console.error(error.stack || error);
91
+ process.exit(1);
92
+ }
93
+ }
9
94
 
10
95
  function intOptionParser(value) {
11
96
  const parsedValue = parseInt(value, 10);
@@ -50,11 +135,12 @@ function configureCommand(cmd, Action, l10nRunner) {
50
135
  });
51
136
  }
52
137
 
138
+ /** @type {import('./interfaces.js').RunMonsterCLI} */
53
139
  export default async function runMonsterCLI(monsterConfig, cliCommand) {
54
140
  const monsterCLI = new Command();
55
141
  monsterCLI
56
142
  .name('l10n')
57
- .version(cliVersion, '--version', 'output the current version number')
143
+ .version(l10nMonsterVersion, '--version', 'output the current version number')
58
144
  .description('Continuous localization for the rest of us.')
59
145
  .option('-v, --verbose [level]', '0=error, 1=warning, 2=info, 3=verbose', intOptionParser)
60
146
  .option('--regression', 'keep variables constant during regression testing');
@@ -82,7 +168,7 @@ export default async function runMonsterCLI(monsterConfig, cliCommand) {
82
168
  const argv = typeof cliCommand === 'string' ? cliCommand.split(' ') : cliCommand;
83
169
  await monsterCLI.parseAsync(argv);
84
170
  } catch(e) {
85
- console.error(`Unable to run CLI: ${(getVerbosity() > 1 ? e.stack : e.message) || e}`);
171
+ console.error(`Unable to run the CLI: ${e.message ?? e}`);
86
172
  process.exit(1);
87
173
  }
88
174
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Central type definitions for @l10nmonster/cli
3
+ * Re-exports L10nAction as CLIAction for CLI-specific use.
4
+ */
5
+
6
+ // Re-export L10nAction from core as CLIAction for backwards compatibility
7
+ export { ActionHelp, L10nAction as CLIAction } from '@l10nmonster/core';
8
+
9
+ /**
10
+ * Function signature for running the L10n Monster CLI.
11
+ */
12
+ export type RunMonsterCLI = (
13
+ monsterConfig: any,
14
+ cliCommand?: string | string[]
15
+ ) => Promise<void>;
package/l10n.mjs CHANGED
@@ -1,5 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // Global unhandled promise rejection handler
4
+ process.on('unhandledRejection', (reason, promise) => {
5
+ console.error('🚨 Unhandled Promise Rejection detected:');
6
+ console.error('Promise:', promise);
7
+ console.error('Reason:', reason);
8
+ if (reason instanceof Error && reason.stack) {
9
+ console.error('Stack trace:', reason.stack);
10
+ }
11
+ // In CLI context, we should exit on unhandled rejections to prevent silent failures
12
+ console.error('Exiting due to unhandled promise rejection...');
13
+ process.exit(1);
14
+ });
15
+
16
+ // Global uncaught exception handler (for completeness)
17
+ process.on('uncaughtException', (error) => {
18
+ console.error('🚨 Uncaught Exception:', error);
19
+ process.exit(1);
20
+ });
21
+
3
22
  import runMonsterCLI from './index.js';
4
23
  import { resolve, dirname, join } from 'path';
5
24
  import { existsSync } from 'fs';
package/package.json CHANGED
@@ -1,16 +1,12 @@
1
1
  {
2
2
  "name": "@l10nmonster/cli",
3
- "version": "3.0.0-alpha.9",
3
+ "version": "3.1.1",
4
4
  "description": "Continuous localization for the rest of us",
5
5
  "bin": {
6
6
  "l10n": "l10n.mjs"
7
7
  },
8
8
  "type": "module",
9
9
  "main": "index.js",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/l10nmonster/l10nmonster.git"
13
- },
14
10
  "keywords": [
15
11
  "translation",
16
12
  "localization",
@@ -19,7 +15,8 @@
19
15
  "translation-files"
20
16
  ],
21
17
  "scripts": {
22
- "test": "node --test"
18
+ "test": "node --test",
19
+ "typecheck": "tsc --noEmit"
23
20
  },
24
21
  "author": "Diego Lagunas",
25
22
  "license": "MIT",
@@ -32,6 +29,6 @@
32
29
  },
33
30
  "dependencies": {
34
31
  "commander": "^14",
35
- "@l10nmonster/core": "^3.0.0-alpha.0"
32
+ "@l10nmonster/core": "3.1.1"
36
33
  }
37
34
  }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../tsconfig.base.json",
3
+ "include": [
4
+ "*.js",
5
+ "**/*.js"
6
+ ],
7
+ "exclude": [
8
+ "node_modules",
9
+ "**/node_modules",
10
+ "test/**",
11
+ "tests/**",
12
+ "**/*.test.js",
13
+ "**/*.spec.js",
14
+ "dist/**",
15
+ "ui/**",
16
+ "types/**"
17
+ ]
18
+ }
package/.releaserc.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "branches": [
3
- "main",
4
- {
5
- "name": "next",
6
- "prerelease": "alpha"
7
- },
8
- {
9
- "name": "beta",
10
- "prerelease": "beta"
11
- }
12
- ],
13
- "tagFormat": "@l10nmonster/cli@${version}",
14
- "plugins": [
15
- "@semantic-release/commit-analyzer",
16
- "@semantic-release/release-notes-generator",
17
- {
18
- "path": "@semantic-release/changelog",
19
- "changelogFile": "CHANGELOG.md"
20
- },
21
- {
22
- "path": "@semantic-release/npm",
23
- "npmPublish": true
24
- },
25
- {
26
- "path": "@semantic-release/git",
27
- "assets": ["CHANGELOG.md", "package.json"],
28
- "message": "chore(release): @l10nmonster/cli@${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
29
- }
30
- ]
31
- }