@t3lnet/sceneforge 1.0.11 → 1.0.13

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/index.js CHANGED
@@ -2574,6 +2574,42 @@ function isValidFormat(format) {
2574
2574
  // context/context-builder.ts
2575
2575
  import * as fs6 from "fs/promises";
2576
2576
  import * as path6 from "path";
2577
+ var SCENEFORGE_START_MARKER = "<!-- SCENEFORGE_CONTEXT_START -->";
2578
+ var SCENEFORGE_END_MARKER = "<!-- SCENEFORGE_CONTEXT_END -->";
2579
+ function wrapWithMarkers(content) {
2580
+ return `${SCENEFORGE_START_MARKER}
2581
+ ${content}
2582
+ ${SCENEFORGE_END_MARKER}`;
2583
+ }
2584
+ async function mergeWithExisting(filePath, newContent) {
2585
+ const wrappedContent = wrapWithMarkers(newContent);
2586
+ try {
2587
+ const existingContent = await fs6.readFile(filePath, "utf-8");
2588
+ const startIndex = existingContent.indexOf(SCENEFORGE_START_MARKER);
2589
+ const endIndex = existingContent.indexOf(SCENEFORGE_END_MARKER);
2590
+ if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
2591
+ const beforeSection = existingContent.slice(0, startIndex);
2592
+ const afterSection = existingContent.slice(
2593
+ endIndex + SCENEFORGE_END_MARKER.length
2594
+ );
2595
+ return {
2596
+ content: beforeSection + wrappedContent + afterSection,
2597
+ merged: true
2598
+ };
2599
+ } else {
2600
+ const separator = existingContent.trim().endsWith("-->") ? "\n\n" : "\n\n---\n\n";
2601
+ return {
2602
+ content: existingContent.trimEnd() + separator + wrappedContent + "\n",
2603
+ merged: true
2604
+ };
2605
+ }
2606
+ } catch (error) {
2607
+ if (error.code === "ENOENT") {
2608
+ return { content: wrappedContent, merged: false };
2609
+ }
2610
+ throw error;
2611
+ }
2612
+ }
2577
2613
  async function buildContext(tool, stage, variables) {
2578
2614
  const templates = [];
2579
2615
  const baseTemplates = await loadTemplatesByCategory("base");
@@ -2611,12 +2647,20 @@ async function deployContext(options) {
2611
2647
  const filePath = getOutputPath(tool, format, outputDir);
2612
2648
  const absolutePath = path6.resolve(filePath);
2613
2649
  await fs6.mkdir(path6.dirname(absolutePath), { recursive: true });
2614
- await fs6.writeFile(absolutePath, content, "utf-8");
2650
+ const { content: finalContent, merged } = await mergeWithExisting(
2651
+ absolutePath,
2652
+ content
2653
+ );
2654
+ await fs6.writeFile(absolutePath, finalContent, "utf-8");
2615
2655
  results.push({
2616
2656
  tool,
2617
2657
  filePath: absolutePath,
2618
- created: true
2658
+ created: true,
2659
+ skipped: false
2619
2660
  });
2661
+ if (merged) {
2662
+ console.log(` [merged] ${path6.relative(outputDir, absolutePath)}`);
2663
+ }
2620
2664
  } catch (error) {
2621
2665
  results.push({
2622
2666
  tool,
@@ -2633,13 +2677,21 @@ async function deployContext(options) {
2633
2677
  const filePath = getOutputPath(tool, format, outputDir, stageName);
2634
2678
  const absolutePath = path6.resolve(filePath);
2635
2679
  await fs6.mkdir(path6.dirname(absolutePath), { recursive: true });
2636
- await fs6.writeFile(absolutePath, content, "utf-8");
2680
+ const { content: finalContent, merged } = await mergeWithExisting(
2681
+ absolutePath,
2682
+ content
2683
+ );
2684
+ await fs6.writeFile(absolutePath, finalContent, "utf-8");
2637
2685
  results.push({
2638
2686
  tool,
2639
2687
  filePath: absolutePath,
2640
2688
  stage: stg,
2641
- created: true
2689
+ created: true,
2690
+ skipped: false
2642
2691
  });
2692
+ if (merged) {
2693
+ console.log(` [merged] ${path6.relative(outputDir, absolutePath)}`);
2694
+ }
2643
2695
  } catch (error) {
2644
2696
  results.push({
2645
2697
  tool,