@ikas/component-cli 1.4.0-beta.55 → 1.4.0-beta.56
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/config.d.ts.map +1 -1
- package/dist/commands/config.js +1 -285
- 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 +9 -86
- package/dist/commands/dev.js.map +1 -1
- package/dist/types.d.ts +10 -27
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/component-helpers.d.ts +2 -29
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +66 -101
- package/dist/utils/component-helpers.js.map +1 -1
- package/dist/utils/editor-action-client.d.ts +1 -1
- package/dist/utils/editor-action-client.d.ts.map +1 -1
- package/dist/utils/editor-action-client.js.map +1 -1
- package/dist/utils/websocket-server.d.ts +6 -83
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +1 -59
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +1 -1
|
@@ -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;AA0lDpC,wBAAgB,mBAAmB,IAAI,OAAO,CA2M7C"}
|
package/dist/commands/config.js
CHANGED
|
@@ -2,16 +2,6 @@ import { Command } from "commander";
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import { PROP_TYPES, toPascalCase, generateTypesFile, generateGlobalTypesFile, collectUsedEnumIds, generateComponentFile, generateStylesFile, generateProjectId, generateComponentId, generateUniqueId, updateBarrelExport, findPropGroup, collectPropGroupIds, movePropGroupInTree, validateFilteredComponentIds, } from "../utils/component-helpers.js";
|
|
5
|
-
import { runEditorAction, printResultAndExit, printErrorAndExit } from "../utils/editor-action-client.js";
|
|
6
|
-
async function listLocales(port) {
|
|
7
|
-
try {
|
|
8
|
-
const result = await runEditorAction("list-locales", {}, port ? { port } : {});
|
|
9
|
-
printResultAndExit(result);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
printErrorAndExit(e);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
5
|
function loadConfig() {
|
|
16
6
|
const configPath = path.resolve(process.cwd(), "ikas.config.json");
|
|
17
7
|
if (!fs.existsSync(configPath)) {
|
|
@@ -373,7 +363,6 @@ async function addComponent(name, options) {
|
|
|
373
363
|
const newComponent = {
|
|
374
364
|
id: componentId,
|
|
375
365
|
name: pascalName,
|
|
376
|
-
...(options.displayName ? { displayName: options.displayName } : {}),
|
|
377
366
|
entry: `./src/components/${pascalName}/index.tsx`,
|
|
378
367
|
styles: `./src/components/${pascalName}/styles.css`,
|
|
379
368
|
...(componentType === "section" ? { type: "section" } : {}),
|
|
@@ -994,217 +983,20 @@ function updateComponent(ref, options) {
|
|
|
994
983
|
delete component.isFooter;
|
|
995
984
|
}
|
|
996
985
|
}
|
|
997
|
-
// displayName is the code-owned default-locale display label (may contain spaces).
|
|
998
|
-
// An empty string clears it (falls back to `name`).
|
|
999
|
-
if (options.displayName !== undefined) {
|
|
1000
|
-
if (options.displayName) {
|
|
1001
|
-
component.displayName = options.displayName;
|
|
1002
|
-
}
|
|
1003
|
-
else {
|
|
1004
|
-
delete component.displayName;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
986
|
saveConfig(configPath, config);
|
|
1008
987
|
console.log(JSON.stringify({
|
|
1009
988
|
success: true,
|
|
1010
989
|
componentName: component.name,
|
|
1011
990
|
type: component.type ?? "component",
|
|
1012
|
-
...(component.displayName ? { displayName: component.displayName } : {}),
|
|
1013
991
|
...(component.isHeader ? { isHeader: true } : {}),
|
|
1014
992
|
...(component.isFooter ? { isFooter: true } : {}),
|
|
1015
993
|
}));
|
|
1016
994
|
}
|
|
1017
|
-
// Upsert a per-locale translation row in `list` by locale, applying only the
|
|
1018
|
-
// provided fields. Studio keeps one translation per locale, so this matches by
|
|
1019
|
-
// locale rather than appending. A row left with no content (all label fields
|
|
1020
|
-
// empty) is not persisted — a new one is skipped, an existing one is pruned —
|
|
1021
|
-
// so we never write a meaningless `{id, locale}` row. Returns the row, or null
|
|
1022
|
-
// when nothing meaningful remains.
|
|
1023
|
-
function upsertTranslation(list, locale, fields) {
|
|
1024
|
-
const existing = list.find((t) => t.locale === locale);
|
|
1025
|
-
const target = existing ?? { id: generateUniqueId(), locale };
|
|
1026
|
-
if (fields.displayName !== undefined)
|
|
1027
|
-
target.displayName = fields.displayName || undefined;
|
|
1028
|
-
if (fields.description !== undefined)
|
|
1029
|
-
target.description = fields.description || undefined;
|
|
1030
|
-
if (fields.name !== undefined)
|
|
1031
|
-
target.name = fields.name || undefined;
|
|
1032
|
-
if (!target.displayName && !target.description && !target.name) {
|
|
1033
|
-
if (existing)
|
|
1034
|
-
list.splice(list.indexOf(existing), 1);
|
|
1035
|
-
return null;
|
|
1036
|
-
}
|
|
1037
|
-
if (!existing)
|
|
1038
|
-
list.push(target);
|
|
1039
|
-
return target;
|
|
1040
|
-
}
|
|
1041
|
-
function setPropTranslation(ref, options) {
|
|
1042
|
-
const { config, configPath } = loadConfig();
|
|
1043
|
-
const component = resolveComponent(config, ref);
|
|
1044
|
-
const prop = component.props.find((p) => p.name === options.prop);
|
|
1045
|
-
if (!prop) {
|
|
1046
|
-
console.log(JSON.stringify({
|
|
1047
|
-
success: false,
|
|
1048
|
-
error: `Prop "${options.prop}" not found on component "${component.name}". Available: ${component.props.map((p) => p.name).join(", ")}`,
|
|
1049
|
-
}));
|
|
1050
|
-
process.exit(1);
|
|
1051
|
-
}
|
|
1052
|
-
if (options.displayName === undefined && options.description === undefined) {
|
|
1053
|
-
console.log(JSON.stringify({
|
|
1054
|
-
success: false,
|
|
1055
|
-
error: "Nothing to set: provide --displayName and/or --description.",
|
|
1056
|
-
}));
|
|
1057
|
-
process.exit(1);
|
|
1058
|
-
}
|
|
1059
|
-
if (!prop.translations)
|
|
1060
|
-
prop.translations = [];
|
|
1061
|
-
const row = upsertTranslation(prop.translations, options.locale, {
|
|
1062
|
-
displayName: options.displayName,
|
|
1063
|
-
description: options.description,
|
|
1064
|
-
});
|
|
1065
|
-
if (prop.translations.length === 0)
|
|
1066
|
-
prop.translations = undefined;
|
|
1067
|
-
saveConfig(configPath, config);
|
|
1068
|
-
console.log(JSON.stringify({
|
|
1069
|
-
success: true,
|
|
1070
|
-
componentName: component.name,
|
|
1071
|
-
prop: prop.name,
|
|
1072
|
-
translation: row,
|
|
1073
|
-
}));
|
|
1074
|
-
}
|
|
1075
|
-
function setGroupTranslation(ref, options) {
|
|
1076
|
-
const { config, configPath } = loadConfig();
|
|
1077
|
-
const component = resolveComponent(config, ref);
|
|
1078
|
-
if (!component.propGroups || component.propGroups.length === 0) {
|
|
1079
|
-
console.log(JSON.stringify({ success: false, error: `No prop groups on component "${component.name}".` }));
|
|
1080
|
-
process.exit(1);
|
|
1081
|
-
}
|
|
1082
|
-
const found = findPropGroup(component.propGroups, options.group);
|
|
1083
|
-
if (!found) {
|
|
1084
|
-
console.log(JSON.stringify({
|
|
1085
|
-
success: false,
|
|
1086
|
-
error: `Prop group "${options.group}" not found on component "${component.name}". Available: ${Array.from(collectPropGroupIds(component.propGroups)).join(", ")}`,
|
|
1087
|
-
}));
|
|
1088
|
-
process.exit(1);
|
|
1089
|
-
}
|
|
1090
|
-
if (options.name === undefined && options.description === undefined) {
|
|
1091
|
-
console.log(JSON.stringify({
|
|
1092
|
-
success: false,
|
|
1093
|
-
error: "Nothing to set: provide --name and/or --description.",
|
|
1094
|
-
}));
|
|
1095
|
-
process.exit(1);
|
|
1096
|
-
}
|
|
1097
|
-
if (!found.group.translations)
|
|
1098
|
-
found.group.translations = [];
|
|
1099
|
-
const row = upsertTranslation(found.group.translations, options.locale, {
|
|
1100
|
-
name: options.name,
|
|
1101
|
-
description: options.description,
|
|
1102
|
-
});
|
|
1103
|
-
if (found.group.translations.length === 0)
|
|
1104
|
-
found.group.translations = undefined;
|
|
1105
|
-
saveConfig(configPath, config);
|
|
1106
|
-
console.log(JSON.stringify({
|
|
1107
|
-
success: true,
|
|
1108
|
-
componentName: component.name,
|
|
1109
|
-
group: found.group.id,
|
|
1110
|
-
translation: row,
|
|
1111
|
-
}));
|
|
1112
|
-
}
|
|
1113
|
-
function removePropTranslation(ref, options) {
|
|
1114
|
-
const { config, configPath } = loadConfig();
|
|
1115
|
-
const component = resolveComponent(config, ref);
|
|
1116
|
-
const prop = component.props.find((p) => p.name === options.prop);
|
|
1117
|
-
if (!prop) {
|
|
1118
|
-
console.log(JSON.stringify({
|
|
1119
|
-
success: false,
|
|
1120
|
-
error: `Prop "${options.prop}" not found on component "${component.name}". Available: ${component.props.map((p) => p.name).join(", ")}`,
|
|
1121
|
-
}));
|
|
1122
|
-
process.exit(1);
|
|
1123
|
-
}
|
|
1124
|
-
const before = prop.translations?.length ?? 0;
|
|
1125
|
-
if (prop.translations) {
|
|
1126
|
-
prop.translations = prop.translations.filter((t) => t.locale !== options.locale);
|
|
1127
|
-
if (prop.translations.length === 0)
|
|
1128
|
-
prop.translations = undefined;
|
|
1129
|
-
}
|
|
1130
|
-
saveConfig(configPath, config);
|
|
1131
|
-
console.log(JSON.stringify({
|
|
1132
|
-
success: true,
|
|
1133
|
-
componentName: component.name,
|
|
1134
|
-
prop: prop.name,
|
|
1135
|
-
removed: before - (prop.translations?.length ?? 0),
|
|
1136
|
-
}));
|
|
1137
|
-
}
|
|
1138
|
-
function removeGroupTranslation(ref, options) {
|
|
1139
|
-
const { config, configPath } = loadConfig();
|
|
1140
|
-
const component = resolveComponent(config, ref);
|
|
1141
|
-
if (!component.propGroups || component.propGroups.length === 0) {
|
|
1142
|
-
console.log(JSON.stringify({ success: false, error: `No prop groups on component "${component.name}".` }));
|
|
1143
|
-
process.exit(1);
|
|
1144
|
-
}
|
|
1145
|
-
const found = findPropGroup(component.propGroups, options.group);
|
|
1146
|
-
if (!found) {
|
|
1147
|
-
console.log(JSON.stringify({
|
|
1148
|
-
success: false,
|
|
1149
|
-
error: `Prop group "${options.group}" not found on component "${component.name}". Available: ${Array.from(collectPropGroupIds(component.propGroups)).join(", ")}`,
|
|
1150
|
-
}));
|
|
1151
|
-
process.exit(1);
|
|
1152
|
-
}
|
|
1153
|
-
const before = found.group.translations?.length ?? 0;
|
|
1154
|
-
if (found.group.translations) {
|
|
1155
|
-
found.group.translations = found.group.translations.filter((t) => t.locale !== options.locale);
|
|
1156
|
-
if (found.group.translations.length === 0)
|
|
1157
|
-
found.group.translations = undefined;
|
|
1158
|
-
}
|
|
1159
|
-
saveConfig(configPath, config);
|
|
1160
|
-
console.log(JSON.stringify({
|
|
1161
|
-
success: true,
|
|
1162
|
-
componentName: component.name,
|
|
1163
|
-
group: found.group.id,
|
|
1164
|
-
removed: before - (found.group.translations?.length ?? 0),
|
|
1165
|
-
}));
|
|
1166
|
-
}
|
|
1167
|
-
function setComponentTranslation(ref, options) {
|
|
1168
|
-
const { config, configPath } = loadConfig();
|
|
1169
|
-
const component = resolveComponent(config, ref);
|
|
1170
|
-
if (options.displayName === undefined) {
|
|
1171
|
-
console.log(JSON.stringify({ success: false, error: "Nothing to set: provide --displayName." }));
|
|
1172
|
-
process.exit(1);
|
|
1173
|
-
}
|
|
1174
|
-
if (!component.translations)
|
|
1175
|
-
component.translations = [];
|
|
1176
|
-
const row = upsertTranslation(component.translations, options.locale, { displayName: options.displayName });
|
|
1177
|
-
if (component.translations.length === 0)
|
|
1178
|
-
component.translations = undefined;
|
|
1179
|
-
saveConfig(configPath, config);
|
|
1180
|
-
console.log(JSON.stringify({
|
|
1181
|
-
success: true,
|
|
1182
|
-
componentName: component.name,
|
|
1183
|
-
translation: row,
|
|
1184
|
-
}));
|
|
1185
|
-
}
|
|
1186
|
-
function removeComponentTranslation(ref, options) {
|
|
1187
|
-
const { config, configPath } = loadConfig();
|
|
1188
|
-
const component = resolveComponent(config, ref);
|
|
1189
|
-
const before = component.translations?.length ?? 0;
|
|
1190
|
-
if (component.translations) {
|
|
1191
|
-
component.translations = component.translations.filter((t) => t.locale !== options.locale);
|
|
1192
|
-
if (component.translations.length === 0)
|
|
1193
|
-
component.translations = undefined;
|
|
1194
|
-
}
|
|
1195
|
-
saveConfig(configPath, config);
|
|
1196
|
-
console.log(JSON.stringify({
|
|
1197
|
-
success: true,
|
|
1198
|
-
componentName: component.name,
|
|
1199
|
-
removed: before - (component.translations?.length ?? 0),
|
|
1200
|
-
}));
|
|
1201
|
-
}
|
|
1202
995
|
function listComponents() {
|
|
1203
996
|
const { config } = loadConfig();
|
|
1204
997
|
const components = config.components.map((c) => ({
|
|
1205
998
|
id: c.id,
|
|
1206
999
|
name: c.name,
|
|
1207
|
-
...(c.displayName ? { displayName: c.displayName } : {}),
|
|
1208
1000
|
type: c.type ?? "component",
|
|
1209
1001
|
...(c.isHeader ? { isHeader: true } : {}),
|
|
1210
1002
|
...(c.isFooter ? { isFooter: true } : {}),
|
|
@@ -1424,7 +1216,6 @@ export function createConfigCommand() {
|
|
|
1424
1216
|
.command("add-component")
|
|
1425
1217
|
.description("Add a new component to the project")
|
|
1426
1218
|
.requiredOption("--name <name>", "Component name (PascalCase or kebab-case)")
|
|
1427
|
-
.option("--displayName <displayName>", "Human-facing display label shown in the editor (may contain spaces; defaults to name)")
|
|
1428
1219
|
.option("--type <type>", "Component type: section or component", "component")
|
|
1429
1220
|
.option("--isHeader", "Mark this section as the store header (only for type: section)")
|
|
1430
1221
|
.option("--isFooter", "Mark this section as the store footer (only for type: section)")
|
|
@@ -1482,10 +1273,9 @@ export function createConfigCommand() {
|
|
|
1482
1273
|
});
|
|
1483
1274
|
config
|
|
1484
1275
|
.command("update-component")
|
|
1485
|
-
.description("Update a component's metadata (
|
|
1276
|
+
.description("Update a component's metadata (isHeader, isFooter). Identify by --id (preferred) or exact --name.")
|
|
1486
1277
|
.option("--id <id>", "Component id (preferred; from `config list-components`)")
|
|
1487
1278
|
.option("--name <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1488
|
-
.option("--displayName <displayName>", "Human-facing display label shown in the editor (may contain spaces; empty string clears it)")
|
|
1489
1279
|
.option("--isHeader", "Mark as store header")
|
|
1490
1280
|
.option("--no-isHeader", "Unmark as store header")
|
|
1491
1281
|
.option("--isFooter", "Mark as store footer")
|
|
@@ -1544,73 +1334,6 @@ export function createConfigCommand() {
|
|
|
1544
1334
|
.action((options) => {
|
|
1545
1335
|
movePropGroup({ id: options.componentId, name: options.component }, options);
|
|
1546
1336
|
});
|
|
1547
|
-
config
|
|
1548
|
-
.command("set-prop-translation")
|
|
1549
|
-
.description("Add or update a per-locale translation for a prop's label/description. " +
|
|
1550
|
-
"Seeded into the editor on first import of a new component or a newly added prop; " +
|
|
1551
|
-
"studio-owned translations for already-imported props are not overwritten.")
|
|
1552
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1553
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1554
|
-
.requiredOption("--prop <propName>", "Prop name to translate")
|
|
1555
|
-
.requiredOption("--locale <locale>", "Target locale (e.g. de, fr, en)")
|
|
1556
|
-
.option("--displayName <text>", "Translated display name")
|
|
1557
|
-
.option("--description <text>", "Translated description")
|
|
1558
|
-
.action((options) => {
|
|
1559
|
-
setPropTranslation({ id: options.componentId, name: options.component }, options);
|
|
1560
|
-
});
|
|
1561
|
-
config
|
|
1562
|
-
.command("set-group-translation")
|
|
1563
|
-
.description("Add or update a per-locale translation for a prop group's name/description. " +
|
|
1564
|
-
"Seeded into the editor only for groups studio has not seen yet (studio wins otherwise).")
|
|
1565
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1566
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1567
|
-
.requiredOption("--group <groupId>", "Prop group id (local, as in ikas.config.json)")
|
|
1568
|
-
.requiredOption("--locale <locale>", "Target locale (e.g. de, fr, en)")
|
|
1569
|
-
.option("--name <text>", "Translated group name")
|
|
1570
|
-
.option("--description <text>", "Translated description")
|
|
1571
|
-
.action((options) => {
|
|
1572
|
-
setGroupTranslation({ id: options.componentId, name: options.component }, options);
|
|
1573
|
-
});
|
|
1574
|
-
config
|
|
1575
|
-
.command("remove-prop-translation")
|
|
1576
|
-
.description("Remove a prop's translation for a given locale")
|
|
1577
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1578
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1579
|
-
.requiredOption("--prop <propName>", "Prop name")
|
|
1580
|
-
.requiredOption("--locale <locale>", "Locale to remove")
|
|
1581
|
-
.action((options) => {
|
|
1582
|
-
removePropTranslation({ id: options.componentId, name: options.component }, options);
|
|
1583
|
-
});
|
|
1584
|
-
config
|
|
1585
|
-
.command("remove-group-translation")
|
|
1586
|
-
.description("Remove a prop group's translation for a given locale")
|
|
1587
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1588
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1589
|
-
.requiredOption("--group <groupId>", "Prop group id (local, as in ikas.config.json)")
|
|
1590
|
-
.requiredOption("--locale <locale>", "Locale to remove")
|
|
1591
|
-
.action((options) => {
|
|
1592
|
-
removeGroupTranslation({ id: options.componentId, name: options.component }, options);
|
|
1593
|
-
});
|
|
1594
|
-
config
|
|
1595
|
-
.command("set-component-translation")
|
|
1596
|
-
.description("Add or update a per-locale translation for a section/component's own display label. " +
|
|
1597
|
-
"Seeded into the editor only for components studio has not seen yet (studio wins otherwise).")
|
|
1598
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1599
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1600
|
-
.requiredOption("--locale <locale>", "Target locale (e.g. de, fr, en)")
|
|
1601
|
-
.option("--displayName <text>", "Translated component display label")
|
|
1602
|
-
.action((options) => {
|
|
1603
|
-
setComponentTranslation({ id: options.componentId, name: options.component }, options);
|
|
1604
|
-
});
|
|
1605
|
-
config
|
|
1606
|
-
.command("remove-component-translation")
|
|
1607
|
-
.description("Remove a section/component name translation for a given locale")
|
|
1608
|
-
.option("--component-id <id>", "Component id (preferred; from `config list-components`)")
|
|
1609
|
-
.option("--component <name>", "Component name — exact match (PascalCase, as stored in ikas.config.json)")
|
|
1610
|
-
.requiredOption("--locale <locale>", "Locale to remove")
|
|
1611
|
-
.action((options) => {
|
|
1612
|
-
removeComponentTranslation({ id: options.componentId, name: options.component }, options);
|
|
1613
|
-
});
|
|
1614
1337
|
config
|
|
1615
1338
|
.command("list-components")
|
|
1616
1339
|
.description("List all components and their props (with canonical ids for use with --id flags)")
|
|
@@ -1630,13 +1353,6 @@ export function createConfigCommand() {
|
|
|
1630
1353
|
.action(async (options) => {
|
|
1631
1354
|
await listTypes(options.componentType);
|
|
1632
1355
|
});
|
|
1633
|
-
config
|
|
1634
|
-
.command("list-locales")
|
|
1635
|
-
.description("List the editor's configured locales — the ONLY valid --locale values for set-prop-translation / set-group-translation. Run this before adding translations; never invent a locale. (Requires a running dev server with the editor connected.)")
|
|
1636
|
-
.option("--port <port>", "Dev server WebSocket port", "5201")
|
|
1637
|
-
.action(async (options) => {
|
|
1638
|
-
await listLocales(options.port ? parseInt(options.port, 10) : undefined);
|
|
1639
|
-
});
|
|
1640
1356
|
config
|
|
1641
1357
|
.command("add-enum")
|
|
1642
1358
|
.description("Create a custom enum type (offline, no editor needed)")
|