@flow.os/client 0.0.1-dev.1771668924 → 0.0.1-dev.1771669831

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/build.ts ADDED
@@ -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);
package/config.ts CHANGED
@@ -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,19 +70,36 @@ const DEFAULTS = {
50
70
  plugins: [] as Plugin[],
51
71
  };
52
72
 
53
- /** Plugin che stampa l'URL effettivo quando il server è in ascolto (utile quando Vite usa una porta diversa, es. 3001). */
54
- function flowServerUrlPlugin(): Plugin {
73
+ /** Banner Flow OS: sostituisce l'output di Vite con uno custom (Local + Network, box, colori). */
74
+ function flowServerUrlPlugin(hostEnabled: boolean): Plugin {
55
75
  return {
56
76
  name: 'flow:server-url',
57
77
  configureServer(server) {
78
+ (server as { printUrls?: () => void }).printUrls = () => {};
58
79
  server.httpServer?.once('listening', () => {
59
80
  const addr = server.httpServer?.address();
60
- if (addr && typeof addr === 'object' && 'port' in addr) {
61
- const port = (addr as { port: number }).port;
62
- const host = (addr as { address: string }).address;
63
- const hostDisplay = host === '::' || host === '0.0.0.0' ? 'localhost' : host;
64
- console.log(`\n Flow OS: http://${hostDisplay}:${port}/\n`);
65
- }
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'));
66
103
  });
67
104
  },
68
105
  };
@@ -76,13 +113,23 @@ export default function config(
76
113
  return async () => {
77
114
  const { flow } = await import('./vite.js');
78
115
  const allPlugins = [
79
- flowServerUrlPlugin(),
116
+ flowServerUrlPlugin(host === true),
80
117
  ...(server ? [server, flow(), ...plugins] : [flow(), ...plugins]),
81
118
  ];
82
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
+ };
83
129
  return {
84
130
  resolve: Object.keys(alias).length ? { alias } : {},
85
131
  server: { port, host, strictPort: false },
132
+ customLogger,
86
133
  build: {
87
134
  rollupOptions: {
88
135
  external: ['@flow.os/server', /^@flow.os\/server\/.+/],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flow.os/client",
3
- "version": "0.0.1-dev.1771668924",
3
+ "version": "0.0.1-dev.1771669831",
4
4
  "type": "module",
5
5
  "main": "./index.ts",
6
6
  "types": "./index.ts",
package/preview.ts ADDED
@@ -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);
package/start-dev.ts ADDED
@@ -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', () => {});