@translation-cms/sync 1.2.25 → 1.2.28
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/README.md +62 -16
- package/package.json +3 -2
- package/dist/api.d.ts +0 -105
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -208
- package/dist/api.js.map +0 -1
- package/dist/bin.d.ts +0 -25
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js +0 -208
- package/dist/bin.js.map +0 -1
- package/dist/commands/init.d.ts +0 -10
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -89
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/pull.d.ts +0 -10
- package/dist/commands/pull.d.ts.map +0 -1
- package/dist/commands/pull.js +0 -35
- package/dist/commands/pull.js.map +0 -1
- package/dist/commands/status.d.ts +0 -15
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -62
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/sync.d.ts +0 -24
- package/dist/commands/sync.d.ts.map +0 -1
- package/dist/commands/sync.js +0 -131
- package/dist/commands/sync.js.map +0 -1
- package/dist/commands/watch.d.ts +0 -18
- package/dist/commands/watch.d.ts.map +0 -1
- package/dist/commands/watch.js +0 -71
- package/dist/commands/watch.js.map +0 -1
- package/dist/config/config-internals/args.d.ts +0 -11
- package/dist/config/config-internals/args.d.ts.map +0 -1
- package/dist/config/config-internals/args.js +0 -22
- package/dist/config/config-internals/args.js.map +0 -1
- package/dist/config/config-internals/env.d.ts +0 -10
- package/dist/config/config-internals/env.d.ts.map +0 -1
- package/dist/config/config-internals/env.js +0 -35
- package/dist/config/config-internals/env.js.map +0 -1
- package/dist/config/config-internals/file.d.ts +0 -11
- package/dist/config/config-internals/file.d.ts.map +0 -1
- package/dist/config/config-internals/file.js +0 -28
- package/dist/config/config-internals/file.js.map +0 -1
- package/dist/config/config-internals/resolve.d.ts +0 -21
- package/dist/config/config-internals/resolve.d.ts.map +0 -1
- package/dist/config/config-internals/resolve.js +0 -73
- package/dist/config/config-internals/resolve.js.map +0 -1
- package/dist/config/config-internals/root.d.ts +0 -9
- package/dist/config/config-internals/root.d.ts.map +0 -1
- package/dist/config/config-internals/root.js +0 -22
- package/dist/config/config-internals/root.js.map +0 -1
- package/dist/config/config-internals/types.d.ts +0 -91
- package/dist/config/config-internals/types.d.ts.map +0 -1
- package/dist/config/config-internals/types.js +0 -9
- package/dist/config/config-internals/types.js.map +0 -1
- package/dist/config/resolve-config.d.ts +0 -11
- package/dist/config/resolve-config.d.ts.map +0 -1
- package/dist/config/resolve-config.js +0 -10
- package/dist/config/resolve-config.js.map +0 -1
- package/dist/core/api-internals/helpers.d.ts +0 -9
- package/dist/core/api-internals/helpers.d.ts.map +0 -1
- package/dist/core/api-internals/helpers.js +0 -14
- package/dist/core/api-internals/helpers.js.map +0 -1
- package/dist/core/api-internals/pull.d.ts +0 -19
- package/dist/core/api-internals/pull.d.ts.map +0 -1
- package/dist/core/api-internals/pull.js +0 -269
- package/dist/core/api-internals/pull.js.map +0 -1
- package/dist/core/api-internals/route-config.d.ts +0 -13
- package/dist/core/api-internals/route-config.d.ts.map +0 -1
- package/dist/core/api-internals/route-config.js +0 -34
- package/dist/core/api-internals/route-config.js.map +0 -1
- package/dist/core/api-internals/sync.d.ts +0 -19
- package/dist/core/api-internals/sync.d.ts.map +0 -1
- package/dist/core/api-internals/sync.js +0 -139
- package/dist/core/api-internals/sync.js.map +0 -1
- package/dist/core/api-internals/types.d.ts +0 -33
- package/dist/core/api-internals/types.d.ts.map +0 -1
- package/dist/core/api-internals/types.js +0 -5
- package/dist/core/api-internals/types.js.map +0 -1
- package/dist/core/api.d.ts +0 -11
- package/dist/core/api.d.ts.map +0 -1
- package/dist/core/api.js +0 -11
- package/dist/core/api.js.map +0 -1
- package/dist/core/cache-internals/format.d.ts +0 -20
- package/dist/core/cache-internals/format.d.ts.map +0 -1
- package/dist/core/cache-internals/format.js +0 -33
- package/dist/core/cache-internals/format.js.map +0 -1
- package/dist/core/cache-internals/params.d.ts +0 -33
- package/dist/core/cache-internals/params.d.ts.map +0 -1
- package/dist/core/cache-internals/params.js +0 -155
- package/dist/core/cache-internals/params.js.map +0 -1
- package/dist/core/cache-internals/pull.d.ts +0 -17
- package/dist/core/cache-internals/pull.d.ts.map +0 -1
- package/dist/core/cache-internals/pull.js +0 -34
- package/dist/core/cache-internals/pull.js.map +0 -1
- package/dist/core/cache-internals/sync.d.ts +0 -29
- package/dist/core/cache-internals/sync.d.ts.map +0 -1
- package/dist/core/cache-internals/sync.js +0 -104
- package/dist/core/cache-internals/sync.js.map +0 -1
- package/dist/core/cache-internals/types.d.ts +0 -48
- package/dist/core/cache-internals/types.d.ts.map +0 -1
- package/dist/core/cache-internals/types.js +0 -2
- package/dist/core/cache-internals/types.js.map +0 -1
- package/dist/core/cache.d.ts +0 -13
- package/dist/core/cache.d.ts.map +0 -1
- package/dist/core/cache.js +0 -33
- package/dist/core/cache.js.map +0 -1
- package/dist/core/scanner-internals/ast.d.ts +0 -40
- package/dist/core/scanner-internals/ast.d.ts.map +0 -1
- package/dist/core/scanner-internals/ast.js +0 -100
- package/dist/core/scanner-internals/ast.js.map +0 -1
- package/dist/core/scanner-internals/file-walker.d.ts +0 -10
- package/dist/core/scanner-internals/file-walker.d.ts.map +0 -1
- package/dist/core/scanner-internals/file-walker.js +0 -23
- package/dist/core/scanner-internals/file-walker.js.map +0 -1
- package/dist/core/scanner-internals/import-resolver.d.ts +0 -21
- package/dist/core/scanner-internals/import-resolver.d.ts.map +0 -1
- package/dist/core/scanner-internals/import-resolver.js +0 -119
- package/dist/core/scanner-internals/import-resolver.js.map +0 -1
- package/dist/core/scanner-internals/key-extractor.d.ts +0 -20
- package/dist/core/scanner-internals/key-extractor.d.ts.map +0 -1
- package/dist/core/scanner-internals/key-extractor.js +0 -274
- package/dist/core/scanner-internals/key-extractor.js.map +0 -1
- package/dist/core/scanner-internals/nav-config-scanner.d.ts +0 -30
- package/dist/core/scanner-internals/nav-config-scanner.d.ts.map +0 -1
- package/dist/core/scanner-internals/nav-config-scanner.js +0 -170
- package/dist/core/scanner-internals/nav-config-scanner.js.map +0 -1
- package/dist/core/scanner-internals/route-detector.d.ts +0 -27
- package/dist/core/scanner-internals/route-detector.d.ts.map +0 -1
- package/dist/core/scanner-internals/route-detector.js +0 -78
- package/dist/core/scanner-internals/route-detector.js.map +0 -1
- package/dist/core/scanner-internals/types.d.ts +0 -60
- package/dist/core/scanner-internals/types.d.ts.map +0 -1
- package/dist/core/scanner-internals/types.js +0 -29
- package/dist/core/scanner-internals/types.js.map +0 -1
- package/dist/core/scanner.d.ts +0 -21
- package/dist/core/scanner.d.ts.map +0 -1
- package/dist/core/scanner.js +0 -162
- package/dist/core/scanner.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/next.d.ts +0 -33
- package/dist/next.d.ts.map +0 -1
- package/dist/next.js +0 -110
- package/dist/next.js.map +0 -1
- package/dist/preview/index.d.ts +0 -39
- package/dist/preview/index.d.ts.map +0 -1
- package/dist/preview/index.js +0 -123
- package/dist/preview/index.js.map +0 -1
- package/dist/preview/internals/highlight.d.ts +0 -31
- package/dist/preview/internals/highlight.d.ts.map +0 -1
- package/dist/preview/internals/highlight.js +0 -184
- package/dist/preview/internals/highlight.js.map +0 -1
- package/dist/preview/internals/interactions.d.ts +0 -15
- package/dist/preview/internals/interactions.d.ts.map +0 -1
- package/dist/preview/internals/interactions.js +0 -38
- package/dist/preview/internals/interactions.js.map +0 -1
- package/dist/preview/internals/interactive.d.ts +0 -14
- package/dist/preview/internals/interactive.d.ts.map +0 -1
- package/dist/preview/internals/interactive.js +0 -122
- package/dist/preview/internals/interactive.js.map +0 -1
- package/dist/preview/internals/locales.d.ts +0 -9
- package/dist/preview/internals/locales.d.ts.map +0 -1
- package/dist/preview/internals/locales.js +0 -24
- package/dist/preview/internals/locales.js.map +0 -1
- package/dist/preview/internals/state.d.ts +0 -37
- package/dist/preview/internals/state.d.ts.map +0 -1
- package/dist/preview/internals/state.js +0 -74
- package/dist/preview/internals/state.js.map +0 -1
- package/dist/preview/internals/styles.d.ts +0 -8
- package/dist/preview/internals/styles.d.ts.map +0 -1
- package/dist/preview/internals/styles.js +0 -28
- package/dist/preview/internals/styles.js.map +0 -1
- package/dist/preview/internals/types.d.ts +0 -74
- package/dist/preview/internals/types.d.ts.map +0 -1
- package/dist/preview/internals/types.js +0 -5
- package/dist/preview/internals/types.js.map +0 -1
- package/dist/preview/internals/ui-indicators.d.ts +0 -15
- package/dist/preview/internals/ui-indicators.d.ts.map +0 -1
- package/dist/preview/internals/ui-indicators.js +0 -92
- package/dist/preview/internals/ui-indicators.js.map +0 -1
- package/dist/scaffold/index.d.ts +0 -3
- package/dist/scaffold/index.d.ts.map +0 -1
- package/dist/scaffold/index.js +0 -3
- package/dist/scaffold/index.js.map +0 -1
- package/dist/scaffold/intenrals/scaffold.d.ts +0 -24
- package/dist/scaffold/intenrals/scaffold.d.ts.map +0 -1
- package/dist/scaffold/intenrals/scaffold.js +0 -53
- package/dist/scaffold/intenrals/scaffold.js.map +0 -1
- package/dist/scaffold/intenrals/templates.d.ts +0 -10
- package/dist/scaffold/intenrals/templates.d.ts.map +0 -1
- package/dist/scaffold/intenrals/templates.js +0 -344
- package/dist/scaffold/intenrals/templates.js.map +0 -1
- package/dist/scaffold/intenrals/types.d.ts +0 -14
- package/dist/scaffold/intenrals/types.d.ts.map +0 -1
- package/dist/scaffold/intenrals/types.js +0 -5
- package/dist/scaffold/intenrals/types.js.map +0 -1
package/dist/bin.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* sync-translations CLI
|
|
4
|
-
*
|
|
5
|
-
* Subcommands:
|
|
6
|
-
* sync (default) Scan codebase and sync translation keys to the CMS.
|
|
7
|
-
* pull Fetch translations from CMS and write local JSON files.
|
|
8
|
-
* status Show what would change on next sync (no network calls).
|
|
9
|
-
* watch Watch for file changes and auto-sync on save.
|
|
10
|
-
* init Interactive setup — creates .translationsrc.json.
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* sync-translations # sync keys + pull
|
|
14
|
-
* sync-translations sync --dry-run # preview changes only
|
|
15
|
-
* sync-translations sync --report scan.json # write JSON report
|
|
16
|
-
* sync-translations pull --output ./locales # custom output dir
|
|
17
|
-
* sync-translations pull --force # ignore TTL cache
|
|
18
|
-
* sync-translations pull --env staging # pull staging env
|
|
19
|
-
* sync-translations pull --ttl 600000 # custom TTL (ms)
|
|
20
|
-
* sync-translations status # diff vs last sync cache
|
|
21
|
-
* sync-translations watch # watch + auto-sync
|
|
22
|
-
* sync-translations init # interactive setup
|
|
23
|
-
*/
|
|
24
|
-
import path from 'path';
|
|
25
|
-
import fs from 'fs';
|
|
26
|
-
import { resolveConfig, resolveRouteParams, findProjectRoot, loadConfigFile, } from './config/resolve-config.js';
|
|
27
|
-
import { fetchRouteParams } from './core/api.js';
|
|
28
|
-
import { runStatus } from './commands/status.js';
|
|
29
|
-
import { runWatch } from './commands/watch.js';
|
|
30
|
-
import { runInit } from './commands/init.js';
|
|
31
|
-
import { runPull } from './commands/pull.js';
|
|
32
|
-
import { runSync } from './commands/sync.js';
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// Helpers
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
function stripJsonComments(input) {
|
|
37
|
-
let result = '';
|
|
38
|
-
let i = 0;
|
|
39
|
-
while (i < input.length) {
|
|
40
|
-
// --- String literal: copy char-by-char, respecting escape sequences ---
|
|
41
|
-
if (input[i] === '"') {
|
|
42
|
-
result += '"';
|
|
43
|
-
i++;
|
|
44
|
-
while (i < input.length) {
|
|
45
|
-
const ch = input[i];
|
|
46
|
-
result += ch;
|
|
47
|
-
i++;
|
|
48
|
-
if (ch === '\\') {
|
|
49
|
-
// Escaped character — copy next char unconditionally
|
|
50
|
-
if (i < input.length)
|
|
51
|
-
result += input[i++];
|
|
52
|
-
}
|
|
53
|
-
else if (ch === '"') {
|
|
54
|
-
break; // closing quote
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
// --- Line comment: skip everything up to the newline ---
|
|
60
|
-
if (input[i] === '/' && input[i + 1] === '/') {
|
|
61
|
-
while (i < input.length && input[i] !== '\n')
|
|
62
|
-
i++;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
// --- Block comment: skip until closing */ ---
|
|
66
|
-
if (input[i] === '/' && input[i + 1] === '*') {
|
|
67
|
-
i += 2;
|
|
68
|
-
while (i < input.length) {
|
|
69
|
-
if (input[i] === '*' && input[i + 1] === '/') {
|
|
70
|
-
i += 2;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
i++;
|
|
74
|
-
}
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
result += input[i++];
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Load TypeScript path alias mappings from `tsconfig.json` at the project root.
|
|
83
|
-
*
|
|
84
|
-
* These mappings are passed to the scanner so that aliased imports such as
|
|
85
|
-
* `@/components/button` can be resolved to absolute file paths. tsconfig
|
|
86
|
-
* files are JSONC (JSON with comments) so we strip comments before parsing.
|
|
87
|
-
*
|
|
88
|
-
* Returns null when tsconfig.json is absent, unreadable, or has no `paths`.
|
|
89
|
-
*/
|
|
90
|
-
function loadTsConfigPathMappings(root) {
|
|
91
|
-
const tsconfigPath = path.join(root, 'tsconfig.json');
|
|
92
|
-
if (!fs.existsSync(tsconfigPath))
|
|
93
|
-
return null;
|
|
94
|
-
try {
|
|
95
|
-
const cleaned = stripJsonComments(fs.readFileSync(tsconfigPath, 'utf-8'));
|
|
96
|
-
const tsconfig = JSON.parse(cleaned);
|
|
97
|
-
// Drill into compilerOptions.paths — guard each level against unexpected shapes
|
|
98
|
-
if (typeof tsconfig !== 'object' || tsconfig === null)
|
|
99
|
-
return null;
|
|
100
|
-
if (!('compilerOptions' in tsconfig))
|
|
101
|
-
return null;
|
|
102
|
-
const opts = tsconfig.compilerOptions;
|
|
103
|
-
if (typeof opts !== 'object' || opts === null)
|
|
104
|
-
return null;
|
|
105
|
-
if (!('paths' in opts))
|
|
106
|
-
return null;
|
|
107
|
-
const paths = opts.paths;
|
|
108
|
-
if (typeof paths === 'object' && paths !== null)
|
|
109
|
-
return paths;
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
// Silently ignore tsconfig parse errors — scanning continues without alias resolution
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
/** Return the value that follows `flag` in `args`, or undefined if absent. */
|
|
117
|
-
function getFlag(args, flag) {
|
|
118
|
-
const idx = args.indexOf(flag);
|
|
119
|
-
return idx !== -1 && args[idx + 1] ? args[idx + 1] : undefined;
|
|
120
|
-
}
|
|
121
|
-
/** Return true when any of the given flag strings is present in `args`. */
|
|
122
|
-
function hasFlag(args, ...flags) {
|
|
123
|
-
return flags.some(f => args.includes(f));
|
|
124
|
-
}
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// Main
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
/** All valid subcommand names. Used for validation and dispatch. */
|
|
129
|
-
const SUBCOMMANDS = new Set(['sync', 'pull', 'status', 'watch', 'init']);
|
|
130
|
-
/**
|
|
131
|
-
* CLI entry point.
|
|
132
|
-
*
|
|
133
|
-
* Resolves config, loads tsconfig path mappings, and dispatches to the
|
|
134
|
-
* appropriate command handler. Config resolution and scanner setup are shared
|
|
135
|
-
* across all commands except `init` (which runs before a config file exists).
|
|
136
|
-
*/
|
|
137
|
-
async function main() {
|
|
138
|
-
const args = process.argv.slice(2);
|
|
139
|
-
// First non-flag argument is the subcommand; default to 'sync' when omitted
|
|
140
|
-
const subcommand = args.find(a => !a.startsWith('-')) ?? 'sync';
|
|
141
|
-
if (!SUBCOMMANDS.has(subcommand)) {
|
|
142
|
-
// eslint-disable-next-line no-console
|
|
143
|
-
console.error(`Unknown subcommand: ${subcommand}`);
|
|
144
|
-
// eslint-disable-next-line no-console
|
|
145
|
-
console.error(`Available: ${[...SUBCOMMANDS].join(', ')}`);
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
const root = findProjectRoot();
|
|
149
|
-
const fileConfig = loadConfigFile(root);
|
|
150
|
-
// `init` runs before a config file exists, so it short-circuits here
|
|
151
|
-
if (subcommand === 'init') {
|
|
152
|
-
await runInit(root);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const config = resolveConfig(root, fileConfig);
|
|
156
|
-
// Path mappings let the scanner resolve aliased imports (e.g. @/components/…)
|
|
157
|
-
const pathMappings = loadTsConfigPathMappings(root);
|
|
158
|
-
// Route params from the CMS are merged with locally configured params;
|
|
159
|
-
// skip the network call for `pull` since it doesn't scan the codebase
|
|
160
|
-
let cmsRouteParams = {};
|
|
161
|
-
if (subcommand !== 'pull') {
|
|
162
|
-
cmsRouteParams = await fetchRouteParams(config);
|
|
163
|
-
}
|
|
164
|
-
// User-defined params (from config) take precedence over CMS-generated ones
|
|
165
|
-
const allRouteParams = resolveRouteParams(root, fileConfig);
|
|
166
|
-
const scanOpts = {
|
|
167
|
-
excludedDirs: fileConfig.excludedDirs,
|
|
168
|
-
sourceExtensions: fileConfig.sourceExtensions,
|
|
169
|
-
routeParams: { ...cmsRouteParams, ...allRouteParams },
|
|
170
|
-
pathMappings: pathMappings ?? undefined,
|
|
171
|
-
projectRoot: root,
|
|
172
|
-
includeNavRoutes: fileConfig.includeNavRoutes,
|
|
173
|
-
};
|
|
174
|
-
if (subcommand === 'status') {
|
|
175
|
-
runStatus(root, scanOpts);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (subcommand === 'watch') {
|
|
179
|
-
const outputDir = fileConfig.outputDir ?? path.join(root, 'public', 'locales');
|
|
180
|
-
await runWatch(root, config, outputDir, scanOpts);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if (subcommand === 'pull') {
|
|
184
|
-
await runPull(root, config, fileConfig, args);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
// --- sync (default) ---
|
|
188
|
-
const outputDir = fileConfig.outputDir ?? path.join(root, 'public', 'locales');
|
|
189
|
-
const reportArg = getFlag(args, '--report');
|
|
190
|
-
await runSync(root, config, scanOpts, {
|
|
191
|
-
outputDir,
|
|
192
|
-
dryRun: hasFlag(args, '--dry-run'),
|
|
193
|
-
force: hasFlag(args, '--force'),
|
|
194
|
-
// Resolve report path relative to project root when not absolute
|
|
195
|
-
reportPath: reportArg
|
|
196
|
-
? path.isAbsolute(reportArg)
|
|
197
|
-
? reportArg
|
|
198
|
-
: path.join(root, reportArg)
|
|
199
|
-
: undefined,
|
|
200
|
-
mockDataPath: fileConfig.mockDataPath,
|
|
201
|
-
userRouteParams: fileConfig.routeParams,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
main().catch(err => {
|
|
205
|
-
process.stderr.write(`${err instanceof Error ? (err.stack ?? err.message) : String(err)}\n`);
|
|
206
|
-
process.exit(1);
|
|
207
|
-
});
|
|
208
|
-
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACH,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,cAAc,GACjB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,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,CAAC,WAAW;KAC1C,CAAC,CAAC;AACP,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CACzE,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
package/dist/commands/init.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interactive `init` command.
|
|
3
|
-
*
|
|
4
|
-
* Walks the user through a series of prompts and writes a
|
|
5
|
-
* `.translationsrc.json` config file to the project root.
|
|
6
|
-
* Optionally scaffolds the i18n boilerplate files (settings,
|
|
7
|
-
* client, server, provider) into the chosen i18n directory.
|
|
8
|
-
*/
|
|
9
|
-
export declare function runInit(root: string): Promise<void>;
|
|
10
|
-
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgGzD"}
|
package/dist/commands/init.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { scaffoldI18n } from '../scaffold/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* Interactive `init` command.
|
|
6
|
-
*
|
|
7
|
-
* Walks the user through a series of prompts and writes a
|
|
8
|
-
* `.translationsrc.json` config file to the project root.
|
|
9
|
-
* Optionally scaffolds the i18n boilerplate files (settings,
|
|
10
|
-
* client, server, provider) into the chosen i18n directory.
|
|
11
|
-
*/
|
|
12
|
-
export async function runInit(root) {
|
|
13
|
-
const { createInterface } = await import('readline');
|
|
14
|
-
// Use readline so we can show prompts and read answers synchronously one by one
|
|
15
|
-
const rl = createInterface({
|
|
16
|
-
input: process.stdin,
|
|
17
|
-
output: process.stdout,
|
|
18
|
-
});
|
|
19
|
-
const question = (prompt) => new Promise(resolve => rl.question(prompt, resolve));
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
21
|
-
console.log('sync-translations init\n');
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
console.log('This creates .translationsrc.json in your project root.');
|
|
24
|
-
// eslint-disable-next-line no-console
|
|
25
|
-
console.log('Values here override env vars for the sync-translations CLI.\n');
|
|
26
|
-
// Collect required config values from the user
|
|
27
|
-
const cmsUrl = await question('CMS URL (e.g. https://cms.example.com): ');
|
|
28
|
-
const projectId = await question('Project ID: ');
|
|
29
|
-
const apiKey = await question('API key: ');
|
|
30
|
-
const i18nDirInput = await question('i18n directory [./src/lib/i18n]: ');
|
|
31
|
-
const pullTtlInput = await question('Pull TTL in seconds [300]: ');
|
|
32
|
-
const scaffoldInput = await question('Scaffold i18n files (settings, client, server, provider)? [Y/n]: ');
|
|
33
|
-
rl.close();
|
|
34
|
-
// Apply defaults for optional fields
|
|
35
|
-
const i18nDir = i18nDirInput.trim() || './src/lib/i18n';
|
|
36
|
-
// Dictionaries live one level deeper than the i18n dir
|
|
37
|
-
const outputDir = `${i18nDir.replace(/\/$/, '')}/dictionaries`;
|
|
38
|
-
// Build the config object — only include keys that the user actually provided
|
|
39
|
-
const config = {
|
|
40
|
-
$schema: './node_modules/@translation-cms/sync/schema.json',
|
|
41
|
-
};
|
|
42
|
-
if (cmsUrl.trim())
|
|
43
|
-
config['cmsUrl'] = cmsUrl.trim();
|
|
44
|
-
if (projectId.trim())
|
|
45
|
-
config['projectId'] = projectId.trim();
|
|
46
|
-
if (apiKey.trim())
|
|
47
|
-
config['apiKey'] = apiKey.trim();
|
|
48
|
-
config['outputDir'] = outputDir;
|
|
49
|
-
if (pullTtlInput.trim()) {
|
|
50
|
-
const ttlSec = parseInt(pullTtlInput.trim(), 10);
|
|
51
|
-
// Convert seconds → milliseconds for the config field
|
|
52
|
-
if (!isNaN(ttlSec))
|
|
53
|
-
config['pullTtlMs'] = ttlSec * 1000;
|
|
54
|
-
}
|
|
55
|
-
// Write the config file
|
|
56
|
-
const configPath = path.join(root, '.translationsrc.json');
|
|
57
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
58
|
-
console.log(`\nCreated: ${configPath}`);
|
|
59
|
-
// Warn if an API key was written to disk — it should ideally stay in .env.local
|
|
60
|
-
if (config['apiKey']) {
|
|
61
|
-
console.log('\nWarning: .translationsrc.json contains an API key. Consider adding it to .gitignore:');
|
|
62
|
-
console.log(' echo ".translationsrc.json" >> .gitignore');
|
|
63
|
-
console.log('Or move the API key to CMS_SYNC_API_KEY in .env.local instead.');
|
|
64
|
-
}
|
|
65
|
-
// Default to scaffolding unless the user explicitly answers "n"
|
|
66
|
-
const doScaffold = scaffoldInput.trim().toLowerCase() !== 'n';
|
|
67
|
-
if (doScaffold) {
|
|
68
|
-
const absI18nDir = path.isAbsolute(i18nDir)
|
|
69
|
-
? i18nDir
|
|
70
|
-
: path.resolve(root, i18nDir);
|
|
71
|
-
const { written, skipped } = scaffoldI18n({ i18nDir: absI18nDir });
|
|
72
|
-
if (written.length > 0) {
|
|
73
|
-
console.log('\nScaffolded i18n files:');
|
|
74
|
-
for (const f of written)
|
|
75
|
-
console.log(` + src/lib/i18n/${f}`);
|
|
76
|
-
}
|
|
77
|
-
if (skipped.length > 0) {
|
|
78
|
-
// Files that already exist are left untouched to avoid overwriting customizations
|
|
79
|
-
console.log('\nSkipped (already exist):');
|
|
80
|
-
for (const f of skipped)
|
|
81
|
-
console.log(` ~ src/lib/i18n/${f}`);
|
|
82
|
-
}
|
|
83
|
-
console.log('\nNext steps:');
|
|
84
|
-
console.log(' 1. Install peer deps: pnpm add i18next react-i18next i18next-resources-to-backend');
|
|
85
|
-
console.log(' 2. Pull translations: sync-translations pull');
|
|
86
|
-
console.log(' 3. Wrap your root layout with <TranslationProvider locale={locale}>');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=init.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,IAAY;IACtC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IAErD,gFAAgF;IAChF,MAAM,EAAE,GAAG,eAAe,CAAC;QACvB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;KACzB,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAmB,EAAE,CACjD,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEzD,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAC;IACvE,sCAAsC;IACtC,OAAO,CAAC,GAAG,CACP,gEAAgE,CACnE,CAAC;IAEF,+CAA+C;IAC/C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,0CAA0C,CAAC,CAAC;IAC1E,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,cAAc,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,MA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EAAE,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC7B,OAAO,CAAC,GAAG,CACP,qFAAqF,CACxF,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;QAC9D,OAAO,CAAC,GAAG,CACP,uEAAuE,CAC1E,CAAC;IACN,CAAC;AACL,CAAC"}
|
package/dist/commands/pull.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Config, TranslationsConfig } from '../config/resolve-config.js';
|
|
2
|
-
/**
|
|
3
|
-
* `pull` command — fetches published translations from the CMS and writes
|
|
4
|
-
* them as JSON dictionary files to the output directory.
|
|
5
|
-
*
|
|
6
|
-
* Resolution order for each option:
|
|
7
|
-
* CLI flag > .translationsrc.json > built-in default
|
|
8
|
-
*/
|
|
9
|
-
export declare function runPull(root: string, config: Config, fileConfig: TranslationsConfig, args: string[]): Promise<void>;
|
|
10
|
-
//# sourceMappingURL=pull.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG9E;;;;;;GAMG;AACH,wBAAsB,OAAO,CACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,kBAAkB,EAC9B,IAAI,EAAE,MAAM,EAAE,GACf,OAAO,CAAC,IAAI,CAAC,CAiBf"}
|
package/dist/commands/pull.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { pullTranslations } from '../core/api.js';
|
|
3
|
-
/**
|
|
4
|
-
* `pull` command — fetches published translations from the CMS and writes
|
|
5
|
-
* them as JSON dictionary files to the output directory.
|
|
6
|
-
*
|
|
7
|
-
* Resolution order for each option:
|
|
8
|
-
* CLI flag > .translationsrc.json > built-in default
|
|
9
|
-
*/
|
|
10
|
-
export async function runPull(root, config, fileConfig, args) {
|
|
11
|
-
// --output overrides the config file value; fall back to public/locales
|
|
12
|
-
const outputArg = getFlag(args, '--output');
|
|
13
|
-
const outputDir = outputArg
|
|
14
|
-
? path.resolve(root, outputArg)
|
|
15
|
-
: fileConfig.outputDir
|
|
16
|
-
? path.resolve(root, fileConfig.outputDir)
|
|
17
|
-
: path.join(root, 'public', 'locales');
|
|
18
|
-
// --ttl overrides the config file value (already in ms)
|
|
19
|
-
const ttlArg = getFlag(args, '--ttl');
|
|
20
|
-
await pullTranslations(config, {
|
|
21
|
-
outputDir,
|
|
22
|
-
force: args.includes('--force'), // skip TTL cache check and always re-fetch
|
|
23
|
-
ttlMs: ttlArg ? parseInt(ttlArg, 10) : fileConfig.pullTtlMs,
|
|
24
|
-
env: getFlag(args, '--env'), // target a specific environment (e.g. staging)
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Returns the value of a named CLI flag (`--flag value`),
|
|
29
|
-
* or `undefined` if the flag is absent or has no value after it.
|
|
30
|
-
*/
|
|
31
|
-
function getFlag(args, flag) {
|
|
32
|
-
const idx = args.indexOf(flag);
|
|
33
|
-
return idx !== -1 && args[idx + 1] ? args[idx + 1] : undefined;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=pull.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pull.js","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CACzB,IAAY,EACZ,MAAc,EACd,UAA8B,EAC9B,IAAc;IAEd,wEAAwE;IACxE,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,SAAS;QACvB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;QAC/B,CAAC,CAAC,UAAU,CAAC,SAAS;YACpB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC;YAC1C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAE7C,wDAAwD;IACxD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtC,MAAM,gBAAgB,CAAC,MAAM,EAAE;QAC3B,SAAS;QACT,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,2CAA2C;QAC5E,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS;QAC3D,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,+CAA+C;KAC/E,CAAC,CAAC;AACP,CAAC;AAED;;;GAGG;AACH,SAAS,OAAO,CAAC,IAAc,EAAE,IAAY;IACzC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,GAAG,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type ScanOptions } from '../core/scanner.js';
|
|
2
|
-
/**
|
|
3
|
-
* `status` command — scans the project for translation keys and compares
|
|
4
|
-
* the result against the last sync cache (.cms-sync-cache.json).
|
|
5
|
-
*
|
|
6
|
-
* Outputs a human-readable diff showing:
|
|
7
|
-
* + keys that are new since the last sync
|
|
8
|
-
* - keys that have been removed
|
|
9
|
-
* ~ keys whose preview routes have changed
|
|
10
|
-
* = keys that are unchanged
|
|
11
|
-
*
|
|
12
|
-
* Does not write anything — safe to run at any time.
|
|
13
|
-
*/
|
|
14
|
-
export declare function runStatus(root: string, scanOpts: ScanOptions): void;
|
|
15
|
-
//# sourceMappingURL=status.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAQnE;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,CA8DnE"}
|
package/dist/commands/status.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { scanProject } from '../core/scanner.js';
|
|
2
|
-
import { serializeNamespaces, loadSyncCache, computeDiff, formatPreviewRoutes, } from '../core/cache.js';
|
|
3
|
-
/**
|
|
4
|
-
* `status` command — scans the project for translation keys and compares
|
|
5
|
-
* the result against the last sync cache (.cms-sync-cache.json).
|
|
6
|
-
*
|
|
7
|
-
* Outputs a human-readable diff showing:
|
|
8
|
-
* + keys that are new since the last sync
|
|
9
|
-
* - keys that have been removed
|
|
10
|
-
* ~ keys whose preview routes have changed
|
|
11
|
-
* = keys that are unchanged
|
|
12
|
-
*
|
|
13
|
-
* Does not write anything — safe to run at any time.
|
|
14
|
-
*/
|
|
15
|
-
export function runStatus(root, scanOpts) {
|
|
16
|
-
console.log(`Scanning project: ${root}`);
|
|
17
|
-
const namespaces = scanProject(root, scanOpts);
|
|
18
|
-
// Flatten the NamespaceMap into a plain serializable object and get the total key count
|
|
19
|
-
const { serialized, totalKeys } = serializeNamespaces(namespaces);
|
|
20
|
-
const namespaceCount = Object.keys(serialized).length;
|
|
21
|
-
console.log(`\nFound ${totalKeys} key(s) across ${namespaceCount} namespace(s): ${Object.keys(serialized).join(', ')}`);
|
|
22
|
-
// Load the baseline written by the last successful sync
|
|
23
|
-
const cached = loadSyncCache(root);
|
|
24
|
-
if (!cached) {
|
|
25
|
-
console.log('\nNo sync cache found (.cms-sync-cache.json). Run sync first to establish a baseline.');
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
// Diff current scan against the cached snapshot
|
|
29
|
-
const diff = computeDiff(serialized, cached);
|
|
30
|
-
console.log('\nStatus vs last sync:');
|
|
31
|
-
console.log(` + ${diff.added.length} new key(s)`);
|
|
32
|
-
console.log(` - ${diff.removed.length} removed key(s)`);
|
|
33
|
-
console.log(` ~ ${diff.routesChanged.length} route update(s)`);
|
|
34
|
-
console.log(` = ${diff.unchanged} unchanged`);
|
|
35
|
-
if (diff.added.length > 0) {
|
|
36
|
-
console.log('\nNew keys:');
|
|
37
|
-
for (const { namespace, key, routes } of diff.added) {
|
|
38
|
-
console.log(` + ${namespace}:${key} (${formatPreviewRoutes(routes)})`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (diff.removed.length > 0) {
|
|
42
|
-
console.log('\nRemoved keys:');
|
|
43
|
-
for (const { namespace, key } of diff.removed) {
|
|
44
|
-
console.log(` - ${namespace}:${key}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (diff.routesChanged.length > 0) {
|
|
48
|
-
console.log('\nRoute updates:');
|
|
49
|
-
for (const { namespace, key, before, after } of diff.routesChanged) {
|
|
50
|
-
console.log(` ~ ${namespace}:${key} [${formatPreviewRoutes(before)}] -> [${formatPreviewRoutes(after)}]`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// Only prompt to sync if there are actual changes
|
|
54
|
-
const total = diff.added.length + diff.removed.length + diff.routesChanged.length;
|
|
55
|
-
if (total > 0) {
|
|
56
|
-
console.log('\nRun "sync-translations sync" to push these changes.');
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
console.log('\nEverything is in sync.');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=status.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,oBAAoB,CAAC;AACnE,OAAO,EACH,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,mBAAmB,GACtB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,QAAqB;IACzD,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE/C,wFAAwF;IACxF,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAClE,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;IAEtD,OAAO,CAAC,GAAG,CACP,WAAW,SAAS,kBAAkB,cAAc,kBAAkB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC7G,CAAC;IAEF,wDAAwD;IACxD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CACP,uFAAuF,CAC1F,CAAC;QACF,OAAO;IACX,CAAC;IAED,gDAAgD;IAChD,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,M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AAC,KAAK,CAAC,GAAG,CACjG,CAAC;QACN,CAAC;IACL,CAAC;IAED,kDAAkD;IAClD,MAAM,KAAK,GACP,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IACxE,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;IACzE,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC5C,CAAC;AACL,CAAC"}
|
package/dist/commands/sync.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Config } from '../config/resolve-config.js';
|
|
2
|
-
import { type ScanOptions } from '../core/scanner.js';
|
|
3
|
-
export interface SyncCommandOptions {
|
|
4
|
-
outputDir: string;
|
|
5
|
-
dryRun: boolean;
|
|
6
|
-
force: boolean;
|
|
7
|
-
reportPath?: string;
|
|
8
|
-
/** Path (relative to root) for the generated mock-params TS file. */
|
|
9
|
-
mockDataPath?: string;
|
|
10
|
-
/** User-configured route params from config file (merged into mock data). */
|
|
11
|
-
userRouteParams?: Record<string, Record<string, string>>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* `sync` command — the main push/pull cycle:
|
|
15
|
-
*
|
|
16
|
-
* 1. Scan the project for translation keys and their preview routes.
|
|
17
|
-
* 2. Auto-generate mock route params for any dynamic routes (e.g. /[slug]).
|
|
18
|
-
* If a mockDataPath is configured, write a TS file with the merged params
|
|
19
|
-
* so the CMS can render live previews.
|
|
20
|
-
* 3. POST the discovered keys to the CMS (dry-run: report only, no writes).
|
|
21
|
-
* 4. Pull the latest published translations back to disk (skipped on dry-run).
|
|
22
|
-
*/
|
|
23
|
-
export declare function runSync(root: string, config: Config, scanOpts: ScanOptions, opts: SyncCommandOptions): Promise<void>;
|
|
24
|
-
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAe,KAAK,WAAW,EAAY,MAAM,oBAAoB,CAAC;AAQ7E,MAAM,WAAW,kBAAkB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC5D;AAED;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,kBAAkB,GACzB,OAAO,CAAC,IAAI,CAAC,CA2Df"}
|
package/dist/commands/sync.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { scanProject, routeKey } from '../core/scanner.js';
|
|
4
|
-
import { postToSync, pullTranslations } from '../core/api.js';
|
|
5
|
-
import { generateRouteParams, saveRouteParamsCache, writeMockDataFile, } from '../core/cache.js';
|
|
6
|
-
/**
|
|
7
|
-
* `sync` command — the main push/pull cycle:
|
|
8
|
-
*
|
|
9
|
-
* 1. Scan the project for translation keys and their preview routes.
|
|
10
|
-
* 2. Auto-generate mock route params for any dynamic routes (e.g. /[slug]).
|
|
11
|
-
* If a mockDataPath is configured, write a TS file with the merged params
|
|
12
|
-
* so the CMS can render live previews.
|
|
13
|
-
* 3. POST the discovered keys to the CMS (dry-run: report only, no writes).
|
|
14
|
-
* 4. Pull the latest published translations back to disk (skipped on dry-run).
|
|
15
|
-
*/
|
|
16
|
-
export async function runSync(root, config, scanOpts, opts) {
|
|
17
|
-
console.log(`Scanning project: ${root}`);
|
|
18
|
-
const namespaces = scanProject(root, scanOpts);
|
|
19
|
-
// Collect every unique route string found across all keys so we can
|
|
20
|
-
// generate placeholder params for dynamic segments (e.g. [slug], [id]).
|
|
21
|
-
const detectedRoutes = new Set();
|
|
22
|
-
for (const keyMap of Object.values(namespaces)) {
|
|
23
|
-
for (const routes of keyMap.values()) {
|
|
24
|
-
for (const route of routes) {
|
|
25
|
-
// routeKey normalises PreviewRoute objects to plain strings
|
|
26
|
-
const routeStr = routeKey(route);
|
|
27
|
-
detectedRoutes.add(routeStr);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (detectedRoutes.size > 0) {
|
|
32
|
-
const autoParams = generateRouteParams(Array.from(detectedRoutes));
|
|
33
|
-
if (Object.keys(autoParams).length > 0) {
|
|
34
|
-
// Persist the auto-generated params to cache so subsequent scans
|
|
35
|
-
// can reuse them without re-deriving them from scratch
|
|
36
|
-
saveRouteParamsCache(root, autoParams);
|
|
37
|
-
console.log(`[route-params] Auto-generated params for ${Object.keys(autoParams).length} dynamic routes`);
|
|
38
|
-
if (opts.mockDataPath) {
|
|
39
|
-
// Merge auto-generated with user-configured params (user wins on conflict)
|
|
40
|
-
const merged = {
|
|
41
|
-
...autoParams,
|
|
42
|
-
...(opts.userRouteParams ?? {}),
|
|
43
|
-
};
|
|
44
|
-
writeMockDataFile(root, merged, opts.mockDataPath);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// Read local translation values from JSON files to bootstrap drafts in CMS.
|
|
49
|
-
// Keys that already have a draft in the CMS are never overwritten.
|
|
50
|
-
const localValues = readLocalValues(opts.outputDir);
|
|
51
|
-
// Push discovered keys to the CMS; dry-run mode only prints a report
|
|
52
|
-
await postToSync(config, namespaces, {
|
|
53
|
-
root,
|
|
54
|
-
force: opts.force,
|
|
55
|
-
dryRun: opts.dryRun,
|
|
56
|
-
reportPath: opts.reportPath,
|
|
57
|
-
localValues,
|
|
58
|
-
});
|
|
59
|
-
// Pull translations back to disk after a successful push.
|
|
60
|
-
// Skip when dry-running — there's nothing new to pull yet.
|
|
61
|
-
if (!opts.dryRun) {
|
|
62
|
-
await pullTranslations(config, {
|
|
63
|
-
outputDir: opts.outputDir,
|
|
64
|
-
force: opts.force,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Flatten a nested object to dot-notation keys.
|
|
70
|
-
* e.g. { button: { save: "Save" } } → { "button.save": "Save" }
|
|
71
|
-
*/
|
|
72
|
-
function flattenObject(obj, prefix = '') {
|
|
73
|
-
const result = {};
|
|
74
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
75
|
-
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
76
|
-
if (typeof value === 'string') {
|
|
77
|
-
result[fullKey] = value;
|
|
78
|
-
}
|
|
79
|
-
else if (typeof value === 'object' && value !== null) {
|
|
80
|
-
Object.assign(result, flattenObject(value, fullKey));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Read all `{locale}.json` files from outputDir and return a nested map:
|
|
87
|
-
* namespace → translationKey → locale → value
|
|
88
|
-
*
|
|
89
|
-
* Local JSON files use the nested format written by `pull`:
|
|
90
|
-
* { namespace: { "dot.notation.key": "value" } }
|
|
91
|
-
*/
|
|
92
|
-
function readLocalValues(outputDir) {
|
|
93
|
-
const result = {};
|
|
94
|
-
if (!fs.existsSync(outputDir))
|
|
95
|
-
return result;
|
|
96
|
-
let files;
|
|
97
|
-
try {
|
|
98
|
-
files = fs
|
|
99
|
-
.readdirSync(outputDir)
|
|
100
|
-
.filter(f => f.endsWith('.json') && f !== '.last-pulled');
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
for (const file of files) {
|
|
106
|
-
const locale = file.replace('.json', '');
|
|
107
|
-
try {
|
|
108
|
-
const raw = fs.readFileSync(path.join(outputDir, file), 'utf-8');
|
|
109
|
-
const content = JSON.parse(raw);
|
|
110
|
-
for (const [namespace, keys] of Object.entries(content)) {
|
|
111
|
-
if (typeof keys !== 'object' || keys === null)
|
|
112
|
-
continue;
|
|
113
|
-
const flat = flattenObject(keys);
|
|
114
|
-
if (!result[namespace])
|
|
115
|
-
result[namespace] = {};
|
|
116
|
-
for (const [key, value] of Object.entries(flat)) {
|
|
117
|
-
if (!value.trim())
|
|
118
|
-
continue;
|
|
119
|
-
if (!result[namespace][key])
|
|
120
|
-
result[namespace][key] = {};
|
|
121
|
-
result[namespace][key][locale] = value;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
// Skip malformed files silently
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=sync.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,WAAW,EAAoB,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EACH,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,kBAAkB,CAAC;AAa1B;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CACzB,IAAY,EACZ,MAAc,EACd,QAAqB,EACrB,IAAwB;IAExB,OAAO,CAAC,GAAG,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