MCPcopy Create free account
hub / github.com/codename-co/stack / bundleRecipe

Function bundleRecipe

packages/scripts/bundle-recipe.ts:16–66  ·  view source on GitHub ↗
(recipeSlug: string)

Source from the content-addressed store, hash-verified

14const ROOT_DEST_FOLDER = "./recipes/.dist";
15
16const bundleRecipe = (recipeSlug: string) => {
17 const recipePath = `./recipes/${recipeSlug}`;
18
19 const rootCompose = parseYAML(
20 readFileSync(`${recipePath}/compose.yaml`, "utf-8")
21 );
22 // const stack = parseYAML(readFileSync(`${recipePath}/stack.yaml`, "utf-8"));
23
24 const hasComposeIncludes = rootCompose.include?.length > 0;
25
26 if (!hasComposeIncludes) {
27 console.warn("No includes found in compose.yaml");
28 process.exit(0);
29 }
30
31 const dependencies = rootCompose.include.map((file: string) => {
32 console.log(`Reading ${recipePath}/${file}`);
33 const stackFilePath = `${recipePath}/${file}`.replace(
34 /compose\.yaml$/,
35 "stack.yaml"
36 );
37 const content = readFileSync(stackFilePath, "utf-8");
38 const parsed = parseYAML(content);
39 return parsed;
40 });
41
42 rootCompose.include = rootCompose.include.map((file: string) =>
43 file.replace("../../hub/", "./stacks/")
44 );
45
46 // console.log(stringify(rootCompose));
47
48 const outdir = `${ROOT_DEST_FOLDER}/${recipeSlug}`;
49 // create directory if it doesn't exist
50 mkdirSync(outdir, { recursive: true });
51
52 execSync(`cp -R ${recipePath} ${ROOT_DEST_FOLDER}`);
53 console.debug(`Copied ${recipePath} to ${ROOT_DEST_FOLDER}`);
54
55 writeFileSync(`${outdir}/compose.yaml`, stringify(rootCompose));
56 console.log(`Wrote ${outdir}/compose.yaml`);
57
58 dependencies.forEach((dep) => {
59 // Copy ./hub/${dep}/ to ./stacks/${recipeSlug}/
60 const depPath = `./hub/${dep.slug}`;
61 const depOutdir = `${ROOT_DEST_FOLDER}/${recipeSlug}/stacks/`;
62 mkdirSync(depOutdir, { recursive: true });
63 execSync(`cp -R ${depPath} ${depOutdir}`);
64 console.debug(`Copied ${depPath} to ${depOutdir}`);
65 });
66};
67
68if (args.length === 1) {
69 bundleRecipe(args[0]);

Callers 1

bundle-recipe.tsFile · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected