@lifeart/async-dom 2.0.0-alpha.3
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/LICENSE +21 -0
- package/README.md +623 -0
- package/dist/base.d.cts +398 -0
- package/dist/base.d.cts.map +1 -0
- package/dist/base.d.ts +398 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/cli.cjs +528 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +493 -0
- package/dist/cli.js.map +1 -0
- package/dist/debug.d.cts +145 -0
- package/dist/debug.d.cts.map +1 -0
- package/dist/debug.d.ts +145 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/index.cjs +26 -0
- package/dist/index.d.cts +560 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +560 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index2.d.cts +5 -0
- package/dist/index2.d.ts +5 -0
- package/dist/index3.d.cts +882 -0
- package/dist/index3.d.cts.map +1 -0
- package/dist/index3.d.ts +882 -0
- package/dist/index3.d.ts.map +1 -0
- package/dist/main-thread.cjs +5459 -0
- package/dist/main-thread.cjs.map +1 -0
- package/dist/main-thread.js +5429 -0
- package/dist/main-thread.js.map +1 -0
- package/dist/react.cjs +116 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +91 -0
- package/dist/react.d.cts.map +1 -0
- package/dist/react.d.ts +91 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +113 -0
- package/dist/react.js.map +1 -0
- package/dist/resolve-debug.cjs +24 -0
- package/dist/resolve-debug.cjs.map +1 -0
- package/dist/resolve-debug.js +19 -0
- package/dist/resolve-debug.js.map +1 -0
- package/dist/server.cjs +250 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +127 -0
- package/dist/server.d.cts.map +1 -0
- package/dist/server.d.ts +127 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +245 -0
- package/dist/server.js.map +1 -0
- package/dist/svelte.cjs +48 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +38 -0
- package/dist/svelte.d.cts.map +1 -0
- package/dist/svelte.d.ts +38 -0
- package/dist/svelte.d.ts.map +1 -0
- package/dist/svelte.js +47 -0
- package/dist/svelte.js.map +1 -0
- package/dist/sync-channel.cjs +532 -0
- package/dist/sync-channel.cjs.map +1 -0
- package/dist/sync-channel.js +425 -0
- package/dist/sync-channel.js.map +1 -0
- package/dist/transport.cjs +213 -0
- package/dist/transport.cjs.map +1 -0
- package/dist/transport.d.cts +79 -0
- package/dist/transport.d.cts.map +1 -0
- package/dist/transport.d.ts +79 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +202 -0
- package/dist/transport.js.map +1 -0
- package/dist/vite-plugin.cjs +112 -0
- package/dist/vite-plugin.cjs.map +1 -0
- package/dist/vite-plugin.d.cts +39 -0
- package/dist/vite-plugin.d.cts.map +1 -0
- package/dist/vite-plugin.d.ts +39 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +107 -0
- package/dist/vite-plugin.js.map +1 -0
- package/dist/vue.cjs +123 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +126 -0
- package/dist/vue.d.cts.map +1 -0
- package/dist/vue.d.ts +126 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +120 -0
- package/dist/vue.js.map +1 -0
- package/dist/worker-thread.cjs +2751 -0
- package/dist/worker-thread.cjs.map +1 -0
- package/dist/worker-thread.js +2692 -0
- package/dist/worker-thread.js.map +1 -0
- package/dist/worker-transport.cjs +136 -0
- package/dist/worker-transport.cjs.map +1 -0
- package/dist/worker-transport.d.cts +162 -0
- package/dist/worker-transport.d.cts.map +1 -0
- package/dist/worker-transport.d.ts +162 -0
- package/dist/worker-transport.d.ts.map +1 -0
- package/dist/worker-transport.js +125 -0
- package/dist/worker-transport.js.map +1 -0
- package/dist/worker.cjs +12 -0
- package/dist/worker.d.cts +2 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +2 -0
- package/dist/ws-server-transport.cjs +147 -0
- package/dist/ws-server-transport.cjs.map +1 -0
- package/dist/ws-server-transport.d.cts +64 -0
- package/dist/ws-server-transport.d.cts.map +1 -0
- package/dist/ws-server-transport.d.ts +64 -0
- package/dist/ws-server-transport.d.ts.map +1 -0
- package/dist/ws-server-transport.js +142 -0
- package/dist/ws-server-transport.js.map +1 -0
- package/dist/ws-transport.cjs +954 -0
- package/dist/ws-transport.cjs.map +1 -0
- package/dist/ws-transport.js +913 -0
- package/dist/ws-transport.js.map +1 -0
- package/package.json +145 -0
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __exportAll = (all, no_symbols) => {
|
|
10
|
+
let target = {};
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
+
get: ((k) => from[k]).bind(null, key),
|
|
23
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
//#endregion
|
|
33
|
+
let node_fs = require("node:fs");
|
|
34
|
+
node_fs = __toESM(node_fs);
|
|
35
|
+
let node_path = require("node:path");
|
|
36
|
+
node_path = __toESM(node_path);
|
|
37
|
+
let node_readline = require("node:readline");
|
|
38
|
+
node_readline = __toESM(node_readline);
|
|
39
|
+
//#region src/cli/templates.ts
|
|
40
|
+
/**
|
|
41
|
+
* Returns the list of files for a given project template.
|
|
42
|
+
*
|
|
43
|
+
* @param template - Template name (one of {@link AVAILABLE_TEMPLATES}).
|
|
44
|
+
* @param name - Project name, used in package.json and HTML title.
|
|
45
|
+
* @returns Array of files to write to disk.
|
|
46
|
+
* @throws If the template name is not recognized.
|
|
47
|
+
*/
|
|
48
|
+
function getTemplate(template, name) {
|
|
49
|
+
switch (template) {
|
|
50
|
+
case "vanilla-ts": return vanillaTs(name);
|
|
51
|
+
case "react-ts": return reactTs(name);
|
|
52
|
+
case "vue-ts": return vueTs(name);
|
|
53
|
+
default: throw new Error(`Unknown template: ${template}. Available: vanilla-ts, react-ts, vue-ts`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** The list of available project templates for `async-dom init`. */
|
|
57
|
+
const AVAILABLE_TEMPLATES = [
|
|
58
|
+
"vanilla-ts",
|
|
59
|
+
"react-ts",
|
|
60
|
+
"vue-ts"
|
|
61
|
+
];
|
|
62
|
+
function escapeHtml(str) {
|
|
63
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
64
|
+
}
|
|
65
|
+
function vanillaTs(name) {
|
|
66
|
+
return [
|
|
67
|
+
{
|
|
68
|
+
path: "package.json",
|
|
69
|
+
content: JSON.stringify({
|
|
70
|
+
name,
|
|
71
|
+
private: true,
|
|
72
|
+
version: "0.0.0",
|
|
73
|
+
type: "module",
|
|
74
|
+
scripts: {
|
|
75
|
+
dev: "vite",
|
|
76
|
+
build: "tsc && vite build",
|
|
77
|
+
preview: "vite preview"
|
|
78
|
+
},
|
|
79
|
+
devDependencies: {
|
|
80
|
+
typescript: "^5.8.0",
|
|
81
|
+
vite: "^6.0.0",
|
|
82
|
+
"@lifeart/async-dom": "latest"
|
|
83
|
+
}
|
|
84
|
+
}, null, 2)
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
path: "index.html",
|
|
88
|
+
content: `<!DOCTYPE html>
|
|
89
|
+
<html lang="en">
|
|
90
|
+
<head>
|
|
91
|
+
<meta charset="UTF-8" />
|
|
92
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
93
|
+
<title>${escapeHtml(name)}</title>
|
|
94
|
+
</head>
|
|
95
|
+
<body>
|
|
96
|
+
<div id="app"></div>
|
|
97
|
+
<script type="module" src="/src/main.ts"><\/script>
|
|
98
|
+
</body>
|
|
99
|
+
</html>
|
|
100
|
+
`
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
path: "src/main.ts",
|
|
104
|
+
content: `import { createAsyncDom } from "@lifeart/async-dom";
|
|
105
|
+
|
|
106
|
+
const worker = new Worker(new URL("./app.worker.ts", import.meta.url), {
|
|
107
|
+
type: "module",
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const instance = createAsyncDom({
|
|
111
|
+
target: document.getElementById("app")!,
|
|
112
|
+
worker,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
instance.start();
|
|
116
|
+
`
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
path: "src/app.worker.ts",
|
|
120
|
+
content: `import { createWorkerDom } from "@lifeart/async-dom/worker";
|
|
121
|
+
|
|
122
|
+
const { document } = createWorkerDom();
|
|
123
|
+
|
|
124
|
+
const heading = document.createElement("h1");
|
|
125
|
+
heading.textContent = "Hello from async-dom!";
|
|
126
|
+
document.body.appendChild(heading);
|
|
127
|
+
|
|
128
|
+
const counter = document.createElement("button");
|
|
129
|
+
counter.textContent = "Count: 0";
|
|
130
|
+
let count = 0;
|
|
131
|
+
counter.addEventListener("click", () => {
|
|
132
|
+
count++;
|
|
133
|
+
counter.textContent = \`Count: \${count}\`;
|
|
134
|
+
});
|
|
135
|
+
document.body.appendChild(counter);
|
|
136
|
+
`
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
path: "src/vite-env.d.ts",
|
|
140
|
+
content: `/// <reference types="vite/client" />
|
|
141
|
+
`
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
path: "tsconfig.json",
|
|
145
|
+
content: JSON.stringify({
|
|
146
|
+
compilerOptions: {
|
|
147
|
+
target: "ES2022",
|
|
148
|
+
module: "ESNext",
|
|
149
|
+
moduleResolution: "bundler",
|
|
150
|
+
strict: true,
|
|
151
|
+
esModuleInterop: true,
|
|
152
|
+
skipLibCheck: true,
|
|
153
|
+
forceConsistentCasingInFileNames: true,
|
|
154
|
+
isolatedModules: true,
|
|
155
|
+
noEmit: true,
|
|
156
|
+
lib: [
|
|
157
|
+
"ES2022",
|
|
158
|
+
"DOM",
|
|
159
|
+
"DOM.Iterable"
|
|
160
|
+
]
|
|
161
|
+
},
|
|
162
|
+
include: ["src"]
|
|
163
|
+
}, null, 2)
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
path: "vite.config.ts",
|
|
167
|
+
content: `import { defineConfig } from "vite";
|
|
168
|
+
import { asyncDomPlugin } from "@lifeart/async-dom/vite-plugin";
|
|
169
|
+
|
|
170
|
+
export default defineConfig({
|
|
171
|
+
plugins: [asyncDomPlugin()],
|
|
172
|
+
});
|
|
173
|
+
`
|
|
174
|
+
}
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
function reactTs(name) {
|
|
178
|
+
return [
|
|
179
|
+
{
|
|
180
|
+
path: "package.json",
|
|
181
|
+
content: JSON.stringify({
|
|
182
|
+
name,
|
|
183
|
+
private: true,
|
|
184
|
+
version: "0.0.0",
|
|
185
|
+
type: "module",
|
|
186
|
+
scripts: {
|
|
187
|
+
dev: "vite",
|
|
188
|
+
build: "tsc && vite build",
|
|
189
|
+
preview: "vite preview"
|
|
190
|
+
},
|
|
191
|
+
dependencies: {
|
|
192
|
+
react: "^19.0.0",
|
|
193
|
+
"react-dom": "^19.0.0"
|
|
194
|
+
},
|
|
195
|
+
devDependencies: {
|
|
196
|
+
"@types/react": "^19.0.0",
|
|
197
|
+
"@types/react-dom": "^19.0.0",
|
|
198
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
199
|
+
typescript: "^5.8.0",
|
|
200
|
+
vite: "^6.0.0",
|
|
201
|
+
"@lifeart/async-dom": "latest"
|
|
202
|
+
}
|
|
203
|
+
}, null, 2)
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
path: "index.html",
|
|
207
|
+
content: `<!DOCTYPE html>
|
|
208
|
+
<html lang="en">
|
|
209
|
+
<head>
|
|
210
|
+
<meta charset="UTF-8" />
|
|
211
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
212
|
+
<title>${escapeHtml(name)}</title>
|
|
213
|
+
</head>
|
|
214
|
+
<body>
|
|
215
|
+
<div id="root"></div>
|
|
216
|
+
<script type="module" src="/src/main.tsx"><\/script>
|
|
217
|
+
</body>
|
|
218
|
+
</html>
|
|
219
|
+
`
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
path: "src/main.tsx",
|
|
223
|
+
content: `import { StrictMode } from "react";
|
|
224
|
+
import { createRoot } from "react-dom/client";
|
|
225
|
+
import { App } from "./App";
|
|
226
|
+
|
|
227
|
+
createRoot(document.getElementById("root")!).render(
|
|
228
|
+
<StrictMode>
|
|
229
|
+
<App />
|
|
230
|
+
</StrictMode>,
|
|
231
|
+
);
|
|
232
|
+
`
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
path: "src/App.tsx",
|
|
236
|
+
content: `import { AsyncDom } from "@lifeart/async-dom/react";
|
|
237
|
+
|
|
238
|
+
export function App() {
|
|
239
|
+
return (
|
|
240
|
+
<AsyncDom
|
|
241
|
+
worker="./app.worker.ts"
|
|
242
|
+
fallback={<p>Loading...</p>}
|
|
243
|
+
onReady={(instance) => console.log("async-dom ready", instance)}
|
|
244
|
+
/>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
`
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
path: "src/app.worker.ts",
|
|
251
|
+
content: `import { createWorkerDom } from "@lifeart/async-dom/worker";
|
|
252
|
+
|
|
253
|
+
const { document } = createWorkerDom();
|
|
254
|
+
|
|
255
|
+
const heading = document.createElement("h1");
|
|
256
|
+
heading.textContent = "Hello from async-dom + React!";
|
|
257
|
+
document.body.appendChild(heading);
|
|
258
|
+
`
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
path: "src/vite-env.d.ts",
|
|
262
|
+
content: `/// <reference types="vite/client" />
|
|
263
|
+
`
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
path: "tsconfig.json",
|
|
267
|
+
content: JSON.stringify({
|
|
268
|
+
compilerOptions: {
|
|
269
|
+
target: "ES2022",
|
|
270
|
+
module: "ESNext",
|
|
271
|
+
moduleResolution: "bundler",
|
|
272
|
+
strict: true,
|
|
273
|
+
esModuleInterop: true,
|
|
274
|
+
skipLibCheck: true,
|
|
275
|
+
forceConsistentCasingInFileNames: true,
|
|
276
|
+
isolatedModules: true,
|
|
277
|
+
noEmit: true,
|
|
278
|
+
jsx: "react-jsx",
|
|
279
|
+
lib: [
|
|
280
|
+
"ES2022",
|
|
281
|
+
"DOM",
|
|
282
|
+
"DOM.Iterable"
|
|
283
|
+
]
|
|
284
|
+
},
|
|
285
|
+
include: ["src"]
|
|
286
|
+
}, null, 2)
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
path: "vite.config.ts",
|
|
290
|
+
content: `import { defineConfig } from "vite";
|
|
291
|
+
import react from "@vitejs/plugin-react";
|
|
292
|
+
import { asyncDomPlugin } from "@lifeart/async-dom/vite-plugin";
|
|
293
|
+
|
|
294
|
+
export default defineConfig({
|
|
295
|
+
plugins: [react(), asyncDomPlugin()],
|
|
296
|
+
});
|
|
297
|
+
`
|
|
298
|
+
}
|
|
299
|
+
];
|
|
300
|
+
}
|
|
301
|
+
function vueTs(name) {
|
|
302
|
+
return [
|
|
303
|
+
{
|
|
304
|
+
path: "package.json",
|
|
305
|
+
content: JSON.stringify({
|
|
306
|
+
name,
|
|
307
|
+
private: true,
|
|
308
|
+
version: "0.0.0",
|
|
309
|
+
type: "module",
|
|
310
|
+
scripts: {
|
|
311
|
+
dev: "vite",
|
|
312
|
+
build: "vue-tsc && vite build",
|
|
313
|
+
preview: "vite preview"
|
|
314
|
+
},
|
|
315
|
+
dependencies: { vue: "^3.5.0" },
|
|
316
|
+
devDependencies: {
|
|
317
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
318
|
+
typescript: "^5.8.0",
|
|
319
|
+
"vue-tsc": "^2.0.0",
|
|
320
|
+
vite: "^6.0.0",
|
|
321
|
+
"@lifeart/async-dom": "latest"
|
|
322
|
+
}
|
|
323
|
+
}, null, 2)
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
path: "index.html",
|
|
327
|
+
content: `<!DOCTYPE html>
|
|
328
|
+
<html lang="en">
|
|
329
|
+
<head>
|
|
330
|
+
<meta charset="UTF-8" />
|
|
331
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
332
|
+
<title>${escapeHtml(name)}</title>
|
|
333
|
+
</head>
|
|
334
|
+
<body>
|
|
335
|
+
<div id="app"></div>
|
|
336
|
+
<script type="module" src="/src/main.ts"><\/script>
|
|
337
|
+
</body>
|
|
338
|
+
</html>
|
|
339
|
+
`
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
path: "src/main.ts",
|
|
343
|
+
content: `import { createApp } from "vue";
|
|
344
|
+
import App from "./App.vue";
|
|
345
|
+
|
|
346
|
+
createApp(App).mount("#app");
|
|
347
|
+
`
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
path: "src/App.vue",
|
|
351
|
+
content: `<script setup lang="ts">
|
|
352
|
+
import { AsyncDom } from "@lifeart/async-dom/vue";
|
|
353
|
+
|
|
354
|
+
function onReady(instance: any) {
|
|
355
|
+
console.log("async-dom ready", instance);
|
|
356
|
+
}
|
|
357
|
+
<\/script>
|
|
358
|
+
|
|
359
|
+
<template>
|
|
360
|
+
<AsyncDom worker="./app.worker.ts" @ready="onReady">
|
|
361
|
+
<template #fallback>
|
|
362
|
+
<p>Loading...</p>
|
|
363
|
+
</template>
|
|
364
|
+
</AsyncDom>
|
|
365
|
+
</template>
|
|
366
|
+
`
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
path: "src/app.worker.ts",
|
|
370
|
+
content: `import { createWorkerDom } from "@lifeart/async-dom/worker";
|
|
371
|
+
|
|
372
|
+
const { document } = createWorkerDom();
|
|
373
|
+
|
|
374
|
+
const heading = document.createElement("h1");
|
|
375
|
+
heading.textContent = "Hello from async-dom + Vue!";
|
|
376
|
+
document.body.appendChild(heading);
|
|
377
|
+
`
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
path: "src/vite-env.d.ts",
|
|
381
|
+
content: `/// <reference types="vite/client" />
|
|
382
|
+
declare module "*.vue" {
|
|
383
|
+
import type { DefineComponent } from "vue";
|
|
384
|
+
const component: DefineComponent<{}, {}, any>;
|
|
385
|
+
export default component;
|
|
386
|
+
}
|
|
387
|
+
`
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
path: "tsconfig.json",
|
|
391
|
+
content: JSON.stringify({
|
|
392
|
+
compilerOptions: {
|
|
393
|
+
target: "ES2022",
|
|
394
|
+
module: "ESNext",
|
|
395
|
+
moduleResolution: "bundler",
|
|
396
|
+
strict: true,
|
|
397
|
+
esModuleInterop: true,
|
|
398
|
+
skipLibCheck: true,
|
|
399
|
+
forceConsistentCasingInFileNames: true,
|
|
400
|
+
isolatedModules: true,
|
|
401
|
+
noEmit: true,
|
|
402
|
+
lib: [
|
|
403
|
+
"ES2022",
|
|
404
|
+
"DOM",
|
|
405
|
+
"DOM.Iterable"
|
|
406
|
+
]
|
|
407
|
+
},
|
|
408
|
+
include: ["src"]
|
|
409
|
+
}, null, 2)
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
path: "vite.config.ts",
|
|
413
|
+
content: `import { defineConfig } from "vite";
|
|
414
|
+
import vue from "@vitejs/plugin-vue";
|
|
415
|
+
import { asyncDomPlugin } from "@lifeart/async-dom/vite-plugin";
|
|
416
|
+
|
|
417
|
+
export default defineConfig({
|
|
418
|
+
plugins: [vue(), asyncDomPlugin()],
|
|
419
|
+
});
|
|
420
|
+
`
|
|
421
|
+
}
|
|
422
|
+
];
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/cli/index.ts
|
|
426
|
+
function ask(question) {
|
|
427
|
+
const rl = node_readline.createInterface({
|
|
428
|
+
input: process.stdin,
|
|
429
|
+
output: process.stdout
|
|
430
|
+
});
|
|
431
|
+
return new Promise((resolve) => {
|
|
432
|
+
rl.question(question, (answer) => {
|
|
433
|
+
rl.close();
|
|
434
|
+
resolve(answer.trim());
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
async function init(args) {
|
|
439
|
+
let name;
|
|
440
|
+
let template = "";
|
|
441
|
+
for (let i = 0; i < args.length; i++) if (args[i] === "--template" && args[i + 1]) {
|
|
442
|
+
template = args[i + 1];
|
|
443
|
+
i++;
|
|
444
|
+
} else if (!args[i].startsWith("-") && !name) name = args[i];
|
|
445
|
+
if (!name) {
|
|
446
|
+
name = await ask("Project name: ");
|
|
447
|
+
if (!name) {
|
|
448
|
+
console.error("Project name is required.");
|
|
449
|
+
process.exit(1);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (!template) {
|
|
453
|
+
console.log("\nAvailable templates:");
|
|
454
|
+
for (const t of AVAILABLE_TEMPLATES) console.log(` - ${t}`);
|
|
455
|
+
template = await ask("\nTemplate (default: vanilla-ts): ");
|
|
456
|
+
if (!template) template = "vanilla-ts";
|
|
457
|
+
}
|
|
458
|
+
if (!AVAILABLE_TEMPLATES.includes(template)) {
|
|
459
|
+
console.error(`Unknown template: ${template}. Available: ${AVAILABLE_TEMPLATES.join(", ")}`);
|
|
460
|
+
process.exit(1);
|
|
461
|
+
}
|
|
462
|
+
const targetDir = node_path.resolve(process.cwd(), name);
|
|
463
|
+
if (node_fs.existsSync(targetDir)) {
|
|
464
|
+
if (node_fs.readdirSync(targetDir).length > 0) {
|
|
465
|
+
console.error(`Directory "${name}" already exists and is not empty.`);
|
|
466
|
+
process.exit(1);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
console.log(`\nScaffolding project in ${targetDir}...`);
|
|
470
|
+
const files = getTemplate(template, name);
|
|
471
|
+
for (const file of files) {
|
|
472
|
+
const filePath = node_path.join(targetDir, file.path);
|
|
473
|
+
const dir = node_path.dirname(filePath);
|
|
474
|
+
node_fs.mkdirSync(dir, { recursive: true });
|
|
475
|
+
node_fs.writeFileSync(filePath, file.content);
|
|
476
|
+
console.log(` created ${file.path}`);
|
|
477
|
+
}
|
|
478
|
+
console.log(`\nDone! Now run:\n`);
|
|
479
|
+
console.log(` cd ${name}`);
|
|
480
|
+
console.log(" npm install");
|
|
481
|
+
console.log(" npm run dev");
|
|
482
|
+
console.log("");
|
|
483
|
+
}
|
|
484
|
+
function printHelp() {
|
|
485
|
+
console.log(`
|
|
486
|
+
@lifeart/async-dom - Asynchronous DOM rendering CLI
|
|
487
|
+
|
|
488
|
+
Usage:
|
|
489
|
+
async-dom init [name] [--template <template>]
|
|
490
|
+
|
|
491
|
+
Commands:
|
|
492
|
+
init Scaffold a new async-dom project
|
|
493
|
+
|
|
494
|
+
Templates:
|
|
495
|
+
${AVAILABLE_TEMPLATES.join(", ")}
|
|
496
|
+
|
|
497
|
+
Examples:
|
|
498
|
+
npx @lifeart/async-dom init my-app
|
|
499
|
+
npx @lifeart/async-dom init my-app --template react-ts
|
|
500
|
+
`);
|
|
501
|
+
}
|
|
502
|
+
async function main() {
|
|
503
|
+
const args = process.argv.slice(2);
|
|
504
|
+
const command = args[0];
|
|
505
|
+
switch (command) {
|
|
506
|
+
case "init":
|
|
507
|
+
await init(args.slice(1));
|
|
508
|
+
break;
|
|
509
|
+
case "--help":
|
|
510
|
+
case "-h":
|
|
511
|
+
case void 0:
|
|
512
|
+
printHelp();
|
|
513
|
+
break;
|
|
514
|
+
default:
|
|
515
|
+
console.error(`Unknown command: ${command}`);
|
|
516
|
+
printHelp();
|
|
517
|
+
process.exit(1);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
main().catch((err) => {
|
|
521
|
+
console.error(err);
|
|
522
|
+
process.exit(1);
|
|
523
|
+
});
|
|
524
|
+
//#endregion
|
|
525
|
+
exports.__exportAll = __exportAll;
|
|
526
|
+
exports.__toESM = __toESM;
|
|
527
|
+
|
|
528
|
+
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":["readline","path","fs"],"sources":["../src/cli/templates.ts","../src/cli/index.ts"],"sourcesContent":["/** A file to be written during project scaffolding. */\nexport interface TemplateFile {\n\t/** Relative path from the project root (e.g., \"src/main.ts\"). */\n\tpath: string;\n\t/** The full file content to write. */\n\tcontent: string;\n}\n\n/**\n * Returns the list of files for a given project template.\n *\n * @param template - Template name (one of {@link AVAILABLE_TEMPLATES}).\n * @param name - Project name, used in package.json and HTML title.\n * @returns Array of files to write to disk.\n * @throws If the template name is not recognized.\n */\nexport function getTemplate(template: string, name: string): TemplateFile[] {\n\tswitch (template) {\n\t\tcase \"vanilla-ts\":\n\t\t\treturn vanillaTs(name);\n\t\tcase \"react-ts\":\n\t\t\treturn reactTs(name);\n\t\tcase \"vue-ts\":\n\t\t\treturn vueTs(name);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown template: ${template}. Available: vanilla-ts, react-ts, vue-ts`);\n\t}\n}\n\n/** The list of available project templates for `async-dom init`. */\nexport const AVAILABLE_TEMPLATES = [\"vanilla-ts\", \"react-ts\", \"vue-ts\"] as const;\n\nfunction escapeHtml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/\"/g, \""\");\n}\n\nfunction vanillaTs(name: string): TemplateFile[] {\n\treturn [\n\t\t{\n\t\t\tpath: \"package.json\",\n\t\t\tcontent: JSON.stringify(\n\t\t\t\t{\n\t\t\t\t\tname,\n\t\t\t\t\tprivate: true,\n\t\t\t\t\tversion: \"0.0.0\",\n\t\t\t\t\ttype: \"module\",\n\t\t\t\t\tscripts: {\n\t\t\t\t\t\tdev: \"vite\",\n\t\t\t\t\t\tbuild: \"tsc && vite build\",\n\t\t\t\t\t\tpreview: \"vite preview\",\n\t\t\t\t\t},\n\t\t\t\t\tdevDependencies: {\n\t\t\t\t\t\ttypescript: \"^5.8.0\",\n\t\t\t\t\t\tvite: \"^6.0.0\",\n\t\t\t\t\t\t\"@lifeart/async-dom\": \"latest\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t),\n\t\t},\n\t\t{\n\t\t\tpath: \"index.html\",\n\t\t\tcontent: `<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>${escapeHtml(name)}</title>\n </head>\n <body>\n <div id=\"app\"></div>\n <script type=\"module\" src=\"/src/main.ts\"></script>\n </body>\n</html>\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/main.ts\",\n\t\t\tcontent: `import { createAsyncDom } from \"@lifeart/async-dom\";\n\nconst worker = new Worker(new URL(\"./app.worker.ts\", import.meta.url), {\n type: \"module\",\n});\n\nconst instance = createAsyncDom({\n target: document.getElementById(\"app\")!,\n worker,\n});\n\ninstance.start();\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/app.worker.ts\",\n\t\t\tcontent: `import { createWorkerDom } from \"@lifeart/async-dom/worker\";\n\nconst { document } = createWorkerDom();\n\nconst heading = document.createElement(\"h1\");\nheading.textContent = \"Hello from async-dom!\";\ndocument.body.appendChild(heading);\n\nconst counter = document.createElement(\"button\");\ncounter.textContent = \"Count: 0\";\nlet count = 0;\ncounter.addEventListener(\"click\", () => {\n count++;\n counter.textContent = \\`Count: \\${count}\\`;\n});\ndocument.body.appendChild(counter);\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/vite-env.d.ts\",\n\t\t\tcontent: `/// <reference types=\"vite/client\" />\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"tsconfig.json\",\n\t\t\tcontent: JSON.stringify(\n\t\t\t\t{\n\t\t\t\t\tcompilerOptions: {\n\t\t\t\t\t\ttarget: \"ES2022\",\n\t\t\t\t\t\tmodule: \"ESNext\",\n\t\t\t\t\t\tmoduleResolution: \"bundler\",\n\t\t\t\t\t\tstrict: true,\n\t\t\t\t\t\tesModuleInterop: true,\n\t\t\t\t\t\tskipLibCheck: true,\n\t\t\t\t\t\tforceConsistentCasingInFileNames: true,\n\t\t\t\t\t\tisolatedModules: true,\n\t\t\t\t\t\tnoEmit: true,\n\t\t\t\t\t\tlib: [\"ES2022\", \"DOM\", \"DOM.Iterable\"],\n\t\t\t\t\t},\n\t\t\t\t\tinclude: [\"src\"],\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t),\n\t\t},\n\t\t{\n\t\t\tpath: \"vite.config.ts\",\n\t\t\tcontent: `import { defineConfig } from \"vite\";\nimport { asyncDomPlugin } from \"@lifeart/async-dom/vite-plugin\";\n\nexport default defineConfig({\n plugins: [asyncDomPlugin()],\n});\n`,\n\t\t},\n\t];\n}\n\nfunction reactTs(name: string): TemplateFile[] {\n\treturn [\n\t\t{\n\t\t\tpath: \"package.json\",\n\t\t\tcontent: JSON.stringify(\n\t\t\t\t{\n\t\t\t\t\tname,\n\t\t\t\t\tprivate: true,\n\t\t\t\t\tversion: \"0.0.0\",\n\t\t\t\t\ttype: \"module\",\n\t\t\t\t\tscripts: {\n\t\t\t\t\t\tdev: \"vite\",\n\t\t\t\t\t\tbuild: \"tsc && vite build\",\n\t\t\t\t\t\tpreview: \"vite preview\",\n\t\t\t\t\t},\n\t\t\t\t\tdependencies: {\n\t\t\t\t\t\treact: \"^19.0.0\",\n\t\t\t\t\t\t\"react-dom\": \"^19.0.0\",\n\t\t\t\t\t},\n\t\t\t\t\tdevDependencies: {\n\t\t\t\t\t\t\"@types/react\": \"^19.0.0\",\n\t\t\t\t\t\t\"@types/react-dom\": \"^19.0.0\",\n\t\t\t\t\t\t\"@vitejs/plugin-react\": \"^4.0.0\",\n\t\t\t\t\t\ttypescript: \"^5.8.0\",\n\t\t\t\t\t\tvite: \"^6.0.0\",\n\t\t\t\t\t\t\"@lifeart/async-dom\": \"latest\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t),\n\t\t},\n\t\t{\n\t\t\tpath: \"index.html\",\n\t\t\tcontent: `<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>${escapeHtml(name)}</title>\n </head>\n <body>\n <div id=\"root\"></div>\n <script type=\"module\" src=\"/src/main.tsx\"></script>\n </body>\n</html>\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/main.tsx\",\n\t\t\tcontent: `import { StrictMode } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { App } from \"./App\";\n\ncreateRoot(document.getElementById(\"root\")!).render(\n <StrictMode>\n <App />\n </StrictMode>,\n);\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/App.tsx\",\n\t\t\tcontent: `import { AsyncDom } from \"@lifeart/async-dom/react\";\n\nexport function App() {\n return (\n <AsyncDom\n worker=\"./app.worker.ts\"\n fallback={<p>Loading...</p>}\n onReady={(instance) => console.log(\"async-dom ready\", instance)}\n />\n );\n}\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/app.worker.ts\",\n\t\t\tcontent: `import { createWorkerDom } from \"@lifeart/async-dom/worker\";\n\nconst { document } = createWorkerDom();\n\nconst heading = document.createElement(\"h1\");\nheading.textContent = \"Hello from async-dom + React!\";\ndocument.body.appendChild(heading);\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/vite-env.d.ts\",\n\t\t\tcontent: `/// <reference types=\"vite/client\" />\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"tsconfig.json\",\n\t\t\tcontent: JSON.stringify(\n\t\t\t\t{\n\t\t\t\t\tcompilerOptions: {\n\t\t\t\t\t\ttarget: \"ES2022\",\n\t\t\t\t\t\tmodule: \"ESNext\",\n\t\t\t\t\t\tmoduleResolution: \"bundler\",\n\t\t\t\t\t\tstrict: true,\n\t\t\t\t\t\tesModuleInterop: true,\n\t\t\t\t\t\tskipLibCheck: true,\n\t\t\t\t\t\tforceConsistentCasingInFileNames: true,\n\t\t\t\t\t\tisolatedModules: true,\n\t\t\t\t\t\tnoEmit: true,\n\t\t\t\t\t\tjsx: \"react-jsx\",\n\t\t\t\t\t\tlib: [\"ES2022\", \"DOM\", \"DOM.Iterable\"],\n\t\t\t\t\t},\n\t\t\t\t\tinclude: [\"src\"],\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t),\n\t\t},\n\t\t{\n\t\t\tpath: \"vite.config.ts\",\n\t\t\tcontent: `import { defineConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\nimport { asyncDomPlugin } from \"@lifeart/async-dom/vite-plugin\";\n\nexport default defineConfig({\n plugins: [react(), asyncDomPlugin()],\n});\n`,\n\t\t},\n\t];\n}\n\nfunction vueTs(name: string): TemplateFile[] {\n\treturn [\n\t\t{\n\t\t\tpath: \"package.json\",\n\t\t\tcontent: JSON.stringify(\n\t\t\t\t{\n\t\t\t\t\tname,\n\t\t\t\t\tprivate: true,\n\t\t\t\t\tversion: \"0.0.0\",\n\t\t\t\t\ttype: \"module\",\n\t\t\t\t\tscripts: {\n\t\t\t\t\t\tdev: \"vite\",\n\t\t\t\t\t\tbuild: \"vue-tsc && vite build\",\n\t\t\t\t\t\tpreview: \"vite preview\",\n\t\t\t\t\t},\n\t\t\t\t\tdependencies: {\n\t\t\t\t\t\tvue: \"^3.5.0\",\n\t\t\t\t\t},\n\t\t\t\t\tdevDependencies: {\n\t\t\t\t\t\t\"@vitejs/plugin-vue\": \"^5.0.0\",\n\t\t\t\t\t\ttypescript: \"^5.8.0\",\n\t\t\t\t\t\t\"vue-tsc\": \"^2.0.0\",\n\t\t\t\t\t\tvite: \"^6.0.0\",\n\t\t\t\t\t\t\"@lifeart/async-dom\": \"latest\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t),\n\t\t},\n\t\t{\n\t\t\tpath: \"index.html\",\n\t\t\tcontent: `<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>${escapeHtml(name)}</title>\n </head>\n <body>\n <div id=\"app\"></div>\n <script type=\"module\" src=\"/src/main.ts\"></script>\n </body>\n</html>\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/main.ts\",\n\t\t\tcontent: `import { createApp } from \"vue\";\nimport App from \"./App.vue\";\n\ncreateApp(App).mount(\"#app\");\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/App.vue\",\n\t\t\tcontent: `<script setup lang=\"ts\">\nimport { AsyncDom } from \"@lifeart/async-dom/vue\";\n\nfunction onReady(instance: any) {\n console.log(\"async-dom ready\", instance);\n}\n</script>\n\n<template>\n <AsyncDom worker=\"./app.worker.ts\" @ready=\"onReady\">\n <template #fallback>\n <p>Loading...</p>\n </template>\n </AsyncDom>\n</template>\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/app.worker.ts\",\n\t\t\tcontent: `import { createWorkerDom } from \"@lifeart/async-dom/worker\";\n\nconst { document } = createWorkerDom();\n\nconst heading = document.createElement(\"h1\");\nheading.textContent = \"Hello from async-dom + Vue!\";\ndocument.body.appendChild(heading);\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"src/vite-env.d.ts\",\n\t\t\tcontent: `/// <reference types=\"vite/client\" />\ndeclare module \"*.vue\" {\n import type { DefineComponent } from \"vue\";\n const component: DefineComponent<{}, {}, any>;\n export default component;\n}\n`,\n\t\t},\n\t\t{\n\t\t\tpath: \"tsconfig.json\",\n\t\t\tcontent: JSON.stringify(\n\t\t\t\t{\n\t\t\t\t\tcompilerOptions: {\n\t\t\t\t\t\ttarget: \"ES2022\",\n\t\t\t\t\t\tmodule: \"ESNext\",\n\t\t\t\t\t\tmoduleResolution: \"bundler\",\n\t\t\t\t\t\tstrict: true,\n\t\t\t\t\t\tesModuleInterop: true,\n\t\t\t\t\t\tskipLibCheck: true,\n\t\t\t\t\t\tforceConsistentCasingInFileNames: true,\n\t\t\t\t\t\tisolatedModules: true,\n\t\t\t\t\t\tnoEmit: true,\n\t\t\t\t\t\tlib: [\"ES2022\", \"DOM\", \"DOM.Iterable\"],\n\t\t\t\t\t},\n\t\t\t\t\tinclude: [\"src\"],\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t),\n\t\t},\n\t\t{\n\t\t\tpath: \"vite.config.ts\",\n\t\t\tcontent: `import { defineConfig } from \"vite\";\nimport vue from \"@vitejs/plugin-vue\";\nimport { asyncDomPlugin } from \"@lifeart/async-dom/vite-plugin\";\n\nexport default defineConfig({\n plugins: [vue(), asyncDomPlugin()],\n});\n`,\n\t\t},\n\t];\n}\n","import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as readline from \"node:readline\";\nimport { AVAILABLE_TEMPLATES, getTemplate } from \"./templates.ts\";\n\nfunction ask(question: string): Promise<string> {\n\tconst rl = readline.createInterface({\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t});\n\treturn new Promise((resolve) => {\n\t\trl.question(question, (answer) => {\n\t\t\trl.close();\n\t\t\tresolve(answer.trim());\n\t\t});\n\t});\n}\n\nasync function init(args: string[]): Promise<void> {\n\tlet name: string | undefined;\n\tlet template = \"\";\n\n\t// Parse flags\n\tfor (let i = 0; i < args.length; i++) {\n\t\tif (args[i] === \"--template\" && args[i + 1]) {\n\t\t\ttemplate = args[i + 1];\n\t\t\ti++;\n\t\t} else if (!args[i].startsWith(\"-\") && !name) {\n\t\t\tname = args[i];\n\t\t}\n\t}\n\n\t// Interactive prompts for missing values\n\tif (!name) {\n\t\tname = await ask(\"Project name: \");\n\t\tif (!name) {\n\t\t\tconsole.error(\"Project name is required.\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tif (!template) {\n\t\tconsole.log(\"\\nAvailable templates:\");\n\t\tfor (const t of AVAILABLE_TEMPLATES) {\n\t\t\tconsole.log(` - ${t}`);\n\t\t}\n\t\ttemplate = await ask(\"\\nTemplate (default: vanilla-ts): \");\n\t\tif (!template) template = \"vanilla-ts\";\n\t}\n\n\t// Validate template\n\tif (!AVAILABLE_TEMPLATES.includes(template as (typeof AVAILABLE_TEMPLATES)[number])) {\n\t\tconsole.error(`Unknown template: ${template}. Available: ${AVAILABLE_TEMPLATES.join(\", \")}`);\n\t\tprocess.exit(1);\n\t}\n\n\tconst targetDir = path.resolve(process.cwd(), name);\n\n\tif (fs.existsSync(targetDir)) {\n\t\tconst contents = fs.readdirSync(targetDir);\n\t\tif (contents.length > 0) {\n\t\t\tconsole.error(`Directory \"${name}\" already exists and is not empty.`);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tconsole.log(`\\nScaffolding project in ${targetDir}...`);\n\n\tconst files = getTemplate(template, name);\n\n\tfor (const file of files) {\n\t\tconst filePath = path.join(targetDir, file.path);\n\t\tconst dir = path.dirname(filePath);\n\t\tfs.mkdirSync(dir, { recursive: true });\n\t\tfs.writeFileSync(filePath, file.content);\n\t\tconsole.log(` created ${file.path}`);\n\t}\n\n\tconsole.log(`\\nDone! Now run:\\n`);\n\tconsole.log(` cd ${name}`);\n\tconsole.log(\" npm install\");\n\tconsole.log(\" npm run dev\");\n\tconsole.log(\"\");\n}\n\nfunction printHelp(): void {\n\tconsole.log(`\n@lifeart/async-dom - Asynchronous DOM rendering CLI\n\nUsage:\n async-dom init [name] [--template <template>]\n\nCommands:\n init Scaffold a new async-dom project\n\nTemplates:\n ${AVAILABLE_TEMPLATES.join(\", \")}\n\nExamples:\n npx @lifeart/async-dom init my-app\n npx @lifeart/async-dom init my-app --template react-ts\n`);\n}\n\nasync function main(): Promise<void> {\n\tconst args = process.argv.slice(2);\n\tconst command = args[0];\n\n\tswitch (command) {\n\t\tcase \"init\":\n\t\t\tawait init(args.slice(1));\n\t\t\tbreak;\n\t\tcase \"--help\":\n\t\tcase \"-h\":\n\t\tcase undefined:\n\t\t\tprintHelp();\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tconsole.error(`Unknown command: ${command}`);\n\t\t\tprintHelp();\n\t\t\tprocess.exit(1);\n\t}\n}\n\nmain().catch((err) => {\n\tconsole.error(err);\n\tprocess.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAgB,YAAY,UAAkB,MAA8B;AAC3E,SAAQ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