@ikas/component-cli 1.4.0-beta.36 → 1.4.0-beta.38
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/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +5 -168
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +0 -197
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/create.d.ts +4 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +176 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +2 -52
- package/dist/commands/dev.js.map +1 -1
- package/dist/types.d.ts +0 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compile.d.ts.map +1 -1
- package/dist/utils/compile.js +229 -38
- package/dist/utils/compile.js.map +1 -1
- package/dist/utils/component-helpers.d.ts +1 -23
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +15 -94
- package/dist/utils/component-helpers.js.map +1 -1
- package/dist/utils/websocket-server.d.ts +1 -51
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +0 -34
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmIpC,wBAAgB,kBAAkB,IAAI,OAAO,CAK5C"}
|
package/dist/commands/build.js
CHANGED
|
@@ -2,175 +2,12 @@ import { Command } from "commander";
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import ora from "ora";
|
|
4
4
|
import * as fs from "fs";
|
|
5
|
-
import * as os from "os";
|
|
6
5
|
import * as path from "path";
|
|
7
|
-
import * as esbuild from "esbuild";
|
|
8
6
|
import { execSync } from "child_process";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
// pragma and break rendering. See utils/compile.ts for the full rationale.
|
|
14
|
-
const PREACT_JSX_SHIM = path.join(os.tmpdir(), "ikas-preact-jsx-shim.mjs");
|
|
15
|
-
fs.writeFileSync(PREACT_JSX_SHIM, 'export{h as __ikas_h,Fragment as __ikas_Fragment}from"preact";\n');
|
|
16
|
-
async function compileComponent(componentId, entryPath, stylesPath) {
|
|
17
|
-
const componentDir = path.dirname(path.resolve(process.cwd(), entryPath));
|
|
18
|
-
try {
|
|
19
|
-
// Build server bundle (for SSR with preact-render-to-string)
|
|
20
|
-
const serverResult = await esbuild.build({
|
|
21
|
-
entryPoints: [path.resolve(process.cwd(), entryPath)],
|
|
22
|
-
bundle: true,
|
|
23
|
-
format: "esm",
|
|
24
|
-
platform: "node",
|
|
25
|
-
target: "node18",
|
|
26
|
-
write: false,
|
|
27
|
-
external: [
|
|
28
|
-
"preact",
|
|
29
|
-
"preact/hooks",
|
|
30
|
-
"preact-render-to-string",
|
|
31
|
-
"mobx",
|
|
32
|
-
"@ikas/bp-storefront",
|
|
33
|
-
"@ikas/bp-storefront-models",
|
|
34
|
-
"@ikas/bp-storefront-config",
|
|
35
|
-
"@ikas/bp-storefront-api"
|
|
36
|
-
],
|
|
37
|
-
plugins: [ikasComponentUtilsPlugin()],
|
|
38
|
-
jsx: "transform",
|
|
39
|
-
jsxFactory: "__ikas_h",
|
|
40
|
-
jsxFragment: "__ikas_Fragment",
|
|
41
|
-
inject: [PREACT_JSX_SHIM],
|
|
42
|
-
tsconfigRaw: {
|
|
43
|
-
compilerOptions: {
|
|
44
|
-
jsx: "react",
|
|
45
|
-
jsxFactory: "__ikas_h",
|
|
46
|
-
jsxFragmentFactory: "__ikas_Fragment"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
minify: true,
|
|
50
|
-
sourcemap: false,
|
|
51
|
-
});
|
|
52
|
-
// Build client bundle (for hydration)
|
|
53
|
-
const clientResult = await esbuild.build({
|
|
54
|
-
entryPoints: [path.resolve(process.cwd(), entryPath)],
|
|
55
|
-
bundle: true,
|
|
56
|
-
format: "esm",
|
|
57
|
-
platform: "browser",
|
|
58
|
-
target: "es2020",
|
|
59
|
-
write: false,
|
|
60
|
-
external: [
|
|
61
|
-
"preact",
|
|
62
|
-
"preact/hooks",
|
|
63
|
-
"mobx",
|
|
64
|
-
"@ikas/bp-storefront",
|
|
65
|
-
"@ikas/bp-storefront-models",
|
|
66
|
-
"@ikas/bp-storefront-config"
|
|
67
|
-
],
|
|
68
|
-
plugins: [ikasComponentUtilsPlugin()],
|
|
69
|
-
jsx: "transform",
|
|
70
|
-
jsxFactory: "__ikas_h",
|
|
71
|
-
jsxFragment: "__ikas_Fragment",
|
|
72
|
-
inject: [PREACT_JSX_SHIM],
|
|
73
|
-
tsconfigRaw: {
|
|
74
|
-
compilerOptions: {
|
|
75
|
-
jsx: "react",
|
|
76
|
-
jsxFactory: "__ikas_h",
|
|
77
|
-
jsxFragmentFactory: "__ikas_Fragment"
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
minify: true,
|
|
81
|
-
sourcemap: false,
|
|
82
|
-
});
|
|
83
|
-
// Read and scope CSS (with import resolution)
|
|
84
|
-
const cssPath = path.resolve(process.cwd(), stylesPath);
|
|
85
|
-
let css = "";
|
|
86
|
-
if (fs.existsSync(cssPath)) {
|
|
87
|
-
const rawCss = fs.readFileSync(cssPath, "utf-8");
|
|
88
|
-
css = resolveCssImports(rawCss, cssPath);
|
|
89
|
-
}
|
|
90
|
-
// Scope CSS with component ID prefix
|
|
91
|
-
const scopedCss = scopeCSS(css, componentId);
|
|
92
|
-
return {
|
|
93
|
-
success: true,
|
|
94
|
-
serverJs: serverResult.outputFiles[0]?.text || "",
|
|
95
|
-
clientJs: clientResult.outputFiles[0]?.text || "",
|
|
96
|
-
scopedCss
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
return {
|
|
101
|
-
success: false,
|
|
102
|
-
serverJs: "",
|
|
103
|
-
clientJs: "",
|
|
104
|
-
scopedCss: "",
|
|
105
|
-
error: error instanceof Error ? error.message : String(error)
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function scopeCSS(css, componentId) {
|
|
110
|
-
// Add a scoping class to all selectors
|
|
111
|
-
const scopeClass = `cc_${componentId.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
112
|
-
// Simple CSS scoping - prepend scope class to each rule
|
|
113
|
-
// This is a basic implementation; a production version would use a proper CSS parser
|
|
114
|
-
const lines = css.split("\n");
|
|
115
|
-
const scopedLines = [];
|
|
116
|
-
let inMediaQuery = false;
|
|
117
|
-
let keyframesDepth = 0;
|
|
118
|
-
for (const line of lines) {
|
|
119
|
-
const trimmed = line.trim();
|
|
120
|
-
// Skip empty lines
|
|
121
|
-
if (!trimmed) {
|
|
122
|
-
scopedLines.push(line);
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
// Handle @media queries
|
|
126
|
-
if (trimmed.startsWith("@media")) {
|
|
127
|
-
inMediaQuery = true;
|
|
128
|
-
scopedLines.push(line);
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
// Handle @keyframes
|
|
132
|
-
if (trimmed.startsWith("@keyframes") || trimmed.startsWith("@-webkit-keyframes")) {
|
|
133
|
-
keyframesDepth = 1;
|
|
134
|
-
scopedLines.push(line);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
// Inside @keyframes: track brace depth, pass lines through unscoped
|
|
138
|
-
if (keyframesDepth > 0) {
|
|
139
|
-
for (const ch of trimmed) {
|
|
140
|
-
if (ch === "{")
|
|
141
|
-
keyframesDepth++;
|
|
142
|
-
else if (ch === "}")
|
|
143
|
-
keyframesDepth--;
|
|
144
|
-
}
|
|
145
|
-
scopedLines.push(line);
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
// Handle closing braces for @media
|
|
149
|
-
if (trimmed === "}" && inMediaQuery) {
|
|
150
|
-
inMediaQuery = false;
|
|
151
|
-
scopedLines.push(line);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
// Skip lines that don't contain selectors
|
|
155
|
-
if (!trimmed.includes("{") || trimmed.startsWith("@")) {
|
|
156
|
-
scopedLines.push(line);
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
// Scope the selector
|
|
160
|
-
const [selector, rest] = line.split("{");
|
|
161
|
-
if (selector && rest !== undefined) {
|
|
162
|
-
const scopedSelector = selector
|
|
163
|
-
.split(",")
|
|
164
|
-
.map((s) => `.${scopeClass} ${s.trim()}`)
|
|
165
|
-
.join(", ");
|
|
166
|
-
scopedLines.push(`${scopedSelector} {${rest}`);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
scopedLines.push(line);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return scopedLines.join("\n");
|
|
173
|
-
}
|
|
7
|
+
// Single-source the per-component compile pipeline (esbuild config, externals, CSS
|
|
8
|
+
// scoping) from utils/compile.ts. This command previously carried its own copy, which
|
|
9
|
+
// is how the CSS-scoping fix could land in one place and not the other — keep it shared.
|
|
10
|
+
import { compileComponent } from "../utils/compile.js";
|
|
174
11
|
function runTypeCheck() {
|
|
175
12
|
const spinner = ora("Type checking with TypeScript...").start();
|
|
176
13
|
try {
|
|
@@ -216,7 +53,7 @@ async function buildComponents(options) {
|
|
|
216
53
|
// Build each component
|
|
217
54
|
for (const component of config.components) {
|
|
218
55
|
const spinner = ora(`Building ${component.name}...`).start();
|
|
219
|
-
const result = await compileComponent(component.
|
|
56
|
+
const result = await compileComponent(component.entry, component.styles, component.id);
|
|
220
57
|
if (result.success) {
|
|
221
58
|
// Write output files
|
|
222
59
|
const componentOutDir = path.join(outputPath, component.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,mFAAmF;AACnF,sFAAsF;AACtF,yFAAyF;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAMvD,SAAS,YAAY;IACnB,MAAM,OAAO,GAAG,GAAG,CAAC,kCAAkC,CAAC,CAAC,KAAK,EAAE,CAAC;IAChE,IAAI,CAAC;QACH,QAAQ,CAAC,kBAAkB,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACpE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC7C,MAAM,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AAC,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;SACxB,WAAW,CAAC,iCAAiC,CAAC;SAC9C,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,CAAC;SACxD,MAAM,CAAC,eAAe,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAw/CpC,wBAAgB,mBAAmB,IAAI,OAAO,CA2M7C"}
|
package/dist/commands/config.js
CHANGED
|
@@ -908,156 +908,6 @@ function updateComponent(ref, options) {
|
|
|
908
908
|
...(component.isFooter ? { isFooter: true } : {}),
|
|
909
909
|
}));
|
|
910
910
|
}
|
|
911
|
-
// Upsert a per-locale translation row in `list` by locale, applying only the
|
|
912
|
-
// provided fields. Studio keeps one translation per locale, so this matches by
|
|
913
|
-
// locale rather than appending. A row left with no content (all label fields
|
|
914
|
-
// empty) is not persisted — a new one is skipped, an existing one is pruned —
|
|
915
|
-
// so we never write a meaningless `{id, locale}` row. Returns the row, or null
|
|
916
|
-
// when nothing meaningful remains.
|
|
917
|
-
function upsertTranslation(list, locale, fields) {
|
|
918
|
-
const existing = list.find((t) => t.locale === locale);
|
|
919
|
-
const target = existing ?? { id: generateUniqueId(), locale };
|
|
920
|
-
if (fields.displayName !== undefined)
|
|
921
|
-
target.displayName = fields.displayName || undefined;
|
|
922
|
-
if (fields.description !== undefined)
|
|
923
|
-
target.description = fields.description || undefined;
|
|
924
|
-
if (fields.name !== undefined)
|
|
925
|
-
target.name = fields.name || undefined;
|
|
926
|
-
if (!target.displayName && !target.description && !target.name) {
|
|
927
|
-
if (existing)
|
|
928
|
-
list.splice(list.indexOf(existing), 1);
|
|
929
|
-
return null;
|
|
930
|
-
}
|
|
931
|
-
if (!existing)
|
|
932
|
-
list.push(target);
|
|
933
|
-
return target;
|
|
934
|
-
}
|
|
935
|
-
function setPropTranslation(ref, options) {
|
|
936
|
-
const { config, configPath } = loadConfig();
|
|
937
|
-
const component = resolveComponent(config, ref);
|
|
938
|
-
const prop = component.props.find((p) => p.name === options.prop);
|
|
939
|
-
if (!prop) {
|
|
940
|
-
console.log(JSON.stringify({
|
|
941
|
-
success: false,
|
|
942
|
-
error: `Prop "${options.prop}" not found on component "${component.name}". Available: ${component.props.map((p) => p.name).join(", ")}`,
|
|
943
|
-
}));
|
|
944
|
-
process.exit(1);
|
|
945
|
-
}
|
|
946
|
-
if (options.displayName === undefined && options.description === undefined) {
|
|
947
|
-
console.log(JSON.stringify({
|
|
948
|
-
success: false,
|
|
949
|
-
error: "Nothing to set: provide --displayName and/or --description.",
|
|
950
|
-
}));
|
|
951
|
-
process.exit(1);
|
|
952
|
-
}
|
|
953
|
-
if (!prop.translations)
|
|
954
|
-
prop.translations = [];
|
|
955
|
-
const row = upsertTranslation(prop.translations, options.locale, {
|
|
956
|
-
displayName: options.displayName,
|
|
957
|
-
description: options.description,
|
|
958
|
-
});
|
|
959
|
-
if (prop.translations.length === 0)
|
|
960
|
-
prop.translations = undefined;
|
|
961
|
-
saveConfig(configPath, config);
|
|
962
|
-
console.log(JSON.stringify({
|
|
963
|
-
success: true,
|
|
964
|
-
componentName: component.name,
|
|
965
|
-
prop: prop.name,
|
|
966
|
-
translation: row,
|
|
967
|
-
}));
|
|
968
|
-
}
|
|
969
|
-
function setGroupTranslation(ref, options) {
|
|
970
|
-
const { config, configPath } = loadConfig();
|
|
971
|
-
const component = resolveComponent(config, ref);
|
|
972
|
-
if (!component.propGroups || component.propGroups.length === 0) {
|
|
973
|
-
console.log(JSON.stringify({ success: false, error: `No prop groups on component "${component.name}".` }));
|
|
974
|
-
process.exit(1);
|
|
975
|
-
}
|
|
976
|
-
const found = findPropGroup(component.propGroups, options.group);
|
|
977
|
-
if (!found) {
|
|
978
|
-
console.log(JSON.stringify({
|
|
979
|
-
success: false,
|
|
980
|
-
error: `Prop group "${options.group}" not found on component "${component.name}". Available: ${Array.from(collectPropGroupIds(component.propGroups)).join(", ")}`,
|
|
981
|
-
}));
|
|
982
|
-
process.exit(1);
|
|
983
|
-
}
|
|
984
|
-
if (options.name === undefined && options.description === undefined) {
|
|
985
|
-
console.log(JSON.stringify({
|
|
986
|
-
success: false,
|
|
987
|
-
error: "Nothing to set: provide --name and/or --description.",
|
|
988
|
-
}));
|
|
989
|
-
process.exit(1);
|
|
990
|
-
}
|
|
991
|
-
if (!found.group.translations)
|
|
992
|
-
found.group.translations = [];
|
|
993
|
-
const row = upsertTranslation(found.group.translations, options.locale, {
|
|
994
|
-
name: options.name,
|
|
995
|
-
description: options.description,
|
|
996
|
-
});
|
|
997
|
-
if (found.group.translations.length === 0)
|
|
998
|
-
found.group.translations = undefined;
|
|
999
|
-
saveConfig(configPath, config);
|
|
1000
|
-
console.log(JSON.stringify({
|
|
1001
|
-
success: true,
|
|
1002
|
-
componentName: component.name,
|
|
1003
|
-
group: found.group.id,
|
|
1004
|
-
translation: row,
|
|
1005
|
-
}));
|
|
1006
|
-
}
|
|
1007
|
-
function removePropTranslation(ref, options) {
|
|
1008
|
-
const { config, configPath } = loadConfig();
|
|
1009
|
-
const component = resolveComponent(config, ref);
|
|
1010
|
-
const prop = component.props.find((p) => p.name === options.prop);
|
|
1011
|
-
if (!prop) {
|
|
1012
|
-
console.log(JSON.stringify({
|
|
1013
|
-
success: false,
|
|
1014
|
-
error: `Prop "${options.prop}" not found on component "${component.name}". Available: ${component.props.map((p) => p.name).join(", ")}`,
|
|
1015
|
-
}));
|
|
1016
|
-
process.exit(1);
|
|
1017
|
-
}
|
|
1018
|
-
const before = prop.translations?.length ?? 0;
|
|
1019
|
-
if (prop.translations) {
|
|
1020
|
-
prop.translations = prop.translations.filter((t) => t.locale !== options.locale);
|
|
1021
|
-
if (prop.translations.length === 0)
|
|
1022
|
-
prop.translations = undefined;
|
|
1023
|
-
}
|
|
1024
|
-
saveConfig(configPath, config);
|
|
1025
|
-
console.log(JSON.stringify({
|
|
1026
|
-
success: true,
|
|
1027
|
-
componentName: component.name,
|
|
1028
|
-
prop: prop.name,
|
|
1029
|
-
removed: before - (prop.translations?.length ?? 0),
|
|
1030
|
-
}));
|
|
1031
|
-
}
|
|
1032
|
-
function removeGroupTranslation(ref, options) {
|
|
1033
|
-
const { config, configPath } = loadConfig();
|
|
1034
|
-
const component = resolveComponent(config, ref);
|
|
1035
|
-
if (!component.propGroups || component.propGroups.length === 0) {
|
|
1036
|
-
console.log(JSON.stringify({ success: false, error: `No prop groups on component "${component.name}".` }));
|
|
1037
|
-
process.exit(1);
|
|
1038
|
-
}
|
|
1039
|
-
const found = findPropGroup(component.propGroups, options.group);
|
|
1040
|
-
if (!found) {
|
|
1041
|
-
console.log(JSON.stringify({
|
|
1042
|
-
success: false,
|
|
1043
|
-
error: `Prop group "${options.group}" not found on component "${component.name}". Available: ${Array.from(collectPropGroupIds(component.propGroups)).join(", ")}`,
|
|
1044
|
-
}));
|
|
1045
|
-
process.exit(1);
|
|
1046
|
-
}
|
|
1047
|
-
const before = found.group.translations?.length ?? 0;
|
|
1048
|
-
if (found.group.translations) {
|
|
1049
|
-
found.group.translations = found.group.translations.filter((t) => t.locale !== options.locale);
|
|
1050
|
-
if (found.group.translations.length === 0)
|
|
1051
|
-
found.group.translations = undefined;
|
|
1052
|
-
}
|
|
1053
|
-
saveConfig(configPath, config);
|
|
1054
|
-
console.log(JSON.stringify({
|
|
1055
|
-
success: true,
|
|
1056
|
-
componentName: component.name,
|
|
1057
|
-
group: found.group.id,
|
|
1058
|
-
removed: before - (found.group.translations?.length ?? 0),
|
|
1059
|
-
}));
|
|
1060
|
-
}
|
|
1061
911
|
function listComponents() {
|
|
1062
912
|
const { config } = loadConfig();
|
|
1063
913
|
const components = config.components.map((c) => ({
|
|
@@ -1400,53 +1250,6 @@ export function createConfigCommand() {
|
|
|
1400
1250
|
.action((options) => {
|
|
1401
1251
|
movePropGroup({ id: options.componentId, name: options.component }, options);
|
|
1402
1252
|
});
|
|
1403
|
-
config
|
|
1404
|
-
.command("set-prop-translation")
|
|
1405
|
-
.description("Add or update a per-locale translation for a prop's label/description. " +
|
|
1406
|
-
"Seeded into the editor on first import of a new component or a newly added prop; " +
|
|
1407
|
-
"studio-owned translations for already-imported props are not overwritten.")
|
|
1408
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1409
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1410
|
-
.requiredOption("--prop <propName>", "Prop name to translate")
|
|
1411
|
-
.requiredOption("--locale <locale>", "Target locale (e.g. de, fr, en)")
|
|
1412
|
-
.option("--displayName <text>", "Translated display name")
|
|
1413
|
-
.option("--description <text>", "Translated description")
|
|
1414
|
-
.action((options) => {
|
|
1415
|
-
setPropTranslation({ id: options.componentId, name: options.component }, options);
|
|
1416
|
-
});
|
|
1417
|
-
config
|
|
1418
|
-
.command("set-group-translation")
|
|
1419
|
-
.description("Add or update a per-locale translation for a prop group's name/description. " +
|
|
1420
|
-
"Seeded into the editor only for groups studio has not seen yet (studio wins otherwise).")
|
|
1421
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1422
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1423
|
-
.requiredOption("--group <groupId>", "Prop group id (local, as in ikas.config.json)")
|
|
1424
|
-
.requiredOption("--locale <locale>", "Target locale (e.g. de, fr, en)")
|
|
1425
|
-
.option("--name <text>", "Translated group name")
|
|
1426
|
-
.option("--description <text>", "Translated description")
|
|
1427
|
-
.action((options) => {
|
|
1428
|
-
setGroupTranslation({ id: options.componentId, name: options.component }, options);
|
|
1429
|
-
});
|
|
1430
|
-
config
|
|
1431
|
-
.command("remove-prop-translation")
|
|
1432
|
-
.description("Remove a prop's translation for a given locale")
|
|
1433
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1434
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1435
|
-
.requiredOption("--prop <propName>", "Prop name")
|
|
1436
|
-
.requiredOption("--locale <locale>", "Locale to remove")
|
|
1437
|
-
.action((options) => {
|
|
1438
|
-
removePropTranslation({ id: options.componentId, name: options.component }, options);
|
|
1439
|
-
});
|
|
1440
|
-
config
|
|
1441
|
-
.command("remove-group-translation")
|
|
1442
|
-
.description("Remove a prop group's translation for a given locale")
|
|
1443
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1444
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1445
|
-
.requiredOption("--group <groupId>", "Prop group id (local, as in ikas.config.json)")
|
|
1446
|
-
.requiredOption("--locale <locale>", "Locale to remove")
|
|
1447
|
-
.action((options) => {
|
|
1448
|
-
removeGroupTranslation({ id: options.componentId, name: options.component }, options);
|
|
1449
|
-
});
|
|
1450
1253
|
config
|
|
1451
1254
|
.command("list-components")
|
|
1452
1255
|
.description("List all components and their props (with canonical ids for use with --id flags)")
|