create-flow-os 0.0.47-dev.1772043993 → 0.0.47
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/package.json +2 -2
- package/src/init/index.ts +2 -2
- package/src/init/scaffold.ts +14 -64
- package/src/init/ui.ts +12 -16
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-flow-os",
|
|
3
|
-
"version": "0.0.47
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"license": "PolyForm-Shield-1.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@flow-os/client": "
|
|
7
|
+
"@flow-os/client": "^0.0.47"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
10
|
"create-flow-os": "./src/index.ts"
|
package/src/init/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as readline from "readline";
|
|
|
6
6
|
import { join, dirname } from "path";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
import { libsWithConfig, toShortName, toPkgName } from "./lib";
|
|
9
|
-
import { initLib, fetchFlowPackageVersions
|
|
9
|
+
import { initLib, fetchFlowPackageVersions } from "./scaffold";
|
|
10
10
|
import { bannerBox, withLoading, colors } from "./ui";
|
|
11
11
|
|
|
12
12
|
const { V, V_LIGHT, Y, E, R, B } = colors;
|
|
@@ -43,7 +43,7 @@ if (!toInit.length) {
|
|
|
43
43
|
// ───────────────────────────────────────────────────────────────────────────────
|
|
44
44
|
const pkgNames = toInit.map(toPkgName);
|
|
45
45
|
await withLoading(async (onStep) => {
|
|
46
|
-
const versions =
|
|
46
|
+
const versions = await fetchFlowPackageVersions(pkgNames);
|
|
47
47
|
await initLib(toInit, cwd, versions, onStep);
|
|
48
48
|
});
|
|
49
49
|
|
package/src/init/scaffold.ts
CHANGED
|
@@ -79,29 +79,6 @@ function isCreateFlowOsDev(): boolean {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/** Trova la root del repo flow-os salendo da cwd (contiene packages/client) */
|
|
83
|
-
export function findFlowOsRepoRoot(cwd: string): string | null {
|
|
84
|
-
let d = cwd;
|
|
85
|
-
while (true) {
|
|
86
|
-
const pkgClient = join(d, "packages", "client", "package.json");
|
|
87
|
-
if (existsSync(pkgClient)) {
|
|
88
|
-
try {
|
|
89
|
-
const pkg = JSON.parse(readFileSync(pkgClient, "utf-8")) as { name?: string };
|
|
90
|
-
if (pkg?.name === "@flow-os/client") return d;
|
|
91
|
-
} catch {}
|
|
92
|
-
}
|
|
93
|
-
const parent = dirname(d);
|
|
94
|
-
if (parent === d) break;
|
|
95
|
-
d = parent;
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** True se usare workspace:* (cwd dentro repo flow-os) */
|
|
101
|
-
export function shouldUseWorkspace(cwd: string): boolean {
|
|
102
|
-
return !!findFlowOsRepoRoot(cwd);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
82
|
/** Recupera versione di un pacchetto @flow-os/* dal registry npm (con cache 5 min) */
|
|
106
83
|
async function fetchFlowPackageVersion(pkgName: string): Promise<string | undefined> {
|
|
107
84
|
const tag = isCreateFlowOsDev() ? "dev" : "latest";
|
|
@@ -193,17 +170,10 @@ async function fetchConfigFromNpm(
|
|
|
193
170
|
function resolveFlowDeps(
|
|
194
171
|
deps: Record<string, string> | undefined,
|
|
195
172
|
configDir: string,
|
|
196
|
-
versionsFromNpm: Map<string, string
|
|
197
|
-
useWorkspace: boolean
|
|
173
|
+
versionsFromNpm: Map<string, string>
|
|
198
174
|
): Record<string, string> {
|
|
199
175
|
if (!deps) return {};
|
|
200
176
|
const resolved = { ...deps };
|
|
201
|
-
if (useWorkspace) {
|
|
202
|
-
for (const k of Object.keys(resolved)) {
|
|
203
|
-
if (k.startsWith("@flow-os/")) resolved[k] = "workspace:*";
|
|
204
|
-
}
|
|
205
|
-
return resolved;
|
|
206
|
-
}
|
|
207
177
|
const ownerPkgPath = join(configDir, "..", "package.json");
|
|
208
178
|
let ownerVersion: string | undefined;
|
|
209
179
|
if (existsSync(ownerPkgPath)) {
|
|
@@ -235,7 +205,7 @@ function resolveFlowDeps(
|
|
|
235
205
|
return resolved;
|
|
236
206
|
}
|
|
237
207
|
|
|
238
|
-
function mergePkg(configDir: string, cwd: string, versionsFromNpm: Map<string, string
|
|
208
|
+
function mergePkg(configDir: string, cwd: string, versionsFromNpm: Map<string, string>): void {
|
|
239
209
|
const configPkg = join(configDir, "package.json");
|
|
240
210
|
if (!existsSync(configPkg)) return;
|
|
241
211
|
const targetPath = join(cwd, "package.json");
|
|
@@ -245,9 +215,9 @@ function mergePkg(configDir: string, cwd: string, versionsFromNpm: Map<string, s
|
|
|
245
215
|
: { ...config, name: basename(cwd) || "flow-app" };
|
|
246
216
|
target.dependencies = { ...target.dependencies, ...config.dependencies };
|
|
247
217
|
target.devDependencies = { ...target.devDependencies, ...config.devDependencies };
|
|
248
|
-
for (const [k, v] of Object.entries(resolveFlowDeps(config.dependencies, configDir, versionsFromNpm
|
|
218
|
+
for (const [k, v] of Object.entries(resolveFlowDeps(config.dependencies, configDir, versionsFromNpm)))
|
|
249
219
|
target.dependencies[k] = v;
|
|
250
|
-
for (const [k, v] of Object.entries(resolveFlowDeps(config.devDependencies, configDir, versionsFromNpm
|
|
220
|
+
for (const [k, v] of Object.entries(resolveFlowDeps(config.devDependencies, configDir, versionsFromNpm)))
|
|
251
221
|
target.devDependencies[k] = v;
|
|
252
222
|
target.scripts = { ...target.scripts, ...config.scripts };
|
|
253
223
|
writeFileSync(targetPath, JSON.stringify(target, null, 2));
|
|
@@ -281,17 +251,12 @@ async function collectAllTemplates(
|
|
|
281
251
|
done: Set<string>,
|
|
282
252
|
order: string[],
|
|
283
253
|
versionsFromNpm: Map<string, string>,
|
|
284
|
-
tmpDirs: string[]
|
|
285
|
-
flowOsRepoRoot: string | null
|
|
254
|
+
tmpDirs: string[]
|
|
286
255
|
): Promise<void> {
|
|
287
256
|
for (const lib of libs) {
|
|
288
257
|
const pkgName = toPkgName(lib);
|
|
289
258
|
if (done.has(pkgName)) continue;
|
|
290
259
|
|
|
291
|
-
const shortName = toShortName(pkgName);
|
|
292
|
-
const localFromRepo = flowOsRepoRoot ? join(flowOsRepoRoot, "packages", shortName) : "";
|
|
293
|
-
const localConfigFromRepo = localFromRepo ? join(localFromRepo, "config") : "";
|
|
294
|
-
|
|
295
260
|
let root: string;
|
|
296
261
|
let configDir: string;
|
|
297
262
|
try {
|
|
@@ -301,22 +266,12 @@ async function collectAllTemplates(
|
|
|
301
266
|
root = "";
|
|
302
267
|
configDir = "";
|
|
303
268
|
}
|
|
304
|
-
const hasLocalFromRepo = !!localConfigFromRepo && existsSync(localConfigFromRepo);
|
|
305
269
|
const hasLocal = existsSync(configDir);
|
|
306
270
|
|
|
307
271
|
let pkgFiles: Map<string, string>;
|
|
308
272
|
let configDirForPkg: string;
|
|
309
|
-
const useLocalRepo = hasLocalFromRepo && flowOsRepoRoot;
|
|
310
273
|
const npmVer = versionsFromNpm.get(pkgName);
|
|
311
|
-
|
|
312
|
-
if (useLocalRepo) {
|
|
313
|
-
configDirForPkg = localConfigFromRepo;
|
|
314
|
-
pkgFiles = collectConfigFiles(configDirForPkg);
|
|
315
|
-
const subDeps = flowDepsFromPkg(join(configDirForPkg, ".."));
|
|
316
|
-
for (const sub of subDeps) {
|
|
317
|
-
await collectAllTemplates([toShortName(sub)], combined, done, order, versionsFromNpm, tmpDirs, flowOsRepoRoot);
|
|
318
|
-
}
|
|
319
|
-
} else if (npmVer) {
|
|
274
|
+
if (npmVer) {
|
|
320
275
|
const fetched = await fetchConfigFromNpm(pkgName, npmVer, tmpDirs);
|
|
321
276
|
if (fetched) {
|
|
322
277
|
pkgFiles = fetched.files;
|
|
@@ -324,13 +279,13 @@ async function collectAllTemplates(
|
|
|
324
279
|
const subDeps = flowDepsFromPkg(join(configDirForPkg, ".."));
|
|
325
280
|
await ensureVersions(versionsFromNpm, subDeps);
|
|
326
281
|
for (const sub of subDeps) {
|
|
327
|
-
await collectAllTemplates([toShortName(sub)], combined, done, order, versionsFromNpm, tmpDirs
|
|
282
|
+
await collectAllTemplates([toShortName(sub)], combined, done, order, versionsFromNpm, tmpDirs);
|
|
328
283
|
}
|
|
329
284
|
} else if (hasLocal) {
|
|
330
285
|
const subDeps = flowDeps(root);
|
|
331
286
|
await ensureVersions(versionsFromNpm, subDeps);
|
|
332
287
|
for (const sub of subDeps) {
|
|
333
|
-
await collectAllTemplates([toShortName(sub)], combined, done, order, versionsFromNpm, tmpDirs
|
|
288
|
+
await collectAllTemplates([toShortName(sub)], combined, done, order, versionsFromNpm, tmpDirs);
|
|
334
289
|
}
|
|
335
290
|
pkgFiles = collectConfigFiles(configDir);
|
|
336
291
|
configDirForPkg = configDir;
|
|
@@ -341,7 +296,7 @@ async function collectAllTemplates(
|
|
|
341
296
|
const subDeps = flowDeps(root);
|
|
342
297
|
await ensureVersions(versionsFromNpm, subDeps);
|
|
343
298
|
for (const sub of subDeps) {
|
|
344
|
-
await collectAllTemplates([toShortName(sub)], combined, done, order, versionsFromNpm, tmpDirs
|
|
299
|
+
await collectAllTemplates([toShortName(sub)], combined, done, order, versionsFromNpm, tmpDirs);
|
|
345
300
|
}
|
|
346
301
|
pkgFiles = collectConfigFiles(configDir);
|
|
347
302
|
configDirForPkg = configDir;
|
|
@@ -364,33 +319,28 @@ export async function initLib(
|
|
|
364
319
|
onProgress?: (step: InitProgressStep) => void
|
|
365
320
|
): Promise<void> {
|
|
366
321
|
const pkgNames = libs.map(toPkgName);
|
|
367
|
-
const flowOsRepoRoot = findFlowOsRepoRoot(cwd);
|
|
368
|
-
const useWorkspace = !!flowOsRepoRoot;
|
|
369
322
|
const versions = versionsFromNpm ?? new Map<string, string>();
|
|
370
323
|
|
|
371
324
|
onProgress?.("fetch");
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
for (const [k, v] of fetched) versions.set(k, v);
|
|
375
|
-
}
|
|
325
|
+
const fetched = await fetchFlowPackageVersions(pkgNames);
|
|
326
|
+
for (const [k, v] of fetched) versions.set(k, v);
|
|
376
327
|
|
|
377
328
|
onProgress?.("templates");
|
|
378
329
|
const combined = new Map<string, string>();
|
|
379
330
|
const done = new Set<string>();
|
|
380
331
|
const order: string[] = [];
|
|
381
332
|
const tmpDirs: string[] = [];
|
|
382
|
-
await collectAllTemplates(libs, combined, done, order, versions, tmpDirs
|
|
333
|
+
await collectAllTemplates(libs, combined, done, order, versions, tmpDirs);
|
|
383
334
|
|
|
384
335
|
for (const configDir of order) {
|
|
385
|
-
mergePkg(configDir, cwd, versions
|
|
336
|
+
mergePkg(configDir, cwd, versions);
|
|
386
337
|
}
|
|
387
338
|
|
|
388
339
|
onProgress?.("write");
|
|
389
340
|
await writeMergedWithUser(combined, cwd, (path, conflicts) => resolveConflicts(conflicts, path));
|
|
390
341
|
|
|
391
342
|
onProgress?.("install");
|
|
392
|
-
const
|
|
393
|
-
const proc = Bun.spawn(["bun", "install"], { cwd: installCwd, stdout: "inherit", stderr: "inherit" });
|
|
343
|
+
const proc = Bun.spawn(["bun", "install"], { cwd, stdout: "inherit", stderr: "inherit" });
|
|
394
344
|
const exitCode = await proc.exited;
|
|
395
345
|
if (exitCode !== 0) {
|
|
396
346
|
throw new Error(`bun install exited with code ${exitCode}`);
|
package/src/init/ui.ts
CHANGED
|
@@ -9,7 +9,6 @@ const E = "\x1b[91m";
|
|
|
9
9
|
const R = "\x1b[0m";
|
|
10
10
|
const B = "\x1b[1m";
|
|
11
11
|
const DIM = "\x1b[2m";
|
|
12
|
-
const W = "\x1b[97m"; // bianco (solo per headerLogo)
|
|
13
12
|
|
|
14
13
|
const FRAMES = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
|
|
15
14
|
|
|
@@ -26,24 +25,19 @@ export function bannerBox(title: string, lines: string[], color: string, w = 50)
|
|
|
26
25
|
const c = color;
|
|
27
26
|
const inner = " " + c + B + title + R + " ";
|
|
28
27
|
const innerLen = stripAnsi(inner).length;
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const emptyLine = c + "│" + R + " " + " ".repeat(innerW - 2) + c + "│" + R;
|
|
35
|
-
const bodyLines = lines.map((l) => c + "│" + R + " " + pad(l, innerW - 2) + c + "│" + R);
|
|
36
|
-
return "\n" + top + "\n" + emptyLine + "\n" + bodyLines.join("\n") + "\n" + bottom + "\n";
|
|
28
|
+
const half = Math.max(0, Math.floor((w - 2 - innerLen) / 2));
|
|
29
|
+
const top = c + "╭" + "─".repeat(half) + inner + "─".repeat(w - 2 - half - innerLen) + "╮" + R;
|
|
30
|
+
const bottom = c + "╰" + "─".repeat(w - 2) + "╯" + R;
|
|
31
|
+
const bodyLines = lines.map((l) => c + "│" + R + " " + pad(l, w - 2) + c + "│" + R);
|
|
32
|
+
return "\n" + top + "\n" + bodyLines.join("\n") + "\n" + bottom + "\n";
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
export function box(lines: string[], color: string, w =
|
|
35
|
+
export function box(lines: string[], color: string, w = 52): string {
|
|
40
36
|
const c = color;
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const body = lines.map((l) => c + "│" + R + " " + pad(l, innerW - 2) + c + "│" + R).join("\n");
|
|
46
|
-
return "\n" + top + "\n" + emptyLine + "\n" + body + "\n" + bottom + "\n";
|
|
37
|
+
const top = c + "╭" + "─".repeat(w) + "╮" + R;
|
|
38
|
+
const bottom = c + "╰" + "─".repeat(w) + "╯" + R;
|
|
39
|
+
const body = lines.map((l) => c + "│" + R + " " + pad(l, w - 2) + c + "│" + R).join("\n");
|
|
40
|
+
return "\n" + top + "\n" + body + "\n" + bottom + "\n";
|
|
47
41
|
}
|
|
48
42
|
|
|
49
43
|
import type { InitProgressStep } from "./scaffold";
|
|
@@ -93,6 +87,8 @@ export async function withLoading<T>(
|
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
|
|
90
|
+
const W = "\x1b[97m"; // bianco
|
|
91
|
+
|
|
96
92
|
export const colors = { V, V_LIGHT, Y, E, R, B, DIM, W };
|
|
97
93
|
|
|
98
94
|
/** Icona layers: 3 quadrati arrotondati sovrapposti, vista isometrica con shading ▓▒░ */
|