@hanzogui/recipes 8.2.0 → 8.2.1
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 +32 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -44,6 +44,36 @@ async function readConfig(root) {
|
|
|
44
44
|
function resolveInstallDir(root, config) {
|
|
45
45
|
return path.join(root, config.installDir ?? DEFAULT_INSTALL_DIR);
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
// src/write.ts
|
|
49
|
+
import { existsSync as existsSync2, promises as fs2 } from "node:fs";
|
|
50
|
+
import path2 from "node:path";
|
|
51
|
+
async function getInstallDir(opts) {
|
|
52
|
+
if (opts.installDir)
|
|
53
|
+
return opts.installDir;
|
|
54
|
+
const root = await findProjectRoot(opts.cwd);
|
|
55
|
+
return resolveInstallDir(root, await readConfig(root));
|
|
56
|
+
}
|
|
57
|
+
async function installRecipe(recipe, opts = {}) {
|
|
58
|
+
const installDir = await getInstallDir(opts);
|
|
59
|
+
const written = [];
|
|
60
|
+
for (const file of recipe.files) {
|
|
61
|
+
const dest = path2.join(installDir, file.path);
|
|
62
|
+
const dir = path2.dirname(dest);
|
|
63
|
+
if (!existsSync2(dir))
|
|
64
|
+
await fs2.mkdir(dir, { recursive: true });
|
|
65
|
+
await fs2.writeFile(dest, file.source);
|
|
66
|
+
written.push(dest);
|
|
67
|
+
}
|
|
68
|
+
return written;
|
|
69
|
+
}
|
|
70
|
+
async function installPlan(plan, opts = {}) {
|
|
71
|
+
const written = [];
|
|
72
|
+
for (const r of [plan.recipe, ...plan.transitiveRecipes]) {
|
|
73
|
+
written.push(...await installRecipe(r, opts));
|
|
74
|
+
}
|
|
75
|
+
return written;
|
|
76
|
+
}
|
|
47
77
|
// src/read.ts
|
|
48
78
|
async function getJSON(url) {
|
|
49
79
|
const res = await fetch(url, { headers: { Accept: "application/json" } });
|
|
@@ -92,41 +122,11 @@ async function resolveRecipe(slug, opts = {}) {
|
|
|
92
122
|
})();
|
|
93
123
|
const recipe = seen.get(slug);
|
|
94
124
|
const transitiveRecipes = Array.from(seen.values()).filter((r) => r.slug !== slug);
|
|
95
|
-
const
|
|
96
|
-
const targetPaths = [recipe, ...transitiveRecipes].flatMap((r) => r.files.map((f) =>
|
|
125
|
+
const path3 = await import("node:path");
|
|
126
|
+
const targetPaths = [recipe, ...transitiveRecipes].flatMap((r) => r.files.map((f) => path3.join(installDir, f.path)));
|
|
97
127
|
return { recipe, transitiveRecipes, targetPaths };
|
|
98
128
|
}
|
|
99
129
|
|
|
100
|
-
// src/write.ts
|
|
101
|
-
import { existsSync as existsSync2, promises as fs2 } from "node:fs";
|
|
102
|
-
import path2 from "node:path";
|
|
103
|
-
async function getInstallDir(opts) {
|
|
104
|
-
if (opts.installDir)
|
|
105
|
-
return opts.installDir;
|
|
106
|
-
const root = await findProjectRoot(opts.cwd);
|
|
107
|
-
return resolveInstallDir(root, await readConfig(root));
|
|
108
|
-
}
|
|
109
|
-
async function installRecipe(recipe, opts = {}) {
|
|
110
|
-
const installDir = await getInstallDir(opts);
|
|
111
|
-
const written = [];
|
|
112
|
-
for (const file of recipe.files) {
|
|
113
|
-
const dest = path2.join(installDir, file.path);
|
|
114
|
-
const dir = path2.dirname(dest);
|
|
115
|
-
if (!existsSync2(dir))
|
|
116
|
-
await fs2.mkdir(dir, { recursive: true });
|
|
117
|
-
await fs2.writeFile(dest, file.source);
|
|
118
|
-
written.push(dest);
|
|
119
|
-
}
|
|
120
|
-
return written;
|
|
121
|
-
}
|
|
122
|
-
async function installPlan(plan, opts = {}) {
|
|
123
|
-
const written = [];
|
|
124
|
-
for (const r of [plan.recipe, ...plan.transitiveRecipes]) {
|
|
125
|
-
written.push(...await installRecipe(r, opts));
|
|
126
|
-
}
|
|
127
|
-
return written;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
130
|
// src/admin.ts
|
|
131
131
|
async function authAdmin({
|
|
132
132
|
baseUrl,
|
package/package.json
CHANGED