create-flow-os 0.0.1-dev.1771668924 → 0.0.1-dev.1771669629

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/bin/index.js CHANGED
@@ -721,10 +721,6 @@ var he = (s = "") => {
721
721
 
722
722
  `);
723
723
  };
724
- var pe = (s = "") => {
725
- process.stdout.write(`${import_picocolors2.default.gray(Q2)} ${s}
726
- `);
727
- };
728
724
  var ge = (s = "") => {
729
725
  process.stdout.write(`${import_picocolors2.default.gray(a2)}
730
726
  ${import_picocolors2.default.gray($2)} ${s}
@@ -906,71 +902,11 @@ function box(lines) {
906
902
  ` + bottom + `
907
903
  `;
908
904
  }
909
- var LOCAL_URL_RE = /https?:\/\/localhost(:\d+)?(?:\/[^\s]*)?/i;
910
- function flowBanner(url) {
911
- const link = c2.brand(url);
912
- return [
913
- "",
914
- c2.cyan(" \u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E"),
915
- c2.cyan(" \u2502 ") + c2.bold("Flow OS") + c2.cyan(" is running \u2502"),
916
- c2.cyan(" \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"),
917
- "",
918
- " Open: " + link,
919
- ""
920
- ].join(`
921
- `);
922
- }
923
- async function runDevWithBanner(cwd) {
905
+ async function runDev(cwd) {
924
906
  const devProc = Bun.spawn(["bun", "run", "dev"], {
925
907
  cwd,
926
- stdout: "pipe",
927
- stderr: "pipe",
928
- stdio: ["inherit", "pipe", "pipe"]
908
+ stdio: ["inherit", "inherit", "inherit"]
929
909
  });
930
- let bannerShown = false;
931
- const decoder = new TextDecoder;
932
- let outBuf = "";
933
- const drain = (stream, isErr) => {
934
- const target = isErr ? process.stderr : process.stdout;
935
- const reader = stream.getReader();
936
- function read() {
937
- return reader.read().then(({ done, value }) => {
938
- const text = value ? decoder.decode(value, { stream: !done }) : "";
939
- if (isErr) {
940
- if (text)
941
- target.write(text);
942
- return done ? undefined : read();
943
- }
944
- if (text)
945
- outBuf += text;
946
- const lines = outBuf.split(/\r?\n/);
947
- outBuf = done ? "" : lines.pop() ?? "";
948
- for (const line of lines) {
949
- const urlMatch = line.match(LOCAL_URL_RE);
950
- if (!bannerShown && urlMatch) {
951
- bannerShown = true;
952
- process.stdout.write(flowBanner(urlMatch[0]));
953
- }
954
- target.write(line + `
955
- `);
956
- }
957
- if (done && outBuf) {
958
- const urlMatch = outBuf.match(LOCAL_URL_RE);
959
- if (!bannerShown && urlMatch) {
960
- bannerShown = true;
961
- process.stdout.write(flowBanner(urlMatch[0]));
962
- }
963
- target.write(outBuf);
964
- }
965
- return done ? undefined : read();
966
- });
967
- }
968
- return read();
969
- };
970
- await Promise.all([
971
- drain(devProc.stdout, false),
972
- drain(devProc.stderr, true)
973
- ]).catch(() => {});
974
910
  await devProc.exited;
975
911
  }
976
912
  function optsForProfile(config, profileId) {
@@ -984,13 +920,11 @@ function optsForProfile(config, profileId) {
984
920
  });
985
921
  }
986
922
  async function main() {
987
- const devBadge = useDevTag ? c2.brand(" \xB7 dev") : "";
988
- const introLines = [
989
- c2.bold("Flow") + devBadge,
990
- "",
991
- c2.cyan("We're creating your Flow application.")
992
- ];
993
- pe(box(introLines));
923
+ const devBadge = useDevTag ? c2.dim(" \xB7 dev") : "";
924
+ console.log(`
925
+ ` + c2.bold("Flow OS") + devBadge + `
926
+ ` + c2.dim("Create Flow OS application") + `
927
+ `);
994
928
  const config = await Bun.file(join2(DIR, "config.json")).json();
995
929
  const hasDeps = Object.values(config.packages).every((e2) => Array.isArray(e2.deps));
996
930
  if (!hasDeps) {
@@ -1146,7 +1080,7 @@ async function main() {
1146
1080
  const startDev = !noStart && !noInstall;
1147
1081
  if (startDev) {
1148
1082
  ge(c2.cyan(ICON.rocket + " Starting dev server\u2026"));
1149
- await runDevWithBanner(projectPath);
1083
+ await runDev(projectPath);
1150
1084
  } else {
1151
1085
  const outroLines = [
1152
1086
  c2.bold("Done"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-flow-os",
3
- "version": "0.0.1-dev.1771668924",
3
+ "version": "0.0.1-dev.1771669629",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "create-flow-os": "bin/index.js"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bun
2
+ import { pathToFileURL } from 'node:url';
3
+ import { join } from 'node:path';
4
+
5
+ await import(pathToFileURL(join(import.meta.dir, 'packages/client/start-dev.ts')).href);
@@ -4,9 +4,9 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "bunx --bun vite --config flow.config.ts",
8
- "build": "tsc -b && bunx --bun vite build --config flow.config.ts",
9
- "preview": "bunx --bun vite preview --config flow.config.ts",
7
+ "dev": "bun dev.ts",
8
+ "build": "tsc -b && bun packages/client/build.ts",
9
+ "preview": "bun packages/client/preview.ts",
10
10
  "start": "bun node_modules/@flow.os/server/start.ts",
11
11
  "lint": "oxlint .",
12
12
  "fmt": "oxfmt",
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bun
2
+ import { pathToFileURL } from 'node:url';
3
+ import { join } from 'node:path';
4
+ import { build } from 'vite';
5
+
6
+ const cwd = process.cwd();
7
+ const configPath = join(cwd, 'flow.config.ts');
8
+ const mod = await import(pathToFileURL(configPath).href).catch((e: Error) => {
9
+ console.error('Flow: could not load flow.config.ts:', e.message);
10
+ process.exit(1);
11
+ });
12
+ const getConfig = mod.default;
13
+ const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
14
+ await build(config);
@@ -1,6 +1,26 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import os from 'node:os';
3
4
  import type { Plugin } from 'vite';
5
+ import { createLogger } from 'vite';
6
+
7
+ const cyan = (s: string) => `\x1b[36m${s}\x1b[0m`;
8
+ const bold = (s: string) => `\x1b[1m${s}\x1b[0m`;
9
+ const dim = (s: string) => `\x1b[2m${s}\x1b[0m`;
10
+ const stripAnsi = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, '');
11
+ const CONTENT_W = 48;
12
+ const BORDER_W = 52;
13
+
14
+ function getNetworkUrl(port: number): string | null {
15
+ const ifaces = os.networkInterfaces();
16
+ for (const list of Object.values(ifaces ?? {})) {
17
+ if (!list) continue;
18
+ for (const i of list) {
19
+ if (i.family === 'IPv4' && !i.internal) return `http://${i.address}:${port}/`;
20
+ }
21
+ }
22
+ return null;
23
+ }
4
24
 
5
25
  /** Solo in monorepo (esiste packages/): Rollup in Docker non segue i symlink, quindi alias a path assoluti. Generico: legge packages/ e mappa tutto. Fuori monorepo (npm) ritorna {}. */
6
26
  function resolveAlias(): Record<string, string> {
@@ -50,6 +70,41 @@ const DEFAULTS = {
50
70
  plugins: [] as Plugin[],
51
71
  };
52
72
 
73
+ /** Banner Flow OS: sostituisce l'output di Vite con uno custom (Local + Network, box, colori). */
74
+ function flowServerUrlPlugin(hostEnabled: boolean): Plugin {
75
+ return {
76
+ name: 'flow:server-url',
77
+ configureServer(server) {
78
+ (server as { printUrls?: () => void }).printUrls = () => {};
79
+ server.httpServer?.once('listening', () => {
80
+ const addr = server.httpServer?.address();
81
+ if (!addr || typeof addr !== 'object' || !('port' in addr)) return;
82
+ const port = (addr as { port: number }).port;
83
+ const host = (addr as { address: string }).address;
84
+ const localHost = host === '::' || host === '0.0.0.0' ? 'localhost' : host;
85
+ const localUrl = `http://${localHost}:${port}/`;
86
+ const networkUrl = hostEnabled ? getNetworkUrl(port) : null;
87
+
88
+ const line = (content: string) => {
89
+ const pad = Math.max(0, CONTENT_W - stripAnsi(content).length);
90
+ return dim(' │ ') + content + ' '.repeat(pad) + dim(' │');
91
+ };
92
+ const border = (c: string) => dim(' ' + c + '─'.repeat(BORDER_W) + (c === '╭' ? '╮' : '╯'));
93
+ const out: string[] = [
94
+ '',
95
+ border('╭'),
96
+ line(bold('Flow OS') + dim(' is running')),
97
+ line(cyan('◆') + ' ' + dim('Local: ') + cyan(localUrl)),
98
+ ...(networkUrl ? [line(dim('Network: ') + cyan(networkUrl))] : []),
99
+ border('╰'),
100
+ '',
101
+ ];
102
+ console.log(out.join('\n'));
103
+ });
104
+ },
105
+ };
106
+ }
107
+
53
108
  /** Config per flow.config.ts. Client + Vite; server opzionale con server: flowServer(). */
54
109
  export default function config(
55
110
  options: FlowConfigOptions = {}
@@ -57,11 +112,24 @@ export default function config(
57
112
  const { port = DEFAULTS.port, host = DEFAULTS.host, server = DEFAULTS.server, plugins = DEFAULTS.plugins } = options;
58
113
  return async () => {
59
114
  const { flow } = await import('./vite.js');
60
- const allPlugins = server ? [server, flow(), ...plugins] : [flow(), ...plugins];
115
+ const allPlugins = [
116
+ flowServerUrlPlugin(host === true),
117
+ ...(server ? [server, flow(), ...plugins] : [flow(), ...plugins]),
118
+ ];
61
119
  const alias = resolveAlias();
120
+ const baseLogger = createLogger('info');
121
+ const customLogger = {
122
+ ...baseLogger,
123
+ info: (msg: string, opts?: { clear?: boolean }) => {
124
+ const t = msg.replace(/\s+/g, ' ');
125
+ if (/VITE\s+v?\d|ready\s+in|Local:\s*http|Network:\s*http|press\s+h\s+enter/i.test(t)) return;
126
+ baseLogger.info(msg, opts);
127
+ },
128
+ };
62
129
  return {
63
130
  resolve: Object.keys(alias).length ? { alias } : {},
64
- server: { port, host },
131
+ server: { port, host, strictPort: false },
132
+ customLogger,
65
133
  build: {
66
134
  rollupOptions: {
67
135
  external: ['@flow.os/server', /^@flow.os\/server\/.+/],
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bun
2
+ import { pathToFileURL } from 'node:url';
3
+ import { join } from 'node:path';
4
+ import { preview } from 'vite';
5
+
6
+ const cwd = process.cwd();
7
+ const configPath = join(cwd, 'flow.config.ts');
8
+ const mod = await import(pathToFileURL(configPath).href).catch((e: Error) => {
9
+ console.error('Flow: could not load flow.config.ts:', e.message);
10
+ process.exit(1);
11
+ });
12
+ const getConfig = mod.default;
13
+ const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
14
+ await preview(config);
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Flow OS dev server runner. Loads flow.config.ts and starts the dev server.
4
+ * Usage: bun node_modules/@flow.os/client/start-dev.ts (or bun packages/client/start-dev.ts in monorepo)
5
+ */
6
+
7
+ import { pathToFileURL } from 'node:url';
8
+ import { join } from 'node:path';
9
+ import { createServer } from 'vite';
10
+
11
+ const cwd = process.cwd();
12
+ const configPath = join(cwd, 'flow.config.ts');
13
+ const configUrl = pathToFileURL(configPath).href;
14
+
15
+ const mod = await import(configUrl).catch((e: Error) => {
16
+ console.error('Flow: could not load flow.config.ts:', e.message);
17
+ process.exit(1);
18
+ });
19
+ const getConfig = mod.default;
20
+ const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
21
+ const server = await createServer(config);
22
+ await server.listen();
23
+ server.watcher.on('change', () => {});
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bun
2
+ import { pathToFileURL } from 'node:url';
3
+ import { join } from 'node:path';
4
+
5
+ await import(pathToFileURL(join(import.meta.dir, 'packages/client/start-dev.ts')).href);
@@ -4,9 +4,9 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "bunx --bun vite --config flow.config.ts",
8
- "build": "tsc -b && bunx --bun vite build --config flow.config.ts",
9
- "preview": "bunx --bun vite preview --config flow.config.ts",
7
+ "dev": "bun dev.ts",
8
+ "build": "tsc -b && bun packages/client/build.ts",
9
+ "preview": "bun packages/client/preview.ts",
10
10
  "start": "bun node_modules/@flow.os/server/start.ts",
11
11
  "lint": "oxlint .",
12
12
  "fmt": "oxfmt",
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bun
2
+ import { pathToFileURL } from 'node:url';
3
+ import { join } from 'node:path';
4
+ import { build } from 'vite';
5
+
6
+ const cwd = process.cwd();
7
+ const configPath = join(cwd, 'flow.config.ts');
8
+ const mod = await import(pathToFileURL(configPath).href).catch((e: Error) => {
9
+ console.error('Flow: could not load flow.config.ts:', e.message);
10
+ process.exit(1);
11
+ });
12
+ const getConfig = mod.default;
13
+ const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
14
+ await build(config);
@@ -1,6 +1,26 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import os from 'node:os';
3
4
  import type { Plugin } from 'vite';
5
+ import { createLogger } from 'vite';
6
+
7
+ const cyan = (s: string) => `\x1b[36m${s}\x1b[0m`;
8
+ const bold = (s: string) => `\x1b[1m${s}\x1b[0m`;
9
+ const dim = (s: string) => `\x1b[2m${s}\x1b[0m`;
10
+ const stripAnsi = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, '');
11
+ const CONTENT_W = 48;
12
+ const BORDER_W = 52;
13
+
14
+ function getNetworkUrl(port: number): string | null {
15
+ const ifaces = os.networkInterfaces();
16
+ for (const list of Object.values(ifaces ?? {})) {
17
+ if (!list) continue;
18
+ for (const i of list) {
19
+ if (i.family === 'IPv4' && !i.internal) return `http://${i.address}:${port}/`;
20
+ }
21
+ }
22
+ return null;
23
+ }
4
24
 
5
25
  /** Solo in monorepo (esiste packages/): Rollup in Docker non segue i symlink, quindi alias a path assoluti. Generico: legge packages/ e mappa tutto. Fuori monorepo (npm) ritorna {}. */
6
26
  function resolveAlias(): Record<string, string> {
@@ -50,6 +70,41 @@ const DEFAULTS = {
50
70
  plugins: [] as Plugin[],
51
71
  };
52
72
 
73
+ /** Banner Flow OS: sostituisce l'output di Vite con uno custom (Local + Network, box, colori). */
74
+ function flowServerUrlPlugin(hostEnabled: boolean): Plugin {
75
+ return {
76
+ name: 'flow:server-url',
77
+ configureServer(server) {
78
+ (server as { printUrls?: () => void }).printUrls = () => {};
79
+ server.httpServer?.once('listening', () => {
80
+ const addr = server.httpServer?.address();
81
+ if (!addr || typeof addr !== 'object' || !('port' in addr)) return;
82
+ const port = (addr as { port: number }).port;
83
+ const host = (addr as { address: string }).address;
84
+ const localHost = host === '::' || host === '0.0.0.0' ? 'localhost' : host;
85
+ const localUrl = `http://${localHost}:${port}/`;
86
+ const networkUrl = hostEnabled ? getNetworkUrl(port) : null;
87
+
88
+ const line = (content: string) => {
89
+ const pad = Math.max(0, CONTENT_W - stripAnsi(content).length);
90
+ return dim(' │ ') + content + ' '.repeat(pad) + dim(' │');
91
+ };
92
+ const border = (c: string) => dim(' ' + c + '─'.repeat(BORDER_W) + (c === '╭' ? '╮' : '╯'));
93
+ const out: string[] = [
94
+ '',
95
+ border('╭'),
96
+ line(bold('Flow OS') + dim(' is running')),
97
+ line(cyan('◆') + ' ' + dim('Local: ') + cyan(localUrl)),
98
+ ...(networkUrl ? [line(dim('Network: ') + cyan(networkUrl))] : []),
99
+ border('╰'),
100
+ '',
101
+ ];
102
+ console.log(out.join('\n'));
103
+ });
104
+ },
105
+ };
106
+ }
107
+
53
108
  /** Config per flow.config.ts. Client + Vite; server opzionale con server: flowServer(). */
54
109
  export default function config(
55
110
  options: FlowConfigOptions = {}
@@ -57,11 +112,24 @@ export default function config(
57
112
  const { port = DEFAULTS.port, host = DEFAULTS.host, server = DEFAULTS.server, plugins = DEFAULTS.plugins } = options;
58
113
  return async () => {
59
114
  const { flow } = await import('./vite.js');
60
- const allPlugins = server ? [server, flow(), ...plugins] : [flow(), ...plugins];
115
+ const allPlugins = [
116
+ flowServerUrlPlugin(host === true),
117
+ ...(server ? [server, flow(), ...plugins] : [flow(), ...plugins]),
118
+ ];
61
119
  const alias = resolveAlias();
120
+ const baseLogger = createLogger('info');
121
+ const customLogger = {
122
+ ...baseLogger,
123
+ info: (msg: string, opts?: { clear?: boolean }) => {
124
+ const t = msg.replace(/\s+/g, ' ');
125
+ if (/VITE\s+v?\d|ready\s+in|Local:\s*http|Network:\s*http|press\s+h\s+enter/i.test(t)) return;
126
+ baseLogger.info(msg, opts);
127
+ },
128
+ };
62
129
  return {
63
130
  resolve: Object.keys(alias).length ? { alias } : {},
64
- server: { port, host },
131
+ server: { port, host, strictPort: false },
132
+ customLogger,
65
133
  build: {
66
134
  rollupOptions: {
67
135
  external: ['@flow.os/server', /^@flow.os\/server\/.+/],
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bun
2
+ import { pathToFileURL } from 'node:url';
3
+ import { join } from 'node:path';
4
+ import { preview } from 'vite';
5
+
6
+ const cwd = process.cwd();
7
+ const configPath = join(cwd, 'flow.config.ts');
8
+ const mod = await import(pathToFileURL(configPath).href).catch((e: Error) => {
9
+ console.error('Flow: could not load flow.config.ts:', e.message);
10
+ process.exit(1);
11
+ });
12
+ const getConfig = mod.default;
13
+ const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
14
+ await preview(config);
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Flow OS dev server runner. Loads flow.config.ts and starts the dev server.
4
+ * Usage: bun node_modules/@flow.os/client/start-dev.ts (or bun packages/client/start-dev.ts in monorepo)
5
+ */
6
+
7
+ import { pathToFileURL } from 'node:url';
8
+ import { join } from 'node:path';
9
+ import { createServer } from 'vite';
10
+
11
+ const cwd = process.cwd();
12
+ const configPath = join(cwd, 'flow.config.ts');
13
+ const configUrl = pathToFileURL(configPath).href;
14
+
15
+ const mod = await import(configUrl).catch((e: Error) => {
16
+ console.error('Flow: could not load flow.config.ts:', e.message);
17
+ process.exit(1);
18
+ });
19
+ const getConfig = mod.default;
20
+ const config = typeof getConfig === 'function' ? await getConfig() : getConfig;
21
+ const server = await createServer(config);
22
+ await server.listen();
23
+ server.watcher.on('change', () => {});
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bun
2
+ import { pathToFileURL } from 'node:url';
3
+ import { join } from 'node:path';
4
+
5
+ await import(pathToFileURL(join(import.meta.dir, 'packages/client/start-dev.ts')).href);
@@ -4,9 +4,9 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "bunx --bun vite --config flow.config.ts",
8
- "build": "tsc -b && bunx --bun vite build --config flow.config.ts",
9
- "preview": "bunx --bun vite preview --config flow.config.ts",
7
+ "dev": "bun dev.ts",
8
+ "build": "tsc -b && bun packages/client/build.ts",
9
+ "preview": "bun packages/client/preview.ts",
10
10
  "start": "bun node_modules/@flow.os/server/start.ts",
11
11
  "lint": "oxlint .",
12
12
  "fmt": "oxfmt",