create-flow-os 0.0.15 → 0.0.16

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 CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "create-flow-os",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "license": "PolyForm-Shield-1.0.0",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@flow-os/client": "^0.0.11"
7
+ "@flow-os/client": "^0.0.16"
8
8
  },
9
9
  "bin": {
10
10
  "create-flow-os": "./src/index.ts"
package/src/init/index.ts CHANGED
@@ -4,7 +4,7 @@ import * as readline from "readline";
4
4
  import { join, dirname } from "path";
5
5
  import { fileURLToPath } from "url";
6
6
  import { libsWithConfig, toShortName } from "./lib";
7
- import { initLib } from "./scaffold";
7
+ import { initLib, fetchFlowClientVersion } from "./scaffold";
8
8
 
9
9
  // ───────────────────────────────────────────────────────────────────────────────
10
10
  // Usage: bun create flow-os i [lib...] | bun create flow-os i (prompt interattivo)
@@ -62,10 +62,11 @@ if (!toInit.length) {
62
62
  }
63
63
 
64
64
  // ───────────────────────────────────────────────────────────────────────────────
65
- // Execute: init libs, poi output box
65
+ // Execute: fetch versione client da npm (latest/dev), init libs, poi output box
66
66
  // ───────────────────────────────────────────────────────────────────────────────
67
+ const clientVersion = await fetchFlowClientVersion();
67
68
  const done = new Set<string>();
68
- for (const lib of toInit) initLib(lib, cwd, done);
69
+ for (const lib of toInit) initLib(lib, cwd, done, clientVersion);
69
70
 
70
71
  const iconOk = V + "◆" + R;
71
72
  const iconUnrec = Y + "?" + R;
@@ -4,6 +4,7 @@ import { fileURLToPath } from "url";
4
4
  import { pkgRoot, flowDeps, toPkgName, toShortName } from "./lib";
5
5
 
6
6
  const SKIP = new Set(["node_modules", ".git", ".vite", "package.json"]);
7
+ const NPM_REGISTRY = "https://registry.npmjs.org";
7
8
 
8
9
  function copyConfig(configDir: string, cwd: string): void {
9
10
  for (const e of readdirSync(configDir, { withFileTypes: true })) {
@@ -12,13 +13,27 @@ function copyConfig(configDir: string, cwd: string): void {
12
13
  }
13
14
  }
14
15
 
15
- /** Versione @flow-os/client da create-flow-os (fallback quando pkgRoot non risolve) */
16
- function getCreateFlowOsClientDep(): string | undefined {
16
+ /** Indica se create-flow-os è in modalità dev (flow-os@dev) */
17
+ function isCreateFlowOsDev(): boolean {
17
18
  try {
18
19
  const cliRoot = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
19
20
  const pkg = JSON.parse(readFileSync(join(cliRoot, "package.json"), "utf-8")) as { dependencies?: Record<string, string> };
20
21
  const v = pkg.dependencies?.["@flow-os/client"];
21
- return v && v !== "workspace:*" ? v : undefined;
22
+ return !!v?.includes("dev");
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+
28
+ /** Recupera la versione di @flow-os/client dal registry npm in tempo reale (latest o dev) */
29
+ export async function fetchFlowClientVersion(): Promise<string | undefined> {
30
+ const tag = isCreateFlowOsDev() ? "dev" : "latest";
31
+ try {
32
+ const res = await fetch(`${NPM_REGISTRY}/@flow-os/client`);
33
+ if (!res.ok) return undefined;
34
+ const data = (await res.json()) as { "dist-tags"?: Record<string, string> };
35
+ const version = data["dist-tags"]?.[tag] ?? data["dist-tags"]?.["latest"];
36
+ return version;
22
37
  } catch {
23
38
  return undefined;
24
39
  }
@@ -27,7 +42,8 @@ function getCreateFlowOsClientDep(): string | undefined {
27
42
  /** Sostituisce workspace:* e 0.0.1 con versione concreta (workspace va bene solo dentro flow-os) */
28
43
  function resolveFlowDeps(
29
44
  deps: Record<string, string> | undefined,
30
- configDir: string
45
+ configDir: string,
46
+ clientVersionFromNpm: string | undefined
31
47
  ): Record<string, string> {
32
48
  if (!deps) return {};
33
49
  const resolved = { ...deps };
@@ -38,14 +54,25 @@ function resolveFlowDeps(
38
54
  ownerVersion = (JSON.parse(readFileSync(ownerPkgPath, "utf-8")) as { version?: string }).version;
39
55
  } catch {}
40
56
  }
41
- const createFlowOsClientDep = getCreateFlowOsClientDep();
42
- const isDevSpec = createFlowOsClientDep?.includes("dev");
57
+ const isDevSpec = isCreateFlowOsDev();
43
58
  for (const k of Object.keys(resolved)) {
44
- if (!k.startsWith("@flow-os/") || (resolved[k] !== "workspace:*" && resolved[k] !== "0.0.1")) continue;
59
+ if (!k.startsWith("@flow-os/")) continue;
60
+ const v = resolved[k];
61
+ if (v !== "workspace:*" && v !== "0.0.1" && k !== "@flow-os/client") continue;
45
62
  let spec: string | undefined;
46
- // flow-os@dev usa tag "dev" per installare @flow-os/client@dev
47
- if (k === "@flow-os/client" && isDevSpec) {
48
- spec = "dev";
63
+ if (k === "@flow-os/client") {
64
+ if (clientVersionFromNpm) {
65
+ spec = isDevSpec ? "dev" : `^${clientVersionFromNpm}`;
66
+ } else if (isDevSpec) {
67
+ spec = "dev";
68
+ } else {
69
+ try {
70
+ const root = pkgRoot(k);
71
+ const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf-8")) as { version?: string };
72
+ if (pkg.version) spec = `^${pkg.version}`;
73
+ } catch {}
74
+ if (!spec && ownerVersion) spec = `^${ownerVersion}`;
75
+ }
49
76
  } else {
50
77
  try {
51
78
  const root = pkgRoot(k);
@@ -53,14 +80,13 @@ function resolveFlowDeps(
53
80
  if (pkg.version) spec = `^${pkg.version}`;
54
81
  } catch {}
55
82
  if (!spec && ownerVersion) spec = `^${ownerVersion}`;
56
- if (!spec && k === "@flow-os/client" && createFlowOsClientDep) spec = createFlowOsClientDep;
57
83
  }
58
84
  if (spec) resolved[k] = spec;
59
85
  }
60
86
  return resolved;
61
87
  }
62
88
 
63
- function mergePkg(configDir: string, cwd: string): void {
89
+ function mergePkg(configDir: string, cwd: string, clientVersionFromNpm: string | undefined): void {
64
90
  const configPkg = join(configDir, "package.json");
65
91
  if (!existsSync(configPkg)) return;
66
92
  const targetPath = join(cwd, "package.json");
@@ -70,13 +96,15 @@ function mergePkg(configDir: string, cwd: string): void {
70
96
  : { ...config, name: basename(cwd) || "flow-app" };
71
97
  target.dependencies = { ...target.dependencies, ...config.dependencies };
72
98
  target.devDependencies = { ...target.devDependencies, ...config.devDependencies };
73
- for (const [k, v] of Object.entries(resolveFlowDeps(config.dependencies, configDir))) target.dependencies[k] = v;
74
- for (const [k, v] of Object.entries(resolveFlowDeps(config.devDependencies, configDir))) target.devDependencies[k] = v;
99
+ for (const [k, v] of Object.entries(resolveFlowDeps(config.dependencies, configDir, clientVersionFromNpm)))
100
+ target.dependencies[k] = v;
101
+ for (const [k, v] of Object.entries(resolveFlowDeps(config.devDependencies, configDir, clientVersionFromNpm)))
102
+ target.devDependencies[k] = v;
75
103
  target.scripts = { ...target.scripts, ...config.scripts };
76
104
  writeFileSync(targetPath, JSON.stringify(target, null, 2));
77
105
  }
78
106
 
79
- export function initLib(lib: string, cwd: string, done: Set<string>): void {
107
+ export function initLib(lib: string, cwd: string, done: Set<string>, clientVersionFromNpm?: string): void {
80
108
  const pkgName = toPkgName(lib);
81
109
  if (done.has(pkgName)) return;
82
110
 
@@ -85,10 +113,10 @@ export function initLib(lib: string, cwd: string, done: Set<string>): void {
85
113
  if (!existsSync(configDir)) return;
86
114
 
87
115
  for (const sub of flowDeps(root)) {
88
- initLib(toShortName(sub), cwd, done);
116
+ initLib(toShortName(sub), cwd, done, clientVersionFromNpm);
89
117
  }
90
118
 
91
119
  copyConfig(configDir, cwd);
92
- mergePkg(configDir, cwd);
120
+ mergePkg(configDir, cwd, clientVersionFromNpm);
93
121
  done.add(pkgName);
94
122
  }