create-flow-os 0.0.1 → 0.0.2
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 +8 -21
- package/src/create/index.ts +31 -0
- package/src/index.ts +14 -0
- package/src/init/index.ts +66 -0
- package/src/init/lib.ts +36 -0
- package/src/init/scaffold.ts +43 -0
- package/LICENSE +0 -97
- package/README.md +0 -7
- package/bin/index.js +0 -1139
- package/config.json +0 -86
- package/flow.config.client.ts +0 -3
- package/packages/client/client/root.css +0 -9
- package/packages/client/client/root.tsx +0 -13
- package/packages/client/client/routes/404.tsx +0 -24
- package/packages/client/client/routes/index.tsx +0 -47
- package/packages/server/server/routes/hello.get.ts +0 -3
- package/profiles/client/.dockerignore +0 -12
- package/profiles/client/.oxfmtrc.json +0 -7
- package/profiles/client/.oxlintrc.json +0 -13
- package/profiles/client/.vscode/settings.json +0 -12
- package/profiles/client/Dockerfile +0 -26
- package/profiles/client/LICENSE +0 -97
- package/profiles/client/bun.lock +0 -335
- package/profiles/client/client/root.css +0 -10
- package/profiles/client/client/root.tsx +0 -14
- package/profiles/client/client/routes/404.tsx +0 -25
- package/profiles/client/client/routes/index.tsx +0 -48
- package/profiles/client/flow.config.ts +0 -3
- package/profiles/client/index.html +0 -5
- package/profiles/client/package.json +0 -29
- package/profiles/client/packages/client/LICENSE +0 -97
- package/profiles/client/packages/client/build.ts +0 -14
- package/profiles/client/packages/client/config.ts +0 -141
- package/profiles/client/packages/client/dom.ts +0 -5
- package/profiles/client/packages/client/features/attrs.ts +0 -32
- package/profiles/client/packages/client/features/class-flow.ts +0 -116
- package/profiles/client/packages/client/features/index.ts +0 -8
- package/profiles/client/packages/client/features/pseudo-injector.ts +0 -40
- package/profiles/client/packages/client/features/style-flow.ts +0 -106
- package/profiles/client/packages/client/features/style.ts +0 -27
- package/profiles/client/packages/client/features/utils.ts +0 -4
- package/profiles/client/packages/client/features/viewport.ts +0 -20
- package/profiles/client/packages/client/index.ts +0 -4
- package/profiles/client/packages/client/jsx-dev-runtime.ts +0 -1
- package/profiles/client/packages/client/jsx-runtime.ts +0 -1
- package/profiles/client/packages/client/jsx-types.d.ts +0 -64
- package/profiles/client/packages/client/jsx.ts +0 -99
- package/profiles/client/packages/client/package.json +0 -42
- package/profiles/client/packages/client/preview.ts +0 -14
- package/profiles/client/packages/client/start-dev.ts +0 -23
- package/profiles/client/packages/client/vite.ts +0 -54
- package/profiles/client/packages/core/LICENSE +0 -97
- package/profiles/client/packages/core/dom.ts +0 -43
- package/profiles/client/packages/core/for.ts +0 -42
- package/profiles/client/packages/core/index.ts +0 -5
- package/profiles/client/packages/core/lifecycle.ts +0 -6
- package/profiles/client/packages/core/package.json +0 -15
- package/profiles/client/packages/core/show-switch.ts +0 -56
- package/profiles/client/packages/core/state.ts +0 -56
- package/profiles/client/packages/router/LICENSE +0 -97
- package/profiles/client/packages/router/index.ts +0 -174
- package/profiles/client/packages/router/package.json +0 -10
- package/profiles/client/packages/style/LICENSE +0 -97
- package/profiles/client/packages/style/breakpoints.ts +0 -20
- package/profiles/client/packages/style/extension/.vscodeignore +0 -5
- package/profiles/client/packages/style/extension/README.md +0 -7
- package/profiles/client/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
- package/profiles/client/packages/style/extension/out/extension.js +0 -130
- package/profiles/client/packages/style/extension/package.json +0 -24
- package/profiles/client/packages/style/extension/src/extension.ts +0 -146
- package/profiles/client/packages/style/extension/tsconfig.json +0 -12
- package/profiles/client/packages/style/index.ts +0 -16
- package/profiles/client/packages/style/package.json +0 -14
- package/profiles/client/packages/style/resolve.ts +0 -84
- package/profiles/client/packages/style/shorthand.ts +0 -62
- package/profiles/client/tsconfig.json +0 -30
- package/profiles/full/.dockerignore +0 -12
- package/profiles/full/.oxfmtrc.json +0 -7
- package/profiles/full/.oxlintrc.json +0 -13
- package/profiles/full/.vscode/settings.json +0 -12
- package/profiles/full/Dockerfile +0 -26
- package/profiles/full/LICENSE +0 -97
- package/profiles/full/bun.lock +0 -335
- package/profiles/full/client/root.css +0 -10
- package/profiles/full/client/root.tsx +0 -14
- package/profiles/full/client/routes/404.tsx +0 -25
- package/profiles/full/client/routes/index.tsx +0 -48
- package/profiles/full/flow.config.ts +0 -8
- package/profiles/full/index.html +0 -5
- package/profiles/full/package.json +0 -29
- package/profiles/full/packages/client/LICENSE +0 -97
- package/profiles/full/packages/client/build.ts +0 -14
- package/profiles/full/packages/client/config.ts +0 -141
- package/profiles/full/packages/client/dom.ts +0 -5
- package/profiles/full/packages/client/features/attrs.ts +0 -32
- package/profiles/full/packages/client/features/class-flow.ts +0 -116
- package/profiles/full/packages/client/features/index.ts +0 -8
- package/profiles/full/packages/client/features/pseudo-injector.ts +0 -40
- package/profiles/full/packages/client/features/style-flow.ts +0 -106
- package/profiles/full/packages/client/features/style.ts +0 -27
- package/profiles/full/packages/client/features/utils.ts +0 -4
- package/profiles/full/packages/client/features/viewport.ts +0 -20
- package/profiles/full/packages/client/index.ts +0 -4
- package/profiles/full/packages/client/jsx-dev-runtime.ts +0 -1
- package/profiles/full/packages/client/jsx-runtime.ts +0 -1
- package/profiles/full/packages/client/jsx-types.d.ts +0 -64
- package/profiles/full/packages/client/jsx.ts +0 -99
- package/profiles/full/packages/client/package.json +0 -42
- package/profiles/full/packages/client/preview.ts +0 -14
- package/profiles/full/packages/client/start-dev.ts +0 -23
- package/profiles/full/packages/client/vite.ts +0 -54
- package/profiles/full/packages/core/LICENSE +0 -97
- package/profiles/full/packages/core/dom.ts +0 -43
- package/profiles/full/packages/core/for.ts +0 -42
- package/profiles/full/packages/core/index.ts +0 -5
- package/profiles/full/packages/core/lifecycle.ts +0 -6
- package/profiles/full/packages/core/package.json +0 -15
- package/profiles/full/packages/core/show-switch.ts +0 -56
- package/profiles/full/packages/core/state.ts +0 -56
- package/profiles/full/packages/router/LICENSE +0 -97
- package/profiles/full/packages/router/index.ts +0 -174
- package/profiles/full/packages/router/package.json +0 -10
- package/profiles/full/packages/server/LICENSE +0 -97
- package/profiles/full/packages/server/core.ts +0 -140
- package/profiles/full/packages/server/index.ts +0 -24
- package/profiles/full/packages/server/package.json +0 -29
- package/profiles/full/packages/server/plugin.ts +0 -79
- package/profiles/full/packages/server/production.ts +0 -75
- package/profiles/full/packages/server/start.ts +0 -15
- package/profiles/full/packages/style/LICENSE +0 -97
- package/profiles/full/packages/style/breakpoints.ts +0 -20
- package/profiles/full/packages/style/extension/.vscodeignore +0 -5
- package/profiles/full/packages/style/extension/README.md +0 -7
- package/profiles/full/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
- package/profiles/full/packages/style/extension/out/extension.js +0 -130
- package/profiles/full/packages/style/extension/package.json +0 -24
- package/profiles/full/packages/style/extension/src/extension.ts +0 -146
- package/profiles/full/packages/style/extension/tsconfig.json +0 -12
- package/profiles/full/packages/style/index.ts +0 -16
- package/profiles/full/packages/style/package.json +0 -14
- package/profiles/full/packages/style/resolve.ts +0 -84
- package/profiles/full/packages/style/shorthand.ts +0 -62
- package/profiles/full/server/routes/hello.get.ts +0 -4
- package/profiles/full/tsconfig.json +0 -30
- package/profiles/server/.dockerignore +0 -12
- package/profiles/server/.oxfmtrc.json +0 -7
- package/profiles/server/.oxlintrc.json +0 -13
- package/profiles/server/.vscode/settings.json +0 -12
- package/profiles/server/Dockerfile +0 -26
- package/profiles/server/LICENSE +0 -97
- package/profiles/server/bun.lock +0 -335
- package/profiles/server/flow.config.ts +0 -8
- package/profiles/server/index.html +0 -5
- package/profiles/server/package.json +0 -29
- package/profiles/server/packages/core/LICENSE +0 -97
- package/profiles/server/packages/core/dom.ts +0 -43
- package/profiles/server/packages/core/for.ts +0 -42
- package/profiles/server/packages/core/index.ts +0 -5
- package/profiles/server/packages/core/lifecycle.ts +0 -6
- package/profiles/server/packages/core/package.json +0 -15
- package/profiles/server/packages/core/show-switch.ts +0 -56
- package/profiles/server/packages/core/state.ts +0 -56
- package/profiles/server/packages/router/LICENSE +0 -97
- package/profiles/server/packages/router/index.ts +0 -174
- package/profiles/server/packages/router/package.json +0 -10
- package/profiles/server/packages/server/LICENSE +0 -97
- package/profiles/server/packages/server/core.ts +0 -140
- package/profiles/server/packages/server/index.ts +0 -24
- package/profiles/server/packages/server/package.json +0 -29
- package/profiles/server/packages/server/plugin.ts +0 -79
- package/profiles/server/packages/server/production.ts +0 -75
- package/profiles/server/packages/server/start.ts +0 -15
- package/profiles/server/packages/style/LICENSE +0 -97
- package/profiles/server/packages/style/breakpoints.ts +0 -20
- package/profiles/server/packages/style/extension/.vscodeignore +0 -5
- package/profiles/server/packages/style/extension/README.md +0 -7
- package/profiles/server/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
- package/profiles/server/packages/style/extension/out/extension.js +0 -130
- package/profiles/server/packages/style/extension/package.json +0 -24
- package/profiles/server/packages/style/extension/src/extension.ts +0 -146
- package/profiles/server/packages/style/extension/tsconfig.json +0 -12
- package/profiles/server/packages/style/index.ts +0 -16
- package/profiles/server/packages/style/package.json +0 -14
- package/profiles/server/packages/style/resolve.ts +0 -84
- package/profiles/server/packages/style/shorthand.ts +0 -62
- package/profiles/server/server/routes/hello.get.ts +0 -4
- package/profiles/server/tsconfig.json +0 -30
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
export const APP_ID = 'flow-app';
|
|
2
|
-
|
|
3
|
-
/** Contenitore dove il router monta la pagina corrente. In root: <App /> (da @flow.os/router). */
|
|
4
|
-
export function App(): HTMLDivElement {
|
|
5
|
-
const el = document.createElement('div');
|
|
6
|
-
el.id = APP_ID;
|
|
7
|
-
el.setAttribute('role', 'main');
|
|
8
|
-
return el;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type RouteModule = {
|
|
12
|
-
default: (() => Node) | ((params: Record<string, string>) => Node) | (() => string) | string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type RunOptions = {
|
|
16
|
-
/** Nodo (o factory) mostrato mentre la route lazy viene caricata. */
|
|
17
|
-
fallback?: Node | (() => Node);
|
|
18
|
-
/** Pagina 404: se fornita, viene mostrata full-page (sostituisce tutto #app, senza layout comune). */
|
|
19
|
-
notFound?: Node | ((path: string) => Node);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function pathToPattern(key: string): string {
|
|
23
|
-
const afterRoutes = key.replace(/^.*[/\\]routes[/\\]?/i, '').replace(/\.tsx?$/i, '');
|
|
24
|
-
const s = afterRoutes.split(/[/\\]/).filter(Boolean).join('/');
|
|
25
|
-
if (s === 'index' || s === '') return '';
|
|
26
|
-
return s
|
|
27
|
-
.split('/')
|
|
28
|
-
.map((x) => (x.startsWith('[') && x.endsWith(']') ? `:${x.slice(1, -1)}` : x))
|
|
29
|
-
.join('/');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function match(pattern: string, path: string): Record<string, string> | null {
|
|
33
|
-
const pa = pattern ? pattern.split('/').filter(Boolean) : [];
|
|
34
|
-
const ph = path.replace(/^\//, '').split('/').filter(Boolean);
|
|
35
|
-
if (pa.length !== ph.length) return null;
|
|
36
|
-
const params: Record<string, string> = {};
|
|
37
|
-
for (let i = 0; i < pa.length; i++) {
|
|
38
|
-
if (pa[i]!.startsWith(':')) params[pa[i]!.slice(1)] = ph[i] ?? '';
|
|
39
|
-
else if (pa[i] !== ph[i]) return null;
|
|
40
|
-
}
|
|
41
|
-
return params;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function setContent(container: HTMLElement, content: Node | string): void {
|
|
45
|
-
container.innerHTML = '';
|
|
46
|
-
if (typeof content === 'string') container.textContent = content;
|
|
47
|
-
else container.appendChild(content);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function defaultNotFound(path: string): Node {
|
|
51
|
-
const wrap = document.createElement('div');
|
|
52
|
-
wrap.setAttribute('role', 'alert');
|
|
53
|
-
const h = document.createElement('h1');
|
|
54
|
-
h.textContent = '404';
|
|
55
|
-
const p = document.createElement('p');
|
|
56
|
-
p.textContent = `Pagina non trovata: ${path || '/'}`;
|
|
57
|
-
wrap.append(h, p);
|
|
58
|
-
return wrap;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type RouterOptions = {
|
|
62
|
-
fallback?: Node | (() => Node);
|
|
63
|
-
notFound?: Node | ((path: string) => Node);
|
|
64
|
-
/** Per 404 full-page: elemento #app e factory del layout da ripristinare quando si naviga via. */
|
|
65
|
-
appRoot?: HTMLElement;
|
|
66
|
-
getLayout?: () => Node;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export function createRouter(
|
|
70
|
-
modules: Record<string, () => Promise<RouteModule>>,
|
|
71
|
-
container: HTMLElement,
|
|
72
|
-
options: RouterOptions = {}
|
|
73
|
-
) {
|
|
74
|
-
const routes = Object.entries(modules).map(([key, loader]) => ({
|
|
75
|
-
pattern: pathToPattern(key),
|
|
76
|
-
loader,
|
|
77
|
-
}));
|
|
78
|
-
routes.sort(
|
|
79
|
-
(a, b) =>
|
|
80
|
-
b.pattern.split('/').filter(Boolean).length - a.pattern.split('/').filter(Boolean).length
|
|
81
|
-
);
|
|
82
|
-
const notFound = options.notFound ?? defaultNotFound;
|
|
83
|
-
const fullPageNotFound = Boolean(options.appRoot && options.getLayout && options.notFound);
|
|
84
|
-
|
|
85
|
-
function getContainer(): HTMLElement | null {
|
|
86
|
-
return document.getElementById(APP_ID);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function render(pathname: string): Promise<boolean> {
|
|
90
|
-
const path = pathname === '/' ? '' : pathname.slice(1);
|
|
91
|
-
for (const { pattern, loader } of routes) {
|
|
92
|
-
const params = match(pattern, path);
|
|
93
|
-
if (params === null) continue;
|
|
94
|
-
let target = getContainer();
|
|
95
|
-
if (fullPageNotFound && !target) {
|
|
96
|
-
options.appRoot!.innerHTML = '';
|
|
97
|
-
options.appRoot!.appendChild(options.getLayout!());
|
|
98
|
-
target = getContainer();
|
|
99
|
-
}
|
|
100
|
-
if (!target) continue;
|
|
101
|
-
const fallbackNode =
|
|
102
|
-
options.fallback != null
|
|
103
|
-
? typeof options.fallback === 'function'
|
|
104
|
-
? options.fallback()
|
|
105
|
-
: options.fallback
|
|
106
|
-
: null;
|
|
107
|
-
if (fallbackNode) setContent(target, fallbackNode);
|
|
108
|
-
const mod = await loader();
|
|
109
|
-
const def = mod.default;
|
|
110
|
-
if (typeof def === 'function') {
|
|
111
|
-
const out = def.length
|
|
112
|
-
? (def as (p: Record<string, string>) => Node)(params)
|
|
113
|
-
: (def as () => Node | string)();
|
|
114
|
-
if (out instanceof Node) setContent(target, out);
|
|
115
|
-
else if (typeof out === 'string') target.innerHTML = out;
|
|
116
|
-
else target.innerHTML = '';
|
|
117
|
-
} else setContent(target, typeof def === 'string' ? def : (def as unknown as Node));
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
const nfNode = typeof notFound === 'function' ? notFound(pathname) : notFound;
|
|
121
|
-
if (fullPageNotFound) {
|
|
122
|
-
options.appRoot!.innerHTML = '';
|
|
123
|
-
options.appRoot!.appendChild(nfNode);
|
|
124
|
-
} else {
|
|
125
|
-
setContent(container, nfNode);
|
|
126
|
-
}
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function go(path: string, replace = false): void {
|
|
131
|
-
const p = path.startsWith('/') ? path : `/${path}`;
|
|
132
|
-
render(p).then((ok) => {
|
|
133
|
-
if (ok) (replace ? history.replaceState : history.pushState).call(history, null, '', p);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function start(): void {
|
|
138
|
-
render(location.pathname || '/');
|
|
139
|
-
window.addEventListener('popstate', () => render(location.pathname || '/'));
|
|
140
|
-
document.addEventListener('click', (e) => {
|
|
141
|
-
const a = (e.target as Element).closest('a');
|
|
142
|
-
if (a?.getAttribute('href')?.startsWith('/') && !a.href.startsWith('//')) {
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
go(a.getAttribute('href')!);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return { go, start };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** Monta App e avvia il router. Da usare nell'entry virtuale. */
|
|
153
|
-
export function run(
|
|
154
|
-
App: () => Node,
|
|
155
|
-
modules: Record<string, () => Promise<RouteModule>>,
|
|
156
|
-
options?: RunOptions
|
|
157
|
-
): void {
|
|
158
|
-
const app = document.getElementById('app')!;
|
|
159
|
-
app.appendChild(App());
|
|
160
|
-
const appContainer = document.getElementById(APP_ID);
|
|
161
|
-
if (!appContainer)
|
|
162
|
-
throw new Error(
|
|
163
|
-
`#${APP_ID} not found: use <App /> from @flow.os/router in your root layout.`
|
|
164
|
-
);
|
|
165
|
-
const routerOptions: RouterOptions = {
|
|
166
|
-
fallback: options?.fallback,
|
|
167
|
-
notFound: options?.notFound,
|
|
168
|
-
};
|
|
169
|
-
if (options?.notFound != null) {
|
|
170
|
-
routerOptions.appRoot = app;
|
|
171
|
-
routerOptions.getLayout = () => App();
|
|
172
|
-
}
|
|
173
|
-
createRouter(modules, appContainer as HTMLElement, routerOptions).start();
|
|
174
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
Flow OS Framework and all packages in this repository are licensed under the
|
|
2
|
-
PolyForm Shield License 1.0.0. This license applies to the entire repository
|
|
3
|
-
(framework, packages/*, client, server, and any other code herein).
|
|
4
|
-
|
|
5
|
-
Required Notice: Copyright (c) Flow OS. All rights reserved.
|
|
6
|
-
|
|
7
|
-
-------------------------------------------------------------------------------
|
|
8
|
-
|
|
9
|
-
# PolyForm Shield License 1.0.0
|
|
10
|
-
|
|
11
|
-
## Acceptance
|
|
12
|
-
|
|
13
|
-
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
14
|
-
|
|
15
|
-
## Copyright License
|
|
16
|
-
|
|
17
|
-
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
-
|
|
19
|
-
## Distribution License
|
|
20
|
-
|
|
21
|
-
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
22
|
-
|
|
23
|
-
## Notices
|
|
24
|
-
|
|
25
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
26
|
-
|
|
27
|
-
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
28
|
-
|
|
29
|
-
## Changes and New Works License
|
|
30
|
-
|
|
31
|
-
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
32
|
-
|
|
33
|
-
## Patent License
|
|
34
|
-
|
|
35
|
-
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
36
|
-
|
|
37
|
-
## Noncompete
|
|
38
|
-
|
|
39
|
-
Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
|
|
40
|
-
|
|
41
|
-
## Competition
|
|
42
|
-
|
|
43
|
-
Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
|
|
44
|
-
|
|
45
|
-
## New Products
|
|
46
|
-
|
|
47
|
-
If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
|
|
48
|
-
|
|
49
|
-
## Discontinued Products
|
|
50
|
-
|
|
51
|
-
You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
|
|
52
|
-
|
|
53
|
-
> Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
|
|
54
|
-
|
|
55
|
-
Licensor Line of Business: Flow OS application framework and development tooling (create-flow, @flow.os/* packages, and related framework components).
|
|
56
|
-
|
|
57
|
-
## Sales of Business
|
|
58
|
-
|
|
59
|
-
If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
|
|
60
|
-
|
|
61
|
-
## Fair Use
|
|
62
|
-
|
|
63
|
-
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
64
|
-
|
|
65
|
-
## No Other Rights
|
|
66
|
-
|
|
67
|
-
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
68
|
-
|
|
69
|
-
## Patent Defense
|
|
70
|
-
|
|
71
|
-
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
72
|
-
|
|
73
|
-
## Violations
|
|
74
|
-
|
|
75
|
-
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
76
|
-
|
|
77
|
-
## No Liability
|
|
78
|
-
|
|
79
|
-
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
80
|
-
|
|
81
|
-
## Definitions
|
|
82
|
-
|
|
83
|
-
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
84
|
-
|
|
85
|
-
A **product** can be a good or service, or a combination of them.
|
|
86
|
-
|
|
87
|
-
**You** refers to the individual or entity agreeing to these terms.
|
|
88
|
-
|
|
89
|
-
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
|
|
90
|
-
|
|
91
|
-
**Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
|
|
92
|
-
|
|
93
|
-
**Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
94
|
-
|
|
95
|
-
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
96
|
-
|
|
97
|
-
**Use** means anything you do with the software requiring one of your licenses.
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { readdirSync } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import type { FlowHandler, FlowRequest } from './index.js';
|
|
5
|
-
|
|
6
|
-
const METHOD_SUFFIXES = [
|
|
7
|
-
'.get',
|
|
8
|
-
'.post',
|
|
9
|
-
'.put',
|
|
10
|
-
'.delete',
|
|
11
|
-
'.patch',
|
|
12
|
-
'.head',
|
|
13
|
-
'.options',
|
|
14
|
-
] as const;
|
|
15
|
-
|
|
16
|
-
export type RouteMeta = { path: string; method: string; filePath: string };
|
|
17
|
-
|
|
18
|
-
function fileSegmentToRoute(segment: string): string {
|
|
19
|
-
return segment.replace(/^\[([^\]]+)\]$/, ':$1');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function parseRoutePath(relativePath: string): { path: string; method: string } | null {
|
|
23
|
-
const lower = relativePath.toLowerCase();
|
|
24
|
-
for (const suffix of METHOD_SUFFIXES) {
|
|
25
|
-
const ext = lower.endsWith('.tsx') ? '.tsx' : '.ts';
|
|
26
|
-
if (lower.endsWith(suffix + ext)) {
|
|
27
|
-
const withoutExt = relativePath.slice(0, -(suffix.length + ext.length));
|
|
28
|
-
const segments = withoutExt.split(/[/\\]/).filter(Boolean);
|
|
29
|
-
const routeSegments = segments.map((s) => fileSegmentToRoute(s));
|
|
30
|
-
const path = '/' + routeSegments.join('/');
|
|
31
|
-
const pathNorm = path === '/index' ? '/' : path;
|
|
32
|
-
const method = suffix.slice(1).toUpperCase();
|
|
33
|
-
return { path: pathNorm, method };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function walkRoutes(dir: string, base = ''): RouteMeta[] {
|
|
40
|
-
let entries: Array<{ name: string; isDirectory(): boolean; isFile(): boolean }>;
|
|
41
|
-
try {
|
|
42
|
-
entries = readdirSync(dir, { withFileTypes: true }) as Array<{
|
|
43
|
-
name: string;
|
|
44
|
-
isDirectory(): boolean;
|
|
45
|
-
isFile(): boolean;
|
|
46
|
-
}>;
|
|
47
|
-
} catch {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
const routes: RouteMeta[] = [];
|
|
51
|
-
for (const e of entries) {
|
|
52
|
-
const name = e.name;
|
|
53
|
-
const rel = base ? `${base}/${name}` : name;
|
|
54
|
-
if (e.isDirectory()) {
|
|
55
|
-
routes.push(...walkRoutes(join(dir, name), rel));
|
|
56
|
-
} else if (e.isFile() && (name.endsWith('.ts') || name.endsWith('.tsx'))) {
|
|
57
|
-
const parsed = parseRoutePath(rel);
|
|
58
|
-
if (parsed) routes.push({ ...parsed, filePath: join(dir, name) });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return routes;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function routePatternToRegex(path: string): { re: RegExp; keys: string[] } {
|
|
65
|
-
const keys: string[] = [];
|
|
66
|
-
const pattern =
|
|
67
|
-
'^' +
|
|
68
|
-
path.replace(/:(\w+)/g, (_, key) => {
|
|
69
|
-
keys.push(key);
|
|
70
|
-
return '([^/]+)';
|
|
71
|
-
}) +
|
|
72
|
-
'$';
|
|
73
|
-
return { re: new RegExp(pattern), keys };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export type LoadHandler = (filePath: string) => Promise<{ default: FlowHandler }>;
|
|
77
|
-
|
|
78
|
-
type RouteEntry = {
|
|
79
|
-
method: string;
|
|
80
|
-
re: RegExp;
|
|
81
|
-
keys: string[];
|
|
82
|
-
handler: FlowHandler;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export async function createFlowServer(
|
|
86
|
-
routesDir: string,
|
|
87
|
-
loadHandler: LoadHandler
|
|
88
|
-
): Promise<{
|
|
89
|
-
dispatch: (pathname: string, method: string, request: Request) => Promise<Response | null>;
|
|
90
|
-
matches: (pathname: string, method: string) => boolean;
|
|
91
|
-
}> {
|
|
92
|
-
const routeList = walkRoutes(routesDir);
|
|
93
|
-
const routes: RouteEntry[] = [];
|
|
94
|
-
|
|
95
|
-
for (const r of routeList) {
|
|
96
|
-
const mod = await loadHandler(r.filePath);
|
|
97
|
-
const handler = mod.default;
|
|
98
|
-
if (!handler) continue;
|
|
99
|
-
const { re, keys } = routePatternToRegex(r.path);
|
|
100
|
-
routes.push({ method: r.method, re, keys, handler });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getMatch(
|
|
104
|
-
pathname: string,
|
|
105
|
-
method: string
|
|
106
|
-
): { handler: FlowHandler; params: Record<string, string> } | null {
|
|
107
|
-
const norm = pathname.split('?')[0] || '/';
|
|
108
|
-
for (const route of routes) {
|
|
109
|
-
if (route.method !== method) continue;
|
|
110
|
-
const m = route.re.exec(norm);
|
|
111
|
-
if (!m) continue;
|
|
112
|
-
const params: Record<string, string> = {};
|
|
113
|
-
route.keys.forEach((k, i) => (params[k] = m[i + 1] ?? ''));
|
|
114
|
-
return { handler: route.handler, params };
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function dispatch(
|
|
120
|
-
pathname: string,
|
|
121
|
-
method: string,
|
|
122
|
-
request: Request
|
|
123
|
-
): Promise<Response | null> {
|
|
124
|
-
const match = getMatch(pathname, method);
|
|
125
|
-
if (!match) return null;
|
|
126
|
-
const flowReq = request as FlowRequest;
|
|
127
|
-
flowReq.params = match.params;
|
|
128
|
-
const out = await match.handler(flowReq);
|
|
129
|
-
if (out instanceof Response) return out;
|
|
130
|
-
return new Response(JSON.stringify(out), {
|
|
131
|
-
headers: { 'Content-Type': 'application/json' },
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function matches(pathname: string, method: string): boolean {
|
|
136
|
-
return getMatch(pathname, method) !== null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return { dispatch, matches };
|
|
140
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API native: Request/Response (Bun/Web). Zero dipendenze.
|
|
3
|
-
* Per route dinamiche usa request.params (iniettato dal router).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export { flowServer } from './plugin.js';
|
|
7
|
-
export type FlowRequest = Request & { params: Record<string, string> };
|
|
8
|
-
|
|
9
|
-
export type FlowHandler = (
|
|
10
|
-
request: FlowRequest
|
|
11
|
-
) => Response | Promise<Response> | object | Promise<object>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Wrapper per gli handler: ritorna oggetti come JSON, Response come sono.
|
|
15
|
-
*/
|
|
16
|
-
export function defineHandler(fn: FlowHandler): FlowHandler {
|
|
17
|
-
return async (request: FlowRequest) => {
|
|
18
|
-
const out = await fn(request);
|
|
19
|
-
if (out instanceof Response) return out;
|
|
20
|
-
return new Response(JSON.stringify(out), {
|
|
21
|
-
headers: { 'Content-Type': 'application/json' },
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@flow.os/server",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "./index.ts",
|
|
6
|
-
"types": "./index.ts",
|
|
7
|
-
"bin": "./start.ts",
|
|
8
|
-
"dependencies": {},
|
|
9
|
-
"peerDependencies": {
|
|
10
|
-
"vite": ">=5.0.0"
|
|
11
|
-
},
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"types": "./index.ts",
|
|
15
|
-
"import": "./index.ts",
|
|
16
|
-
"default": "./index.ts"
|
|
17
|
-
},
|
|
18
|
-
"./vite": {
|
|
19
|
-
"types": "./plugin.ts",
|
|
20
|
-
"import": "./plugin.ts",
|
|
21
|
-
"default": "./plugin.ts"
|
|
22
|
-
},
|
|
23
|
-
"./production": {
|
|
24
|
-
"types": "./production.ts",
|
|
25
|
-
"import": "./production.ts",
|
|
26
|
-
"default": "./production.ts"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { resolve } from 'path';
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
|
-
import type { Plugin } from 'vite';
|
|
5
|
-
import { createFlowServer, type LoadHandler } from './core.js';
|
|
6
|
-
import type { FlowHandler } from './index.js';
|
|
7
|
-
|
|
8
|
-
type NodeReq = import('http').IncomingMessage;
|
|
9
|
-
type NodeRes = import('http').ServerResponse;
|
|
10
|
-
|
|
11
|
-
function nodeRequestToWebRequest(req: NodeReq, baseUrl: string): Request {
|
|
12
|
-
const url = (req.url ?? '/').startsWith('http') ? req.url! : baseUrl + (req.url ?? '/');
|
|
13
|
-
const opts: RequestInit = {
|
|
14
|
-
method: req.method ?? 'GET',
|
|
15
|
-
headers: req.headers as HeadersInit,
|
|
16
|
-
};
|
|
17
|
-
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
18
|
-
(opts as RequestInit & { duplex?: string }).body = req as unknown as BodyInit;
|
|
19
|
-
(opts as RequestInit & { duplex?: string }).duplex = 'half';
|
|
20
|
-
}
|
|
21
|
-
return new Request(url, opts);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function webResponseToNodeResponse(webRes: Response, res: NodeRes): Promise<void> {
|
|
25
|
-
res.writeHead(webRes.status, Object.fromEntries(webRes.headers));
|
|
26
|
-
if (webRes.body) {
|
|
27
|
-
const buf = Buffer.from(await webRes.arrayBuffer());
|
|
28
|
-
res.end(buf);
|
|
29
|
-
} else {
|
|
30
|
-
res.end();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function flowServerMiddleware(
|
|
35
|
-
dispatch: (pathname: string, method: string, request: Request) => Promise<Response | null>,
|
|
36
|
-
matches: (pathname: string, method: string) => boolean
|
|
37
|
-
): (req: NodeReq, res: NodeRes, next: () => void) => void {
|
|
38
|
-
return (req, res, next) => {
|
|
39
|
-
const pathname = req.url?.split('?')[0] ?? '/';
|
|
40
|
-
const method = req.method ?? 'GET';
|
|
41
|
-
if (!matches(pathname, method)) return next();
|
|
42
|
-
const baseUrl = `http://${req.headers.host ?? 'localhost'}`;
|
|
43
|
-
const request = nodeRequestToWebRequest(req, baseUrl);
|
|
44
|
-
dispatch(pathname, method, request)
|
|
45
|
-
.then((response) => {
|
|
46
|
-
if (response) return webResponseToNodeResponse(response, res);
|
|
47
|
-
next();
|
|
48
|
-
})
|
|
49
|
-
.catch((err) => {
|
|
50
|
-
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
|
51
|
-
res.end(String(err?.message ?? err));
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type FlowServerOptions = {
|
|
57
|
-
/** Cartella route API (file-based). Default: server/routes */
|
|
58
|
-
routesDir?: string;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
type ConnectStack = Array<{ route: string; handle: (req: NodeReq, res: NodeRes, next: () => void) => void }>;
|
|
62
|
-
|
|
63
|
-
export function flowServer(options?: FlowServerOptions): Plugin {
|
|
64
|
-
const routesDir = options?.routesDir ?? resolve(process.cwd(), 'server', 'routes');
|
|
65
|
-
return {
|
|
66
|
-
name: 'flow-server',
|
|
67
|
-
enforce: 'pre',
|
|
68
|
-
configureServer: async (server) => {
|
|
69
|
-
const loadHandler: LoadHandler = (filePath) =>
|
|
70
|
-
server.ssrLoadModule(pathToFileURL(filePath).href) as Promise<{ default: FlowHandler }>;
|
|
71
|
-
const { dispatch, matches } = await createFlowServer(routesDir, loadHandler);
|
|
72
|
-
const middleware = flowServerMiddleware(dispatch, matches);
|
|
73
|
-
(server.middlewares as unknown as { stack: ConnectStack }).stack.unshift({
|
|
74
|
-
route: '',
|
|
75
|
-
handle: middleware,
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { join, resolve } from 'path';
|
|
2
|
-
import { pathToFileURL } from 'url';
|
|
3
|
-
import { createFlowServer } from './core.js';
|
|
4
|
-
|
|
5
|
-
declare const Bun: {
|
|
6
|
-
file(path: string): { exists(): Promise<boolean> };
|
|
7
|
-
serve(options: { port: number; hostname: string; fetch(req: Request): Promise<Response> }): { hostname: string; port: number };
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type ProductionServerOptions = {
|
|
11
|
-
/** Cartella route (es. server/routes). Default: server/routes */
|
|
12
|
-
routesDir?: string;
|
|
13
|
-
/** Cartella statici (es. dist). Default: dist */
|
|
14
|
-
staticDir?: string;
|
|
15
|
-
/** Porta. Default: 3000 */
|
|
16
|
-
port?: number;
|
|
17
|
-
/** Hostname. Default: 0.0.0.0 */
|
|
18
|
-
hostname?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Serve un file dalla cartella staticDir. pathname = / -> index.html.
|
|
23
|
-
* Se il file non esiste (SPA client-side routing) ritorna index.html.
|
|
24
|
-
*/
|
|
25
|
-
async function serveStatic(staticDir: string, pathname: string): Promise<Response> {
|
|
26
|
-
const path = pathname === '/' ? '/index.html' : pathname;
|
|
27
|
-
const filePath = join(staticDir, path.replace(/^\//, ''));
|
|
28
|
-
try {
|
|
29
|
-
const file = Bun.file(filePath);
|
|
30
|
-
if (await file.exists()) {
|
|
31
|
-
return new Response(file as unknown as BodyInit, { headers: { 'Cache-Control': 'public, max-age=0' } });
|
|
32
|
-
}
|
|
33
|
-
} catch {
|
|
34
|
-
// ignore
|
|
35
|
-
}
|
|
36
|
-
// SPA fallback: qualsiasi path non trovato → index.html
|
|
37
|
-
const indexFile = Bun.file(join(staticDir, 'index.html'));
|
|
38
|
-
if (await indexFile.exists()) return new Response(indexFile as unknown as BodyInit);
|
|
39
|
-
return new Response('Not Found', { status: 404 });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Avvia il server di produzione: API da routesDir + statici da staticDir.
|
|
44
|
-
* Usa Bun.serve() (solo Bun).
|
|
45
|
-
*/
|
|
46
|
-
export async function runProductionServer(options: ProductionServerOptions = {}): Promise<void> {
|
|
47
|
-
const cwd = process.cwd();
|
|
48
|
-
const routesDir = resolve(cwd, options.routesDir ?? 'server/routes');
|
|
49
|
-
const staticDir = resolve(cwd, options.staticDir ?? 'dist');
|
|
50
|
-
const port = options.port ?? 3000;
|
|
51
|
-
const hostname = options.hostname ?? '0.0.0.0';
|
|
52
|
-
|
|
53
|
-
const loadHandler = async (filePath: string) => {
|
|
54
|
-
return import(pathToFileURL(filePath).href) as Promise<{ default: import('./index.js').FlowHandler }>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const { dispatch, matches } = await createFlowServer(routesDir, loadHandler);
|
|
58
|
-
|
|
59
|
-
const server = Bun.serve({
|
|
60
|
-
port,
|
|
61
|
-
hostname,
|
|
62
|
-
async fetch(req: Request) {
|
|
63
|
-
const url = new URL(req.url);
|
|
64
|
-
const pathname = url.pathname;
|
|
65
|
-
const method = req.method;
|
|
66
|
-
|
|
67
|
-
const apiRes = await dispatch(pathname, method, req);
|
|
68
|
-
if (apiRes) return apiRes;
|
|
69
|
-
|
|
70
|
-
return serveStatic(staticDir, pathname);
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
console.log(`Server: http://${server.hostname}:${server.port}`);
|
|
75
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/**
|
|
3
|
-
* Entry produzione: lancia il server (statici + API).
|
|
4
|
-
* Uso: bunx @flow.os/server oppure "start": "bunx @flow.os/server" in package.json.
|
|
5
|
-
*/
|
|
6
|
-
import { runProductionServer } from './production.js';
|
|
7
|
-
|
|
8
|
-
const port = process.env['PORT'] ? Number(process.env['PORT']) : 3000;
|
|
9
|
-
|
|
10
|
-
runProductionServer({
|
|
11
|
-
routesDir: 'server/routes',
|
|
12
|
-
staticDir: 'dist',
|
|
13
|
-
port,
|
|
14
|
-
hostname: '0.0.0.0',
|
|
15
|
-
});
|