@embeddables/cli 0.6.5 → 0.6.6

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.js CHANGED
@@ -85,6 +85,7 @@ program
85
85
  .option('-o, --out <path>', 'Output json path')
86
86
  .option('-b, --branch <branch_id>', 'Embeddable branch ID')
87
87
  .option('-f, --fix', 'Fix by removing components missing required props (warn instead of error)')
88
+ .option('-p, --preserve', 'Preserve component order in config for forward compile')
88
89
  .action(async (opts) => {
89
90
  await runPull(opts);
90
91
  });
@@ -4,6 +4,7 @@ export type RunPullOptions = {
4
4
  branch?: string;
5
5
  branchName?: string;
6
6
  fix?: boolean;
7
+ preserve?: boolean;
7
8
  };
8
9
  export declare function runPull(opts: RunPullOptions): Promise<void>;
9
10
  //# sourceMappingURL=pull.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AA+GA,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,cAAc,iBAqPjD"}
1
+ {"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AA+GA,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,cAAc,iBA6PjD"}
@@ -264,7 +264,11 @@ export async function runPull(opts) {
264
264
  };
265
265
  let usedFix = opts.fix;
266
266
  try {
267
- await reverseCompile(flow, embeddableId, { fix: opts.fix, pullMetadata });
267
+ await reverseCompile(flow, embeddableId, {
268
+ fix: opts.fix,
269
+ preserve: opts.preserve,
270
+ pullMetadata,
271
+ });
268
272
  }
269
273
  catch (compileError) {
270
274
  // If fix mode wasn't already enabled, offer to retry with fix mode
@@ -288,7 +292,11 @@ export async function runPull(opts) {
288
292
  console.log('');
289
293
  console.log(pc.cyan('Retrying with auto-fix enabled...'));
290
294
  console.log('');
291
- await reverseCompile(flow, embeddableId, { fix: true, pullMetadata });
295
+ await reverseCompile(flow, embeddableId, {
296
+ fix: true,
297
+ preserve: opts.preserve,
298
+ pullMetadata,
299
+ });
292
300
  }
293
301
  else {
294
302
  process.exit(1);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAmDA;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CA2DlF;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,UAAU,GAAG,QAAQ,CAAA;IAClC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mHAAmH;IACnH,OAAO,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAA;CAC1B,iBA4cA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAmDA;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CA2DlF;AA6BD,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,UAAU,GAAG,QAAQ,CAAA;IAClC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mHAAmH;IACnH,OAAO,CAAC,EAAE,IAAI,GAAG,QAAQ,CAAA;CAC1B,iBAoeA"}
@@ -99,6 +99,32 @@ export function reorderObjectKeysToMatch(oldVal, newVal) {
99
99
  }
100
100
  return newVal;
101
101
  }
102
+ /**
103
+ * Orders an array of items with an `id` property to match the given id list.
104
+ * Items whose id is in the list appear first in that order; items not in the list appear at the end.
105
+ */
106
+ function orderByIdList(items, idList) {
107
+ if (!Array.isArray(idList) || idList.length === 0)
108
+ return items;
109
+ const byId = new Map();
110
+ for (const item of items) {
111
+ if (item.id !== undefined && item.id !== null)
112
+ byId.set(item.id, item);
113
+ }
114
+ const ordered = [];
115
+ const orderedIds = new Set(idList);
116
+ for (const id of idList) {
117
+ const item = byId.get(id);
118
+ if (item)
119
+ ordered.push(item);
120
+ }
121
+ for (const item of items) {
122
+ if (item.id === undefined || item.id === null || !orderedIds.has(item.id)) {
123
+ ordered.push(item);
124
+ }
125
+ }
126
+ return ordered;
127
+ }
102
128
  export async function compileAllPages(opts) {
103
129
  const files = await fg(opts.pagesGlob, { dot: false });
104
130
  if (files.length === 0) {
@@ -356,15 +382,24 @@ export async function compileAllPages(opts) {
356
382
  // Apply metadata from config (preserving nested object order)
357
383
  const pageMetadata = orderedPageMap.get(key);
358
384
  if (pageMetadata) {
359
- // Merge metadata (excluding key and components)
360
- // Preserve order by iterating through keys in original order
385
+ // Merge metadata (excluding key, components, and components_order which is used only for ordering)
361
386
  const pageMetadataKeys = Object.keys(pageMetadata);
362
387
  for (const metaKey of pageMetadataKeys) {
363
- if (metaKey !== 'key' && metaKey !== 'components') {
388
+ if (metaKey !== 'key' &&
389
+ metaKey !== 'components' &&
390
+ metaKey !== 'components_order') {
364
391
  ;
365
392
  page[metaKey] = deepClonePreservingOrder(pageMetadata[metaKey]);
366
393
  }
367
394
  }
395
+ // If components_order is present (from pull --preserve), order page.components to match
396
+ const orderIds = pageMetadata.components_order;
397
+ if (Array.isArray(orderIds) &&
398
+ orderIds.length > 0 &&
399
+ page.components &&
400
+ page.components.length > 0) {
401
+ page.components = orderByIdList(page.components, orderIds);
402
+ }
368
403
  }
369
404
  return page;
370
405
  }
@@ -419,6 +454,10 @@ export async function compileAllPages(opts) {
419
454
  // Skip _branch_id / _branch_name - CLI metadata (current branch), not part of the embeddable
420
455
  continue;
421
456
  }
457
+ else if (key === 'components_order') {
458
+ // Skip components_order - used only to order global components when building, not part of output
459
+ continue;
460
+ }
422
461
  else if (key === 'computedFields') {
423
462
  // Replace computedFields with loaded computedFields (which include code)
424
463
  if (computedFields.length > 0) {
@@ -432,9 +471,13 @@ export async function compileAllPages(opts) {
432
471
  }
433
472
  }
434
473
  else if (key === 'components') {
435
- // Replace components with loaded global components
474
+ // Replace components with loaded global components (optionally ordered by config.components_order)
436
475
  if (globalComponents.length > 0) {
437
- embeddable.components = globalComponents;
476
+ const orderIds = config.components_order;
477
+ embeddable.components =
478
+ Array.isArray(orderIds) && orderIds.length > 0
479
+ ? orderByIdList(globalComponents, orderIds)
480
+ : globalComponents;
438
481
  }
439
482
  }
440
483
  else {
@@ -487,7 +530,11 @@ export async function compileAllPages(opts) {
487
530
  embeddable.dataOutputs = dataOutputs;
488
531
  }
489
532
  if (globalComponents.length > 0 && !embeddable.components) {
490
- embeddable.components = globalComponents;
533
+ const orderIds = config?.components_order;
534
+ embeddable.components =
535
+ Array.isArray(orderIds) && orderIds.length > 0
536
+ ? orderByIdList(globalComponents, orderIds)
537
+ : globalComponents;
491
538
  }
492
539
  let toWrite = embeddable;
493
540
  if (fs.existsSync(opts.outPath)) {
@@ -9,6 +9,7 @@ export declare function reverseCompile(embeddable: {
9
9
  [key: string]: any;
10
10
  }, embeddableId: string, opts?: {
11
11
  fix?: boolean;
12
+ preserve?: boolean;
12
13
  pullMetadata?: {
13
14
  version?: number;
14
15
  branchId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"reverse.d.ts","sourceRoot":"","sources":["../../src/compiler/reverse.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,YAAY,CAAA;AAqlBzD,wBAAsB,cAAc,CAClC,UAAU,EAAE;IACV,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,cAAc,CAAC,EAAE,GAAG,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,GAAG,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAA;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,EACD,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE;IACL,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,YAAY,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5E,iBAmFF;AA0gDD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKpD"}
1
+ {"version":3,"file":"reverse.d.ts","sourceRoot":"","sources":["../../src/compiler/reverse.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,YAAY,CAAA;AAqlBzD,wBAAsB,cAAc,CAClC,UAAU,EAAE;IACV,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,cAAc,CAAC,EAAE,GAAG,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,GAAG,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAA;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,EACD,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE;IACL,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,YAAY,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAC5E,iBAoFF;AAyhDD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKpD"}
@@ -522,6 +522,7 @@ function hasDeprecatedParentKey(components) {
522
522
  }
523
523
  export async function reverseCompile(embeddable, embeddableId, opts) {
524
524
  const fix = opts?.fix ?? false;
525
+ const preserve = opts?.preserve ?? false;
525
526
  const pullMetadata = opts?.pullMetadata;
526
527
  // When fix is disabled, throw on deprecated parent_key so user gets interactive retry prompt
527
528
  if (!fix) {
@@ -563,7 +564,7 @@ export async function reverseCompile(embeddable, embeddableId, opts) {
563
564
  await generateStylesFile(embeddable.styles, embeddableId);
564
565
  }
565
566
  // Generate config.json
566
- await generateConfigFile(embeddable, embeddableId, pullMetadata);
567
+ await generateConfigFile(embeddable, embeddableId, { pullMetadata, preserve });
567
568
  // Extract computedFields to JS files
568
569
  if (embeddable.computedFields && embeddable.computedFields.length > 0) {
569
570
  await extractComputedFields(embeddable.computedFields, embeddableId);
@@ -1550,7 +1551,9 @@ function escapeStringForJS(str) {
1550
1551
  * This file controls page ordering and stores embeddable-level metadata.
1551
1552
  * Preserves the order of top-level properties from embeddable.json.
1552
1553
  */
1553
- async function generateConfigFile(embeddable, embeddableId, pullMetadata) {
1554
+ async function generateConfigFile(embeddable, embeddableId, opts) {
1555
+ const pullMetadata = opts?.pullMetadata;
1556
+ const preserve = opts?.preserve ?? false;
1554
1557
  try {
1555
1558
  const configPath = path.join('embeddables', embeddableId, 'config.json');
1556
1559
  // CLI-only fields: from pull (when branching/saving) or from existing config file.
@@ -1590,6 +1593,10 @@ async function generateConfigFile(embeddable, embeddableId, pullMetadata) {
1590
1593
  }
1591
1594
  }
1592
1595
  }
1596
+ // When --preserve: record component order for forward compile
1597
+ if (preserve && Array.isArray(page.components) && page.components.length > 0) {
1598
+ pageMetadata.components_order = page.components.map((c) => c.id);
1599
+ }
1593
1600
  return pageMetadata;
1594
1601
  });
1595
1602
  // Extract computedFields metadata (without code, as code is in JS files)
@@ -1639,6 +1646,10 @@ async function generateConfigFile(embeddable, embeddableId, pullMetadata) {
1639
1646
  }
1640
1647
  else if (key === 'components') {
1641
1648
  // Skip components (they're in TSX files in global-components/)
1649
+ // When --preserve: record global component order for forward compile
1650
+ if (preserve && embeddable.components && Array.isArray(embeddable.components)) {
1651
+ config.components_order = embeddable.components.map((c) => c.id);
1652
+ }
1642
1653
  continue;
1643
1654
  }
1644
1655
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddables/cli",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "embeddables": "./bin/embeddables.mjs"