@magmonium/cli 0.8.17 → 0.8.19
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/bin/cli.js +2 -0
- package/bin/commands/assets.js +73 -0
- package/bin/commands/config-ci.js +10 -11
- package/bin/commands/configure-wc.js +14 -11
- package/bin/commands/connect.js +11 -8
- package/bin/commands/deploy.js +38 -7
- package/bin/commands/fix-i18n.js +27 -12
- package/bin/commands/i18n-baseline.js +33 -0
- package/codegen/index.js +1742 -687
- package/package.json +1 -1
- package/src/compilers/logo-compiler.d.ts.map +1 -1
- package/src/compilers/logo-compiler.js +3 -1
- package/src/compilers/logo-compiler.js.map +1 -1
- package/src/compilers/web-component/lib/installed-pins.d.ts +13 -0
- package/src/compilers/web-component/lib/installed-pins.d.ts.map +1 -0
- package/src/compilers/web-component/lib/installed-pins.js +49 -0
- package/src/compilers/web-component/lib/installed-pins.js.map +1 -0
- package/src/compilers/web-component/lib/ng-build.d.ts.map +1 -1
- package/src/compilers/web-component/lib/ng-build.js +5 -0
- package/src/compilers/web-component/lib/ng-build.js.map +1 -1
- package/src/compilers/web-component/lib/web-component-wrapper.d.ts.map +1 -1
- package/src/compilers/web-component/lib/web-component-wrapper.js +62 -48
- package/src/compilers/web-component/lib/web-component-wrapper.js.map +1 -1
- package/src/compilers/web-component/model/type.d.ts +1 -0
- package/src/compilers/web-component/model/type.d.ts.map +1 -1
- package/src/compilers/worker-compiler.d.ts.map +1 -1
- package/src/compilers/worker-compiler.js +9 -2
- package/src/compilers/worker-compiler.js.map +1 -1
- package/src/core/config.d.ts +44 -0
- package/src/core/config.d.ts.map +1 -1
- package/src/core/config.js +34 -1
- package/src/core/config.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/utils/ai-provider-translator.d.ts +10 -5
- package/src/utils/ai-provider-translator.d.ts.map +1 -1
- package/src/utils/ai-provider-translator.js +37 -31
- package/src/utils/ai-provider-translator.js.map +1 -1
- package/src/utils/app-logo-svg.d.ts +4 -3
- package/src/utils/app-logo-svg.d.ts.map +1 -1
- package/src/utils/app-logo-svg.js +30 -4
- package/src/utils/app-logo-svg.js.map +1 -1
- package/src/utils/i18n-fixer.d.ts +2 -3
- package/src/utils/i18n-fixer.d.ts.map +1 -1
- package/src/utils/i18n-fixer.js +24 -56
- package/src/utils/i18n-fixer.js.map +1 -1
- package/src/utils/i18n-gate.d.ts +30 -0
- package/src/utils/i18n-gate.d.ts.map +1 -0
- package/src/utils/i18n-gate.js +76 -0
- package/src/utils/i18n-gate.js.map +1 -0
package/bin/cli.js
CHANGED
|
@@ -19,6 +19,7 @@ const refractorCommand = require('./commands/refractor');
|
|
|
19
19
|
const fixI18nCommand = require('./commands/fix-i18n');
|
|
20
20
|
const sanitizeI18nCommand = require('./commands/sanitize-i18n');
|
|
21
21
|
const compileI18nCommand = require('./commands/compile-i18n');
|
|
22
|
+
const i18nBaselineCommand = require('./commands/i18n-baseline');
|
|
22
23
|
const generateCommand = require('./commands/generate');
|
|
23
24
|
const patchWcEnvCommand = require('./commands/patch-wc-env');
|
|
24
25
|
const genCodeCommand = require('./commands/gen-code');
|
|
@@ -51,6 +52,7 @@ refractorCommand(program);
|
|
|
51
52
|
fixI18nCommand(program);
|
|
52
53
|
sanitizeI18nCommand(program);
|
|
53
54
|
compileI18nCommand(program);
|
|
55
|
+
i18nBaselineCommand(program);
|
|
54
56
|
generateCommand(program);
|
|
55
57
|
patchWcEnvCommand(program);
|
|
56
58
|
genCodeCommand(program);
|
package/bin/commands/assets.js
CHANGED
|
@@ -15,11 +15,56 @@ const {
|
|
|
15
15
|
DEFAULT_PATHS_CONFIG,
|
|
16
16
|
WebComponentBuilder,
|
|
17
17
|
collectDocs,
|
|
18
|
+
runI18nGate,
|
|
19
|
+
I18N_BASELINE_FILE,
|
|
18
20
|
} = require('../../src/index.js');
|
|
19
21
|
|
|
20
22
|
const fs = require('fs').promises;
|
|
21
23
|
const path = require('path');
|
|
22
24
|
|
|
25
|
+
const I18N_GATE_WHY = {
|
|
26
|
+
new: 'not in baseline',
|
|
27
|
+
'more-missing': 'more langs missing than baseline',
|
|
28
|
+
'en-changed': 'en changed since baseline',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Stop the run when an i18n key lacks langs it may not lack: a key the
|
|
33
|
+
* baseline does not grandfather, one missing more than recorded, or one whose
|
|
34
|
+
* `en` changed since. Runs before cleaning, so a stopped run leaves the last
|
|
35
|
+
* good assets in place for a running app.
|
|
36
|
+
*/
|
|
37
|
+
async function assertI18nComplete(root, verbose) {
|
|
38
|
+
const { failures, tightenable, enOnly } = await runI18nGate(root, verbose);
|
|
39
|
+
if (enOnly.length > 0) {
|
|
40
|
+
console.log(
|
|
41
|
+
`ℹ️ ${enOnly.length} i18n key(s) in en only — npm run translate:fix -- --key ${enOnly.join(' ')}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (tightenable > 0) {
|
|
45
|
+
console.log(
|
|
46
|
+
`ℹ️ ${tightenable} baseline key(s) translated further — npm run i18n:baseline to tighten ${I18N_BASELINE_FILE}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (failures.length === 0) return;
|
|
50
|
+
|
|
51
|
+
console.error(
|
|
52
|
+
`\n❌ ${failures.length} i18n key(s) missing translations — compile stopped:`
|
|
53
|
+
);
|
|
54
|
+
for (const failure of failures) {
|
|
55
|
+
const where = failure.file
|
|
56
|
+
? path.relative(root, failure.file)
|
|
57
|
+
: `${failure.key} (no i18n yml)`;
|
|
58
|
+
console.error(
|
|
59
|
+
` ${where}: ${failure.missingLangs.length} lang(s) missing, ${I18N_GATE_WHY[failure.reason]}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
console.error(
|
|
63
|
+
`\nFix: npm run translate:fix -- --key ${failures.map((f) => f.key).join(' ')}`
|
|
64
|
+
);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
23
68
|
/**
|
|
24
69
|
* Create a YamlCompiler with validation rules for a specific asset type
|
|
25
70
|
* @param {string} assetType - The asset type (Button, Card, etc.)
|
|
@@ -299,6 +344,8 @@ function assetsCommand(program) {
|
|
|
299
344
|
);
|
|
300
345
|
}
|
|
301
346
|
|
|
347
|
+
await assertI18nComplete(process.cwd(), options.verbose);
|
|
348
|
+
|
|
302
349
|
// Function to resolve paths from config or command line options
|
|
303
350
|
const resolvePathsConfig = () => {
|
|
304
351
|
// Priority: config.paths > command line -p option > defaults
|
|
@@ -423,6 +470,11 @@ function assetsCommand(program) {
|
|
|
423
470
|
outputPaths: PATHS.forms.output,
|
|
424
471
|
...config.forms,
|
|
425
472
|
},
|
|
473
|
+
effects: {
|
|
474
|
+
inputPaths: PATHS.effects.input,
|
|
475
|
+
outputPaths: PATHS.effects.output,
|
|
476
|
+
...config.effects,
|
|
477
|
+
},
|
|
426
478
|
buttons: {
|
|
427
479
|
inputPaths: PATHS.buttons.input,
|
|
428
480
|
outputPaths: PATHS.buttons.output,
|
|
@@ -508,6 +560,15 @@ function assetsCommand(program) {
|
|
|
508
560
|
format: 'iife',
|
|
509
561
|
...config.workers,
|
|
510
562
|
},
|
|
563
|
+
// Model binaries (ADR 0017) — copied verbatim, so a `.wasm` denoiser
|
|
564
|
+
// and a network's weights reach the bake Worker exactly as vendored.
|
|
565
|
+
models: {
|
|
566
|
+
inputPaths: PATHS.models.input,
|
|
567
|
+
outputPaths: PATHS.models.output,
|
|
568
|
+
preserveStructure: true,
|
|
569
|
+
overwrite: true,
|
|
570
|
+
...config.models,
|
|
571
|
+
},
|
|
511
572
|
cards: {
|
|
512
573
|
inputPaths: PATHS.cards.input,
|
|
513
574
|
outputPaths: PATHS.cards.output,
|
|
@@ -754,6 +815,12 @@ function assetsCommand(program) {
|
|
|
754
815
|
);
|
|
755
816
|
}
|
|
756
817
|
|
|
818
|
+
// The Effect Preset catalogue: a list asset Studio's Look group reads
|
|
819
|
+
// and the compositor resolves a Clip's preset against by name.
|
|
820
|
+
if (buildConfig.effects) {
|
|
821
|
+
compilers.push(createYamlCompiler('Effect', buildConfig.effects));
|
|
822
|
+
}
|
|
823
|
+
|
|
757
824
|
if (buildConfig.buttonGroups) {
|
|
758
825
|
compilers.push(new ButtonGroupCompiler(buildConfig.buttonGroups));
|
|
759
826
|
}
|
|
@@ -864,6 +931,12 @@ function assetsCommand(program) {
|
|
|
864
931
|
}
|
|
865
932
|
}
|
|
866
933
|
|
|
934
|
+
// Model binaries, before the catch-all copy: the generic pass skips
|
|
935
|
+
// `.json`, which a weight file is.
|
|
936
|
+
if (buildConfig.models) {
|
|
937
|
+
compilers.push(new CopyCompiler(buildConfig.models));
|
|
938
|
+
}
|
|
939
|
+
|
|
867
940
|
// Always add copy compiler for remaining files
|
|
868
941
|
compilers.push(new CopyCompiler(buildConfig.copy));
|
|
869
942
|
|
|
@@ -8,7 +8,6 @@ function configCiCommand(program) {
|
|
|
8
8
|
'Generate a GitHub Actions CI/CD pipeline: CI builds assets & web component, CD deploys to Magmonium'
|
|
9
9
|
)
|
|
10
10
|
.requiredOption('--app-id <id>', 'Magmonium app ID')
|
|
11
|
-
.requiredOption('--token <token>', 'Magmonium deploy token')
|
|
12
11
|
.option(
|
|
13
12
|
'--endpoint <url>',
|
|
14
13
|
'Magmonium API endpoint',
|
|
@@ -41,6 +40,7 @@ function configCiCommand(program) {
|
|
|
41
40
|
deployBranch: options.branch,
|
|
42
41
|
nodeVersion: detected.nodeVersion,
|
|
43
42
|
wcDistPath: detected.wcDistPath,
|
|
43
|
+
appId: options.appId,
|
|
44
44
|
endpoint: options.endpoint,
|
|
45
45
|
remoteYmlPath,
|
|
46
46
|
});
|
|
@@ -49,10 +49,10 @@ function configCiCommand(program) {
|
|
|
49
49
|
|
|
50
50
|
console.log(`Generated: ${workflowFile}`);
|
|
51
51
|
console.log('');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.log(
|
|
55
|
-
console.log(
|
|
52
|
+
// The app id and endpoint are written into the workflow; neither is
|
|
53
|
+
// secret. The Deploy Token is the one secret, and is never printed.
|
|
54
|
+
console.log('Add this GitHub Secret to your repository:');
|
|
55
|
+
console.log(' MAG_DEPLOY_TOKEN = your personal deploy token');
|
|
56
56
|
console.log('');
|
|
57
57
|
console.log(
|
|
58
58
|
'Settings > Secrets and variables > Actions > New repository secret'
|
|
@@ -183,6 +183,8 @@ function buildCiWorkflow({
|
|
|
183
183
|
deployBranch,
|
|
184
184
|
nodeVersion,
|
|
185
185
|
wcDistPath,
|
|
186
|
+
appId,
|
|
187
|
+
endpoint,
|
|
186
188
|
remoteYmlPath,
|
|
187
189
|
}) {
|
|
188
190
|
const hasVersionCheck = Boolean(remoteYmlPath);
|
|
@@ -251,14 +253,11 @@ ${buildNeeds} runs-on: ubuntu-latest
|
|
|
251
253
|
- name: Install Magmonium CLI
|
|
252
254
|
run: npm install -g @magmonium/cli
|
|
253
255
|
- name: Deploy to Magmonium
|
|
254
|
-
run:
|
|
255
|
-
MAG_ENDPOINT="\${{ secrets.MAG_ENDPOINT }}"
|
|
256
|
-
MAG_ENDPOINT="\${MAG_ENDPOINT%/}"
|
|
257
|
-
mag-build deploy
|
|
256
|
+
run: mag-cli deploy
|
|
258
257
|
env:
|
|
259
|
-
MAG_APP_ID:
|
|
258
|
+
MAG_APP_ID: '${appId}'
|
|
260
259
|
MAG_DEPLOY_TOKEN: \${{ secrets.MAG_DEPLOY_TOKEN }}
|
|
261
|
-
MAG_ENDPOINT:
|
|
260
|
+
MAG_ENDPOINT: '${endpoint.replace(/\/+$/, '')}'
|
|
262
261
|
MAG_DIST_PATH: ${wcDistPath}
|
|
263
262
|
`;
|
|
264
263
|
}
|
|
@@ -13,12 +13,17 @@ function configureWcCommand(program) {
|
|
|
13
13
|
'--app-path <path>',
|
|
14
14
|
'Path to the app (e.g., apps/m-comics)'
|
|
15
15
|
)
|
|
16
|
+
.requiredOption('--app-id <id>', 'Magmonium app ID')
|
|
17
|
+
.option(
|
|
18
|
+
'--endpoint <url>',
|
|
19
|
+
'Magmonium API endpoint',
|
|
20
|
+
'https://api.magmonium.com'
|
|
21
|
+
)
|
|
16
22
|
.option('--force', 'Overwrite existing files')
|
|
17
23
|
.action((options) => {
|
|
18
24
|
try {
|
|
19
25
|
const appPath = options.appPath.replace(/\/$/, '');
|
|
20
26
|
const appName = path.basename(appPath);
|
|
21
|
-
const appNameUpper = appName.toUpperCase().replace(/-/g, '_');
|
|
22
27
|
|
|
23
28
|
console.log(`Configuring web component for: ${appName}`);
|
|
24
29
|
|
|
@@ -26,7 +31,7 @@ function configureWcCommand(program) {
|
|
|
26
31
|
createAppWcYaml(appPath, appName, options.force);
|
|
27
32
|
|
|
28
33
|
// 2. Create GitHub Actions CI/CD workflow
|
|
29
|
-
createWorkflow(appName,
|
|
34
|
+
createWorkflow(appName, options.appId, options.endpoint, options.force);
|
|
30
35
|
|
|
31
36
|
console.log('');
|
|
32
37
|
console.log('Done! Next steps:');
|
|
@@ -39,12 +44,10 @@ function configureWcCommand(program) {
|
|
|
39
44
|
);
|
|
40
45
|
console.log(` 3. Build & preview locally:`);
|
|
41
46
|
console.log(` npm run assets:compile`);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.log(`
|
|
45
|
-
console.log(
|
|
46
|
-
` MAG_ENDPOINT (default: https://api.magmonium.com)`
|
|
47
|
-
);
|
|
47
|
+
// The app id and endpoint are written into the workflow; neither is
|
|
48
|
+
// secret. One Deploy Token serves every app the User deploys.
|
|
49
|
+
console.log(` 4. Add the GitHub Secret, once per repository:`);
|
|
50
|
+
console.log(` MAG_DEPLOY_TOKEN (your personal deploy token)`);
|
|
48
51
|
} catch (err) {
|
|
49
52
|
console.error(`configure-wc failed: ${err.message}`);
|
|
50
53
|
process.exit(1);
|
|
@@ -78,7 +81,7 @@ appConfigPath: ${appPath}/src/app/app.config
|
|
|
78
81
|
console.log(` [created] ${dest}`);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
function createWorkflow(appName,
|
|
84
|
+
function createWorkflow(appName, appId, endpoint, force) {
|
|
82
85
|
const workflowDir = '.github/workflows';
|
|
83
86
|
const workflowFile = path.join(workflowDir, `${appName}-wc.yml`);
|
|
84
87
|
|
|
@@ -138,9 +141,9 @@ jobs:
|
|
|
138
141
|
- name: Deploy to Magmonium
|
|
139
142
|
run: |
|
|
140
143
|
mag-cli deploy \\
|
|
141
|
-
--app-id
|
|
144
|
+
--app-id ${appId} \\
|
|
142
145
|
--token \${{ secrets.MAG_DEPLOY_TOKEN }} \\
|
|
143
|
-
--endpoint
|
|
146
|
+
--endpoint ${endpoint.replace(/\/+$/, '')} \\
|
|
144
147
|
--dist-path ${wcDistPath}
|
|
145
148
|
`;
|
|
146
149
|
|
package/bin/commands/connect.js
CHANGED
|
@@ -8,7 +8,6 @@ function connectCommand(program) {
|
|
|
8
8
|
'Connect your Angular repository to Magmonium for automated deployment via GitHub Actions'
|
|
9
9
|
)
|
|
10
10
|
.requiredOption('--app-id <id>', 'Magmonium app ID')
|
|
11
|
-
.requiredOption('--token <token>', 'Magmonium deploy token')
|
|
12
11
|
.option(
|
|
13
12
|
'--endpoint <url>',
|
|
14
13
|
'Magmonium API endpoint',
|
|
@@ -39,16 +38,18 @@ function connectCommand(program) {
|
|
|
39
38
|
distPath: detected.distPath,
|
|
40
39
|
appRoot: detected.appRoot,
|
|
41
40
|
isNx: detected.isNx,
|
|
41
|
+
appId: options.appId,
|
|
42
|
+
endpoint: options.endpoint,
|
|
42
43
|
});
|
|
43
44
|
|
|
44
45
|
fs.writeFileSync(workflowFile, workflow, 'utf-8');
|
|
45
46
|
|
|
46
47
|
console.log(`Generated: ${workflowFile}`);
|
|
47
48
|
console.log('');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
console.log(
|
|
51
|
-
console.log(
|
|
49
|
+
// The app id and endpoint are written into the workflow; neither is
|
|
50
|
+
// secret. The Deploy Token is the one secret, and is never printed.
|
|
51
|
+
console.log('Add this GitHub Secret to your repository:');
|
|
52
|
+
console.log(' MAG_DEPLOY_TOKEN = your personal deploy token');
|
|
52
53
|
console.log('');
|
|
53
54
|
console.log(
|
|
54
55
|
'Settings > Secrets and variables > Actions > New repository secret'
|
|
@@ -152,6 +153,8 @@ function buildWorkflow({
|
|
|
152
153
|
distPath,
|
|
153
154
|
appRoot,
|
|
154
155
|
isNx,
|
|
156
|
+
appId,
|
|
157
|
+
endpoint,
|
|
155
158
|
}) {
|
|
156
159
|
const appRootLine = appRoot ? ` working-directory: ${appRoot}\n` : '';
|
|
157
160
|
|
|
@@ -176,11 +179,11 @@ jobs:
|
|
|
176
179
|
${buildSteps} - name: Install Magmonium CLI
|
|
177
180
|
run: npm install -g @magmonium/cli
|
|
178
181
|
- name: Deploy to Magmonium
|
|
179
|
-
run: mag-
|
|
182
|
+
run: mag-cli deploy
|
|
180
183
|
env:
|
|
181
|
-
MAG_APP_ID:
|
|
184
|
+
MAG_APP_ID: '${appId}'
|
|
182
185
|
MAG_DEPLOY_TOKEN: \${{ secrets.MAG_DEPLOY_TOKEN }}
|
|
183
|
-
MAG_ENDPOINT:
|
|
186
|
+
MAG_ENDPOINT: '${endpoint.replace(/\/+$/, '')}'
|
|
184
187
|
MAG_DIST_PATH: ${distPath}
|
|
185
188
|
`;
|
|
186
189
|
}
|
package/bin/commands/deploy.js
CHANGED
|
@@ -3,38 +3,69 @@ const fs = require('fs');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const os = require('os');
|
|
5
5
|
|
|
6
|
+
const DEFAULT_ENDPOINT = 'https://api.magmonium.com';
|
|
7
|
+
const DESIGN_SOURCE_INDEX = '.magmonium/index.json';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Linked App's id and its Environment's Backend URL, as One UI wrote them
|
|
11
|
+
* into the design source — what a scaffold's `cd.yml` deploys with, so the
|
|
12
|
+
* Deploy Token is the one value left to supply.
|
|
13
|
+
*/
|
|
14
|
+
function readDesignSource() {
|
|
15
|
+
try {
|
|
16
|
+
const { appTarget } = JSON.parse(
|
|
17
|
+
fs.readFileSync(DESIGN_SOURCE_INDEX, 'utf-8')
|
|
18
|
+
);
|
|
19
|
+
return {
|
|
20
|
+
appId: appTarget?.appId,
|
|
21
|
+
endpoint: appTarget?.environment?.hosts?.backendUrl,
|
|
22
|
+
};
|
|
23
|
+
} catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
6
28
|
function deployCommand(program) {
|
|
7
29
|
program
|
|
8
30
|
.command('deploy')
|
|
9
31
|
.description(
|
|
10
32
|
'Upload the built Angular bundle to Magmonium (run after build in CI/CD)'
|
|
11
33
|
)
|
|
12
|
-
.option(
|
|
34
|
+
.option(
|
|
35
|
+
'--app-id <id>',
|
|
36
|
+
`Magmonium app ID (overrides MAG_APP_ID env var, then ${DESIGN_SOURCE_INDEX})`
|
|
37
|
+
)
|
|
13
38
|
.option(
|
|
14
39
|
'--token <token>',
|
|
15
40
|
'Deploy token (overrides MAG_DEPLOY_TOKEN env var)'
|
|
16
41
|
)
|
|
17
42
|
.option(
|
|
18
43
|
'--endpoint <url>',
|
|
19
|
-
|
|
20
|
-
'https://api.magmonium.com'
|
|
44
|
+
`API endpoint (overrides MAG_ENDPOINT env var, then ${DESIGN_SOURCE_INDEX}; default ${DEFAULT_ENDPOINT})`
|
|
21
45
|
)
|
|
22
46
|
.option(
|
|
23
47
|
'--dist-path <path>',
|
|
24
48
|
'Built dist directory (overrides MAG_DIST_PATH env var)'
|
|
25
49
|
)
|
|
26
50
|
.action(async (options) => {
|
|
27
|
-
const
|
|
51
|
+
const designSource = readDesignSource();
|
|
52
|
+
const appId =
|
|
53
|
+
options.appId || process.env.MAG_APP_ID || designSource.appId;
|
|
28
54
|
const token = options.token || process.env.MAG_DEPLOY_TOKEN;
|
|
29
55
|
const endpoint = (
|
|
30
56
|
options.endpoint ||
|
|
31
57
|
process.env.MAG_ENDPOINT ||
|
|
32
|
-
|
|
33
|
-
|
|
58
|
+
designSource.endpoint ||
|
|
59
|
+
DEFAULT_ENDPOINT
|
|
60
|
+
)
|
|
61
|
+
.replace(/\/+$/, '')
|
|
62
|
+
.replace(/\/swagger\.json$/, '');
|
|
34
63
|
const distPath = options.distPath || process.env.MAG_DIST_PATH;
|
|
35
64
|
|
|
36
65
|
if (!appId) {
|
|
37
|
-
console.error(
|
|
66
|
+
console.error(
|
|
67
|
+
`Missing app ID. Set MAG_APP_ID, pass --app-id, or link the app in One UI and Push (${DESIGN_SOURCE_INDEX}).`
|
|
68
|
+
);
|
|
38
69
|
process.exit(1);
|
|
39
70
|
}
|
|
40
71
|
if (!token) {
|
package/bin/commands/fix-i18n.js
CHANGED
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const inquirer = require('inquirer');
|
|
3
|
+
const { FREELLM_BASE_URL, FREELLM_MODEL } = require('../../src/index.js');
|
|
4
|
+
|
|
5
|
+
/** The token from env, else asked for once — a terminal only, never on a dry run (which translates nothing). */
|
|
6
|
+
async function resolveAiToken(baseUrl, dryRun) {
|
|
7
|
+
const fromEnv = process.env.MAG_AI_TOKEN || process.env.FREELLMAPI_API_KEY;
|
|
8
|
+
if (fromEnv || dryRun || !process.stdin.isTTY) return fromEnv;
|
|
9
|
+
const { token } = await inquirer.prompt([
|
|
10
|
+
{
|
|
11
|
+
type: 'password',
|
|
12
|
+
name: 'token',
|
|
13
|
+
mask: '*',
|
|
14
|
+
message: `🔑 AI provider token for ${baseUrl}:`,
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
17
|
+
return token.trim() || undefined;
|
|
18
|
+
}
|
|
2
19
|
|
|
3
20
|
function fixI18nCommand(program) {
|
|
4
21
|
program
|
|
5
22
|
.command('fix-i18n')
|
|
6
23
|
.description(
|
|
7
|
-
'Scan templates and TypeScript for missing i18n keys and auto-translate them.
|
|
24
|
+
'Scan templates and TypeScript for missing i18n keys and auto-translate them. FreeLLMAPI (or another OpenAI-compatible endpoint m-one-ui uses) is the only translator: every language of a key in one ask, existing translations re-done.'
|
|
8
25
|
)
|
|
9
26
|
.option('--dry-run', 'Preview what would be created/deleted without writing files', false)
|
|
10
27
|
.option('-v, --verbose', 'Log per-language translation results', false)
|
|
11
28
|
.option('--root <path>', 'Workspace root (defaults to cwd)', process.cwd())
|
|
12
29
|
.option('--limit <n>', 'Process at most N keys per run (for batching large workspaces)', parseInt)
|
|
13
30
|
.option('--key <keys...>', 'Only these keys (i18n file names, e.g. nav-delete-references-left); skips stale-copy cleanup')
|
|
14
|
-
.option('--ai-base-url <url>', 'AI provider base URL, ending in /v1 (env MAG_AI_BASE_URL); token from env MAG_AI_TOKEN', process.env.MAG_AI_BASE_URL)
|
|
15
|
-
.option('--ai-model <id>', 'AI provider model id (env MAG_AI_MODEL)', process.env.MAG_AI_MODEL)
|
|
16
|
-
.option('--
|
|
31
|
+
.option('--ai-base-url <url>', 'AI provider base URL, ending in /v1 (env MAG_AI_BASE_URL); token from env MAG_AI_TOKEN or FREELLMAPI_API_KEY, else asked for', process.env.MAG_AI_BASE_URL || FREELLM_BASE_URL)
|
|
32
|
+
.option('--ai-model <id>', 'AI provider model id (env MAG_AI_MODEL)', process.env.MAG_AI_MODEL || FREELLM_MODEL)
|
|
33
|
+
.option('--ai-reasoning-effort <level>', 'reasoning_effort sent to the provider (env MAG_AI_REASONING_EFFORT); unset sends none', process.env.MAG_AI_REASONING_EFFORT)
|
|
17
34
|
.action(async (options) => {
|
|
18
35
|
const root = path.resolve(options.root);
|
|
19
36
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
: undefined;
|
|
37
|
+
const aiProvider = {
|
|
38
|
+
baseUrl: options.aiBaseUrl,
|
|
39
|
+
model: options.aiModel,
|
|
40
|
+
token: await resolveAiToken(options.aiBaseUrl, options.dryRun),
|
|
41
|
+
reasoningEffort: options.aiReasoningEffort,
|
|
42
|
+
};
|
|
27
43
|
|
|
28
44
|
try {
|
|
29
45
|
const { I18nFixer } = require('../../src/index.js');
|
|
@@ -33,7 +49,6 @@ function fixI18nCommand(program) {
|
|
|
33
49
|
dryRun: options.dryRun,
|
|
34
50
|
verbose: options.verbose,
|
|
35
51
|
limit: options.limit,
|
|
36
|
-
llamaHost: options.llamaHost,
|
|
37
52
|
aiProvider,
|
|
38
53
|
keys: options.key,
|
|
39
54
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
function i18nBaselineCommand(program) {
|
|
4
|
+
program
|
|
5
|
+
.command('i18n-baseline')
|
|
6
|
+
.description(
|
|
7
|
+
'Record every i18n key still missing langs into i18n-baseline.json — the only incomplete keys `assets` lets through. Run after translate:fix to tighten it.'
|
|
8
|
+
)
|
|
9
|
+
.option('--root <path>', 'Workspace root (defaults to cwd)', process.cwd())
|
|
10
|
+
.option('-v, --verbose', 'Verbose logging', false)
|
|
11
|
+
.action(async (options) => {
|
|
12
|
+
const {
|
|
13
|
+
I18nFixer,
|
|
14
|
+
buildI18nBaseline,
|
|
15
|
+
readI18nBaseline,
|
|
16
|
+
writeI18nBaseline,
|
|
17
|
+
I18N_BASELINE_FILE,
|
|
18
|
+
} = require('../../src/index.js');
|
|
19
|
+
const root = path.resolve(options.root);
|
|
20
|
+
|
|
21
|
+
const before = Object.keys(await readI18nBaseline(root)).length;
|
|
22
|
+
const baseline = buildI18nBaseline(
|
|
23
|
+
await new I18nFixer(root, options.verbose).scan()
|
|
24
|
+
);
|
|
25
|
+
await writeI18nBaseline(root, baseline);
|
|
26
|
+
|
|
27
|
+
console.log(
|
|
28
|
+
`${I18N_BASELINE_FILE}: ${before} → ${Object.keys(baseline).length} incomplete key(s)`
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = i18nBaselineCommand;
|