@uniformdev/transformer 1.1.29 → 1.1.30
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/cli/index.js +320 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +30 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command15 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/cli/commands/propagate-root-component-property.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -5019,10 +5019,325 @@ function createRemoveFieldCommand() {
|
|
|
5019
5019
|
return command;
|
|
5020
5020
|
}
|
|
5021
5021
|
|
|
5022
|
+
// src/cli/commands/add-component-parameter.ts
|
|
5023
|
+
import { Command as Command13 } from "commander";
|
|
5024
|
+
|
|
5025
|
+
// src/core/services/component-parameter-adder.service.ts
|
|
5026
|
+
var ComponentParameterAdderService = class {
|
|
5027
|
+
constructor(fileSystem, componentService, logger) {
|
|
5028
|
+
this.fileSystem = fileSystem;
|
|
5029
|
+
this.componentService = componentService;
|
|
5030
|
+
this.logger = logger;
|
|
5031
|
+
}
|
|
5032
|
+
async add(options) {
|
|
5033
|
+
const {
|
|
5034
|
+
rootDir,
|
|
5035
|
+
componentsDir,
|
|
5036
|
+
componentId,
|
|
5037
|
+
parameterId,
|
|
5038
|
+
parameterType,
|
|
5039
|
+
parameterConfig,
|
|
5040
|
+
groupId,
|
|
5041
|
+
whatIf,
|
|
5042
|
+
strict
|
|
5043
|
+
} = options;
|
|
5044
|
+
const findOptions = { strict };
|
|
5045
|
+
const fullComponentsDir = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
5046
|
+
this.logger.info(`Loading component: ${componentId}`);
|
|
5047
|
+
const { component, filePath: componentFilePath } = await this.componentService.loadComponent(fullComponentsDir, componentId, findOptions);
|
|
5048
|
+
let parsedConfig = {};
|
|
5049
|
+
if (parameterConfig) {
|
|
5050
|
+
try {
|
|
5051
|
+
parsedConfig = JSON.parse(parameterConfig);
|
|
5052
|
+
} catch (e) {
|
|
5053
|
+
throw new TransformError(
|
|
5054
|
+
`Invalid JSON in --parameterConfig: ${e instanceof Error ? e.message : String(e)}`
|
|
5055
|
+
);
|
|
5056
|
+
}
|
|
5057
|
+
}
|
|
5058
|
+
const { id: _ignoreId, type: _ignoreType, ...restConfig } = parsedConfig;
|
|
5059
|
+
const parameter = {
|
|
5060
|
+
id: parameterId,
|
|
5061
|
+
name: parsedConfig.name ?? parameterId,
|
|
5062
|
+
type: parameterType,
|
|
5063
|
+
...restConfig
|
|
5064
|
+
};
|
|
5065
|
+
const existing = this.componentService.findParameter(component, parameterId, findOptions);
|
|
5066
|
+
const parameterReplaced = existing !== void 0;
|
|
5067
|
+
if (parameterReplaced) {
|
|
5068
|
+
this.logger.warn(
|
|
5069
|
+
`Parameter "${parameterId}" already exists on component "${component.id}" \u2014 replacing`
|
|
5070
|
+
);
|
|
5071
|
+
}
|
|
5072
|
+
this.logger.action(
|
|
5073
|
+
whatIf,
|
|
5074
|
+
parameterReplaced ? "UPDATE" : "ADD",
|
|
5075
|
+
`parameter "${parameterId}" to component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
5076
|
+
);
|
|
5077
|
+
let updatedComponent = this.componentService.addParameterToComponent(
|
|
5078
|
+
component,
|
|
5079
|
+
parameter,
|
|
5080
|
+
findOptions
|
|
5081
|
+
);
|
|
5082
|
+
if (groupId) {
|
|
5083
|
+
const group = this.componentService.findParameter(updatedComponent, groupId, findOptions);
|
|
5084
|
+
if (!group || !this.componentService.isGroupParameter(group)) {
|
|
5085
|
+
throw new TransformError(
|
|
5086
|
+
`Group "${groupId}" not found on component "${component.id}"`
|
|
5087
|
+
);
|
|
5088
|
+
}
|
|
5089
|
+
updatedComponent = this.componentService.addParameterToGroup(
|
|
5090
|
+
updatedComponent,
|
|
5091
|
+
groupId,
|
|
5092
|
+
parameterId,
|
|
5093
|
+
findOptions
|
|
5094
|
+
);
|
|
5095
|
+
}
|
|
5096
|
+
if (!whatIf) {
|
|
5097
|
+
await this.componentService.saveComponent(componentFilePath, updatedComponent);
|
|
5098
|
+
}
|
|
5099
|
+
this.logger.info("");
|
|
5100
|
+
this.logger.info(`Summary: 1 component definition updated.`);
|
|
5101
|
+
return {
|
|
5102
|
+
componentDefinitionUpdated: true,
|
|
5103
|
+
parameterReplaced
|
|
5104
|
+
};
|
|
5105
|
+
}
|
|
5106
|
+
};
|
|
5107
|
+
|
|
5108
|
+
// src/cli/commands/add-component-parameter.ts
|
|
5109
|
+
function createAddComponentParameterCommand() {
|
|
5110
|
+
const command = new Command13("add-component-parameter");
|
|
5111
|
+
command.description(
|
|
5112
|
+
"Adds a new parameter definition to a component. If the parameter already exists it is replaced."
|
|
5113
|
+
).option("--componentId <id>", "The ID of the component to add the parameter to").option("--parameterId <id>", "The ID of the new parameter").option("--parameterType <type>", "The type of the new parameter (e.g. text, checkbox, select)").option(
|
|
5114
|
+
"--parameterConfig <json>",
|
|
5115
|
+
"Optional JSON string with additional parameter properties (e.g. name, typeConfig, localizable)"
|
|
5116
|
+
).option(
|
|
5117
|
+
"--groupId <id>",
|
|
5118
|
+
"Optional ID of an existing group parameter to register the new parameter under"
|
|
5119
|
+
).hook("preAction", (thisCommand) => {
|
|
5120
|
+
const opts = thisCommand.opts();
|
|
5121
|
+
const requiredOptions = [
|
|
5122
|
+
{ name: "componentId", flag: "--componentId" },
|
|
5123
|
+
{ name: "parameterId", flag: "--parameterId" },
|
|
5124
|
+
{ name: "parameterType", flag: "--parameterType" }
|
|
5125
|
+
];
|
|
5126
|
+
const missing = requiredOptions.filter((opt) => !opts[opt.name]).map((opt) => opt.flag);
|
|
5127
|
+
if (missing.length > 0) {
|
|
5128
|
+
console.error(`error: missing required options: ${missing.join(", ")}`);
|
|
5129
|
+
process.exit(1);
|
|
5130
|
+
}
|
|
5131
|
+
}).action(async (opts, cmd) => {
|
|
5132
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5133
|
+
const options = {
|
|
5134
|
+
...globalOpts,
|
|
5135
|
+
componentId: opts.componentId,
|
|
5136
|
+
parameterId: opts.parameterId,
|
|
5137
|
+
parameterType: opts.parameterType,
|
|
5138
|
+
parameterConfig: opts.parameterConfig,
|
|
5139
|
+
groupId: opts.groupId
|
|
5140
|
+
};
|
|
5141
|
+
const logger = new Logger();
|
|
5142
|
+
const fileSystem = new FileSystemService();
|
|
5143
|
+
const componentService = new ComponentService(fileSystem);
|
|
5144
|
+
const adder = new ComponentParameterAdderService(fileSystem, componentService, logger);
|
|
5145
|
+
try {
|
|
5146
|
+
const result = await adder.add({
|
|
5147
|
+
rootDir: options.rootDir,
|
|
5148
|
+
componentsDir: options.componentsDir,
|
|
5149
|
+
componentId: options.componentId,
|
|
5150
|
+
parameterId: options.parameterId,
|
|
5151
|
+
parameterType: options.parameterType,
|
|
5152
|
+
parameterConfig: options.parameterConfig,
|
|
5153
|
+
groupId: options.groupId,
|
|
5154
|
+
whatIf: options.whatIf ?? false,
|
|
5155
|
+
strict: options.strict ?? false
|
|
5156
|
+
});
|
|
5157
|
+
logger.success(
|
|
5158
|
+
`${result.parameterReplaced ? "Replaced" : "Added"} parameter "${options.parameterId}" on component "${options.componentId}"`
|
|
5159
|
+
);
|
|
5160
|
+
} catch (error) {
|
|
5161
|
+
if (error instanceof TransformError) {
|
|
5162
|
+
logger.error(error.message);
|
|
5163
|
+
process.exit(1);
|
|
5164
|
+
}
|
|
5165
|
+
throw error;
|
|
5166
|
+
}
|
|
5167
|
+
});
|
|
5168
|
+
return command;
|
|
5169
|
+
}
|
|
5170
|
+
|
|
5171
|
+
// src/cli/commands/add-contenttype-field.ts
|
|
5172
|
+
import { Command as Command14 } from "commander";
|
|
5173
|
+
|
|
5174
|
+
// src/core/services/contenttype-field-adder.service.ts
|
|
5175
|
+
var ContentTypeFieldAdderService = class {
|
|
5176
|
+
constructor(fileSystem, logger) {
|
|
5177
|
+
this.fileSystem = fileSystem;
|
|
5178
|
+
this.logger = logger;
|
|
5179
|
+
}
|
|
5180
|
+
compareIds(id1, id2, strict) {
|
|
5181
|
+
if (strict) {
|
|
5182
|
+
return id1 === id2;
|
|
5183
|
+
}
|
|
5184
|
+
return id1.toLowerCase() === id2.toLowerCase();
|
|
5185
|
+
}
|
|
5186
|
+
async loadContentType(contentTypesDir, contentTypeId, strict) {
|
|
5187
|
+
const jsonPath = this.fileSystem.joinPath(contentTypesDir, `${contentTypeId}.json`);
|
|
5188
|
+
const yamlPath = this.fileSystem.joinPath(contentTypesDir, `${contentTypeId}.yaml`);
|
|
5189
|
+
const ymlPath = this.fileSystem.joinPath(contentTypesDir, `${contentTypeId}.yml`);
|
|
5190
|
+
if (await this.fileSystem.fileExists(jsonPath)) {
|
|
5191
|
+
const contentType = await this.fileSystem.readFile(jsonPath);
|
|
5192
|
+
return { contentType, filePath: jsonPath };
|
|
5193
|
+
}
|
|
5194
|
+
if (await this.fileSystem.fileExists(yamlPath)) {
|
|
5195
|
+
const contentType = await this.fileSystem.readFile(yamlPath);
|
|
5196
|
+
return { contentType, filePath: yamlPath };
|
|
5197
|
+
}
|
|
5198
|
+
if (await this.fileSystem.fileExists(ymlPath)) {
|
|
5199
|
+
const contentType = await this.fileSystem.readFile(ymlPath);
|
|
5200
|
+
return { contentType, filePath: ymlPath };
|
|
5201
|
+
}
|
|
5202
|
+
if (!strict) {
|
|
5203
|
+
const files = await this.fileSystem.findFiles(contentTypesDir, "*.{json,yaml,yml}");
|
|
5204
|
+
for (const filePath of files) {
|
|
5205
|
+
const basename2 = this.fileSystem.getBasename(filePath);
|
|
5206
|
+
const nameWithoutExt = basename2.replace(/\.(json|yaml|yml)$/i, "");
|
|
5207
|
+
if (nameWithoutExt.toLowerCase() === contentTypeId.toLowerCase()) {
|
|
5208
|
+
const contentType = await this.fileSystem.readFile(filePath);
|
|
5209
|
+
return { contentType, filePath };
|
|
5210
|
+
}
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
throw new TransformError(`Content type not found: ${contentTypeId} (searched: ${contentTypesDir})`);
|
|
5214
|
+
}
|
|
5215
|
+
async add(options) {
|
|
5216
|
+
const {
|
|
5217
|
+
rootDir,
|
|
5218
|
+
contentTypesDir,
|
|
5219
|
+
contentTypeId,
|
|
5220
|
+
fieldId,
|
|
5221
|
+
fieldType,
|
|
5222
|
+
fieldConfig,
|
|
5223
|
+
whatIf,
|
|
5224
|
+
strict
|
|
5225
|
+
} = options;
|
|
5226
|
+
const fullContentTypesDir = this.fileSystem.resolvePath(rootDir, contentTypesDir);
|
|
5227
|
+
this.logger.info(`Loading content type: ${contentTypeId}`);
|
|
5228
|
+
const { contentType, filePath: contentTypeFilePath } = await this.loadContentType(fullContentTypesDir, contentTypeId, strict);
|
|
5229
|
+
let parsedConfig = {};
|
|
5230
|
+
if (fieldConfig) {
|
|
5231
|
+
try {
|
|
5232
|
+
parsedConfig = JSON.parse(fieldConfig);
|
|
5233
|
+
} catch (e) {
|
|
5234
|
+
throw new TransformError(
|
|
5235
|
+
`Invalid JSON in --fieldConfig: ${e instanceof Error ? e.message : String(e)}`
|
|
5236
|
+
);
|
|
5237
|
+
}
|
|
5238
|
+
}
|
|
5239
|
+
const { id: _ignoreId, type: _ignoreType, ...restConfig } = parsedConfig;
|
|
5240
|
+
const field = {
|
|
5241
|
+
id: fieldId,
|
|
5242
|
+
name: parsedConfig.name ?? fieldId,
|
|
5243
|
+
type: fieldType,
|
|
5244
|
+
...restConfig
|
|
5245
|
+
};
|
|
5246
|
+
if (!contentType.fields) {
|
|
5247
|
+
contentType.fields = [];
|
|
5248
|
+
}
|
|
5249
|
+
const existingIndex = contentType.fields.findIndex(
|
|
5250
|
+
(f) => this.compareIds(f.id, fieldId, strict)
|
|
5251
|
+
);
|
|
5252
|
+
const fieldReplaced = existingIndex >= 0;
|
|
5253
|
+
if (fieldReplaced) {
|
|
5254
|
+
this.logger.warn(
|
|
5255
|
+
`Field "${fieldId}" already exists on content type "${contentType.id}" \u2014 replacing`
|
|
5256
|
+
);
|
|
5257
|
+
}
|
|
5258
|
+
this.logger.action(
|
|
5259
|
+
whatIf,
|
|
5260
|
+
fieldReplaced ? "UPDATE" : "ADD",
|
|
5261
|
+
`field "${fieldId}" to contentType/${this.fileSystem.getBasename(contentTypeFilePath)}`
|
|
5262
|
+
);
|
|
5263
|
+
if (fieldReplaced) {
|
|
5264
|
+
contentType.fields[existingIndex] = field;
|
|
5265
|
+
} else {
|
|
5266
|
+
contentType.fields.push(field);
|
|
5267
|
+
}
|
|
5268
|
+
if (!whatIf) {
|
|
5269
|
+
await this.fileSystem.writeFile(contentTypeFilePath, contentType);
|
|
5270
|
+
}
|
|
5271
|
+
this.logger.info("");
|
|
5272
|
+
this.logger.info(`Summary: 1 content type definition updated.`);
|
|
5273
|
+
return {
|
|
5274
|
+
contentTypeDefinitionUpdated: true,
|
|
5275
|
+
fieldReplaced
|
|
5276
|
+
};
|
|
5277
|
+
}
|
|
5278
|
+
};
|
|
5279
|
+
|
|
5280
|
+
// src/cli/commands/add-contenttype-field.ts
|
|
5281
|
+
function createAddContentTypeFieldCommand() {
|
|
5282
|
+
const command = new Command14("add-contenttype-field");
|
|
5283
|
+
command.description(
|
|
5284
|
+
"Adds a new field definition to a content type. If the field already exists it is replaced."
|
|
5285
|
+
).option("--contentTypeId <id>", "The ID of the content type to add the field to").option("--fieldId <id>", "The ID of the new field").option("--fieldType <type>", "The type of the new field (e.g. text, richText, reference)").option(
|
|
5286
|
+
"--fieldConfig <json>",
|
|
5287
|
+
"Optional JSON string with additional field properties (e.g. name, typeConfig, localizable)"
|
|
5288
|
+
).hook("preAction", (thisCommand) => {
|
|
5289
|
+
const opts = thisCommand.opts();
|
|
5290
|
+
const requiredOptions = [
|
|
5291
|
+
{ name: "contentTypeId", flag: "--contentTypeId" },
|
|
5292
|
+
{ name: "fieldId", flag: "--fieldId" },
|
|
5293
|
+
{ name: "fieldType", flag: "--fieldType" }
|
|
5294
|
+
];
|
|
5295
|
+
const missing = requiredOptions.filter((opt) => !opts[opt.name]).map((opt) => opt.flag);
|
|
5296
|
+
if (missing.length > 0) {
|
|
5297
|
+
console.error(`error: missing required options: ${missing.join(", ")}`);
|
|
5298
|
+
process.exit(1);
|
|
5299
|
+
}
|
|
5300
|
+
}).action(async (opts, cmd) => {
|
|
5301
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5302
|
+
const options = {
|
|
5303
|
+
...globalOpts,
|
|
5304
|
+
contentTypeId: opts.contentTypeId,
|
|
5305
|
+
fieldId: opts.fieldId,
|
|
5306
|
+
fieldType: opts.fieldType,
|
|
5307
|
+
fieldConfig: opts.fieldConfig
|
|
5308
|
+
};
|
|
5309
|
+
const logger = new Logger();
|
|
5310
|
+
const fileSystem = new FileSystemService();
|
|
5311
|
+
const adder = new ContentTypeFieldAdderService(fileSystem, logger);
|
|
5312
|
+
try {
|
|
5313
|
+
const result = await adder.add({
|
|
5314
|
+
rootDir: options.rootDir,
|
|
5315
|
+
contentTypesDir: options.contentTypesDir,
|
|
5316
|
+
contentTypeId: options.contentTypeId,
|
|
5317
|
+
fieldId: options.fieldId,
|
|
5318
|
+
fieldType: options.fieldType,
|
|
5319
|
+
fieldConfig: options.fieldConfig,
|
|
5320
|
+
whatIf: options.whatIf ?? false,
|
|
5321
|
+
strict: options.strict ?? false
|
|
5322
|
+
});
|
|
5323
|
+
logger.success(
|
|
5324
|
+
`${result.fieldReplaced ? "Replaced" : "Added"} field "${options.fieldId}" on content type "${options.contentTypeId}"`
|
|
5325
|
+
);
|
|
5326
|
+
} catch (error) {
|
|
5327
|
+
if (error instanceof TransformError) {
|
|
5328
|
+
logger.error(error.message);
|
|
5329
|
+
process.exit(1);
|
|
5330
|
+
}
|
|
5331
|
+
throw error;
|
|
5332
|
+
}
|
|
5333
|
+
});
|
|
5334
|
+
return command;
|
|
5335
|
+
}
|
|
5336
|
+
|
|
5022
5337
|
// package.json
|
|
5023
5338
|
var package_default = {
|
|
5024
5339
|
name: "@uniformdev/transformer",
|
|
5025
|
-
version: "1.1.
|
|
5340
|
+
version: "1.1.30",
|
|
5026
5341
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
5027
5342
|
type: "module",
|
|
5028
5343
|
bin: {
|
|
@@ -5091,7 +5406,7 @@ var package_default = {
|
|
|
5091
5406
|
};
|
|
5092
5407
|
|
|
5093
5408
|
// src/cli/index.ts
|
|
5094
|
-
var program = new
|
|
5409
|
+
var program = new Command15();
|
|
5095
5410
|
var appVersion = package_default.version;
|
|
5096
5411
|
console.error(`uniform-transform v${appVersion}`);
|
|
5097
5412
|
program.name("uniform-transform").description("CLI tool for transforming Uniform.dev serialization files offline").version(appVersion);
|
|
@@ -5116,5 +5431,7 @@ program.addCommand(createPropagateRootComponentSlotCommand());
|
|
|
5116
5431
|
program.addCommand(createConvertCompositionsToEntriesCommand());
|
|
5117
5432
|
program.addCommand(createRemoveParameterCommand());
|
|
5118
5433
|
program.addCommand(createRemoveFieldCommand());
|
|
5434
|
+
program.addCommand(createAddComponentParameterCommand());
|
|
5435
|
+
program.addCommand(createAddContentTypeFieldCommand());
|
|
5119
5436
|
program.parse();
|
|
5120
5437
|
//# sourceMappingURL=index.js.map
|