@fluid-app/fluid-cli-widget 0.1.3 → 0.1.5

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.mjs CHANGED
@@ -687,11 +687,12 @@ async function copyWidgetTemplate(templatePath, targetPath, variables) {
687
687
  const files = await getFiles(templatePath);
688
688
  for (const file of files) {
689
689
  const sourcePath = path.join(templatePath, file);
690
- const outputFile = getOutputFilename(file);
691
- const destinationPath = path.join(targetPath, outputFile);
692
- await mkdir(path.dirname(destinationPath), { recursive: true });
693
- await writeFile(destinationPath, renderTemplate(await readFile(sourcePath, "utf-8"), variables), "utf-8");
690
+ const isTemplate = file.endsWith(".template");
691
+ const outputFiles = getOutputFilenames(file);
692
+ const content = await readFile(sourcePath, "utf-8");
693
+ await writeOutputFiles(targetPath, outputFiles, isTemplate ? renderTemplate(content, variables) : content);
694
694
  }
695
+ for (const skillFile of await getSharedTemplateSkillFiles()) await writeOutputFiles(targetPath, getOutputFilenames(skillFile.relativePath), skillFile.content);
695
696
  }
696
697
  async function getPortalSdkVersion(options = {}) {
697
698
  return getWorkspacePackageVersion(["portal", "sdk"], "^0.1.0", options);
@@ -727,6 +728,26 @@ async function getFiles(dir, baseDir = dir) {
727
728
  }
728
729
  return files;
729
730
  }
731
+ async function getSharedTemplateSkillFiles() {
732
+ const packageRoot = findFluidCliPackageRoot();
733
+ const skillsRoot = path.join(packageRoot, "template-skills");
734
+ const files = await getFiles(skillsRoot);
735
+ return Promise.all(files.map(async (file) => ({
736
+ relativePath: path.join("skills", file),
737
+ content: await readFile(path.join(skillsRoot, file), "utf-8")
738
+ })));
739
+ }
740
+ function findFluidCliPackageRoot() {
741
+ const workspacePackageRoot = path.join(findPackageRoot(), "..", "core");
742
+ if (existsSync(path.join(workspacePackageRoot, "template-skills"))) return workspacePackageRoot;
743
+ let dir = path.dirname(fileURLToPath(import.meta.resolve("@fluid-app/fluid-cli")));
744
+ while (!existsSync(path.join(dir, "package.json"))) {
745
+ const parent = path.dirname(dir);
746
+ if (parent === dir) throw new Error("Could not find Fluid CLI package root");
747
+ dir = parent;
748
+ }
749
+ return dir;
750
+ }
730
751
  function renderTemplate(content, variables) {
731
752
  return content.replace(/{{\s*#if\s+([a-zA-Z0-9_]+)\s*}}([\s\S]*?){{\s*\/if\s*}}/g, (match, key, block) => {
732
753
  if (!isTemplateVariableKey(key)) return match;
@@ -748,6 +769,20 @@ function isTemplateVariableKey(key) {
748
769
  "droplet"
749
770
  ].includes(key);
750
771
  }
772
+ async function writeOutputFiles(targetPath, outputFiles, content) {
773
+ for (const outputFile of outputFiles) {
774
+ const destinationPath = path.join(targetPath, outputFile);
775
+ await mkdir(path.dirname(destinationPath), { recursive: true });
776
+ await writeFile(destinationPath, content, "utf-8");
777
+ }
778
+ }
779
+ function getOutputFilenames(filename) {
780
+ const outputFilename = getOutputFilename(filename);
781
+ const normalized = outputFilename.replace(/\\/g, "/");
782
+ if (normalized === "AGENTS.md") return ["AGENTS.md", "CLAUDE.md"];
783
+ if (normalized.startsWith("skills/")) return [path.join(".agents", outputFilename), path.join(".claude", outputFilename)];
784
+ return [outputFilename];
785
+ }
751
786
  function getOutputFilename(filename) {
752
787
  return filename.endsWith(".template") ? filename.slice(0, -9) : filename;
753
788
  }