@uniformdev/transformer 1.1.1 → 1.1.3
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 +34 -32
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +32 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -2437,25 +2437,9 @@ var ComponentAdderService = class {
|
|
|
2437
2437
|
generateId(baseName) {
|
|
2438
2438
|
return `${baseName}-${randomUUID().slice(0, 8)}`;
|
|
2439
2439
|
}
|
|
2440
|
-
cloneComponentInstance(instance) {
|
|
2441
|
-
const clone = JSON.parse(JSON.stringify(instance));
|
|
2442
|
-
if (clone._id) {
|
|
2443
|
-
clone._id = this.generateId(clone.type);
|
|
2444
|
-
}
|
|
2445
|
-
if (clone.slots) {
|
|
2446
|
-
for (const slotInstances of Object.values(clone.slots)) {
|
|
2447
|
-
if (Array.isArray(slotInstances)) {
|
|
2448
|
-
for (const nestedInstance of slotInstances) {
|
|
2449
|
-
this.regenerateInstanceIds(nestedInstance);
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
return clone;
|
|
2455
|
-
}
|
|
2456
2440
|
regenerateInstanceIds(instance) {
|
|
2457
2441
|
if (instance._id) {
|
|
2458
|
-
instance._id = this.generateId(instance.type);
|
|
2442
|
+
instance._id = instance._pattern ? randomUUID() : this.generateId(instance.type);
|
|
2459
2443
|
}
|
|
2460
2444
|
if (instance.slots) {
|
|
2461
2445
|
for (const slotInstances of Object.values(instance.slots)) {
|
|
@@ -2675,7 +2659,11 @@ var ComponentAdderService = class {
|
|
|
2675
2659
|
allowedComponentsUpdated = true;
|
|
2676
2660
|
}
|
|
2677
2661
|
}
|
|
2678
|
-
const newInstance =
|
|
2662
|
+
const newInstance = {
|
|
2663
|
+
type: componentTypeInPattern,
|
|
2664
|
+
_pattern: pattern.componentPatternId,
|
|
2665
|
+
_id: randomUUID()
|
|
2666
|
+
};
|
|
2679
2667
|
const compositionsResult = await this.addComponentToDirectory(
|
|
2680
2668
|
fullCompositionsDir,
|
|
2681
2669
|
parentComponentType,
|
|
@@ -2719,26 +2707,42 @@ var ComponentAdderService = class {
|
|
|
2719
2707
|
const jsonPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.json`);
|
|
2720
2708
|
const yamlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yaml`);
|
|
2721
2709
|
const ymlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yml`);
|
|
2710
|
+
let raw;
|
|
2722
2711
|
if (await this.fileSystem.fileExists(jsonPath)) {
|
|
2723
|
-
|
|
2724
|
-
}
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
if (await this.fileSystem.fileExists(ymlPath)) {
|
|
2729
|
-
return this.fileSystem.readFile(ymlPath);
|
|
2712
|
+
raw = await this.fileSystem.readFile(jsonPath);
|
|
2713
|
+
} else if (await this.fileSystem.fileExists(yamlPath)) {
|
|
2714
|
+
raw = await this.fileSystem.readFile(yamlPath);
|
|
2715
|
+
} else if (await this.fileSystem.fileExists(ymlPath)) {
|
|
2716
|
+
raw = await this.fileSystem.readFile(ymlPath);
|
|
2730
2717
|
}
|
|
2731
|
-
if (!strict) {
|
|
2718
|
+
if (!raw && !strict) {
|
|
2732
2719
|
const files = await this.fileSystem.findFiles(componentPatternsDir, "*.{json,yaml,yml}");
|
|
2733
2720
|
for (const filePath of files) {
|
|
2734
2721
|
const basename2 = this.fileSystem.getBasename(filePath);
|
|
2735
2722
|
const nameWithoutExt = basename2.replace(/\.(json|yaml|yml)$/i, "");
|
|
2736
2723
|
if (nameWithoutExt.toLowerCase() === patternId.toLowerCase()) {
|
|
2737
|
-
|
|
2724
|
+
raw = await this.fileSystem.readFile(filePath);
|
|
2725
|
+
break;
|
|
2738
2726
|
}
|
|
2739
2727
|
}
|
|
2740
2728
|
}
|
|
2741
|
-
|
|
2729
|
+
if (!raw) {
|
|
2730
|
+
throw new TransformError(`Component pattern "${patternId}" not found in ${componentPatternsDir}`);
|
|
2731
|
+
}
|
|
2732
|
+
return this.normalizeComponentPattern(raw, patternId);
|
|
2733
|
+
}
|
|
2734
|
+
normalizeComponentPattern(raw, patternId) {
|
|
2735
|
+
if (raw.definition && typeof raw.definition === "object" && raw.definition.type) {
|
|
2736
|
+
return raw;
|
|
2737
|
+
}
|
|
2738
|
+
if (raw.composition && typeof raw.composition === "object" && raw.composition.type) {
|
|
2739
|
+
const composition = raw.composition;
|
|
2740
|
+
return {
|
|
2741
|
+
componentPatternId: patternId,
|
|
2742
|
+
definition: composition
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
return raw;
|
|
2742
2746
|
}
|
|
2743
2747
|
async addComponentToDirectory(directory, parentComponentType, slot, newInstance, whatIf, strict, dirType) {
|
|
2744
2748
|
const exists = await this.fileSystem.fileExists(directory);
|
|
@@ -2911,7 +2915,7 @@ function createAddComponentCommand() {
|
|
|
2911
2915
|
import { Command as Command8 } from "commander";
|
|
2912
2916
|
function createAddComponentPatternCommand() {
|
|
2913
2917
|
const command = new Command8("add-component-pattern");
|
|
2914
|
-
command.description("Adds a component pattern instance to existing component slots across all compositions.").option("--parentComponentType <type>", "The component type that owns the slot").option("--slot <slotId>", "The slot ID where the component pattern will be added").option("--componentPatternId <id>", "The component pattern ID to add").
|
|
2918
|
+
command.description("Adds a component pattern instance to existing component slots across all compositions.").option("--parentComponentType <type>", "The component type that owns the slot").option("--slot <slotId>", "The slot ID where the component pattern will be added").option("--componentPatternId <id>", "The component pattern ID to add").hook("preAction", (thisCommand) => {
|
|
2915
2919
|
const opts = thisCommand.opts();
|
|
2916
2920
|
const requiredOptions = [
|
|
2917
2921
|
{ name: "parentComponentType", flag: "--parentComponentType" },
|
|
@@ -2929,8 +2933,7 @@ function createAddComponentPatternCommand() {
|
|
|
2929
2933
|
...globalOpts,
|
|
2930
2934
|
parentComponentType: opts.parentComponentType,
|
|
2931
2935
|
slot: opts.slot,
|
|
2932
|
-
componentPatternId: opts.componentPatternId
|
|
2933
|
-
parameters: opts.parameters
|
|
2936
|
+
componentPatternId: opts.componentPatternId
|
|
2934
2937
|
};
|
|
2935
2938
|
const logger = new Logger();
|
|
2936
2939
|
const fileSystem = new FileSystemService();
|
|
@@ -2946,7 +2949,6 @@ function createAddComponentPatternCommand() {
|
|
|
2946
2949
|
parentComponentType: options.parentComponentType,
|
|
2947
2950
|
slot: options.slot,
|
|
2948
2951
|
componentPatternId: options.componentPatternId,
|
|
2949
|
-
parameters: options.parameters,
|
|
2950
2952
|
whatIf: options.whatIf ?? false,
|
|
2951
2953
|
strict: options.strict ?? false
|
|
2952
2954
|
});
|