@funnelsgrove/cli 0.1.233 → 0.1.237
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 +4 -2
- package/dist/cli.js +1 -1
- package/dist/localeContentSource.d.ts +13 -0
- package/dist/localeContentSource.js +117 -0
- package/dist/localeFilePlan.d.ts +4 -0
- package/dist/localeFilePlan.js +63 -0
- package/dist/localeModuleEdits.d.ts +19 -0
- package/dist/localeModuleEdits.js +97 -0
- package/dist/locales.d.ts +1 -1
- package/dist/locales.js +59 -93
- package/funnel-contract-compatibility.json +35 -35
- package/package.json +1 -1
- package/template_docs/.funnelsgrove-docs.json +4 -4
- package/template_docs/docs/funnelsgrove/contracts/content-answers.md +33 -14
- package/template_docs/docs/funnelsgrove/migrations/step-contract-v3.md +1 -1
- package/template_docs/funnel-docs.config.json +1 -1
- package/template_scaffold/.funnelsgrove-docs.json +4 -4
- package/template_scaffold/.funnelsgrove-scaffold.json +8 -8
- package/template_scaffold/docs/funnelsgrove/contracts/content-answers.md +33 -14
- package/template_scaffold/docs/funnelsgrove/migrations/step-contract-v3.md +1 -1
- package/template_scaffold/funnel-docs.config.json +1 -1
- package/template_scaffold/src/steps/content/runtime.content.ts +1 -1
- package/template_scaffold/src/steps/content/subscription-dashboard.content.ts +1 -1
package/README.md
CHANGED
|
@@ -154,8 +154,10 @@ Use `--config` or `FUNNELSGROVE_CONFIG` to keep test credentials separate from t
|
|
|
154
154
|
### Add a content locale
|
|
155
155
|
|
|
156
156
|
Run `fgrove locales add ru --dir ./my-funnel` to copy every default content
|
|
157
|
-
object into
|
|
158
|
-
|
|
157
|
+
object into `src/localization/ru/`, preserving its path relative to `src/`.
|
|
158
|
+
Original content stays in place; translated files import its structural type.
|
|
159
|
+
Repeat runs preserve translations, add missing exports and repair registrations.
|
|
160
|
+
Translate the new content, run `npx tsc --noEmit`, review `?locale=ru` and the live builder Preview language
|
|
159
161
|
selector, then sync and publish through the normal workflow. Run `fgrove docs`
|
|
160
162
|
for the full localization guide. The funnel must use a runtime release supporting
|
|
161
163
|
URL locale selection; this command does not upgrade dependencies.
|
package/dist/cli.js
CHANGED
|
@@ -2984,7 +2984,7 @@ addExamples(githubCommand
|
|
|
2984
2984
|
program.command('locales')
|
|
2985
2985
|
.description('Manage local funnel content languages')
|
|
2986
2986
|
.command('add <locale>')
|
|
2987
|
-
.description('
|
|
2987
|
+
.description('Create or complete typed localization files without translating')
|
|
2988
2988
|
.option('--dir <path>', 'Local funnel directory', '.')
|
|
2989
2989
|
.action(async (locale, options) => {
|
|
2990
2990
|
const result = await addFunnelLocale(path.resolve(options.dir), locale);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export declare const modulePath: (from: string, to: string) => string;
|
|
3
|
+
export declare function property(object: ts.ObjectLiteralExpression, name: string): ts.PropertyAssignment | undefined;
|
|
4
|
+
export type ContentDefinition = {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
defaultLocale: string;
|
|
8
|
+
map: ts.ObjectLiteralExpression;
|
|
9
|
+
};
|
|
10
|
+
export declare function readContentDefinitions(parsed: ts.SourceFile): ContentDefinition[];
|
|
11
|
+
/** Copies authored expressions, redirecting same-file inheritance to the translated export. */
|
|
12
|
+
export declare function translatedExpression(value: ts.Expression, parsed: ts.SourceFile, definitions: ContentDefinition[], locale: string, existingBindings?: ReadonlyMap<string, string | null>): string;
|
|
13
|
+
export declare function contentImports(parsed: ts.SourceFile, destination: string, payload: string): string[];
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { selectImport } from './localeModuleEdits.js';
|
|
4
|
+
export const modulePath = (from, to) => {
|
|
5
|
+
const relative = path.relative(path.dirname(from), to).split(path.sep).join('/').replace(/\.ts$/, '');
|
|
6
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
7
|
+
};
|
|
8
|
+
export function property(object, name) {
|
|
9
|
+
return object.properties.find((node) => ts.isPropertyAssignment(node) && (ts.isIdentifier(node.name) || ts.isStringLiteral(node.name)) && node.name.text === name);
|
|
10
|
+
}
|
|
11
|
+
export function readContentDefinitions(parsed) {
|
|
12
|
+
const definitions = [];
|
|
13
|
+
for (const statement of parsed.statements) {
|
|
14
|
+
if (!ts.isVariableStatement(statement))
|
|
15
|
+
continue;
|
|
16
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
17
|
+
let expression = declaration.initializer;
|
|
18
|
+
let type = declaration.type;
|
|
19
|
+
while (expression && (ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isParenthesizedExpression(expression))) {
|
|
20
|
+
if (!ts.isParenthesizedExpression(expression) && ts.isTypeReferenceNode(expression.type) && expression.type.typeArguments?.length)
|
|
21
|
+
type = expression.type;
|
|
22
|
+
expression = expression.expression;
|
|
23
|
+
}
|
|
24
|
+
if (!expression || !ts.isObjectLiteralExpression(expression))
|
|
25
|
+
continue;
|
|
26
|
+
const base = property(expression, 'defaultLocale');
|
|
27
|
+
const locales = property(expression, 'locales');
|
|
28
|
+
if (!base || !locales)
|
|
29
|
+
continue;
|
|
30
|
+
if (!ts.isStringLiteral(base.initializer) || !ts.isObjectLiteralExpression(locales.initializer))
|
|
31
|
+
throw new Error('defaultLocale and locales must be literals.');
|
|
32
|
+
if (locales.initializer.properties.some((item) => !ts.isPropertyAssignment(item) || !(ts.isIdentifier(item.name) || ts.isStringLiteral(item.name))))
|
|
33
|
+
throw new Error('locale entries must be explicit properties, without spreads or computed names.');
|
|
34
|
+
const contentType = type && ts.isTypeReferenceNode(type) && type.typeArguments?.[0];
|
|
35
|
+
if (!ts.isIdentifier(declaration.name) || !contentType || !ts.isTypeReferenceNode(contentType) || !ts.isIdentifier(contentType.typeName))
|
|
36
|
+
throw new Error('Declare a named content type and use satisfies LocalizedStepContent<YourContentType>.');
|
|
37
|
+
if (contentType.typeArguments?.length)
|
|
38
|
+
throw new Error('Use a named non-generic content type; generic content types are not supported by locale copying.');
|
|
39
|
+
const typeName = contentType.typeName.text;
|
|
40
|
+
const owner = parsed.statements.find((item) => (ts.isTypeAliasDeclaration(item) || ts.isInterfaceDeclaration(item)) && item.name.text === typeName);
|
|
41
|
+
if (!owner)
|
|
42
|
+
throw new Error(`Declare ${typeName} in this original content file so translations can import its structure.`);
|
|
43
|
+
definitions.push({ name: declaration.name.text, type: typeName, defaultLocale: base.initializer.text, map: locales.initializer });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!definitions.length)
|
|
47
|
+
throw new Error('No localized content definition found.');
|
|
48
|
+
return definitions;
|
|
49
|
+
}
|
|
50
|
+
/** Copies authored expressions, redirecting same-file inheritance to the translated export. */
|
|
51
|
+
export function translatedExpression(value, parsed, definitions, locale, existingBindings = new Map()) {
|
|
52
|
+
const edits = [];
|
|
53
|
+
const options = { noLib: true, noResolve: true };
|
|
54
|
+
const host = ts.createCompilerHost(options);
|
|
55
|
+
host.getSourceFile = (name) => path.resolve(name) === path.resolve(parsed.fileName) ? parsed : undefined;
|
|
56
|
+
const checker = ts.createProgram([parsed.fileName], options, host).getTypeChecker();
|
|
57
|
+
const visit = (node) => {
|
|
58
|
+
if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
|
|
59
|
+
const map = node.expression;
|
|
60
|
+
const key = ts.isPropertyAccessExpression(node) ? node.name.text : ts.isStringLiteral(node.argumentExpression) ? node.argumentExpression.text : null;
|
|
61
|
+
if (ts.isPropertyAccessExpression(map) && map.name.text === 'locales' && ts.isIdentifier(map.expression)) {
|
|
62
|
+
const definition = definitions.find((item) => item.name === map.expression.getText(parsed));
|
|
63
|
+
if (definition && key) {
|
|
64
|
+
if (key !== definition.defaultLocale && key !== locale) {
|
|
65
|
+
throw new Error(`Cannot copy ${node.getText(parsed)}: inheritance must use the default or requested locale. Make this copy explicit before retrying.`);
|
|
66
|
+
}
|
|
67
|
+
const binding = existingBindings.get(definition.name);
|
|
68
|
+
if (binding === null)
|
|
69
|
+
throw new Error(`Import the re-exported ${definition.name} into the translation before adding inherited content.`);
|
|
70
|
+
edits.push({ start: node.getStart(parsed), end: node.end, text: binding ?? definition.name });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (ts.isIdentifier(node)
|
|
76
|
+
&& !(ts.isPropertyAssignment(node.parent) && node.parent.name === node)
|
|
77
|
+
&& !(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node)) {
|
|
78
|
+
const symbol = ts.isShorthandPropertyAssignment(node.parent)
|
|
79
|
+
? checker.getShorthandAssignmentValueSymbol(node.parent)
|
|
80
|
+
: checker.getSymbolAtLocation(node);
|
|
81
|
+
const uncopied = symbol?.declarations?.some((declaration) => {
|
|
82
|
+
if (declaration.getSourceFile() !== parsed || declaration.pos >= value.pos && declaration.end <= value.end)
|
|
83
|
+
return false;
|
|
84
|
+
let parent = declaration;
|
|
85
|
+
while (parent && parent !== parsed) {
|
|
86
|
+
if (ts.isImportDeclaration(parent))
|
|
87
|
+
return false;
|
|
88
|
+
parent = parent.parent;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
});
|
|
92
|
+
if (uncopied)
|
|
93
|
+
throw new Error(`Content references local helper ${node.text}. Inline it in the content object or move it into an independent imported module before adding a locale.`);
|
|
94
|
+
}
|
|
95
|
+
ts.forEachChild(node, visit);
|
|
96
|
+
};
|
|
97
|
+
visit(value);
|
|
98
|
+
let result = value.getText(parsed);
|
|
99
|
+
const offset = value.getStart(parsed);
|
|
100
|
+
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
101
|
+
result = result.slice(0, edit.start - offset) + edit.text + result.slice(edit.end - offset);
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
export function contentImports(parsed, destination, payload) {
|
|
105
|
+
const identifiers = new Set();
|
|
106
|
+
const visit = (node) => { if (ts.isIdentifier(node))
|
|
107
|
+
identifiers.add(node.text); ts.forEachChild(node, visit); };
|
|
108
|
+
visit(ts.createSourceFile('content.ts', payload, ts.ScriptTarget.Latest, true));
|
|
109
|
+
return parsed.statements.flatMap((statement) => {
|
|
110
|
+
if (!ts.isImportDeclaration(statement) || !statement.importClause || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
111
|
+
return [];
|
|
112
|
+
const specifier = statement.moduleSpecifier.text;
|
|
113
|
+
const target = specifier.startsWith('.') ? modulePath(destination, path.resolve(path.dirname(parsed.fileName), specifier)) : specifier;
|
|
114
|
+
const selected = selectImport(statement, parsed, (name) => identifiers.has(name), ts.factory.createStringLiteral(target));
|
|
115
|
+
return selected ? [selected] : [];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { contentImports, modulePath, property, readContentDefinitions, translatedExpression } from './localeContentSource.js';
|
|
3
|
+
import { appendTranslation, applySourceEdits, exportedBindings, importedNames, insertImports } from './localeModuleEdits.js';
|
|
4
|
+
export function planLocaleFile(file, source, destination, translated, locale) {
|
|
5
|
+
const parsed = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true);
|
|
6
|
+
const definitions = readContentDefinitions(parsed);
|
|
7
|
+
const canonical = (tag) => Intl.getCanonicalLocales(tag)[0];
|
|
8
|
+
if (new Set(definitions.map((item) => canonical(item.defaultLocale))).size !== 1) {
|
|
9
|
+
throw new Error('Definitions in one content file must use the same defaultLocale.');
|
|
10
|
+
}
|
|
11
|
+
if (canonical(definitions[0].defaultLocale) === locale)
|
|
12
|
+
return { source, translated };
|
|
13
|
+
const translatedModule = ts.createSourceFile(destination, translated ?? '', ts.ScriptTarget.Latest, true);
|
|
14
|
+
const present = exportedBindings(translatedModule);
|
|
15
|
+
const sourceImports = importedNames(parsed);
|
|
16
|
+
const registrationPath = modulePath(file, destination);
|
|
17
|
+
const edits = [];
|
|
18
|
+
const exports = [];
|
|
19
|
+
const imports = [];
|
|
20
|
+
const newTypes = new Set();
|
|
21
|
+
const typeNames = new Set(definitions.map((item) => item.type));
|
|
22
|
+
for (const definition of definitions) {
|
|
23
|
+
const previous = definition.map.properties.find((item) => ts.isPropertyAssignment(item)
|
|
24
|
+
&& canonical(item.name.text) === locale);
|
|
25
|
+
if (!present.has(definition.name)) {
|
|
26
|
+
const value = (previous ?? property(definition.map, definition.defaultLocale))?.initializer;
|
|
27
|
+
if (!value || !ts.isObjectLiteralExpression(value)) {
|
|
28
|
+
throw new Error(`Restore the missing translation for ${definition.name} or provide inline object content before retrying.`);
|
|
29
|
+
}
|
|
30
|
+
exports.push(`export const ${definition.name}: ${definition.type} = ${translatedExpression(value, parsed, definitions, locale, present)};`);
|
|
31
|
+
newTypes.add(definition.type);
|
|
32
|
+
}
|
|
33
|
+
const registered = [...sourceImports].find(([, value]) => value.module === registrationPath && value.name === definition.name && !value.typeOnly)?.[0];
|
|
34
|
+
if (registered && previous && ts.isIdentifier(previous.initializer) && previous.initializer.text === registered)
|
|
35
|
+
continue;
|
|
36
|
+
let alias = registered ?? `${definition.name}_${locale.replace(/-/g, '_')}`;
|
|
37
|
+
if (!registered) {
|
|
38
|
+
const initial = alias;
|
|
39
|
+
let suffix = 1;
|
|
40
|
+
while (source.includes(alias))
|
|
41
|
+
alias = `${initial}_${suffix++}`;
|
|
42
|
+
imports.push(`import { ${definition.name} as ${alias} } from ${JSON.stringify(registrationPath)};`);
|
|
43
|
+
}
|
|
44
|
+
if (previous)
|
|
45
|
+
edits.push({ start: previous.initializer.getStart(parsed), end: previous.initializer.end, text: alias });
|
|
46
|
+
else
|
|
47
|
+
edits.push({ start: definition.map.end - 1, end: definition.map.end - 1, text: `${definition.map.properties.hasTrailingComma ? '' : ','}\n ${JSON.stringify(locale)}: ${alias},\n ` });
|
|
48
|
+
}
|
|
49
|
+
for (const statement of parsed.statements) {
|
|
50
|
+
if ((ts.isTypeAliasDeclaration(statement) || ts.isInterfaceDeclaration(statement)) && typeNames.has(statement.name.text)
|
|
51
|
+
&& !statement.modifiers?.some((item) => item.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
52
|
+
edits.push({ start: statement.getStart(parsed), end: statement.getStart(parsed), text: 'export ' });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const payload = exports.join('\n\n');
|
|
56
|
+
const dependencies = exports.length ? contentImports(parsed, destination, payload) : [];
|
|
57
|
+
if (newTypes.size)
|
|
58
|
+
dependencies.unshift(`import type { ${[...newTypes].join(', ')} } from ${JSON.stringify(modulePath(destination, file))};`);
|
|
59
|
+
return {
|
|
60
|
+
source: insertImports(applySourceEdits(source, edits), imports),
|
|
61
|
+
translated: appendTranslation(translated ?? '', dependencies, exports),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export type SourceEdit = {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
text: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function applySourceEdits(source: string, edits: SourceEdit[]): string;
|
|
8
|
+
/** Keep module directives and leading comments before generated imports. */
|
|
9
|
+
export declare function insertImports(source: string, imports: string[]): string;
|
|
10
|
+
export declare function importedNames(parsed: ts.SourceFile): Map<string, {
|
|
11
|
+
module: string;
|
|
12
|
+
name: string;
|
|
13
|
+
typeOnly: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function exportedBindings(parsed: ts.SourceFile): Map<string, string | null>;
|
|
16
|
+
/** Print the selected bindings, preserving import kinds and attributes. */
|
|
17
|
+
export declare function selectImport(statement: ts.ImportDeclaration, parsed: ts.SourceFile, keep: (name: string) => boolean, module?: ts.Expression): string | null;
|
|
18
|
+
/** Reuse matching imports when adding definitions to an already translated module. */
|
|
19
|
+
export declare function appendTranslation(source: string, imports: string[], definitions: string[]): string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export function applySourceEdits(source, edits) {
|
|
3
|
+
return [...edits].sort((a, b) => b.start - a.start).reduce((result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end), source);
|
|
4
|
+
}
|
|
5
|
+
/** Keep module directives and leading comments before generated imports. */
|
|
6
|
+
export function insertImports(source, imports) {
|
|
7
|
+
if (!imports.length)
|
|
8
|
+
return source;
|
|
9
|
+
const parsed = ts.createSourceFile('content.ts', source, ts.ScriptTarget.Latest, true);
|
|
10
|
+
const first = parsed.statements.find((statement) => !ts.isExpressionStatement(statement) || !ts.isStringLiteral(statement.expression));
|
|
11
|
+
const offset = first?.getStart(parsed) ?? source.length;
|
|
12
|
+
return source.slice(0, offset) + imports.join('\n') + '\n' + source.slice(offset);
|
|
13
|
+
}
|
|
14
|
+
export function importedNames(parsed) {
|
|
15
|
+
const names = new Map();
|
|
16
|
+
for (const statement of parsed.statements) {
|
|
17
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
18
|
+
continue;
|
|
19
|
+
const clause = statement.importClause;
|
|
20
|
+
if (!clause)
|
|
21
|
+
continue;
|
|
22
|
+
const module = statement.moduleSpecifier.text;
|
|
23
|
+
if (clause.name)
|
|
24
|
+
names.set(clause.name.text, { module, name: 'default', typeOnly: clause.isTypeOnly });
|
|
25
|
+
const bindings = clause.namedBindings;
|
|
26
|
+
if (bindings && ts.isNamespaceImport(bindings))
|
|
27
|
+
names.set(bindings.name.text, { module, name: '*', typeOnly: clause.isTypeOnly });
|
|
28
|
+
if (bindings && ts.isNamedImports(bindings)) {
|
|
29
|
+
for (const item of bindings.elements)
|
|
30
|
+
names.set(item.name.text, { module, name: (item.propertyName ?? item.name).text, typeOnly: clause.isTypeOnly || item.isTypeOnly });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return names;
|
|
34
|
+
}
|
|
35
|
+
export function exportedBindings(parsed) {
|
|
36
|
+
const names = new Map();
|
|
37
|
+
for (const statement of parsed.statements) {
|
|
38
|
+
if (ts.isVariableStatement(statement)
|
|
39
|
+
&& statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
40
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
41
|
+
if (ts.isIdentifier(declaration.name))
|
|
42
|
+
names.set(declaration.name.text, declaration.name.text);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (ts.isExportDeclaration(statement) && !statement.isTypeOnly
|
|
46
|
+
&& statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
47
|
+
for (const item of statement.exportClause.elements) {
|
|
48
|
+
if (!item.isTypeOnly)
|
|
49
|
+
names.set(item.name.text, statement.moduleSpecifier ? null : (item.propertyName ?? item.name).text);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return names;
|
|
54
|
+
}
|
|
55
|
+
/** Print the selected bindings, preserving import kinds and attributes. */
|
|
56
|
+
export function selectImport(statement, parsed, keep, module = statement.moduleSpecifier) {
|
|
57
|
+
const clause = statement.importClause;
|
|
58
|
+
if (!clause)
|
|
59
|
+
return null;
|
|
60
|
+
const name = clause.name && keep(clause.name.text) ? clause.name : undefined;
|
|
61
|
+
const bindings = clause.namedBindings;
|
|
62
|
+
const named = bindings && (ts.isNamespaceImport(bindings)
|
|
63
|
+
? keep(bindings.name.text) ? bindings : undefined
|
|
64
|
+
: ts.factory.createNamedImports(bindings.elements.filter((item) => keep(item.name.text))));
|
|
65
|
+
if (!name && (!named || ts.isNamedImports(named) && !named.elements.length))
|
|
66
|
+
return null;
|
|
67
|
+
const updated = ts.factory.updateImportDeclaration(statement, statement.modifiers, ts.factory.updateImportClause(clause, clause.isTypeOnly, name, named), module, statement.attributes);
|
|
68
|
+
return ts.createPrinter().printNode(ts.EmitHint.Unspecified, updated, parsed);
|
|
69
|
+
}
|
|
70
|
+
/** Reuse matching imports when adding definitions to an already translated module. */
|
|
71
|
+
export function appendTranslation(source, imports, definitions) {
|
|
72
|
+
const parsed = ts.createSourceFile('content.ts', source, ts.ScriptTarget.Latest, true);
|
|
73
|
+
const existing = importedNames(parsed);
|
|
74
|
+
const additions = [];
|
|
75
|
+
for (const text of imports) {
|
|
76
|
+
const imported = ts.createSourceFile('import.ts', text, ts.ScriptTarget.Latest, true);
|
|
77
|
+
const statement = imported.statements[0];
|
|
78
|
+
const names = importedNames(imported);
|
|
79
|
+
const needed = (name) => {
|
|
80
|
+
const previous = existing.get(name);
|
|
81
|
+
const next = names.get(name);
|
|
82
|
+
if (!previous) {
|
|
83
|
+
existing.set(name, next);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (previous.module !== next.module || previous.name !== next.name || previous.typeOnly !== next.typeOnly) {
|
|
87
|
+
throw new Error(`Translation import ${name} conflicts with an existing import. Resolve the import before retrying.`);
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
};
|
|
91
|
+
const addition = selectImport(statement, imported, needed);
|
|
92
|
+
if (addition)
|
|
93
|
+
additions.push(addition);
|
|
94
|
+
}
|
|
95
|
+
const updated = insertImports(source, additions);
|
|
96
|
+
return definitions.length ? `${updated}${updated.endsWith('\n') || !updated ? '' : '\n'}\n${definitions.join('\n\n')}\n` : updated;
|
|
97
|
+
}
|
package/dist/locales.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Plan every source change before writing; original content keeps its existing location. */
|
|
2
2
|
export declare function addFunnelLocale(directory: string, requestedLocale: string): Promise<{
|
|
3
3
|
locale: string;
|
|
4
4
|
added: string[];
|
package/dist/locales.js
CHANGED
|
@@ -1,126 +1,92 @@
|
|
|
1
|
-
import { readFile, readdir, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { lstat, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import
|
|
3
|
+
import { planLocaleFile } from './localeFilePlan.js';
|
|
4
4
|
function canonicalLocale(value) {
|
|
5
5
|
try {
|
|
6
6
|
const [locale] = Intl.getCanonicalLocales(value);
|
|
7
7
|
if (locale)
|
|
8
8
|
return locale;
|
|
9
9
|
}
|
|
10
|
-
catch { /*
|
|
10
|
+
catch { /* Invalid tag. */ }
|
|
11
11
|
throw new Error(`Invalid locale: ${value}. Use a language tag such as ru or pt-BR.`);
|
|
12
12
|
}
|
|
13
|
-
async function contentFiles(directory) {
|
|
14
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
13
|
+
async function contentFiles(directory, localizationRoot) {
|
|
15
14
|
const files = [];
|
|
16
|
-
for (const entry of
|
|
15
|
+
for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
17
16
|
const file = path.join(directory, entry.name);
|
|
17
|
+
if (file === localizationRoot)
|
|
18
|
+
continue;
|
|
18
19
|
if (entry.isDirectory())
|
|
19
|
-
files.push(...await contentFiles(file));
|
|
20
|
+
files.push(...await contentFiles(file, localizationRoot));
|
|
20
21
|
else if (entry.isFile() && entry.name.endsWith('.content.ts'))
|
|
21
22
|
files.push(file);
|
|
22
23
|
}
|
|
23
24
|
return files;
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
async function exists(file) {
|
|
27
|
+
try {
|
|
28
|
+
await lstat(file);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error.code === 'ENOENT')
|
|
33
|
+
return false;
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
for (const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
while (value && (ts.isAsExpression(value) || ts.isSatisfiesExpression(value) || ts.isParenthesizedExpression(value)))
|
|
37
|
-
value = value.expression;
|
|
38
|
-
if (!value || !ts.isObjectLiteralExpression(value) || !ts.isIdentifier(declaration.name))
|
|
39
|
-
continue;
|
|
40
|
-
const defaultLocale = property(value, 'defaultLocale')?.initializer;
|
|
41
|
-
if (defaultLocale && ts.isStringLiteral(defaultLocale) && property(value, 'locales')) {
|
|
42
|
-
localDefinitions.set(declaration.name.text, defaultLocale.text);
|
|
43
|
-
}
|
|
37
|
+
async function assertDestinationPath(root, file) {
|
|
38
|
+
let current = root;
|
|
39
|
+
for (const part of path.relative(root, file).split(path.sep)) {
|
|
40
|
+
current = path.join(current, part);
|
|
41
|
+
try {
|
|
42
|
+
if ((await lstat(current)).isSymbolicLink())
|
|
43
|
+
throw new Error(`Localization destination contains a symbolic link: ${current}`);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const key = ts.isPropertyAccessExpression(node) ? node.name.text
|
|
49
|
-
: ts.isElementAccessExpression(node) && ts.isStringLiteral(node.argumentExpression) ? node.argumentExpression.text : null;
|
|
50
|
-
if (key && (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))) {
|
|
51
|
-
const map = node.expression;
|
|
52
|
-
if (ts.isPropertyAccessExpression(map) && map.name.text === 'locales' && ts.isIdentifier(map.expression)
|
|
53
|
-
&& localDefinitions.get(map.expression.text) === key) {
|
|
54
|
-
replacements.push({ start: node.getStart(parsed), end: node.end, text: `${map.getText(parsed)}[${JSON.stringify(locale)}]` });
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code !== 'ENOENT')
|
|
47
|
+
throw error;
|
|
57
48
|
}
|
|
58
|
-
ts.forEachChild(node, visit);
|
|
59
|
-
};
|
|
60
|
-
visit(content);
|
|
61
|
-
const offset = content.getStart(parsed);
|
|
62
|
-
let source = content.getText(parsed);
|
|
63
|
-
for (const replacement of replacements.sort((a, b) => b.start - a.start)) {
|
|
64
|
-
source = source.slice(0, replacement.start - offset) + replacement.text + source.slice(replacement.end - offset);
|
|
65
49
|
}
|
|
66
|
-
return source;
|
|
67
50
|
}
|
|
68
|
-
/**
|
|
51
|
+
/** Plan every source change before writing; original content keeps its existing location. */
|
|
69
52
|
export async function addFunnelLocale(directory, requestedLocale) {
|
|
53
|
+
directory = path.resolve(directory);
|
|
70
54
|
const locale = canonicalLocale(requestedLocale);
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const files = await contentFiles(
|
|
55
|
+
const sourceRoot = path.join(directory, 'src');
|
|
56
|
+
const localizationRoot = path.join(sourceRoot, 'localization');
|
|
57
|
+
const files = await contentFiles(sourceRoot, localizationRoot);
|
|
74
58
|
if (!files.length)
|
|
75
59
|
throw new Error('No src/**/*.content.ts files found. Move translatable copy into content definitions first.');
|
|
60
|
+
const edits = [];
|
|
61
|
+
const added = [];
|
|
62
|
+
const existing = [];
|
|
76
63
|
for (const file of files) {
|
|
77
|
-
const source = await readFile(file, 'utf8');
|
|
78
|
-
const parsed = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
79
64
|
const relative = path.relative(directory, file).split(path.sep).join('/');
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
const map = locales.initializer;
|
|
92
|
-
if (map.properties.some((item) => !ts.isPropertyAssignment(item) ||
|
|
93
|
-
!(ts.isIdentifier(item.name) || ts.isStringLiteral(item.name)))) {
|
|
94
|
-
throw new Error(`${relative}: locale entries must be explicit properties, without spreads or computed names.`);
|
|
95
|
-
}
|
|
96
|
-
const keys = map.properties;
|
|
97
|
-
if (keys.some((item) => canonicalLocale(item.name.text) === locale))
|
|
98
|
-
return;
|
|
99
|
-
const base = property(map, defaultLocale.initializer.text);
|
|
100
|
-
if (!base || !ts.isObjectLiteralExpression(base.initializer)) {
|
|
101
|
-
throw new Error(`${relative}: default locale content must be an object literal.`);
|
|
102
|
-
}
|
|
103
|
-
const separator = map.properties.hasTrailingComma ? '' : ',';
|
|
104
|
-
insertions.push({ offset: map.end - 1, text: `${separator}\n ${JSON.stringify(locale)}: ${copyLocaleContent(base.initializer, parsed, locale)},\n ` });
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
65
|
+
try {
|
|
66
|
+
const source = await readFile(file, 'utf8');
|
|
67
|
+
const destination = path.join(localizationRoot, locale, path.relative(sourceRoot, file));
|
|
68
|
+
const localizedPath = path.relative(directory, destination).split(path.sep).join('/');
|
|
69
|
+
await assertDestinationPath(sourceRoot, destination);
|
|
70
|
+
const translated = await exists(destination) ? await readFile(destination, 'utf8') : null;
|
|
71
|
+
const plan = planLocaleFile(file, source, destination, translated, locale);
|
|
72
|
+
if (plan.source === source && plan.translated === translated) {
|
|
73
|
+
existing.push(translated === null ? relative : localizedPath);
|
|
74
|
+
continue;
|
|
107
75
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
visit(parsed);
|
|
111
|
-
if (!definitions)
|
|
112
|
-
throw new Error(`${relative}: no localized content definition found.`);
|
|
113
|
-
if (!insertions.length)
|
|
114
|
-
existing.push(relative);
|
|
115
|
-
else {
|
|
116
|
-
let nextSource = source;
|
|
117
|
-
for (const insertion of insertions.sort((a, b) => b.offset - a.offset)) {
|
|
118
|
-
nextSource = nextSource.slice(0, insertion.offset) + insertion.text + nextSource.slice(insertion.offset);
|
|
76
|
+
if (plan.translated !== translated && plan.translated !== null) {
|
|
77
|
+
edits.push({ file: destination, source: plan.translated, create: translated === null });
|
|
119
78
|
}
|
|
120
|
-
|
|
79
|
+
if (plan.source !== source)
|
|
80
|
+
edits.push({ file, source: plan.source });
|
|
81
|
+
added.push(localizedPath);
|
|
121
82
|
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new Error(`${relative}: ${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const edit of edits) {
|
|
88
|
+
await mkdir(path.dirname(edit.file), { recursive: true });
|
|
89
|
+
await writeFile(edit.file, edit.source, edit.create ? { flag: 'wx' } : undefined);
|
|
122
90
|
}
|
|
123
|
-
|
|
124
|
-
await writeFile(edit.file, edit.source);
|
|
125
|
-
return { locale, added: edits.map(({ file }) => path.relative(directory, file).split(path.sep).join('/')), existing };
|
|
91
|
+
return { locale, added, existing };
|
|
126
92
|
}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
"minimumCliVersion": "0.1.20",
|
|
5
5
|
"entries": [
|
|
6
6
|
{
|
|
7
|
-
"repositoryCliVersion": "0.1.
|
|
7
|
+
"repositoryCliVersion": "0.1.237",
|
|
8
8
|
"manifest": {
|
|
9
9
|
"schemaVersion": 1,
|
|
10
|
-
"bundleVersion": "2.0.
|
|
10
|
+
"bundleVersion": "2.0.229",
|
|
11
11
|
"stepContractVersion": 3,
|
|
12
12
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
13
13
|
"managedFiles": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
"path": "docs/funnelsgrove/contracts/content-answers.md",
|
|
32
|
-
"sha256": "
|
|
32
|
+
"sha256": "17c8a91800ec1d2247b1e0fd12cc80fbfce162297aa928432cc0a574acd9fc06"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
"path": "docs/funnelsgrove/contracts/flow-routing.md",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
48
|
-
"sha256": "
|
|
48
|
+
"sha256": "eec04cc76ab67b9ba06ff1b32c68c657d86488883942c70c5a8ce526d05c4c20"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -145,16 +145,16 @@
|
|
|
145
145
|
},
|
|
146
146
|
{
|
|
147
147
|
"path": "funnel-docs.config.json",
|
|
148
|
-
"sha256": "
|
|
148
|
+
"sha256": "6018305fe5a4b85b9411dc53e1d7169e9d0a3670f422b046ab24759f66392c98"
|
|
149
149
|
}
|
|
150
150
|
]
|
|
151
151
|
}
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
|
-
"repositoryCliVersion": "0.1.
|
|
154
|
+
"repositoryCliVersion": "0.1.236",
|
|
155
155
|
"manifest": {
|
|
156
156
|
"schemaVersion": 1,
|
|
157
|
-
"bundleVersion": "2.0.
|
|
157
|
+
"bundleVersion": "2.0.228",
|
|
158
158
|
"stepContractVersion": 3,
|
|
159
159
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
160
160
|
"managedFiles": [
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
},
|
|
193
193
|
{
|
|
194
194
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
195
|
-
"sha256": "
|
|
195
|
+
"sha256": "9c83f0df832c3279b39e7eec870ce48831ffbbca5a329f20e98a0c5f981fdb70"
|
|
196
196
|
},
|
|
197
197
|
{
|
|
198
198
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -292,22 +292,22 @@
|
|
|
292
292
|
},
|
|
293
293
|
{
|
|
294
294
|
"path": "funnel-docs.config.json",
|
|
295
|
-
"sha256": "
|
|
295
|
+
"sha256": "1ca7b4ab4b9bfebb726441adf8af784b7fc4405524b6ec0435382315e61e7a07"
|
|
296
296
|
}
|
|
297
297
|
]
|
|
298
298
|
}
|
|
299
299
|
},
|
|
300
300
|
{
|
|
301
|
-
"repositoryCliVersion": "0.1.
|
|
301
|
+
"repositoryCliVersion": "0.1.235",
|
|
302
302
|
"manifest": {
|
|
303
303
|
"schemaVersion": 1,
|
|
304
|
-
"bundleVersion": "2.0.
|
|
304
|
+
"bundleVersion": "2.0.227",
|
|
305
305
|
"stepContractVersion": 3,
|
|
306
306
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
307
307
|
"managedFiles": [
|
|
308
308
|
{
|
|
309
309
|
"path": "AGENTS.md",
|
|
310
|
-
"sha256": "
|
|
310
|
+
"sha256": "3860d21f4a3f9b0c25ca54f7a87762d801f14b82a181b4c0b941c57187908f99"
|
|
311
311
|
},
|
|
312
312
|
{
|
|
313
313
|
"path": "CLAUDE.md",
|
|
@@ -323,7 +323,7 @@
|
|
|
323
323
|
},
|
|
324
324
|
{
|
|
325
325
|
"path": "docs/funnelsgrove/contracts/content-answers.md",
|
|
326
|
-
"sha256": "
|
|
326
|
+
"sha256": "44686934b2a6837142a12e76f9fc84bd5181179bcd3bf82d636a8ad26b72ce01"
|
|
327
327
|
},
|
|
328
328
|
{
|
|
329
329
|
"path": "docs/funnelsgrove/contracts/flow-routing.md",
|
|
@@ -339,7 +339,7 @@
|
|
|
339
339
|
},
|
|
340
340
|
{
|
|
341
341
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
342
|
-
"sha256": "
|
|
342
|
+
"sha256": "b3cf273905125a0308291828e4f9ec39d6478cbcbe27396f1b1756686850bba6"
|
|
343
343
|
},
|
|
344
344
|
{
|
|
345
345
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -439,16 +439,16 @@
|
|
|
439
439
|
},
|
|
440
440
|
{
|
|
441
441
|
"path": "funnel-docs.config.json",
|
|
442
|
-
"sha256": "
|
|
442
|
+
"sha256": "a8289d598d0adb9bfb3f20ada3d20c3e175dafce4efcdf6a6e5ec2af6b29a625"
|
|
443
443
|
}
|
|
444
444
|
]
|
|
445
445
|
}
|
|
446
446
|
},
|
|
447
447
|
{
|
|
448
|
-
"repositoryCliVersion": "0.1.
|
|
448
|
+
"repositoryCliVersion": "0.1.234",
|
|
449
449
|
"manifest": {
|
|
450
450
|
"schemaVersion": 1,
|
|
451
|
-
"bundleVersion": "2.0.
|
|
451
|
+
"bundleVersion": "2.0.226",
|
|
452
452
|
"stepContractVersion": 3,
|
|
453
453
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
454
454
|
"managedFiles": [
|
|
@@ -486,7 +486,7 @@
|
|
|
486
486
|
},
|
|
487
487
|
{
|
|
488
488
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
489
|
-
"sha256": "
|
|
489
|
+
"sha256": "898f23a02a53cc70322fae87a715c0ffc4192a8d06dcdd1f4672af3a1d69e527"
|
|
490
490
|
},
|
|
491
491
|
{
|
|
492
492
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -586,22 +586,22 @@
|
|
|
586
586
|
},
|
|
587
587
|
{
|
|
588
588
|
"path": "funnel-docs.config.json",
|
|
589
|
-
"sha256": "
|
|
589
|
+
"sha256": "2c6634aec2abd46a30c6eecac138323396af8ca9550d2d91488c6a80613af179"
|
|
590
590
|
}
|
|
591
591
|
]
|
|
592
592
|
}
|
|
593
593
|
},
|
|
594
594
|
{
|
|
595
|
-
"repositoryCliVersion": "0.1.
|
|
595
|
+
"repositoryCliVersion": "0.1.233",
|
|
596
596
|
"manifest": {
|
|
597
597
|
"schemaVersion": 1,
|
|
598
|
-
"bundleVersion": "2.0.
|
|
598
|
+
"bundleVersion": "2.0.225",
|
|
599
599
|
"stepContractVersion": 3,
|
|
600
600
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
601
601
|
"managedFiles": [
|
|
602
602
|
{
|
|
603
603
|
"path": "AGENTS.md",
|
|
604
|
-
"sha256": "
|
|
604
|
+
"sha256": "3860d21f4a3f9b0c25ca54f7a87762d801f14b82a181b4c0b941c57187908f99"
|
|
605
605
|
},
|
|
606
606
|
{
|
|
607
607
|
"path": "CLAUDE.md",
|
|
@@ -617,7 +617,7 @@
|
|
|
617
617
|
},
|
|
618
618
|
{
|
|
619
619
|
"path": "docs/funnelsgrove/contracts/content-answers.md",
|
|
620
|
-
"sha256": "
|
|
620
|
+
"sha256": "44686934b2a6837142a12e76f9fc84bd5181179bcd3bf82d636a8ad26b72ce01"
|
|
621
621
|
},
|
|
622
622
|
{
|
|
623
623
|
"path": "docs/funnelsgrove/contracts/flow-routing.md",
|
|
@@ -633,7 +633,7 @@
|
|
|
633
633
|
},
|
|
634
634
|
{
|
|
635
635
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
636
|
-
"sha256": "
|
|
636
|
+
"sha256": "02e1409d391497b8860b5c2942bc07881853f53480daa4fb2972f561e8baa047"
|
|
637
637
|
},
|
|
638
638
|
{
|
|
639
639
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -733,22 +733,22 @@
|
|
|
733
733
|
},
|
|
734
734
|
{
|
|
735
735
|
"path": "funnel-docs.config.json",
|
|
736
|
-
"sha256": "
|
|
736
|
+
"sha256": "6767f2a0ee02bc43a4fd4b1b9c07e938099fac90976796636ebc66202050fe54"
|
|
737
737
|
}
|
|
738
738
|
]
|
|
739
739
|
}
|
|
740
740
|
},
|
|
741
741
|
{
|
|
742
|
-
"repositoryCliVersion": "0.1.
|
|
742
|
+
"repositoryCliVersion": "0.1.232",
|
|
743
743
|
"manifest": {
|
|
744
744
|
"schemaVersion": 1,
|
|
745
|
-
"bundleVersion": "2.0.
|
|
745
|
+
"bundleVersion": "2.0.224",
|
|
746
746
|
"stepContractVersion": 3,
|
|
747
747
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
748
748
|
"managedFiles": [
|
|
749
749
|
{
|
|
750
750
|
"path": "AGENTS.md",
|
|
751
|
-
"sha256": "
|
|
751
|
+
"sha256": "3860d21f4a3f9b0c25ca54f7a87762d801f14b82a181b4c0b941c57187908f99"
|
|
752
752
|
},
|
|
753
753
|
{
|
|
754
754
|
"path": "CLAUDE.md",
|
|
@@ -764,7 +764,7 @@
|
|
|
764
764
|
},
|
|
765
765
|
{
|
|
766
766
|
"path": "docs/funnelsgrove/contracts/content-answers.md",
|
|
767
|
-
"sha256": "
|
|
767
|
+
"sha256": "44686934b2a6837142a12e76f9fc84bd5181179bcd3bf82d636a8ad26b72ce01"
|
|
768
768
|
},
|
|
769
769
|
{
|
|
770
770
|
"path": "docs/funnelsgrove/contracts/flow-routing.md",
|
|
@@ -780,7 +780,7 @@
|
|
|
780
780
|
},
|
|
781
781
|
{
|
|
782
782
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
783
|
-
"sha256": "
|
|
783
|
+
"sha256": "cd4e0392bc88e2c24459a5132b8c7573bdb3e5a01aa7d9684139c30de39e4813"
|
|
784
784
|
},
|
|
785
785
|
{
|
|
786
786
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -880,16 +880,16 @@
|
|
|
880
880
|
},
|
|
881
881
|
{
|
|
882
882
|
"path": "funnel-docs.config.json",
|
|
883
|
-
"sha256": "
|
|
883
|
+
"sha256": "fd3117529acd5a83faf9ffb7bc004d5c1166ba783bcc57c2457ffc5e83c936f4"
|
|
884
884
|
}
|
|
885
885
|
]
|
|
886
886
|
}
|
|
887
887
|
},
|
|
888
888
|
{
|
|
889
|
-
"repositoryCliVersion": "0.1.
|
|
889
|
+
"repositoryCliVersion": "0.1.231",
|
|
890
890
|
"manifest": {
|
|
891
891
|
"schemaVersion": 1,
|
|
892
|
-
"bundleVersion": "2.0.
|
|
892
|
+
"bundleVersion": "2.0.223",
|
|
893
893
|
"stepContractVersion": 3,
|
|
894
894
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
895
895
|
"managedFiles": [
|
|
@@ -927,7 +927,7 @@
|
|
|
927
927
|
},
|
|
928
928
|
{
|
|
929
929
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
930
|
-
"sha256": "
|
|
930
|
+
"sha256": "b77101d16260357a891c26a6f0e6298f5763b3a8d76b38ba94378064a753e9f0"
|
|
931
931
|
},
|
|
932
932
|
{
|
|
933
933
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -1027,7 +1027,7 @@
|
|
|
1027
1027
|
},
|
|
1028
1028
|
{
|
|
1029
1029
|
"path": "funnel-docs.config.json",
|
|
1030
|
-
"sha256": "
|
|
1030
|
+
"sha256": "e111086760618c659a1f72b0e463bf2aa4c67ba9ebc1b4728c84e0d6b20b6510"
|
|
1031
1031
|
}
|
|
1032
1032
|
]
|
|
1033
1033
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"bundleVersion": "2.0.
|
|
3
|
+
"bundleVersion": "2.0.229",
|
|
4
4
|
"stepContractVersion": 3,
|
|
5
5
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
6
6
|
"managedFiles": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"path": "docs/funnelsgrove/contracts/content-answers.md",
|
|
25
|
-
"sha256": "
|
|
25
|
+
"sha256": "17c8a91800ec1d2247b1e0fd12cc80fbfce162297aa928432cc0a574acd9fc06"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"path": "docs/funnelsgrove/contracts/flow-routing.md",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
41
|
-
"sha256": "
|
|
41
|
+
"sha256": "eec04cc76ab67b9ba06ff1b32c68c657d86488883942c70c5a8ce526d05c4c20"
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
"path": "funnel-docs.config.json",
|
|
141
|
-
"sha256": "
|
|
141
|
+
"sha256": "6018305fe5a4b85b9411dc53e1d7169e9d0a3670f422b046ab24759f66392c98"
|
|
142
142
|
}
|
|
143
143
|
]
|
|
144
144
|
}
|
|
@@ -52,20 +52,39 @@ paywall/legal copy. JSX renders resolved content; metadata IDs, answer keys,
|
|
|
52
52
|
provider IDs, prices and billing rules retain their existing owners. Provider-hosted
|
|
53
53
|
payment fields and messages are configured through that provider's locale support.
|
|
54
54
|
|
|
55
|
-
1.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
such as `
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
1. Keep original `*.content.ts` files at their existing locations alongside the
|
|
56
|
+
funnel's steps/shared code. They own the default English content and exported
|
|
57
|
+
content types. Run `fgrove locales add ru --dir .` to create translations under
|
|
58
|
+
`src/localization/ru/`, mirroring each original path relative to `src/`:
|
|
59
|
+
`src/steps/content/intro.content.ts` →
|
|
60
|
+
`src/localization/ru/steps/content/intro.content.ts`.
|
|
61
|
+
Use BCP 47 tags such as `pt-BR`. CLI copies source only: no translation, login,
|
|
62
|
+
sync or publication. Repeating the command preserves translated values, adds missing exports and
|
|
63
|
+
repairs missing registrations in the originals.
|
|
64
|
+
An existing inline locale is extracted with its authored text preserved.
|
|
65
|
+
2. Translate **every** generated content file, including shared shell and
|
|
66
|
+
returning-subscriber content. Each translated export imports its named type
|
|
67
|
+
with `import type` from the original file. Original definitions import these
|
|
68
|
+
translated values into their `locales` map; the reverse import is type-only.
|
|
69
|
+
Preserve keys, option IDs, placeholders such as `{amount}`, URLs and tokens.
|
|
70
|
+
Same-file inheritance from the default or requested locale refers to the
|
|
71
|
+
translated export. References to other locales require explicit copy before
|
|
72
|
+
running the command. Relative imports
|
|
73
|
+
are rebased; imported expressions remain authored references. Inspect those
|
|
74
|
+
references for remaining visitor copy before completing a translation.
|
|
75
|
+
3. Define the complete structure in an exported type in the original content file
|
|
76
|
+
and use `satisfies LocalizedStepContent<YourContentType>`. When adding a field,
|
|
77
|
+
update this type and the English content, then supply the field in **every**
|
|
78
|
+
translation. Keep required fields required; do not silence errors with casts,
|
|
79
|
+
optional fields or English spreads. Run `npx tsc --noEmit` at the funnel root:
|
|
80
|
+
an incomplete translation must fail with its file and missing field.
|
|
81
|
+
Keep `defaultLocale` and `locales` as explicit literal properties. CLI preflights
|
|
82
|
+
unsupported definitions before writing. Use named non-generic content types
|
|
83
|
+
and one default language per file. Local helpers referenced by copied
|
|
84
|
+
content (including enums, classes and type casts) must be inlined or moved to
|
|
85
|
+
independent imported modules. If a registered translation file is lost, restore
|
|
86
|
+
it before retrying; CLI cannot recover translated text from an import. A new step
|
|
87
|
+
must include every supported locale: rerun `locales add` for each language.
|
|
69
88
|
4. Resolve step copy with `usePreviewStepLocalizedContent(stepId, definition,
|
|
70
89
|
getStepContentLocale(attributes))`. Runtime versions supporting localization
|
|
71
90
|
give `?locale=ru` priority; otherwise the requested/browser language applies.
|
|
@@ -17,7 +17,7 @@ Supported read versions: `1`, `2`, `3`. Authoring and publish target version `3`
|
|
|
17
17
|
|
|
18
18
|
### Package release order
|
|
19
19
|
|
|
20
|
-
Release `@funnelsgrove/
|
|
20
|
+
Release `@funnelsgrove/sdk` `0.4.0` first, then `@funnelsgrove/runtime` `0.19.0`, then `@funnelsgrove/analytics` `0.1.110`, then `@funnelsgrove/payments` `0.20.0`. The production deploy verifies the zero-traffic API candidate, publishes and verifies `@funnelsgrove/cli` `0.1.237`, and only then promotes the candidate to production traffic. The serving API must never advertise an unpublished preferred CLI. Publishing packages and deploying production remain separately approved operational actions.
|
|
21
21
|
<!-- funnelsgrove:generated:end contract-v3/migration/step-contract-v3 -->
|
|
22
22
|
|
|
23
23
|
## Version-last policy
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"bundleVersion": "2.0.
|
|
3
|
+
"bundleVersion": "2.0.229",
|
|
4
4
|
"stepContractVersion": 3,
|
|
5
5
|
"contractHash": "d761e91d5ac6ff9e72c6d49c5bcd014270912473a66f99c49d726c65998085cf",
|
|
6
6
|
"managedFiles": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"path": "docs/funnelsgrove/contracts/content-answers.md",
|
|
25
|
-
"sha256": "
|
|
25
|
+
"sha256": "17c8a91800ec1d2247b1e0fd12cc80fbfce162297aa928432cc0a574acd9fc06"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"path": "docs/funnelsgrove/contracts/flow-routing.md",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
41
|
-
"sha256": "
|
|
41
|
+
"sha256": "eec04cc76ab67b9ba06ff1b32c68c657d86488883942c70c5a8ce526d05c4c20"
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
"path": "docs/funnelsgrove/qa/analytics.md",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
"path": "funnel-docs.config.json",
|
|
141
|
-
"sha256": "
|
|
141
|
+
"sha256": "6018305fe5a4b85b9411dc53e1d7169e9d0a3670f422b046ab24759f66392c98"
|
|
142
142
|
}
|
|
143
143
|
]
|
|
144
144
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"sourceTreeHash": "
|
|
3
|
+
"sourceTreeHash": "f14834edab3f8d7a98828a6a0253b40c4457f4d720ec913e3f917da0d3a626e4",
|
|
4
4
|
"stepContractVersion": 3,
|
|
5
|
-
"docsBundleVersion": "2.0.
|
|
5
|
+
"docsBundleVersion": "2.0.229",
|
|
6
6
|
"files": [
|
|
7
7
|
{
|
|
8
8
|
"path": ".env.example",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
"path": ".funnelsgrove-docs.json",
|
|
19
|
-
"sha256": "
|
|
19
|
+
"sha256": "c56225fdfe22673279acfa36ee110d4098d3b2ccc44a2290042f4ede26b0988b",
|
|
20
20
|
"mode": "100644"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
83
|
"path": "docs/funnelsgrove/contracts/content-answers.md",
|
|
84
|
-
"sha256": "
|
|
84
|
+
"sha256": "17c8a91800ec1d2247b1e0fd12cc80fbfce162297aa928432cc0a574acd9fc06",
|
|
85
85
|
"mode": "100644"
|
|
86
86
|
},
|
|
87
87
|
{
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
103
|
"path": "docs/funnelsgrove/migrations/step-contract-v3.md",
|
|
104
|
-
"sha256": "
|
|
104
|
+
"sha256": "eec04cc76ab67b9ba06ff1b32c68c657d86488883942c70c5a8ce526d05c4c20",
|
|
105
105
|
"mode": "100644"
|
|
106
106
|
},
|
|
107
107
|
{
|
|
@@ -236,7 +236,7 @@
|
|
|
236
236
|
},
|
|
237
237
|
{
|
|
238
238
|
"path": "funnel-docs.config.json",
|
|
239
|
-
"sha256": "
|
|
239
|
+
"sha256": "6018305fe5a4b85b9411dc53e1d7169e9d0a3670f422b046ab24759f66392c98",
|
|
240
240
|
"mode": "100644"
|
|
241
241
|
},
|
|
242
242
|
{
|
|
@@ -491,7 +491,7 @@
|
|
|
491
491
|
},
|
|
492
492
|
{
|
|
493
493
|
"path": "src/steps/content/runtime.content.ts",
|
|
494
|
-
"sha256": "
|
|
494
|
+
"sha256": "c69d6129aac089842d3c046abeae0d6a0e29ff53471116651194d02e4000a9af",
|
|
495
495
|
"mode": "100644"
|
|
496
496
|
},
|
|
497
497
|
{
|
|
@@ -506,7 +506,7 @@
|
|
|
506
506
|
},
|
|
507
507
|
{
|
|
508
508
|
"path": "src/steps/content/subscription-dashboard.content.ts",
|
|
509
|
-
"sha256": "
|
|
509
|
+
"sha256": "b54b05675a3c239f6003508818e64f6ee19e02e2bcec2fe8c3ce95bed4b90d04",
|
|
510
510
|
"mode": "100644"
|
|
511
511
|
},
|
|
512
512
|
{
|
|
@@ -52,20 +52,39 @@ paywall/legal copy. JSX renders resolved content; metadata IDs, answer keys,
|
|
|
52
52
|
provider IDs, prices and billing rules retain their existing owners. Provider-hosted
|
|
53
53
|
payment fields and messages are configured through that provider's locale support.
|
|
54
54
|
|
|
55
|
-
1.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
such as `
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
1. Keep original `*.content.ts` files at their existing locations alongside the
|
|
56
|
+
funnel's steps/shared code. They own the default English content and exported
|
|
57
|
+
content types. Run `fgrove locales add ru --dir .` to create translations under
|
|
58
|
+
`src/localization/ru/`, mirroring each original path relative to `src/`:
|
|
59
|
+
`src/steps/content/intro.content.ts` →
|
|
60
|
+
`src/localization/ru/steps/content/intro.content.ts`.
|
|
61
|
+
Use BCP 47 tags such as `pt-BR`. CLI copies source only: no translation, login,
|
|
62
|
+
sync or publication. Repeating the command preserves translated values, adds missing exports and
|
|
63
|
+
repairs missing registrations in the originals.
|
|
64
|
+
An existing inline locale is extracted with its authored text preserved.
|
|
65
|
+
2. Translate **every** generated content file, including shared shell and
|
|
66
|
+
returning-subscriber content. Each translated export imports its named type
|
|
67
|
+
with `import type` from the original file. Original definitions import these
|
|
68
|
+
translated values into their `locales` map; the reverse import is type-only.
|
|
69
|
+
Preserve keys, option IDs, placeholders such as `{amount}`, URLs and tokens.
|
|
70
|
+
Same-file inheritance from the default or requested locale refers to the
|
|
71
|
+
translated export. References to other locales require explicit copy before
|
|
72
|
+
running the command. Relative imports
|
|
73
|
+
are rebased; imported expressions remain authored references. Inspect those
|
|
74
|
+
references for remaining visitor copy before completing a translation.
|
|
75
|
+
3. Define the complete structure in an exported type in the original content file
|
|
76
|
+
and use `satisfies LocalizedStepContent<YourContentType>`. When adding a field,
|
|
77
|
+
update this type and the English content, then supply the field in **every**
|
|
78
|
+
translation. Keep required fields required; do not silence errors with casts,
|
|
79
|
+
optional fields or English spreads. Run `npx tsc --noEmit` at the funnel root:
|
|
80
|
+
an incomplete translation must fail with its file and missing field.
|
|
81
|
+
Keep `defaultLocale` and `locales` as explicit literal properties. CLI preflights
|
|
82
|
+
unsupported definitions before writing. Use named non-generic content types
|
|
83
|
+
and one default language per file. Local helpers referenced by copied
|
|
84
|
+
content (including enums, classes and type casts) must be inlined or moved to
|
|
85
|
+
independent imported modules. If a registered translation file is lost, restore
|
|
86
|
+
it before retrying; CLI cannot recover translated text from an import. A new step
|
|
87
|
+
must include every supported locale: rerun `locales add` for each language.
|
|
69
88
|
4. Resolve step copy with `usePreviewStepLocalizedContent(stepId, definition,
|
|
70
89
|
getStepContentLocale(attributes))`. Runtime versions supporting localization
|
|
71
90
|
give `?locale=ru` priority; otherwise the requested/browser language applies.
|
|
@@ -17,7 +17,7 @@ Supported read versions: `1`, `2`, `3`. Authoring and publish target version `3`
|
|
|
17
17
|
|
|
18
18
|
### Package release order
|
|
19
19
|
|
|
20
|
-
Release `@funnelsgrove/
|
|
20
|
+
Release `@funnelsgrove/sdk` `0.4.0` first, then `@funnelsgrove/runtime` `0.19.0`, then `@funnelsgrove/analytics` `0.1.110`, then `@funnelsgrove/payments` `0.20.0`. The production deploy verifies the zero-traffic API candidate, publishes and verifies `@funnelsgrove/cli` `0.1.237`, and only then promotes the candidate to production traffic. The serving API must never advertise an unpublished preferred CLI. Publishing packages and deploying production remain separately approved operational actions.
|
|
21
21
|
<!-- funnelsgrove:generated:end contract-v3/migration/step-contract-v3 -->
|
|
22
22
|
|
|
23
23
|
## Version-last policy
|