create-krispya 0.6.0 → 0.7.0
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/README.md +7 -346
- package/dist/index.cjs +2969 -21
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +2953 -5
- package/package.json +29 -15
- package/LICENSE +0 -15
- package/dist/chunks/index.cjs +0 -2976
- package/dist/chunks/index.mjs +0 -2947
- package/dist/cli.cjs +0 -3025
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +0 -3004
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,2953 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import 'fs
|
|
4
|
-
import '
|
|
5
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { readFile, access } from 'fs/promises';
|
|
3
|
+
import { constants } from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
const HtmlContent = `<!DOCTYPE html>
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="UTF-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
|
+
<title>$title</title>
|
|
12
|
+
</head>
|
|
13
|
+
<body style="margin: 0; overscroll-behavior: none; user-select: none; touch-action: none;">
|
|
14
|
+
<script type="module" src="$indexPath"><\/script>
|
|
15
|
+
<div style="width: 100dvw; height: 100dvh; overflow: hidden;" id="root"></div>
|
|
16
|
+
</body>
|
|
17
|
+
</html>`;
|
|
18
|
+
const ViteHtmlContent = `<!DOCTYPE html>
|
|
19
|
+
<html lang="en">
|
|
20
|
+
<head>
|
|
21
|
+
<meta charset="UTF-8">
|
|
22
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
23
|
+
<title>$title</title>
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<div id="app"></div>
|
|
27
|
+
<script type="module" src="$indexPath"><\/script>
|
|
28
|
+
</body>
|
|
29
|
+
</html>`;
|
|
30
|
+
const IndexContent = `import { StrictMode } from 'react'
|
|
31
|
+
import { createRoot } from 'react-dom/client'
|
|
32
|
+
import { App } from './app.js'
|
|
33
|
+
|
|
34
|
+
createRoot(document.getElementById('root')!).render(
|
|
35
|
+
<StrictMode>
|
|
36
|
+
<App />
|
|
37
|
+
</StrictMode>,
|
|
38
|
+
)`;
|
|
39
|
+
const ViteIndexContent = `import './style.css'
|
|
40
|
+
|
|
41
|
+
document.querySelector('#app')!.innerHTML = \`
|
|
42
|
+
<h1>Hello Vite!</h1>
|
|
43
|
+
<p>Edit src/main.ts and save to see HMR in action.</p>
|
|
44
|
+
\``;
|
|
45
|
+
const ViteStyleContent = `body {
|
|
46
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
47
|
+
margin: 0;
|
|
48
|
+
padding: 2rem;
|
|
49
|
+
min-height: 100vh;
|
|
50
|
+
background: #1a1a1a;
|
|
51
|
+
color: #fff;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
h1 {
|
|
55
|
+
color: #646cff;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
a {
|
|
59
|
+
color: #646cff;
|
|
60
|
+
}`;
|
|
61
|
+
const GitAttributes = [
|
|
62
|
+
"* text eol=lf",
|
|
63
|
+
"*.png binary",
|
|
64
|
+
"*.jpg binary",
|
|
65
|
+
"*.jpeg binary",
|
|
66
|
+
"*.gif binary",
|
|
67
|
+
"*.ico binary",
|
|
68
|
+
"*.mov binary",
|
|
69
|
+
"*.mp4 binary",
|
|
70
|
+
"*.mp3 binary",
|
|
71
|
+
"*.flv binary",
|
|
72
|
+
"*.fla binary",
|
|
73
|
+
"*.wav binary",
|
|
74
|
+
"*.swf binary",
|
|
75
|
+
"*.gz binary",
|
|
76
|
+
"*.zip binary",
|
|
77
|
+
"*.7z binary",
|
|
78
|
+
"*.ttf binary",
|
|
79
|
+
"*.eot binary",
|
|
80
|
+
"*.woff binary",
|
|
81
|
+
"*.pyc binary",
|
|
82
|
+
"*.pdf binary",
|
|
83
|
+
"*.glb binary",
|
|
84
|
+
"*.gltf binary"
|
|
85
|
+
].join("\n");
|
|
86
|
+
const defaultFormatterConfig = {
|
|
87
|
+
printWidth: 102,
|
|
88
|
+
tabWidth: 2,
|
|
89
|
+
useTabs: false,
|
|
90
|
+
semi: true,
|
|
91
|
+
singleQuote: true,
|
|
92
|
+
trailingComma: "es5",
|
|
93
|
+
bracketSpacing: true,
|
|
94
|
+
arrowParens: "always"
|
|
95
|
+
};
|
|
96
|
+
const defaultPrettierConfig = {
|
|
97
|
+
$schema: "https://json.schemastore.org/prettierrc",
|
|
98
|
+
...defaultFormatterConfig,
|
|
99
|
+
overrides: [
|
|
100
|
+
{
|
|
101
|
+
files: ["*.md", "**/*.md"],
|
|
102
|
+
options: { semi: false }
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
files: ["*.yml", "*.yaml", "**/*.yml", "**/*.yaml"],
|
|
106
|
+
options: { semi: false }
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
const defaultOxfmtConfig = {
|
|
111
|
+
printWidth: defaultFormatterConfig.printWidth,
|
|
112
|
+
tabWidth: defaultFormatterConfig.tabWidth,
|
|
113
|
+
useTabs: defaultFormatterConfig.useTabs,
|
|
114
|
+
semi: defaultFormatterConfig.semi,
|
|
115
|
+
singleQuote: defaultFormatterConfig.singleQuote,
|
|
116
|
+
trailingComma: defaultFormatterConfig.trailingComma,
|
|
117
|
+
bracketSpacing: defaultFormatterConfig.bracketSpacing,
|
|
118
|
+
arrowParens: defaultFormatterConfig.arrowParens
|
|
119
|
+
};
|
|
120
|
+
const defaultLinterConfig = {
|
|
121
|
+
ignorePatterns: ["dist"],
|
|
122
|
+
rules: {
|
|
123
|
+
noUnusedVars: {
|
|
124
|
+
level: "warn",
|
|
125
|
+
argsIgnorePattern: "^_",
|
|
126
|
+
varsIgnorePattern: "^_",
|
|
127
|
+
caughtErrorsIgnorePattern: "^_"
|
|
128
|
+
},
|
|
129
|
+
noUnusedExpressions: {
|
|
130
|
+
level: "warn",
|
|
131
|
+
allowShortCircuit: true
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function generateAiFiles(files, params) {
|
|
137
|
+
const { platforms, isMonorepo, configStrategy, ...rest } = params;
|
|
138
|
+
if (platforms.length === 0) return;
|
|
139
|
+
files[".ai/workspace.md"] = {
|
|
140
|
+
type: "text",
|
|
141
|
+
content: generateWorkspace({
|
|
142
|
+
...rest,
|
|
143
|
+
isMonorepo: !!isMonorepo,
|
|
144
|
+
configStrategy: configStrategy ?? "stealth"
|
|
145
|
+
})
|
|
146
|
+
};
|
|
147
|
+
const pointer = "See `.ai/` for project rules.\n";
|
|
148
|
+
for (const platform of platforms) {
|
|
149
|
+
const path = platform === "agents" ? "AGENTS.md" : "CLAUDE.md";
|
|
150
|
+
files[path] = { type: "text", content: pointer };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function generateWorkspace(ctx) {
|
|
154
|
+
const { name, packageManager, linter, formatter, isMonorepo, configStrategy } = ctx;
|
|
155
|
+
const sections = [
|
|
156
|
+
`# ${name}`,
|
|
157
|
+
"",
|
|
158
|
+
`- **Type:** ${isMonorepo ? "pnpm monorepo" : "standalone project"}`,
|
|
159
|
+
`- **Package Manager:** ${packageManager}`,
|
|
160
|
+
`- **Linter:** ${linter}`,
|
|
161
|
+
`- **Formatter:** ${formatter}`,
|
|
162
|
+
"",
|
|
163
|
+
"## Commands",
|
|
164
|
+
"",
|
|
165
|
+
`- \`${packageManager} test\` \u2014 run tests`,
|
|
166
|
+
`- \`${packageManager} build\` \u2014 build`,
|
|
167
|
+
`- \`${packageManager} lint\` and \`${packageManager} format\` \u2014 run before committing`
|
|
168
|
+
];
|
|
169
|
+
if (isMonorepo) {
|
|
170
|
+
sections.push(
|
|
171
|
+
"",
|
|
172
|
+
"## Structure",
|
|
173
|
+
"",
|
|
174
|
+
"- `apps/` \u2014 applications",
|
|
175
|
+
"- `packages/` \u2014 shared libraries",
|
|
176
|
+
"- `.config/` \u2014 shared config packages",
|
|
177
|
+
"",
|
|
178
|
+
"## Monorepo",
|
|
179
|
+
"",
|
|
180
|
+
"- Use `workspace:*` for internal dependencies",
|
|
181
|
+
`- New packages: \`${packageManager} create krispya <name> --workspace\``
|
|
182
|
+
);
|
|
183
|
+
} else if (configStrategy === "root") {
|
|
184
|
+
sections.push(
|
|
185
|
+
"",
|
|
186
|
+
"## Structure",
|
|
187
|
+
"",
|
|
188
|
+
"- `src/` \u2014 source code",
|
|
189
|
+
"- `dist/` \u2014 generated, don't edit",
|
|
190
|
+
"- Config files (`tsconfig.json`, etc.) are at project root"
|
|
191
|
+
);
|
|
192
|
+
} else {
|
|
193
|
+
sections.push(
|
|
194
|
+
"",
|
|
195
|
+
"## Structure",
|
|
196
|
+
"",
|
|
197
|
+
"- `src/` \u2014 source code",
|
|
198
|
+
"- `.config/` \u2014 configs, don't move",
|
|
199
|
+
"- `dist/` \u2014 generated, don't edit"
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
sections.push("");
|
|
203
|
+
return sections.join("\n");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function generateTypescriptConfig(baseTemplateOrParams) {
|
|
207
|
+
const params = typeof baseTemplateOrParams === "string" ? { baseTemplate: baseTemplateOrParams } : baseTemplateOrParams;
|
|
208
|
+
const { baseTemplate, useConfigPackage, configStrategy = "stealth", nodeVersion } = params;
|
|
209
|
+
const isReact = baseTemplate === "react";
|
|
210
|
+
const isR3f = baseTemplate === "r3f";
|
|
211
|
+
const files = {};
|
|
212
|
+
const devDependencies = {};
|
|
213
|
+
if (nodeVersion) {
|
|
214
|
+
const majorVersion = nodeVersion.split(".")[0];
|
|
215
|
+
devDependencies["@types/node"] = `^${majorVersion}.0.0`;
|
|
216
|
+
} else {
|
|
217
|
+
devDependencies["@types/node"] = "^22.0.0";
|
|
218
|
+
}
|
|
219
|
+
if (isReact || isR3f) {
|
|
220
|
+
devDependencies["@types/react"] = "^19.0.0";
|
|
221
|
+
devDependencies["@types/react-dom"] = "^19.0.0";
|
|
222
|
+
}
|
|
223
|
+
if (isR3f) {
|
|
224
|
+
devDependencies["@types/three"] = "~0.175.0";
|
|
225
|
+
}
|
|
226
|
+
if (useConfigPackage) {
|
|
227
|
+
devDependencies["@config/typescript"] = "workspace:*";
|
|
228
|
+
const baseConfig = isReact || isR3f ? "@config/typescript/react.json" : "@config/typescript/app.json";
|
|
229
|
+
files["tsconfig.json"] = {
|
|
230
|
+
type: "text",
|
|
231
|
+
content: JSON.stringify(
|
|
232
|
+
{
|
|
233
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
234
|
+
extends: baseConfig,
|
|
235
|
+
include: ["src/**/*", "tests/**/*"]
|
|
236
|
+
},
|
|
237
|
+
null,
|
|
238
|
+
2
|
|
239
|
+
)
|
|
240
|
+
};
|
|
241
|
+
return { files, devDependencies };
|
|
242
|
+
}
|
|
243
|
+
if (configStrategy === "stealth") {
|
|
244
|
+
const tsConfig = {
|
|
245
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
246
|
+
files: [],
|
|
247
|
+
references: [{ path: "./.config/tsconfig.app.json" }, { path: "./.config/tsconfig.node.json" }]
|
|
248
|
+
};
|
|
249
|
+
files["tsconfig.json"] = {
|
|
250
|
+
type: "text",
|
|
251
|
+
content: JSON.stringify(tsConfig, null, 2)
|
|
252
|
+
};
|
|
253
|
+
const tsConfigApp = {
|
|
254
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
255
|
+
compilerOptions: {
|
|
256
|
+
target: "ESNext",
|
|
257
|
+
module: "ESNext",
|
|
258
|
+
moduleResolution: "bundler",
|
|
259
|
+
lib: ["DOM", "DOM.Iterable", "ESNext"],
|
|
260
|
+
esModuleInterop: true,
|
|
261
|
+
allowSyntheticDefaultImports: true,
|
|
262
|
+
strict: true,
|
|
263
|
+
skipLibCheck: true,
|
|
264
|
+
composite: true,
|
|
265
|
+
rewriteRelativeImportExtensions: true,
|
|
266
|
+
erasableSyntaxOnly: true,
|
|
267
|
+
...isReact || isR3f ? { jsx: "react-jsx" } : {}
|
|
268
|
+
},
|
|
269
|
+
include: ["../src", "../tests"]
|
|
270
|
+
};
|
|
271
|
+
files[".config/tsconfig.app.json"] = {
|
|
272
|
+
type: "text",
|
|
273
|
+
content: JSON.stringify(tsConfigApp, null, 2)
|
|
274
|
+
};
|
|
275
|
+
const tsConfigNode = {
|
|
276
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
277
|
+
compilerOptions: {
|
|
278
|
+
target: "ESNext",
|
|
279
|
+
module: "ESNext",
|
|
280
|
+
moduleResolution: "bundler",
|
|
281
|
+
lib: ["ESNext"],
|
|
282
|
+
esModuleInterop: true,
|
|
283
|
+
allowSyntheticDefaultImports: true,
|
|
284
|
+
strict: true,
|
|
285
|
+
skipLibCheck: true,
|
|
286
|
+
composite: true,
|
|
287
|
+
rewriteRelativeImportExtensions: true,
|
|
288
|
+
erasableSyntaxOnly: true
|
|
289
|
+
},
|
|
290
|
+
include: ["../*.config.ts", "./*.ts"]
|
|
291
|
+
};
|
|
292
|
+
files[".config/tsconfig.node.json"] = {
|
|
293
|
+
type: "text",
|
|
294
|
+
content: JSON.stringify(tsConfigNode, null, 2)
|
|
295
|
+
};
|
|
296
|
+
} else {
|
|
297
|
+
const tsConfig = {
|
|
298
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
299
|
+
files: [],
|
|
300
|
+
references: [{ path: "./tsconfig.app.json" }, { path: "./tsconfig.node.json" }]
|
|
301
|
+
};
|
|
302
|
+
files["tsconfig.json"] = {
|
|
303
|
+
type: "text",
|
|
304
|
+
content: JSON.stringify(tsConfig, null, 2)
|
|
305
|
+
};
|
|
306
|
+
const tsConfigApp = {
|
|
307
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
308
|
+
compilerOptions: {
|
|
309
|
+
target: "ESNext",
|
|
310
|
+
module: "ESNext",
|
|
311
|
+
moduleResolution: "bundler",
|
|
312
|
+
lib: ["DOM", "DOM.Iterable", "ESNext"],
|
|
313
|
+
esModuleInterop: true,
|
|
314
|
+
allowSyntheticDefaultImports: true,
|
|
315
|
+
strict: true,
|
|
316
|
+
skipLibCheck: true,
|
|
317
|
+
composite: true,
|
|
318
|
+
rewriteRelativeImportExtensions: true,
|
|
319
|
+
erasableSyntaxOnly: true,
|
|
320
|
+
...isReact || isR3f ? { jsx: "react-jsx" } : {}
|
|
321
|
+
},
|
|
322
|
+
include: ["src", "tests"]
|
|
323
|
+
};
|
|
324
|
+
files["tsconfig.app.json"] = {
|
|
325
|
+
type: "text",
|
|
326
|
+
content: JSON.stringify(tsConfigApp, null, 2)
|
|
327
|
+
};
|
|
328
|
+
const tsConfigNode = {
|
|
329
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
330
|
+
compilerOptions: {
|
|
331
|
+
target: "ESNext",
|
|
332
|
+
module: "ESNext",
|
|
333
|
+
moduleResolution: "bundler",
|
|
334
|
+
lib: ["ESNext"],
|
|
335
|
+
esModuleInterop: true,
|
|
336
|
+
allowSyntheticDefaultImports: true,
|
|
337
|
+
strict: true,
|
|
338
|
+
skipLibCheck: true,
|
|
339
|
+
composite: true,
|
|
340
|
+
rewriteRelativeImportExtensions: true,
|
|
341
|
+
erasableSyntaxOnly: true
|
|
342
|
+
},
|
|
343
|
+
include: ["*.config.ts"]
|
|
344
|
+
};
|
|
345
|
+
files["tsconfig.node.json"] = {
|
|
346
|
+
type: "text",
|
|
347
|
+
content: JSON.stringify(tsConfigNode, null, 2)
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
return { files, devDependencies };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const DEFAULT_LIBRARY_VERSION = "0.1.0";
|
|
354
|
+
function generatePackageJson(params) {
|
|
355
|
+
const {
|
|
356
|
+
name,
|
|
357
|
+
language,
|
|
358
|
+
isLibrary,
|
|
359
|
+
dependencies,
|
|
360
|
+
devDependencies,
|
|
361
|
+
peerDependencies,
|
|
362
|
+
scripts,
|
|
363
|
+
options,
|
|
364
|
+
workspaceDependencies
|
|
365
|
+
} = params;
|
|
366
|
+
const files = {};
|
|
367
|
+
const packageManager = options.packageManager ?? "pnpm";
|
|
368
|
+
const isPnpm = packageManager === "pnpm";
|
|
369
|
+
const packageJson = {
|
|
370
|
+
name,
|
|
371
|
+
description: "Built with \u{1F339} create-krispya",
|
|
372
|
+
type: "module"
|
|
373
|
+
};
|
|
374
|
+
if (isLibrary) {
|
|
375
|
+
packageJson.version = DEFAULT_LIBRARY_VERSION;
|
|
376
|
+
packageJson.main = "./dist/index.mjs";
|
|
377
|
+
packageJson.module = "./dist/index.mjs";
|
|
378
|
+
if (language === "typescript") {
|
|
379
|
+
packageJson.types = "./dist/index.d.ts";
|
|
380
|
+
}
|
|
381
|
+
packageJson.exports = {
|
|
382
|
+
".": {
|
|
383
|
+
...language === "typescript" && { types: "./dist/index.d.ts" },
|
|
384
|
+
import: "./dist/index.mjs",
|
|
385
|
+
require: "./dist/index.cjs"
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
packageJson.files = ["dist"];
|
|
389
|
+
}
|
|
390
|
+
const sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
|
|
391
|
+
const allDependencies = { ...dependencies };
|
|
392
|
+
if (workspaceDependencies && workspaceDependencies.length > 0) {
|
|
393
|
+
for (const pkgName of workspaceDependencies) {
|
|
394
|
+
allDependencies[pkgName] = "workspace:*";
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
const allDevDependencies = { ...devDependencies };
|
|
398
|
+
if (options.nodeVersion) {
|
|
399
|
+
const majorVersion = options.nodeVersion.split(".")[0];
|
|
400
|
+
allDevDependencies["@types/node"] ??= `^${majorVersion}.0.0`;
|
|
401
|
+
}
|
|
402
|
+
packageJson.scripts = scripts;
|
|
403
|
+
packageJson.dependencies = sortKeys(allDependencies);
|
|
404
|
+
if (Object.keys(allDevDependencies).length > 0) {
|
|
405
|
+
packageJson.devDependencies = sortKeys(allDevDependencies);
|
|
406
|
+
}
|
|
407
|
+
if (isLibrary && Object.keys(peerDependencies).length > 0) {
|
|
408
|
+
packageJson.peerDependencies = sortKeys(peerDependencies);
|
|
409
|
+
}
|
|
410
|
+
const isMonorepoPackage = options.workspaceRoot != null;
|
|
411
|
+
if (!isMonorepoPackage) {
|
|
412
|
+
const engines = {};
|
|
413
|
+
if (isPnpm) {
|
|
414
|
+
const pnpmVersion = options.pnpmVersion ?? "10.11.0";
|
|
415
|
+
const majorVersion = pnpmVersion.split(".")[0];
|
|
416
|
+
engines.pnpm = `>=${majorVersion}.0.0`;
|
|
417
|
+
packageJson.packageManager = `pnpm@${pnpmVersion}`;
|
|
418
|
+
} else if (packageManager === "yarn") {
|
|
419
|
+
const yarnVersion = options.yarnVersion ?? "4.6.0";
|
|
420
|
+
const majorVersion = yarnVersion.split(".")[0];
|
|
421
|
+
engines.yarn = `>=${majorVersion}.0.0`;
|
|
422
|
+
packageJson.packageManager = `yarn@${yarnVersion}`;
|
|
423
|
+
} else if (packageManager === "npm") {
|
|
424
|
+
const npmVersion = options.npmVersion ?? "11.0.0";
|
|
425
|
+
const majorVersion = npmVersion.split(".")[0];
|
|
426
|
+
engines.npm = `>=${majorVersion}.0.0`;
|
|
427
|
+
packageJson.packageManager = `npm@${npmVersion}`;
|
|
428
|
+
}
|
|
429
|
+
if (options.nodeVersion) {
|
|
430
|
+
const majorVersion = options.nodeVersion.split(".")[0];
|
|
431
|
+
engines.node = `>=${majorVersion}.0.0`;
|
|
432
|
+
}
|
|
433
|
+
if (Object.keys(engines).length > 0) {
|
|
434
|
+
packageJson.engines = engines;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
files["package.json"] = {
|
|
438
|
+
type: "text",
|
|
439
|
+
content: JSON.stringify(packageJson, null, 2)
|
|
440
|
+
};
|
|
441
|
+
if (isPnpm && !options.workspaceRoot) {
|
|
442
|
+
const manageVersions = options.pnpmManageVersions ?? true;
|
|
443
|
+
const workspaceLines = [];
|
|
444
|
+
if (manageVersions) {
|
|
445
|
+
workspaceLines.push("manage-package-manager-versions: true", "");
|
|
446
|
+
}
|
|
447
|
+
workspaceLines.push("onlyBuiltDependencies:", " - esbuild");
|
|
448
|
+
files["pnpm-workspace.yaml"] = {
|
|
449
|
+
type: "text",
|
|
450
|
+
content: workspaceLines.join("\n")
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
return { files };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function generateReadme(params) {
|
|
457
|
+
const { name, baseTemplate, isLibrary, libraryBundler, packageManager, codeSnippets } = params;
|
|
458
|
+
const isVanilla = baseTemplate === "vanilla";
|
|
459
|
+
const isReact = baseTemplate === "react";
|
|
460
|
+
const isR3f = baseTemplate === "r3f";
|
|
461
|
+
const ext = "ts";
|
|
462
|
+
const jsxExt = "tsx";
|
|
463
|
+
codeSnippets["readme-libraries"] ??= [];
|
|
464
|
+
codeSnippets["readme-commands"] ??= [];
|
|
465
|
+
if (isLibrary) ; else if (isVanilla) {
|
|
466
|
+
codeSnippets["readme-libraries"].unshift(
|
|
467
|
+
`[Vite](https://vitejs.dev/) - Next generation frontend tooling`
|
|
468
|
+
);
|
|
469
|
+
} else if (isReact) {
|
|
470
|
+
codeSnippets["readme-libraries"].unshift(
|
|
471
|
+
`[React](https://react.dev/) - A JavaScript library for building user interfaces`,
|
|
472
|
+
`[Vite](https://vitejs.dev/) - Next generation frontend tooling`
|
|
473
|
+
);
|
|
474
|
+
} else {
|
|
475
|
+
codeSnippets["readme-libraries"].unshift(
|
|
476
|
+
`[React](https://react.dev/) - A JavaScript library for building user interfaces`,
|
|
477
|
+
`[Three.js](https://threejs.org/) - JavaScript 3D library`,
|
|
478
|
+
`[@react-three/fiber](https://docs.pmnd.rs/react-three-fiber) - lets you create Three.js scenes using React components`
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
if (isLibrary) {
|
|
482
|
+
codeSnippets["readme-commands"].unshift(
|
|
483
|
+
`\`${packageManager} install\` to install the dependencies`,
|
|
484
|
+
`\`${packageManager} run build\` to build the library into the \`dist\` folder`,
|
|
485
|
+
`\`${packageManager} run test\` to run the tests`,
|
|
486
|
+
`\`${packageManager} run release\` to build and publish to npm`
|
|
487
|
+
);
|
|
488
|
+
} else {
|
|
489
|
+
codeSnippets["readme-commands"].unshift(
|
|
490
|
+
`\`${packageManager} install\` to install the dependencies`,
|
|
491
|
+
`\`${packageManager} run dev\` to run the development server and preview the app with live updates`,
|
|
492
|
+
`\`${packageManager} run build\` to build the app into the \`dist\` folder`,
|
|
493
|
+
`\`${packageManager} run test\` to run the tests`
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
let architectureDesc;
|
|
497
|
+
if (isLibrary) {
|
|
498
|
+
architectureDesc = [
|
|
499
|
+
`- \`src/index.${isReact || isR3f ? jsxExt : ext}\` is the main entry point for your library exports`,
|
|
500
|
+
`- Add your library code in the \`src\` folder`,
|
|
501
|
+
`- \`tests/\` contains your test files`
|
|
502
|
+
];
|
|
503
|
+
} else if (isVanilla) {
|
|
504
|
+
architectureDesc = [
|
|
505
|
+
`- \`src/main.${ext}\` is the entry point for your application`,
|
|
506
|
+
`- \`tests/\` contains your test files`,
|
|
507
|
+
`- Static assets can be placed in the \`public\` folder`
|
|
508
|
+
];
|
|
509
|
+
} else if (isReact) {
|
|
510
|
+
architectureDesc = [
|
|
511
|
+
`- \`src/app.${jsxExt}\` defines the main application component`,
|
|
512
|
+
`- \`src/index.${jsxExt}\` renders the React app into the DOM`,
|
|
513
|
+
`- \`tests/\` contains your test files`,
|
|
514
|
+
`- Static assets can be placed in the \`public\` folder`
|
|
515
|
+
];
|
|
516
|
+
} else {
|
|
517
|
+
architectureDesc = [
|
|
518
|
+
`- \`app.${jsxExt}\` defines the main application component containing your 3D content`,
|
|
519
|
+
`- Modify the content inside the \`<Canvas>\` component to change what is visible on screen`,
|
|
520
|
+
`- \`tests/\` contains your test files`,
|
|
521
|
+
`- Static assets can be placed in the \`public\` folder`
|
|
522
|
+
];
|
|
523
|
+
}
|
|
524
|
+
const bundlerDescription = isLibrary ? libraryBundler === "unbuild" ? `This library uses [unbuild](https://github.com/unjs/unbuild) for building.` : `This library uses [tsdown](https://github.com/nicepkg/tsdown) for building.` : `This project uses [Vite](https://vitejs.dev/) as the bundler for fast development and optimized production builds.`;
|
|
525
|
+
const content = [
|
|
526
|
+
`# ${name}`,
|
|
527
|
+
`This ${isLibrary ? "library" : "project"} was generated with create-krispya`,
|
|
528
|
+
...codeSnippets["readme-start"] ?? [],
|
|
529
|
+
"\n",
|
|
530
|
+
`## Project Architecture`,
|
|
531
|
+
bundlerDescription,
|
|
532
|
+
...architectureDesc,
|
|
533
|
+
"\n",
|
|
534
|
+
`## Libraries`,
|
|
535
|
+
`The following libraries are used - checkout the linked docs to learn more`,
|
|
536
|
+
...(codeSnippets["readme-libraries"] ?? []).map((library) => `- ${library}`),
|
|
537
|
+
"\n",
|
|
538
|
+
codeSnippets["readme-tools"] && `## Tools`,
|
|
539
|
+
...(codeSnippets["readme-tools"] ?? []).map((tool) => `- ${tool}`),
|
|
540
|
+
codeSnippets["readme-tools"] && `
|
|
541
|
+
`,
|
|
542
|
+
`## Development Commands`,
|
|
543
|
+
...(codeSnippets["readme-commands"] ?? []).map((command) => `- ${command}`),
|
|
544
|
+
...codeSnippets["readme-end"] ?? []
|
|
545
|
+
].filter(Boolean).join("\n");
|
|
546
|
+
return { type: "text", content };
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function generateSourceFiles(params) {
|
|
550
|
+
const { name, baseTemplate, language, isLibrary, codeSnippets, replacements } = params;
|
|
551
|
+
const files = {};
|
|
552
|
+
const ext = language === "typescript" ? "ts" : "js";
|
|
553
|
+
const jsxExt = language === "typescript" ? "tsx" : "jsx";
|
|
554
|
+
const isVanilla = baseTemplate === "vanilla";
|
|
555
|
+
const isReact = baseTemplate === "react";
|
|
556
|
+
const isR3f = baseTemplate === "r3f";
|
|
557
|
+
if (isLibrary) {
|
|
558
|
+
const libExt = isReact || isR3f ? jsxExt : ext;
|
|
559
|
+
let libContent;
|
|
560
|
+
if (isVanilla) {
|
|
561
|
+
libContent = [
|
|
562
|
+
`// Library entry point`,
|
|
563
|
+
`export function hello(name: string = "world"): string {`,
|
|
564
|
+
` return \`Hello, \${name}!\``,
|
|
565
|
+
`}`
|
|
566
|
+
].join("\n");
|
|
567
|
+
} else if (isReact) {
|
|
568
|
+
libContent = [
|
|
569
|
+
`// Library entry point`,
|
|
570
|
+
`export function MyComponent({ message = "Hello from library!" }: { message?: string }) {`,
|
|
571
|
+
` return <div>{message}</div>`,
|
|
572
|
+
`}`
|
|
573
|
+
].join("\n");
|
|
574
|
+
} else {
|
|
575
|
+
libContent = [
|
|
576
|
+
`// Library entry point`,
|
|
577
|
+
`export function MyMesh({ color = "orange" }: { color?: string }) {`,
|
|
578
|
+
` return (`,
|
|
579
|
+
` <mesh>`,
|
|
580
|
+
` <boxGeometry />`,
|
|
581
|
+
` <meshStandardMaterial color={color} />`,
|
|
582
|
+
` </mesh>`,
|
|
583
|
+
` )`,
|
|
584
|
+
`}`
|
|
585
|
+
].join("\n");
|
|
586
|
+
}
|
|
587
|
+
files[`src/index.${libExt}`] = { type: "text", content: libContent };
|
|
588
|
+
} else if (isVanilla) {
|
|
589
|
+
files[`src/main.${ext}`] = { type: "text", content: ViteIndexContent };
|
|
590
|
+
files["src/style.css"] = { type: "text", content: ViteStyleContent };
|
|
591
|
+
const indexHtml = ViteHtmlContent.replace("$indexPath", `./src/main.${ext}`).replace(
|
|
592
|
+
"$title",
|
|
593
|
+
name
|
|
594
|
+
);
|
|
595
|
+
files["index.html"] = { type: "text", content: indexHtml };
|
|
596
|
+
} else {
|
|
597
|
+
files[`src/index.tsx`] = { type: "text", content: IndexContent };
|
|
598
|
+
const indexHtml = HtmlContent.replace(
|
|
599
|
+
"$indexPath",
|
|
600
|
+
language === "javascript" ? "./src/index.jsx" : "./src/index.tsx"
|
|
601
|
+
).replace("$title", name);
|
|
602
|
+
files["index.html"] = { type: "text", content: indexHtml };
|
|
603
|
+
codeSnippets["dom-end"]?.reverse();
|
|
604
|
+
codeSnippets["global-end"]?.reverse();
|
|
605
|
+
codeSnippets["scene-end"]?.reverse();
|
|
606
|
+
let appCode;
|
|
607
|
+
if (isReact) {
|
|
608
|
+
appCode = [
|
|
609
|
+
...codeSnippets["import"] ?? [],
|
|
610
|
+
...codeSnippets["global-start"] ?? [],
|
|
611
|
+
`export function App() {`,
|
|
612
|
+
" return (",
|
|
613
|
+
' <div style={{ padding: "2rem" }}>',
|
|
614
|
+
" <h1>Hello React!</h1>",
|
|
615
|
+
" <p>Edit src/app.tsx and save to see changes.</p>",
|
|
616
|
+
" </div>",
|
|
617
|
+
" )",
|
|
618
|
+
"}",
|
|
619
|
+
...codeSnippets["global-end"] ?? []
|
|
620
|
+
].join("\n");
|
|
621
|
+
} else {
|
|
622
|
+
appCode = [
|
|
623
|
+
...codeSnippets["import"] ?? [],
|
|
624
|
+
...codeSnippets["global-start"] ?? [],
|
|
625
|
+
`export function App() {`,
|
|
626
|
+
" return <>",
|
|
627
|
+
...codeSnippets["dom-start"] ?? [],
|
|
628
|
+
...codeSnippets["dom"] ?? [],
|
|
629
|
+
" <Canvas>",
|
|
630
|
+
...codeSnippets["scene-start"] ?? [],
|
|
631
|
+
...codeSnippets["scene"] ?? [],
|
|
632
|
+
...codeSnippets["scene-end"] ?? [],
|
|
633
|
+
" </Canvas>",
|
|
634
|
+
...codeSnippets["dom-end"] ?? [],
|
|
635
|
+
" </>",
|
|
636
|
+
"}",
|
|
637
|
+
...codeSnippets["global-end"] ?? []
|
|
638
|
+
].join("\n");
|
|
639
|
+
}
|
|
640
|
+
for (const { search, replace } of replacements) {
|
|
641
|
+
appCode = appCode.replace(search, replace);
|
|
642
|
+
}
|
|
643
|
+
files[`src/app.tsx`] = { type: "text", content: appCode };
|
|
644
|
+
}
|
|
645
|
+
return files;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function generateTestFiles(params) {
|
|
649
|
+
const { baseTemplate, language, isLibrary } = params;
|
|
650
|
+
const files = {};
|
|
651
|
+
const ext = language === "typescript" ? "ts" : "js";
|
|
652
|
+
const jsxExt = language === "typescript" ? "tsx" : "jsx";
|
|
653
|
+
const isVanilla = baseTemplate === "vanilla";
|
|
654
|
+
const isReact = baseTemplate === "react";
|
|
655
|
+
const isR3f = baseTemplate === "r3f";
|
|
656
|
+
if (isLibrary) {
|
|
657
|
+
const testExt = isReact || isR3f ? jsxExt : ext;
|
|
658
|
+
let testContent;
|
|
659
|
+
if (isVanilla) {
|
|
660
|
+
testContent = [
|
|
661
|
+
`import { describe, it, expect } from "vitest"`,
|
|
662
|
+
`import { hello } from "../src/index.js"`,
|
|
663
|
+
``,
|
|
664
|
+
`describe("hello", () => {`,
|
|
665
|
+
` it("returns greeting with default name", () => {`,
|
|
666
|
+
` expect(hello()).toBe("Hello, world!")`,
|
|
667
|
+
` })`,
|
|
668
|
+
``,
|
|
669
|
+
` it("returns greeting with custom name", () => {`,
|
|
670
|
+
` expect(hello("vitest")).toBe("Hello, vitest!")`,
|
|
671
|
+
` })`,
|
|
672
|
+
`})`
|
|
673
|
+
].join("\n");
|
|
674
|
+
} else if (isReact) {
|
|
675
|
+
testContent = [
|
|
676
|
+
`import { describe, it, expect } from "vitest"`,
|
|
677
|
+
`import { render, screen } from "@testing-library/react"`,
|
|
678
|
+
`import { MyComponent } from "../src/index.js"`,
|
|
679
|
+
``,
|
|
680
|
+
`describe("MyComponent", () => {`,
|
|
681
|
+
` it("renders with default message", () => {`,
|
|
682
|
+
` render(<MyComponent />)`,
|
|
683
|
+
` expect(screen.getByText("Hello from library!")).toBeDefined()`,
|
|
684
|
+
` })`,
|
|
685
|
+
``,
|
|
686
|
+
` it("renders with custom message", () => {`,
|
|
687
|
+
` render(<MyComponent message="Custom message" />)`,
|
|
688
|
+
` expect(screen.getByText("Custom message")).toBeDefined()`,
|
|
689
|
+
` })`,
|
|
690
|
+
`})`
|
|
691
|
+
].join("\n");
|
|
692
|
+
} else {
|
|
693
|
+
testContent = [
|
|
694
|
+
`import { describe, it, expect } from "vitest"`,
|
|
695
|
+
`import { MyMesh } from "../src/index.js"`,
|
|
696
|
+
``,
|
|
697
|
+
`describe("MyMesh", () => {`,
|
|
698
|
+
` it("is defined", () => {`,
|
|
699
|
+
` expect(MyMesh).toBeDefined()`,
|
|
700
|
+
` })`,
|
|
701
|
+
`})`
|
|
702
|
+
].join("\n");
|
|
703
|
+
}
|
|
704
|
+
files[`tests/index.test.${testExt}`] = {
|
|
705
|
+
type: "text",
|
|
706
|
+
content: testContent
|
|
707
|
+
};
|
|
708
|
+
} else if (isVanilla) {
|
|
709
|
+
const testContent = [
|
|
710
|
+
`import { describe, it, expect } from "vitest"`,
|
|
711
|
+
``,
|
|
712
|
+
`describe("example", () => {`,
|
|
713
|
+
` it("works", () => {`,
|
|
714
|
+
` expect(1 + 1).toBe(2)`,
|
|
715
|
+
` })`,
|
|
716
|
+
`})`
|
|
717
|
+
].join("\n");
|
|
718
|
+
files[`tests/main.test.${ext}`] = { type: "text", content: testContent };
|
|
719
|
+
} else if (isReact) {
|
|
720
|
+
const testContent = [
|
|
721
|
+
`import { describe, it, expect } from "vitest"`,
|
|
722
|
+
`import { render, screen } from "@testing-library/react"`,
|
|
723
|
+
`import { App } from "../src/app.js"`,
|
|
724
|
+
``,
|
|
725
|
+
`describe("App", () => {`,
|
|
726
|
+
` it("renders heading", () => {`,
|
|
727
|
+
` render(<App />)`,
|
|
728
|
+
` expect(screen.getByText("Hello React!")).toBeDefined()`,
|
|
729
|
+
` })`,
|
|
730
|
+
`})`
|
|
731
|
+
].join("\n");
|
|
732
|
+
files[`tests/app.test.${jsxExt}`] = { type: "text", content: testContent };
|
|
733
|
+
} else {
|
|
734
|
+
const testContent = [
|
|
735
|
+
`import { describe, it, expect } from "vitest"`,
|
|
736
|
+
`import { App } from "../src/app.js"`,
|
|
737
|
+
``,
|
|
738
|
+
`describe("App", () => {`,
|
|
739
|
+
` it("is defined", () => {`,
|
|
740
|
+
` expect(App).toBeDefined()`,
|
|
741
|
+
` })`,
|
|
742
|
+
`})`
|
|
743
|
+
].join("\n");
|
|
744
|
+
files[`tests/app.test.${jsxExt}`] = { type: "text", content: testContent };
|
|
745
|
+
}
|
|
746
|
+
return files;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const COMMON_GITIGNORE_LINES = ["node_modules", "dist", "*.tsbuildinfo", ".env", ".env.*", "!.env.example"];
|
|
750
|
+
function generateGitignore(variant) {
|
|
751
|
+
const lines = variant === "workspace-root" ? [...COMMON_GITIGNORE_LINES, ".DS_Store"] : COMMON_GITIGNORE_LINES;
|
|
752
|
+
return {
|
|
753
|
+
type: "text",
|
|
754
|
+
content: lines.join("\n")
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
function generateVscodeFiles$1(params) {
|
|
759
|
+
const { codeSnippets, vscodeSettings } = params;
|
|
760
|
+
const files = {};
|
|
761
|
+
if (codeSnippets["vscode-extension-suggestion"]?.length) {
|
|
762
|
+
const uniqueRecommendations = [...new Set(codeSnippets["vscode-extension-suggestion"])];
|
|
763
|
+
files[".vscode/extensions.json"] = {
|
|
764
|
+
type: "text",
|
|
765
|
+
content: JSON.stringify(
|
|
766
|
+
{
|
|
767
|
+
recommendations: uniqueRecommendations
|
|
768
|
+
},
|
|
769
|
+
null,
|
|
770
|
+
2
|
|
771
|
+
)
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
if (Object.keys(vscodeSettings).length > 0) {
|
|
775
|
+
const sortedSettings = Object.fromEntries(
|
|
776
|
+
Object.entries(vscodeSettings).sort(([a], [b]) => a.localeCompare(b))
|
|
777
|
+
);
|
|
778
|
+
files[".vscode/settings.json"] = {
|
|
779
|
+
type: "text",
|
|
780
|
+
content: JSON.stringify(sortedSettings, null, 2)
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
return files;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
function formatValue(value, indent) {
|
|
787
|
+
const spaces = " ".repeat(indent);
|
|
788
|
+
const innerSpaces = " ".repeat(indent + 1);
|
|
789
|
+
if (typeof value === "string") {
|
|
790
|
+
if (value.startsWith("$raw:")) {
|
|
791
|
+
return value.slice(5);
|
|
792
|
+
}
|
|
793
|
+
return JSON.stringify(value);
|
|
794
|
+
}
|
|
795
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
796
|
+
return String(value);
|
|
797
|
+
}
|
|
798
|
+
if (value === null) {
|
|
799
|
+
return "null";
|
|
800
|
+
}
|
|
801
|
+
if (Array.isArray(value)) {
|
|
802
|
+
if (value.length === 0) return "[]";
|
|
803
|
+
const items = value.map((v) => `${innerSpaces}${formatValue(v, indent + 1)}`);
|
|
804
|
+
return `[
|
|
805
|
+
${items.join(",\n")}
|
|
806
|
+
${spaces}]`;
|
|
807
|
+
}
|
|
808
|
+
if (typeof value === "object") {
|
|
809
|
+
const entries = Object.entries(value);
|
|
810
|
+
if (entries.length === 0) return "{}";
|
|
811
|
+
const props = entries.map(
|
|
812
|
+
([key, val]) => `${innerSpaces}${key}: ${formatValue(val, indent + 1)}`
|
|
813
|
+
);
|
|
814
|
+
return `{
|
|
815
|
+
${props.join(",\n")}
|
|
816
|
+
${spaces}}`;
|
|
817
|
+
}
|
|
818
|
+
return String(value);
|
|
819
|
+
}
|
|
820
|
+
function generateViteConfig(params) {
|
|
821
|
+
const { viteConfig, codeSnippets } = params;
|
|
822
|
+
const configBody = formatValue(viteConfig, 0);
|
|
823
|
+
const viteConfigContent = [
|
|
824
|
+
`import { defineConfig } from "vite"`,
|
|
825
|
+
...codeSnippets["vite-config-import"] ?? [],
|
|
826
|
+
``,
|
|
827
|
+
`export default defineConfig(${configBody})`,
|
|
828
|
+
``
|
|
829
|
+
].join("\n");
|
|
830
|
+
return { type: "text", content: viteConfigContent };
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
function generateTypescriptConfigPackage(files) {
|
|
834
|
+
const basePath = ".config/typescript";
|
|
835
|
+
files[`${basePath}/package.json`] = {
|
|
836
|
+
type: "text",
|
|
837
|
+
content: JSON.stringify(
|
|
838
|
+
{
|
|
839
|
+
name: "@config/typescript",
|
|
840
|
+
version: "0.1.0",
|
|
841
|
+
private: true,
|
|
842
|
+
files: ["base.json", "app.json", "node.json", "react.json"]
|
|
843
|
+
},
|
|
844
|
+
null,
|
|
845
|
+
2
|
|
846
|
+
)
|
|
847
|
+
};
|
|
848
|
+
files[`${basePath}/README.md`] = {
|
|
849
|
+
type: "text",
|
|
850
|
+
content: `# \`@config/typescript\`
|
|
851
|
+
|
|
852
|
+
These are base shared \`tsconfig.json\`s from which all other \`tsconfig.json\`s inherit.
|
|
853
|
+
|
|
854
|
+
## Usage
|
|
855
|
+
|
|
856
|
+
In your package's \`tsconfig.json\`:
|
|
857
|
+
|
|
858
|
+
\`\`\`json
|
|
859
|
+
{
|
|
860
|
+
"extends": "@config/typescript/app.json",
|
|
861
|
+
"include": ["src/**/*", "tests"]
|
|
862
|
+
}
|
|
863
|
+
\`\`\`
|
|
864
|
+
|
|
865
|
+
## Available Configs
|
|
866
|
+
|
|
867
|
+
- \`base.json\` - Common TypeScript compiler options
|
|
868
|
+
- \`app.json\` - For browser/DOM code (extends base)
|
|
869
|
+
- \`node.json\` - For Node.js code (extends base)
|
|
870
|
+
- \`react.json\` - For React projects with JSX (extends app)
|
|
871
|
+
`
|
|
872
|
+
};
|
|
873
|
+
files[`${basePath}/base.json`] = {
|
|
874
|
+
type: "text",
|
|
875
|
+
content: JSON.stringify(
|
|
876
|
+
{
|
|
877
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
878
|
+
compilerOptions: {
|
|
879
|
+
target: "ESNext",
|
|
880
|
+
module: "ESNext",
|
|
881
|
+
moduleResolution: "bundler",
|
|
882
|
+
esModuleInterop: true,
|
|
883
|
+
allowSyntheticDefaultImports: true,
|
|
884
|
+
strict: true,
|
|
885
|
+
skipLibCheck: true,
|
|
886
|
+
composite: true,
|
|
887
|
+
rewriteRelativeImportExtensions: true,
|
|
888
|
+
erasableSyntaxOnly: true
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
null,
|
|
892
|
+
2
|
|
893
|
+
)
|
|
894
|
+
};
|
|
895
|
+
files[`${basePath}/app.json`] = {
|
|
896
|
+
type: "text",
|
|
897
|
+
content: JSON.stringify(
|
|
898
|
+
{
|
|
899
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
900
|
+
extends: "./base.json",
|
|
901
|
+
compilerOptions: {
|
|
902
|
+
lib: ["DOM", "DOM.Iterable", "ESNext"]
|
|
903
|
+
}
|
|
904
|
+
},
|
|
905
|
+
null,
|
|
906
|
+
2
|
|
907
|
+
)
|
|
908
|
+
};
|
|
909
|
+
files[`${basePath}/node.json`] = {
|
|
910
|
+
type: "text",
|
|
911
|
+
content: JSON.stringify(
|
|
912
|
+
{
|
|
913
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
914
|
+
extends: "./base.json",
|
|
915
|
+
compilerOptions: {
|
|
916
|
+
lib: ["ESNext"]
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
null,
|
|
920
|
+
2
|
|
921
|
+
)
|
|
922
|
+
};
|
|
923
|
+
files[`${basePath}/react.json`] = {
|
|
924
|
+
type: "text",
|
|
925
|
+
content: JSON.stringify(
|
|
926
|
+
{
|
|
927
|
+
$schema: "https://json.schemastore.org/tsconfig",
|
|
928
|
+
extends: "./app.json",
|
|
929
|
+
compilerOptions: {
|
|
930
|
+
jsx: "react-jsx"
|
|
931
|
+
}
|
|
932
|
+
},
|
|
933
|
+
null,
|
|
934
|
+
2
|
|
935
|
+
)
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function generateOxlintConfigPackage(files) {
|
|
939
|
+
const basePath = ".config/oxlint";
|
|
940
|
+
const { rules } = defaultLinterConfig;
|
|
941
|
+
files[`${basePath}/package.json`] = {
|
|
942
|
+
type: "text",
|
|
943
|
+
content: JSON.stringify(
|
|
944
|
+
{
|
|
945
|
+
name: "@config/oxlint",
|
|
946
|
+
version: "0.1.0",
|
|
947
|
+
private: true,
|
|
948
|
+
files: ["base.json", "react.json"]
|
|
949
|
+
},
|
|
950
|
+
null,
|
|
951
|
+
2
|
|
952
|
+
)
|
|
953
|
+
};
|
|
954
|
+
files[`${basePath}/README.md`] = {
|
|
955
|
+
type: "text",
|
|
956
|
+
content: `# \`@config/oxlint\`
|
|
957
|
+
|
|
958
|
+
Shared oxlint configurations for the monorepo.
|
|
959
|
+
|
|
960
|
+
## Usage
|
|
961
|
+
|
|
962
|
+
Run oxlint with a config:
|
|
963
|
+
|
|
964
|
+
\`\`\`bash
|
|
965
|
+
oxlint -c node_modules/@config/oxlint/base.json
|
|
966
|
+
\`\`\`
|
|
967
|
+
|
|
968
|
+
## Available Configs
|
|
969
|
+
|
|
970
|
+
- \`base.json\` - Base linting rules for TypeScript projects
|
|
971
|
+
- \`react.json\` - Extends base with React-specific rules
|
|
972
|
+
`
|
|
973
|
+
};
|
|
974
|
+
files[`${basePath}/base.json`] = {
|
|
975
|
+
type: "text",
|
|
976
|
+
content: JSON.stringify(
|
|
977
|
+
{
|
|
978
|
+
$schema: "./node_modules/oxlint/configuration_schema.json",
|
|
979
|
+
plugins: ["unicorn", "typescript", "oxc"],
|
|
980
|
+
rules: {
|
|
981
|
+
"no-unused-vars": [
|
|
982
|
+
rules.noUnusedVars.level,
|
|
983
|
+
{
|
|
984
|
+
argsIgnorePattern: rules.noUnusedVars.argsIgnorePattern,
|
|
985
|
+
varsIgnorePattern: rules.noUnusedVars.varsIgnorePattern,
|
|
986
|
+
caughtErrorsIgnorePattern: rules.noUnusedVars.caughtErrorsIgnorePattern
|
|
987
|
+
}
|
|
988
|
+
],
|
|
989
|
+
"no-useless-escape": "off",
|
|
990
|
+
"no-unused-expressions": [
|
|
991
|
+
rules.noUnusedExpressions.level,
|
|
992
|
+
{ allowShortCircuit: rules.noUnusedExpressions.allowShortCircuit }
|
|
993
|
+
]
|
|
994
|
+
},
|
|
995
|
+
ignorePatterns: defaultLinterConfig.ignorePatterns
|
|
996
|
+
},
|
|
997
|
+
null,
|
|
998
|
+
2
|
|
999
|
+
)
|
|
1000
|
+
};
|
|
1001
|
+
files[`${basePath}/react.json`] = {
|
|
1002
|
+
type: "text",
|
|
1003
|
+
content: JSON.stringify(
|
|
1004
|
+
{
|
|
1005
|
+
$schema: "./node_modules/oxlint/configuration_schema.json",
|
|
1006
|
+
plugins: ["unicorn", "typescript", "oxc", "react"],
|
|
1007
|
+
rules: {
|
|
1008
|
+
"no-unused-vars": [
|
|
1009
|
+
rules.noUnusedVars.level,
|
|
1010
|
+
{
|
|
1011
|
+
argsIgnorePattern: rules.noUnusedVars.argsIgnorePattern,
|
|
1012
|
+
varsIgnorePattern: rules.noUnusedVars.varsIgnorePattern,
|
|
1013
|
+
caughtErrorsIgnorePattern: rules.noUnusedVars.caughtErrorsIgnorePattern
|
|
1014
|
+
}
|
|
1015
|
+
],
|
|
1016
|
+
"no-useless-escape": "off",
|
|
1017
|
+
"no-unused-expressions": [
|
|
1018
|
+
rules.noUnusedExpressions.level,
|
|
1019
|
+
{ allowShortCircuit: rules.noUnusedExpressions.allowShortCircuit }
|
|
1020
|
+
]
|
|
1021
|
+
},
|
|
1022
|
+
ignorePatterns: defaultLinterConfig.ignorePatterns
|
|
1023
|
+
},
|
|
1024
|
+
null,
|
|
1025
|
+
2
|
|
1026
|
+
)
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
function generateEslintConfigPackage(files) {
|
|
1030
|
+
const basePath = ".config/eslint";
|
|
1031
|
+
files[`${basePath}/package.json`] = {
|
|
1032
|
+
type: "text",
|
|
1033
|
+
content: JSON.stringify(
|
|
1034
|
+
{
|
|
1035
|
+
name: "@config/eslint",
|
|
1036
|
+
version: "0.1.0",
|
|
1037
|
+
private: true,
|
|
1038
|
+
type: "module",
|
|
1039
|
+
exports: {
|
|
1040
|
+
"./base": "./base.js",
|
|
1041
|
+
"./react": "./react.js"
|
|
1042
|
+
},
|
|
1043
|
+
files: ["base.js", "react.js"],
|
|
1044
|
+
devDependencies: {
|
|
1045
|
+
"@eslint/js": "^9.17.0",
|
|
1046
|
+
"typescript-eslint": "^8.18.0"
|
|
1047
|
+
}
|
|
1048
|
+
},
|
|
1049
|
+
null,
|
|
1050
|
+
2
|
|
1051
|
+
)
|
|
1052
|
+
};
|
|
1053
|
+
files[`${basePath}/README.md`] = {
|
|
1054
|
+
type: "text",
|
|
1055
|
+
content: `# \`@config/eslint\`
|
|
1056
|
+
|
|
1057
|
+
Shared ESLint configurations for the monorepo.
|
|
1058
|
+
|
|
1059
|
+
## Usage
|
|
1060
|
+
|
|
1061
|
+
In your package's \`eslint.config.js\`:
|
|
1062
|
+
|
|
1063
|
+
\`\`\`js
|
|
1064
|
+
import base from "@config/eslint/base";
|
|
1065
|
+
|
|
1066
|
+
export default [...base];
|
|
1067
|
+
\`\`\`
|
|
1068
|
+
|
|
1069
|
+
Or for React projects:
|
|
1070
|
+
|
|
1071
|
+
\`\`\`js
|
|
1072
|
+
import react from "@config/eslint/react";
|
|
1073
|
+
|
|
1074
|
+
export default [...react];
|
|
1075
|
+
\`\`\`
|
|
1076
|
+
|
|
1077
|
+
## Available Configs
|
|
1078
|
+
|
|
1079
|
+
- \`base\` - Base linting rules for TypeScript projects
|
|
1080
|
+
- \`react\` - Extends base with React-specific rules
|
|
1081
|
+
`
|
|
1082
|
+
};
|
|
1083
|
+
files[`${basePath}/base.js`] = {
|
|
1084
|
+
type: "text",
|
|
1085
|
+
content: `import js from "@eslint/js";
|
|
1086
|
+
import tseslint from "typescript-eslint";
|
|
1087
|
+
|
|
1088
|
+
export default tseslint.config(
|
|
1089
|
+
js.configs.recommended,
|
|
1090
|
+
...tseslint.configs.recommended,
|
|
1091
|
+
{
|
|
1092
|
+
rules: {
|
|
1093
|
+
"@typescript-eslint/no-unused-vars": [
|
|
1094
|
+
"error",
|
|
1095
|
+
{
|
|
1096
|
+
argsIgnorePattern: "^_",
|
|
1097
|
+
varsIgnorePattern: "^_",
|
|
1098
|
+
caughtErrorsIgnorePattern: "^_",
|
|
1099
|
+
},
|
|
1100
|
+
],
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
ignores: ["dist/**", "node_modules/**"],
|
|
1105
|
+
}
|
|
1106
|
+
);
|
|
1107
|
+
`
|
|
1108
|
+
};
|
|
1109
|
+
files[`${basePath}/react.js`] = {
|
|
1110
|
+
type: "text",
|
|
1111
|
+
content: `import js from "@eslint/js";
|
|
1112
|
+
import tseslint from "typescript-eslint";
|
|
1113
|
+
|
|
1114
|
+
export default tseslint.config(
|
|
1115
|
+
js.configs.recommended,
|
|
1116
|
+
...tseslint.configs.recommended,
|
|
1117
|
+
{
|
|
1118
|
+
rules: {
|
|
1119
|
+
"@typescript-eslint/no-unused-vars": [
|
|
1120
|
+
"error",
|
|
1121
|
+
{
|
|
1122
|
+
argsIgnorePattern: "^_",
|
|
1123
|
+
varsIgnorePattern: "^_",
|
|
1124
|
+
caughtErrorsIgnorePattern: "^_",
|
|
1125
|
+
},
|
|
1126
|
+
],
|
|
1127
|
+
},
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
ignores: ["dist/**", "node_modules/**"],
|
|
1131
|
+
}
|
|
1132
|
+
);
|
|
1133
|
+
`
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
function generatePrettierConfigPackage(files) {
|
|
1137
|
+
const basePath = ".config/prettier";
|
|
1138
|
+
files[`${basePath}/package.json`] = {
|
|
1139
|
+
type: "text",
|
|
1140
|
+
content: JSON.stringify(
|
|
1141
|
+
{
|
|
1142
|
+
name: "@config/prettier",
|
|
1143
|
+
version: "0.1.0",
|
|
1144
|
+
private: true,
|
|
1145
|
+
type: "module",
|
|
1146
|
+
exports: {
|
|
1147
|
+
".": "./base.json"
|
|
1148
|
+
},
|
|
1149
|
+
files: ["base.json"]
|
|
1150
|
+
},
|
|
1151
|
+
null,
|
|
1152
|
+
2
|
|
1153
|
+
)
|
|
1154
|
+
};
|
|
1155
|
+
files[`${basePath}/README.md`] = {
|
|
1156
|
+
type: "text",
|
|
1157
|
+
content: `# \`@config/prettier\`
|
|
1158
|
+
|
|
1159
|
+
Shared Prettier configuration for the monorepo.
|
|
1160
|
+
|
|
1161
|
+
## Usage
|
|
1162
|
+
|
|
1163
|
+
In your package's \`package.json\`:
|
|
1164
|
+
|
|
1165
|
+
\`\`\`json
|
|
1166
|
+
{
|
|
1167
|
+
"prettier": "@config/prettier"
|
|
1168
|
+
}
|
|
1169
|
+
\`\`\`
|
|
1170
|
+
|
|
1171
|
+
Or in \`.prettierrc.json\`:
|
|
1172
|
+
|
|
1173
|
+
\`\`\`json
|
|
1174
|
+
"@config/prettier"
|
|
1175
|
+
\`\`\`
|
|
1176
|
+
|
|
1177
|
+
## Available Configs
|
|
1178
|
+
|
|
1179
|
+
- Default export - Base formatter settings
|
|
1180
|
+
`
|
|
1181
|
+
};
|
|
1182
|
+
files[`${basePath}/base.json`] = {
|
|
1183
|
+
type: "text",
|
|
1184
|
+
content: JSON.stringify(defaultPrettierConfig, null, 2)
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
function generateOxfmtConfigPackage(files) {
|
|
1188
|
+
const basePath = ".config/oxfmt";
|
|
1189
|
+
files[`${basePath}/package.json`] = {
|
|
1190
|
+
type: "text",
|
|
1191
|
+
content: JSON.stringify(
|
|
1192
|
+
{
|
|
1193
|
+
name: "@config/oxfmt",
|
|
1194
|
+
version: "0.1.0",
|
|
1195
|
+
private: true,
|
|
1196
|
+
files: ["base.json"]
|
|
1197
|
+
},
|
|
1198
|
+
null,
|
|
1199
|
+
2
|
|
1200
|
+
)
|
|
1201
|
+
};
|
|
1202
|
+
files[`${basePath}/README.md`] = {
|
|
1203
|
+
type: "text",
|
|
1204
|
+
content: `# \`@config/oxfmt\`
|
|
1205
|
+
|
|
1206
|
+
Shared oxfmt (formatter) configuration for the monorepo.
|
|
1207
|
+
|
|
1208
|
+
## Usage
|
|
1209
|
+
|
|
1210
|
+
Run oxfmt with the config:
|
|
1211
|
+
|
|
1212
|
+
\`\`\`bash
|
|
1213
|
+
oxfmt -c node_modules/@config/oxfmt/base.json --write .
|
|
1214
|
+
\`\`\`
|
|
1215
|
+
|
|
1216
|
+
## Available Configs
|
|
1217
|
+
|
|
1218
|
+
- \`base.json\` - Base formatter settings (Prettier-compatible)
|
|
1219
|
+
`
|
|
1220
|
+
};
|
|
1221
|
+
files[`${basePath}/base.json`] = {
|
|
1222
|
+
type: "text",
|
|
1223
|
+
content: JSON.stringify(defaultOxfmtConfig, null, 2)
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
function generateMonorepo(params) {
|
|
1228
|
+
const {
|
|
1229
|
+
name,
|
|
1230
|
+
linter,
|
|
1231
|
+
formatter,
|
|
1232
|
+
packageManager,
|
|
1233
|
+
pnpmVersion,
|
|
1234
|
+
pnpmManageVersions,
|
|
1235
|
+
nodeVersion,
|
|
1236
|
+
aiPlatforms
|
|
1237
|
+
} = params;
|
|
1238
|
+
const files = {};
|
|
1239
|
+
const isPnpm = packageManager === "pnpm";
|
|
1240
|
+
const devDependencies = {};
|
|
1241
|
+
if (nodeVersion) {
|
|
1242
|
+
const majorVersion = nodeVersion.split(".")[0];
|
|
1243
|
+
devDependencies["@types/node"] = `^${majorVersion}.0.0`;
|
|
1244
|
+
} else {
|
|
1245
|
+
devDependencies["@types/node"] = "^22.0.0";
|
|
1246
|
+
}
|
|
1247
|
+
if (linter === "oxlint") {
|
|
1248
|
+
devDependencies["oxlint"] = "^1.36.0";
|
|
1249
|
+
} else if (linter === "eslint") {
|
|
1250
|
+
devDependencies["eslint"] = "^9.17.0";
|
|
1251
|
+
} else if (linter === "biome") {
|
|
1252
|
+
devDependencies["@biomejs/biome"] = "^1.9.4";
|
|
1253
|
+
}
|
|
1254
|
+
if (formatter === "oxfmt") {
|
|
1255
|
+
devDependencies["oxfmt"] = "^0.21.0";
|
|
1256
|
+
} else if (formatter === "prettier") {
|
|
1257
|
+
devDependencies["prettier"] = "^3.4.2";
|
|
1258
|
+
}
|
|
1259
|
+
const rootPackageJson = {
|
|
1260
|
+
name: "root",
|
|
1261
|
+
version: "0.0.0",
|
|
1262
|
+
private: true,
|
|
1263
|
+
type: "module",
|
|
1264
|
+
scripts: {
|
|
1265
|
+
dev: "pnpm --filter './apps/*' run dev",
|
|
1266
|
+
build: "pnpm --filter './packages/*' run build && pnpm --filter './apps/*' run build",
|
|
1267
|
+
test: "pnpm -r run test",
|
|
1268
|
+
lint: linter === "oxlint" ? "oxlint ." : linter === "biome" ? "biome check ." : "eslint .",
|
|
1269
|
+
format: formatter === "oxfmt" ? "oxfmt -c .config/oxfmt/base.json ." : formatter === "biome" ? "biome format . --write" : "prettier --config .config/prettier/base.json --write ."
|
|
1270
|
+
},
|
|
1271
|
+
devDependencies
|
|
1272
|
+
};
|
|
1273
|
+
const engines = {};
|
|
1274
|
+
if (isPnpm && pnpmVersion) {
|
|
1275
|
+
const majorVersion = pnpmVersion.split(".")[0];
|
|
1276
|
+
engines.pnpm = `>=${majorVersion}.0.0`;
|
|
1277
|
+
rootPackageJson.packageManager = `pnpm@${pnpmVersion}`;
|
|
1278
|
+
}
|
|
1279
|
+
if (nodeVersion) {
|
|
1280
|
+
const majorVersion = nodeVersion.split(".")[0];
|
|
1281
|
+
engines.node = `>=${majorVersion}.0.0`;
|
|
1282
|
+
}
|
|
1283
|
+
if (Object.keys(engines).length > 0) {
|
|
1284
|
+
rootPackageJson.engines = engines;
|
|
1285
|
+
}
|
|
1286
|
+
files["package.json"] = {
|
|
1287
|
+
type: "text",
|
|
1288
|
+
content: JSON.stringify(rootPackageJson, null, 2)
|
|
1289
|
+
};
|
|
1290
|
+
if (isPnpm) {
|
|
1291
|
+
const workspaceLines = [];
|
|
1292
|
+
if (pnpmManageVersions) {
|
|
1293
|
+
workspaceLines.push("manage-package-manager-versions: true", "");
|
|
1294
|
+
}
|
|
1295
|
+
workspaceLines.push(
|
|
1296
|
+
"packages:",
|
|
1297
|
+
' - ".config/*"',
|
|
1298
|
+
' - "apps/*"',
|
|
1299
|
+
' - "packages/*"',
|
|
1300
|
+
""
|
|
1301
|
+
);
|
|
1302
|
+
workspaceLines.push("onlyBuiltDependencies:", " - esbuild");
|
|
1303
|
+
files["pnpm-workspace.yaml"] = {
|
|
1304
|
+
type: "text",
|
|
1305
|
+
content: workspaceLines.join("\n")
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
files["tsconfig.json"] = {
|
|
1309
|
+
type: "text",
|
|
1310
|
+
content: JSON.stringify(
|
|
1311
|
+
{
|
|
1312
|
+
extends: "@config/typescript/base.json",
|
|
1313
|
+
compilerOptions: {
|
|
1314
|
+
noEmit: true
|
|
1315
|
+
},
|
|
1316
|
+
references: []
|
|
1317
|
+
},
|
|
1318
|
+
null,
|
|
1319
|
+
2
|
|
1320
|
+
)
|
|
1321
|
+
};
|
|
1322
|
+
generateTypescriptConfigPackage(files);
|
|
1323
|
+
if (linter === "oxlint") {
|
|
1324
|
+
generateOxlintConfigPackage(files);
|
|
1325
|
+
files["oxlint.json"] = {
|
|
1326
|
+
type: "text",
|
|
1327
|
+
content: JSON.stringify(
|
|
1328
|
+
{
|
|
1329
|
+
$schema: "./node_modules/oxlint/configuration_schema.json",
|
|
1330
|
+
extends: ["@config/oxlint/base.json"]
|
|
1331
|
+
},
|
|
1332
|
+
null,
|
|
1333
|
+
2
|
|
1334
|
+
)
|
|
1335
|
+
};
|
|
1336
|
+
} else if (linter === "eslint") {
|
|
1337
|
+
generateEslintConfigPackage(files);
|
|
1338
|
+
files["eslint.config.js"] = {
|
|
1339
|
+
type: "text",
|
|
1340
|
+
content: `import base from "@config/eslint/base";
|
|
1341
|
+
|
|
1342
|
+
export default [...base];
|
|
1343
|
+
`
|
|
1344
|
+
};
|
|
1345
|
+
} else if (linter === "biome") {
|
|
1346
|
+
const biomeConfig = {
|
|
1347
|
+
$schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
1348
|
+
vcs: {
|
|
1349
|
+
enabled: true,
|
|
1350
|
+
clientKind: "git",
|
|
1351
|
+
useIgnoreFile: true
|
|
1352
|
+
},
|
|
1353
|
+
linter: {
|
|
1354
|
+
enabled: true,
|
|
1355
|
+
rules: {
|
|
1356
|
+
recommended: true
|
|
1357
|
+
}
|
|
1358
|
+
},
|
|
1359
|
+
formatter: {
|
|
1360
|
+
enabled: formatter === "biome"
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
files["biome.json"] = {
|
|
1364
|
+
type: "text",
|
|
1365
|
+
content: JSON.stringify(biomeConfig, null, 2)
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
if (formatter === "oxfmt") {
|
|
1369
|
+
generateOxfmtConfigPackage(files);
|
|
1370
|
+
} else if (formatter === "prettier") {
|
|
1371
|
+
generatePrettierConfigPackage(files);
|
|
1372
|
+
}
|
|
1373
|
+
files[".gitignore"] = generateGitignore("workspace-root");
|
|
1374
|
+
files[".gitattributes"] = {
|
|
1375
|
+
type: "text",
|
|
1376
|
+
content: `* text=auto eol=lf
|
|
1377
|
+
*.{cmd,[cC][mM][dD]} text eol=crlf
|
|
1378
|
+
*.{bat,[bB][aA][tT]} text eol=crlf
|
|
1379
|
+
`
|
|
1380
|
+
};
|
|
1381
|
+
generateVscodeFiles(files, linter, formatter);
|
|
1382
|
+
files["README.md"] = {
|
|
1383
|
+
type: "text",
|
|
1384
|
+
content: `# ${name}
|
|
1385
|
+
|
|
1386
|
+
This monorepo workspace was generated with create-krispya.
|
|
1387
|
+
|
|
1388
|
+
## Structure
|
|
1389
|
+
|
|
1390
|
+
- \`apps/\` - Applications
|
|
1391
|
+
- \`packages/\` - Shared packages and libraries
|
|
1392
|
+
- \`.config/\` - Shared configuration packages
|
|
1393
|
+
|
|
1394
|
+
## Development Commands
|
|
1395
|
+
|
|
1396
|
+
- \`${packageManager} install\` to install all dependencies
|
|
1397
|
+
- \`${packageManager} run dev\` to run all applications in development mode
|
|
1398
|
+
- \`${packageManager} run build\` to build all packages and applications
|
|
1399
|
+
- \`${packageManager} run test\` to run tests across the workspace
|
|
1400
|
+
- \`${packageManager} run lint\` to lint all code
|
|
1401
|
+
- \`${packageManager} run format\` to format all code
|
|
1402
|
+
|
|
1403
|
+
## Adding Packages
|
|
1404
|
+
|
|
1405
|
+
To add a new package to this workspace, run create-krispya from this directory and it will detect the monorepo.
|
|
1406
|
+
`
|
|
1407
|
+
};
|
|
1408
|
+
if (aiPlatforms && aiPlatforms.length > 0) {
|
|
1409
|
+
generateAiFiles(files, {
|
|
1410
|
+
name,
|
|
1411
|
+
packageManager,
|
|
1412
|
+
linter,
|
|
1413
|
+
formatter,
|
|
1414
|
+
isMonorepo: true,
|
|
1415
|
+
platforms: aiPlatforms
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
return { files };
|
|
1419
|
+
}
|
|
1420
|
+
function generateVscodeFiles(files, linter, formatter) {
|
|
1421
|
+
const recommendations = [];
|
|
1422
|
+
const settings = {};
|
|
1423
|
+
if (linter === "oxlint") {
|
|
1424
|
+
recommendations.push("oxc.oxc-vscode");
|
|
1425
|
+
settings["oxc.enable"] = true;
|
|
1426
|
+
settings["eslint.enable"] = false;
|
|
1427
|
+
settings["biome.enabled"] = false;
|
|
1428
|
+
} else if (linter === "eslint") {
|
|
1429
|
+
recommendations.push("dbaeumer.vscode-eslint");
|
|
1430
|
+
settings["eslint.enable"] = true;
|
|
1431
|
+
settings["oxc.enable"] = false;
|
|
1432
|
+
settings["biome.enabled"] = false;
|
|
1433
|
+
} else if (linter === "biome") {
|
|
1434
|
+
recommendations.push("biomejs.biome");
|
|
1435
|
+
settings["biome.enabled"] = true;
|
|
1436
|
+
settings["eslint.enable"] = false;
|
|
1437
|
+
settings["oxc.enable"] = false;
|
|
1438
|
+
}
|
|
1439
|
+
if (formatter === "oxfmt") {
|
|
1440
|
+
if (!recommendations.includes("oxc.oxc-vscode")) {
|
|
1441
|
+
recommendations.push("oxc.oxc-vscode");
|
|
1442
|
+
}
|
|
1443
|
+
settings["editor.defaultFormatter"] = "oxc.oxc-vscode";
|
|
1444
|
+
settings["[json]"] = {
|
|
1445
|
+
"editor.defaultFormatter": "vscode.json-language-features"
|
|
1446
|
+
};
|
|
1447
|
+
settings["[jsonc]"] = {
|
|
1448
|
+
"editor.defaultFormatter": "vscode.json-language-features"
|
|
1449
|
+
};
|
|
1450
|
+
} else if (formatter === "prettier") {
|
|
1451
|
+
recommendations.push("esbenp.prettier-vscode");
|
|
1452
|
+
settings["editor.defaultFormatter"] = "esbenp.prettier-vscode";
|
|
1453
|
+
} else if (formatter === "biome") {
|
|
1454
|
+
if (!recommendations.includes("biomejs.biome")) {
|
|
1455
|
+
recommendations.push("biomejs.biome");
|
|
1456
|
+
}
|
|
1457
|
+
settings["editor.defaultFormatter"] = "biomejs.biome";
|
|
1458
|
+
}
|
|
1459
|
+
files[".vscode/extensions.json"] = {
|
|
1460
|
+
type: "text",
|
|
1461
|
+
content: JSON.stringify({ recommendations }, null, 2)
|
|
1462
|
+
};
|
|
1463
|
+
const codeSnippets = {};
|
|
1464
|
+
if (recommendations.length > 0) {
|
|
1465
|
+
codeSnippets["vscode-extension-suggestion"] = recommendations;
|
|
1466
|
+
}
|
|
1467
|
+
Object.assign(
|
|
1468
|
+
files,
|
|
1469
|
+
generateVscodeFiles$1({
|
|
1470
|
+
codeSnippets,
|
|
1471
|
+
vscodeSettings: settings
|
|
1472
|
+
})
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
function toBiomeLevel(level) {
|
|
1477
|
+
return level;
|
|
1478
|
+
}
|
|
1479
|
+
function generateBiome(generator, options) {
|
|
1480
|
+
if (options == null || !options.linter && !options.formatter) {
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
const version = generator.versions.biome ?? "2.0.0";
|
|
1484
|
+
generator.addDevDependency("@biomejs/biome", `^${version}`);
|
|
1485
|
+
const { rules } = defaultLinterConfig;
|
|
1486
|
+
const biomeConfig = {
|
|
1487
|
+
$schema: `https://biomejs.dev/schemas/${version}/schema.json`
|
|
1488
|
+
};
|
|
1489
|
+
if (options.linter) {
|
|
1490
|
+
biomeConfig.linter = {
|
|
1491
|
+
enabled: true,
|
|
1492
|
+
rules: {
|
|
1493
|
+
recommended: true,
|
|
1494
|
+
correctness: {
|
|
1495
|
+
noUnusedVariables: toBiomeLevel(rules.noUnusedVars.level)
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
} else {
|
|
1500
|
+
biomeConfig.linter = {
|
|
1501
|
+
enabled: false
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
if (options.formatter) {
|
|
1505
|
+
biomeConfig.formatter = {
|
|
1506
|
+
enabled: true,
|
|
1507
|
+
lineWidth: defaultFormatterConfig.printWidth,
|
|
1508
|
+
indentWidth: defaultFormatterConfig.tabWidth,
|
|
1509
|
+
indentStyle: "space"
|
|
1510
|
+
};
|
|
1511
|
+
biomeConfig.javascript = {
|
|
1512
|
+
formatter: {
|
|
1513
|
+
semicolons: "always" ,
|
|
1514
|
+
quoteStyle: "single" ,
|
|
1515
|
+
trailingCommas: defaultFormatterConfig.trailingComma,
|
|
1516
|
+
bracketSpacing: defaultFormatterConfig.bracketSpacing,
|
|
1517
|
+
arrowParentheses: "always"
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
biomeConfig.json = {
|
|
1521
|
+
formatter: {
|
|
1522
|
+
indentWidth: 2
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
} else {
|
|
1526
|
+
biomeConfig.formatter = {
|
|
1527
|
+
enabled: false
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
const isStealth = generator.isStealthConfig();
|
|
1531
|
+
if (isStealth) {
|
|
1532
|
+
generator.addFile(".config/biome.json", {
|
|
1533
|
+
type: "text",
|
|
1534
|
+
content: JSON.stringify(biomeConfig, null, 2)
|
|
1535
|
+
});
|
|
1536
|
+
if (options.linter) {
|
|
1537
|
+
generator.addScript("lint", "biome lint --config-path .config .");
|
|
1538
|
+
}
|
|
1539
|
+
if (options.formatter) {
|
|
1540
|
+
generator.addScript(
|
|
1541
|
+
"format",
|
|
1542
|
+
"biome format --config-path .config --write ."
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
generator.addVscodeSetting("biome.linter.configPath", ".config/biome.json");
|
|
1546
|
+
} else {
|
|
1547
|
+
generator.addFile("biome.json", {
|
|
1548
|
+
type: "text",
|
|
1549
|
+
content: JSON.stringify(biomeConfig, null, 2)
|
|
1550
|
+
});
|
|
1551
|
+
if (options.linter) {
|
|
1552
|
+
generator.addScript("lint", "biome lint .");
|
|
1553
|
+
}
|
|
1554
|
+
if (options.formatter) {
|
|
1555
|
+
generator.addScript("format", "biome format --write .");
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
const roles = [];
|
|
1559
|
+
if (options.linter) roles.push("linter");
|
|
1560
|
+
if (options.formatter) roles.push("formatter");
|
|
1561
|
+
generator.inject(
|
|
1562
|
+
"readme-tools",
|
|
1563
|
+
`[Biome](https://biomejs.dev/) - Fast ${roles.join(
|
|
1564
|
+
" and "
|
|
1565
|
+
)} for JavaScript and TypeScript`
|
|
1566
|
+
);
|
|
1567
|
+
generator.inject("vscode-extension-suggestion", "biomejs.biome");
|
|
1568
|
+
generator.addVscodeSetting("biome.enabled", true);
|
|
1569
|
+
if (options.formatter) {
|
|
1570
|
+
generator.addVscodeSetting("editor.defaultFormatter", "biomejs.biome");
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
function generateDrei(generator, options) {
|
|
1575
|
+
if (options == null) {
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
generator.addDependency("@react-three/drei", "^10.0.0");
|
|
1579
|
+
generator.inject("import", `import { Environment } from "@react-three/drei"`);
|
|
1580
|
+
generator.inject("scene", '<Environment background preset="city" />');
|
|
1581
|
+
generator.inject(
|
|
1582
|
+
"readme-libraries",
|
|
1583
|
+
`[@react-three/drei](https://drei.docs.pmnd.rs/) - Useful helpers for @react-three/fiber`
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
function getLanguageFromTemplate(template) {
|
|
1588
|
+
return template.endsWith("-js") ? "javascript" : "typescript";
|
|
1589
|
+
}
|
|
1590
|
+
function getBaseTemplate(template) {
|
|
1591
|
+
return template.replace("-js", "");
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
function toEslintLevel(level) {
|
|
1595
|
+
return level;
|
|
1596
|
+
}
|
|
1597
|
+
function generateEslint(generator, options) {
|
|
1598
|
+
const version = generator.versions.eslint ?? "9.17.0";
|
|
1599
|
+
generator.addDevDependency("eslint", `^${version}`);
|
|
1600
|
+
const template = generator.options.template ?? "vanilla";
|
|
1601
|
+
const baseTemplate = getBaseTemplate(template);
|
|
1602
|
+
const isTypescript = getLanguageFromTemplate(template) === "typescript";
|
|
1603
|
+
const isReact = baseTemplate === "react" || baseTemplate === "r3f";
|
|
1604
|
+
const { rules } = defaultLinterConfig;
|
|
1605
|
+
const imports = ['import js from "@eslint/js"'];
|
|
1606
|
+
const configs = ["js.configs.recommended"];
|
|
1607
|
+
if (isTypescript) {
|
|
1608
|
+
generator.addDevDependency("typescript-eslint", "^8.18.0");
|
|
1609
|
+
imports.push('import tseslint from "typescript-eslint"');
|
|
1610
|
+
configs.push("...tseslint.configs.recommended");
|
|
1611
|
+
}
|
|
1612
|
+
if (isReact) {
|
|
1613
|
+
generator.addDevDependency("eslint-plugin-react-hooks", "^5.1.0");
|
|
1614
|
+
imports.push('import reactHooks from "eslint-plugin-react-hooks"');
|
|
1615
|
+
}
|
|
1616
|
+
const ignoresArray = JSON.stringify(defaultLinterConfig.ignorePatterns);
|
|
1617
|
+
const unusedVarsRule = isTypescript ? "@typescript-eslint/no-unused-vars" : "no-unused-vars";
|
|
1618
|
+
const rulesConfig = {
|
|
1619
|
+
[unusedVarsRule]: [
|
|
1620
|
+
toEslintLevel(rules.noUnusedVars.level),
|
|
1621
|
+
{
|
|
1622
|
+
argsIgnorePattern: rules.noUnusedVars.argsIgnorePattern,
|
|
1623
|
+
varsIgnorePattern: rules.noUnusedVars.varsIgnorePattern,
|
|
1624
|
+
caughtErrorsIgnorePattern: rules.noUnusedVars.caughtErrorsIgnorePattern
|
|
1625
|
+
}
|
|
1626
|
+
],
|
|
1627
|
+
"no-unused-expressions": [
|
|
1628
|
+
toEslintLevel(rules.noUnusedExpressions.level),
|
|
1629
|
+
{ allowShortCircuit: rules.noUnusedExpressions.allowShortCircuit }
|
|
1630
|
+
]
|
|
1631
|
+
};
|
|
1632
|
+
const rulesString = JSON.stringify(rulesConfig, null, 4).replace(/\n/g, "\n ");
|
|
1633
|
+
const configContent = [
|
|
1634
|
+
...imports,
|
|
1635
|
+
"",
|
|
1636
|
+
"export default [",
|
|
1637
|
+
` { ignores: ${ignoresArray} },`,
|
|
1638
|
+
` ${configs.join(",\n ")},`,
|
|
1639
|
+
isReact ? ` {
|
|
1640
|
+
plugins: {
|
|
1641
|
+
"react-hooks": reactHooks,
|
|
1642
|
+
},
|
|
1643
|
+
rules: reactHooks.configs.recommended.rules,
|
|
1644
|
+
},` : "",
|
|
1645
|
+
` {
|
|
1646
|
+
rules: ${rulesString},
|
|
1647
|
+
},`,
|
|
1648
|
+
"]"
|
|
1649
|
+
].filter(Boolean).join("\n");
|
|
1650
|
+
const isStealth = generator.isStealthConfig();
|
|
1651
|
+
if (isStealth) {
|
|
1652
|
+
generator.addFile(".config/eslint.config.js", {
|
|
1653
|
+
type: "text",
|
|
1654
|
+
content: configContent
|
|
1655
|
+
});
|
|
1656
|
+
generator.addScript("lint", "eslint --config .config/eslint.config.js .");
|
|
1657
|
+
generator.addVscodeSetting("eslint.options", {
|
|
1658
|
+
overrideConfigFile: ".config/eslint.config.js"
|
|
1659
|
+
});
|
|
1660
|
+
} else {
|
|
1661
|
+
generator.addFile("eslint.config.js", {
|
|
1662
|
+
type: "text",
|
|
1663
|
+
content: configContent
|
|
1664
|
+
});
|
|
1665
|
+
generator.addScript("lint", "eslint .");
|
|
1666
|
+
}
|
|
1667
|
+
generator.inject(
|
|
1668
|
+
"readme-tools",
|
|
1669
|
+
"[ESLint](https://eslint.org/) - Linter for JavaScript and TypeScript"
|
|
1670
|
+
);
|
|
1671
|
+
generator.inject("vscode-extension-suggestion", "dbaeumer.vscode-eslint");
|
|
1672
|
+
generator.addVscodeSetting("eslint.enable", true);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
function generateFiber(generator, _options) {
|
|
1676
|
+
generator.inject("import", `import { Box } from "./box.js"`);
|
|
1677
|
+
generator.inject(
|
|
1678
|
+
"scene",
|
|
1679
|
+
[
|
|
1680
|
+
`<ambientLight intensity={Math.PI / 2} />`,
|
|
1681
|
+
`<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />`,
|
|
1682
|
+
`<pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />`,
|
|
1683
|
+
`<Box position={[-1.2, 0, 0]} />`,
|
|
1684
|
+
`<Box position={[1.2, 0, 0]} />`
|
|
1685
|
+
].join("\n")
|
|
1686
|
+
);
|
|
1687
|
+
generator.addFile("src/box.tsx", {
|
|
1688
|
+
type: "text",
|
|
1689
|
+
content: `import type { Mesh } from 'three'
|
|
1690
|
+
import { useRef, useState } from 'react'
|
|
1691
|
+
import { useFrame, ThreeElements } from '@react-three/fiber'
|
|
1692
|
+
|
|
1693
|
+
export function Box(props: ThreeElements['mesh']) {
|
|
1694
|
+
const meshRef = useRef<Mesh>(null!)
|
|
1695
|
+
const [hovered, setHover] = useState(false)
|
|
1696
|
+
const [active, setActive] = useState(false)
|
|
1697
|
+
useFrame((state, delta) => (meshRef.current.rotation.x += delta))
|
|
1698
|
+
return (
|
|
1699
|
+
<mesh
|
|
1700
|
+
{...props}
|
|
1701
|
+
ref={meshRef}
|
|
1702
|
+
scale={active ? 1.5 : 1}
|
|
1703
|
+
onClick={(event) => setActive(!active)}
|
|
1704
|
+
onPointerOver={(event) => setHover(true)}
|
|
1705
|
+
onPointerOut={(event) => setHover(false)}>
|
|
1706
|
+
<boxGeometry args={[1, 1, 1]} />
|
|
1707
|
+
<meshStandardMaterial color={hovered ? 'hotpink' : '#2f74c0'} />
|
|
1708
|
+
</mesh>
|
|
1709
|
+
)
|
|
1710
|
+
}`
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
function generateGithubPages(generator, options) {
|
|
1715
|
+
if (options === false || (generator.options.packageManager ?? "npm") != "npm") {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
generator.addFile(".github/workflows/gh-pages.yml", {
|
|
1719
|
+
type: "text",
|
|
1720
|
+
content: `name: Deploy to Github Pages
|
|
1721
|
+
|
|
1722
|
+
on:
|
|
1723
|
+
push:
|
|
1724
|
+
branches:
|
|
1725
|
+
- main
|
|
1726
|
+
|
|
1727
|
+
jobs:
|
|
1728
|
+
build-and-deploy:
|
|
1729
|
+
runs-on: ubuntu-latest
|
|
1730
|
+
permissions:
|
|
1731
|
+
pages: write
|
|
1732
|
+
contents: read
|
|
1733
|
+
id-token: write
|
|
1734
|
+
|
|
1735
|
+
environment:
|
|
1736
|
+
name: github-pages
|
|
1737
|
+
url: \${{ steps.deployment.outputs.page_url }}
|
|
1738
|
+
|
|
1739
|
+
steps:
|
|
1740
|
+
- name: Checkout code
|
|
1741
|
+
uses: actions/checkout@v3
|
|
1742
|
+
|
|
1743
|
+
- name: Setup Node
|
|
1744
|
+
uses: actions/setup-node@v3
|
|
1745
|
+
with:
|
|
1746
|
+
node-version: 20
|
|
1747
|
+
|
|
1748
|
+
- name: Install dependencies
|
|
1749
|
+
run: npm install
|
|
1750
|
+
|
|
1751
|
+
- name: Build project
|
|
1752
|
+
run: npm run build
|
|
1753
|
+
|
|
1754
|
+
- name: Upload artifact
|
|
1755
|
+
uses: actions/upload-pages-artifact@v3
|
|
1756
|
+
with:
|
|
1757
|
+
path: './dist'
|
|
1758
|
+
|
|
1759
|
+
- name: Deploy to GitHub Pages
|
|
1760
|
+
id: deployment
|
|
1761
|
+
uses: actions/deploy-pages@v4
|
|
1762
|
+
`
|
|
1763
|
+
});
|
|
1764
|
+
generator.inject("readme-start", `A github pages deployment action is configurd.`);
|
|
1765
|
+
if (generator.options.githubUserName != null && generator.options.githubRepoName != null) {
|
|
1766
|
+
const address = `${generator.options.githubUserName}.github.io/${generator.options.githubRepoName}`;
|
|
1767
|
+
generator.inject(
|
|
1768
|
+
"readme-start",
|
|
1769
|
+
`Your app will be publish at [${address}](https://${address}) once the github action is finished.
|
|
1770
|
+
`
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
function generateHandle(generator, options) {
|
|
1776
|
+
if (options == null) {
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
generator.addDependency("@react-three/handle", "^6.6.16");
|
|
1780
|
+
generator.inject(
|
|
1781
|
+
"readme-libraries",
|
|
1782
|
+
`[@react-three/handle](https://pmndrs.github.io/xr/docs/handles/introduction) - interactive controls and handles for your 3D objects`
|
|
1783
|
+
);
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
function generateKoota(generator, options) {
|
|
1787
|
+
if (options == null) {
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
generator.addDependency("koota", "^0.4.0");
|
|
1791
|
+
generator.inject(
|
|
1792
|
+
"readme-libraries",
|
|
1793
|
+
`[koota](https://github.com/pmndrs/koota) - ECS-based state management library optimized for real-time apps, games, and XR experiences`
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
function generateLeva(generator, options) {
|
|
1798
|
+
if (options == null) {
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
generator.addDependency("leva", "^0.10.0");
|
|
1802
|
+
generator.inject(
|
|
1803
|
+
"readme-libraries",
|
|
1804
|
+
`[leva](https://github.com/pmndrs/leva) - HTML GUI panel for React with lightweight, beautiful and extensible controls`
|
|
1805
|
+
);
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
function generateOffscreen(generator, options) {
|
|
1809
|
+
if (options == null) {
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
if (generator.options.xr != null) {
|
|
1813
|
+
console.info(
|
|
1814
|
+
chalk.blue("Info:"),
|
|
1815
|
+
"@react-three/offscreen is disabled because it is not supported with XR"
|
|
1816
|
+
);
|
|
1817
|
+
return;
|
|
1818
|
+
}
|
|
1819
|
+
generator.addDependency("@react-three/offscreen", "^0.0.8");
|
|
1820
|
+
generator.inject(
|
|
1821
|
+
"readme-libraries",
|
|
1822
|
+
`[@react-three/offscreen](https://github.com/pmndrs/offscreen) - Offload your scene to a worker thread for better performance`
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
function generateOxfmt(generator, options) {
|
|
1827
|
+
const isMonorepo = generator.options.workspaceRoot != null;
|
|
1828
|
+
if (isMonorepo) {
|
|
1829
|
+
generator.addDevDependency("@config/oxfmt", "workspace:*");
|
|
1830
|
+
const configPath = "node_modules/@config/oxfmt/base.json";
|
|
1831
|
+
generator.addScript("format", `oxfmt -c ${configPath} --write .`);
|
|
1832
|
+
generator.addVscodeSetting("oxc.fmt.configPath", configPath);
|
|
1833
|
+
} else {
|
|
1834
|
+
const version = generator.versions.oxfmt ?? "0.1.0";
|
|
1835
|
+
generator.addDevDependency("oxfmt", `^${version}`);
|
|
1836
|
+
const isStealth = generator.isStealthConfig();
|
|
1837
|
+
if (isStealth) {
|
|
1838
|
+
generator.addFile(".config/oxfmt.json", {
|
|
1839
|
+
type: "text",
|
|
1840
|
+
content: JSON.stringify(defaultOxfmtConfig, null, 2)
|
|
1841
|
+
});
|
|
1842
|
+
generator.addScript("format", "oxfmt -c .config/oxfmt.json --write .");
|
|
1843
|
+
generator.addVscodeSetting("oxc.fmt.configPath", ".config/oxfmt.json");
|
|
1844
|
+
} else {
|
|
1845
|
+
generator.addFile("oxfmt.json", {
|
|
1846
|
+
type: "text",
|
|
1847
|
+
content: JSON.stringify(defaultOxfmtConfig, null, 2)
|
|
1848
|
+
});
|
|
1849
|
+
generator.addScript("format", "oxfmt -c oxfmt.json --write .");
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
generator.inject(
|
|
1853
|
+
"readme-tools",
|
|
1854
|
+
"[Oxfmt](https://oxc.rs/docs/guide/usage/formatter) - Fast Prettier-compatible code formatter"
|
|
1855
|
+
);
|
|
1856
|
+
generator.inject("vscode-extension-suggestion", "oxc.oxc-vscode");
|
|
1857
|
+
generator.addVscodeSetting("editor.defaultFormatter", "oxc.oxc-vscode");
|
|
1858
|
+
generator.addVscodeSetting("[json]", {
|
|
1859
|
+
"editor.defaultFormatter": "vscode.json-language-features"
|
|
1860
|
+
});
|
|
1861
|
+
generator.addVscodeSetting("[jsonc]", {
|
|
1862
|
+
"editor.defaultFormatter": "vscode.json-language-features"
|
|
1863
|
+
});
|
|
1864
|
+
generator.addVscodeSetting("[markdown]", {
|
|
1865
|
+
"editor.defaultFormatter": "vscode.markdown-language-features"
|
|
1866
|
+
});
|
|
1867
|
+
generator.addVscodeSetting("[yaml]", {
|
|
1868
|
+
"editor.defaultFormatter": "redhat.vscode-yaml"
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
function toOxlintLevel(level) {
|
|
1873
|
+
return level;
|
|
1874
|
+
}
|
|
1875
|
+
function generateOxlint(generator, options) {
|
|
1876
|
+
const template = generator.options.template ?? "vanilla";
|
|
1877
|
+
const baseTemplate = getBaseTemplate(template);
|
|
1878
|
+
const isReact = baseTemplate === "react" || baseTemplate === "r3f";
|
|
1879
|
+
const isMonorepo = generator.options.workspaceRoot != null;
|
|
1880
|
+
if (isMonorepo) {
|
|
1881
|
+
generator.addDevDependency("@config/oxlint", "workspace:*");
|
|
1882
|
+
const configPath = isReact ? "node_modules/@config/oxlint/react.json" : "node_modules/@config/oxlint/base.json";
|
|
1883
|
+
generator.addScript("lint", `oxlint -c ${configPath}`);
|
|
1884
|
+
generator.addVscodeSetting("oxc.configPath", configPath);
|
|
1885
|
+
} else {
|
|
1886
|
+
const version = generator.versions.oxlint ?? "0.16.0";
|
|
1887
|
+
generator.addDevDependency("oxlint", `^${version}`);
|
|
1888
|
+
const isStealth = generator.isStealthConfig();
|
|
1889
|
+
const { rules } = defaultLinterConfig;
|
|
1890
|
+
const plugins = ["unicorn", "typescript", "oxc"];
|
|
1891
|
+
if (isReact) {
|
|
1892
|
+
plugins.push("react");
|
|
1893
|
+
}
|
|
1894
|
+
const oxlintConfig = {
|
|
1895
|
+
$schema: isStealth ? "../node_modules/oxlint/configuration_schema.json" : "./node_modules/oxlint/configuration_schema.json",
|
|
1896
|
+
plugins,
|
|
1897
|
+
rules: {
|
|
1898
|
+
"no-unused-vars": [
|
|
1899
|
+
toOxlintLevel(rules.noUnusedVars.level),
|
|
1900
|
+
{
|
|
1901
|
+
argsIgnorePattern: rules.noUnusedVars.argsIgnorePattern,
|
|
1902
|
+
varsIgnorePattern: rules.noUnusedVars.varsIgnorePattern,
|
|
1903
|
+
caughtErrorsIgnorePattern: rules.noUnusedVars.caughtErrorsIgnorePattern
|
|
1904
|
+
}
|
|
1905
|
+
],
|
|
1906
|
+
"no-useless-escape": "off",
|
|
1907
|
+
"no-unused-expressions": [
|
|
1908
|
+
toOxlintLevel(rules.noUnusedExpressions.level),
|
|
1909
|
+
{ allowShortCircuit: rules.noUnusedExpressions.allowShortCircuit }
|
|
1910
|
+
]
|
|
1911
|
+
},
|
|
1912
|
+
ignorePatterns: defaultLinterConfig.ignorePatterns
|
|
1913
|
+
};
|
|
1914
|
+
if (isStealth) {
|
|
1915
|
+
generator.addFile(".config/oxlint.json", {
|
|
1916
|
+
type: "text",
|
|
1917
|
+
content: JSON.stringify(oxlintConfig, null, 2)
|
|
1918
|
+
});
|
|
1919
|
+
generator.addScript("lint", "oxlint -c .config/oxlint.json");
|
|
1920
|
+
generator.addVscodeSetting("oxc.configPath", ".config/oxlint.json");
|
|
1921
|
+
} else {
|
|
1922
|
+
generator.addFile("oxlint.json", {
|
|
1923
|
+
type: "text",
|
|
1924
|
+
content: JSON.stringify(oxlintConfig, null, 2)
|
|
1925
|
+
});
|
|
1926
|
+
generator.addScript("lint", "oxlint");
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
generator.inject(
|
|
1930
|
+
"readme-tools",
|
|
1931
|
+
"[Oxlint](https://oxc.rs/docs/guide/usage/linter) - A fast linter for JavaScript and TypeScript"
|
|
1932
|
+
);
|
|
1933
|
+
generator.inject("vscode-extension-suggestion", "oxc.oxc-vscode");
|
|
1934
|
+
generator.addVscodeSetting("oxc.enable", true);
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
function generatePostprocessing(generator, options) {
|
|
1938
|
+
if (options == null) {
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
if (generator.options.xr != null) {
|
|
1942
|
+
console.info(
|
|
1943
|
+
chalk.blue("Info:"),
|
|
1944
|
+
"@react-three/postprocessing is disabled because it is not supported with XR"
|
|
1945
|
+
);
|
|
1946
|
+
return;
|
|
1947
|
+
}
|
|
1948
|
+
generator.addDependency("@react-three/postprocessing", "^3.0.4");
|
|
1949
|
+
generator.inject(
|
|
1950
|
+
"readme-libraries",
|
|
1951
|
+
`[@react-three/postprocessing](https://react-postprocessing.docs.pmnd.rs/) - Post-processing effects for @react-three/fiber`
|
|
1952
|
+
);
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
function generatePrettier(generator, options) {
|
|
1956
|
+
const version = generator.versions.prettier ?? "3.4.2";
|
|
1957
|
+
generator.addDevDependency("prettier", `^${version}`);
|
|
1958
|
+
const isStealth = generator.isStealthConfig();
|
|
1959
|
+
if (isStealth) {
|
|
1960
|
+
generator.addFile(".config/prettier.json", {
|
|
1961
|
+
type: "text",
|
|
1962
|
+
content: JSON.stringify(defaultPrettierConfig, null, 2)
|
|
1963
|
+
});
|
|
1964
|
+
generator.addScript(
|
|
1965
|
+
"format",
|
|
1966
|
+
"prettier --config .config/prettier.json --write ."
|
|
1967
|
+
);
|
|
1968
|
+
generator.addVscodeSetting("prettier.configPath", ".config/prettier.json");
|
|
1969
|
+
} else {
|
|
1970
|
+
generator.addFile(".prettierrc", {
|
|
1971
|
+
type: "text",
|
|
1972
|
+
content: JSON.stringify(defaultPrettierConfig, null, 2)
|
|
1973
|
+
});
|
|
1974
|
+
generator.addScript("format", "prettier --write .");
|
|
1975
|
+
}
|
|
1976
|
+
generator.inject(
|
|
1977
|
+
"readme-tools",
|
|
1978
|
+
"[Prettier](https://prettier.io/) - Opinionated code formatter"
|
|
1979
|
+
);
|
|
1980
|
+
generator.inject("vscode-extension-suggestion", "esbenp.prettier-vscode");
|
|
1981
|
+
generator.addVscodeSetting(
|
|
1982
|
+
"editor.defaultFormatter",
|
|
1983
|
+
"esbenp.prettier-vscode"
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
function generateRapier(generator, options) {
|
|
1988
|
+
if (options == null) {
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
generator.addDependency("@react-three/rapier", "^2.1.0");
|
|
1992
|
+
generator.inject(
|
|
1993
|
+
"readme-libraries",
|
|
1994
|
+
`[@react-three/rapier](https://github.com/pmndrs/react-three-rapier) - Physics based on Rapier for your @react-three/fiber scene`
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
function unique(...array) {
|
|
1999
|
+
const set = /* @__PURE__ */ new Set();
|
|
2000
|
+
for (const arr of array) {
|
|
2001
|
+
for (const item of arr) {
|
|
2002
|
+
set.add(item);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
return Array.from(set);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
function generateProvidersModule(generator) {
|
|
2009
|
+
const canvasProviders = [];
|
|
2010
|
+
const globalProviders = [];
|
|
2011
|
+
const providerDefs = {
|
|
2012
|
+
uikit: {
|
|
2013
|
+
type: "layout-effect",
|
|
2014
|
+
props: [
|
|
2015
|
+
{
|
|
2016
|
+
declaredPropDefaultValue: '"light"',
|
|
2017
|
+
declaredPropName: "colorMode",
|
|
2018
|
+
propName: "colorMode",
|
|
2019
|
+
propValue: "colorMode",
|
|
2020
|
+
declaredPropType: '"light" | "dark"'
|
|
2021
|
+
}
|
|
2022
|
+
],
|
|
2023
|
+
code: `
|
|
2024
|
+
setPreferredColorScheme(colorMode);
|
|
2025
|
+
`,
|
|
2026
|
+
import: 'import { setPreferredColorScheme } from "@react-three/uikit"'
|
|
2027
|
+
},
|
|
2028
|
+
rapier: {
|
|
2029
|
+
component: "Physics",
|
|
2030
|
+
type: "wrapped-jsx",
|
|
2031
|
+
import: 'import { Physics } from "@react-three/rapier";',
|
|
2032
|
+
props: [
|
|
2033
|
+
{
|
|
2034
|
+
declaredPropDefaultValue: false,
|
|
2035
|
+
declaredPropName: "physicsEnabled",
|
|
2036
|
+
propName: "paused",
|
|
2037
|
+
propValue: "!physicsEnabled",
|
|
2038
|
+
declaredPropType: "boolean"
|
|
2039
|
+
},
|
|
2040
|
+
{
|
|
2041
|
+
declaredPropDefaultValue: true,
|
|
2042
|
+
declaredPropName: "debugPhysics",
|
|
2043
|
+
propName: "debug",
|
|
2044
|
+
propValue: "debugPhysics",
|
|
2045
|
+
declaredPropType: "boolean"
|
|
2046
|
+
}
|
|
2047
|
+
]
|
|
2048
|
+
},
|
|
2049
|
+
postprocessing: {
|
|
2050
|
+
type: "inline-jsx",
|
|
2051
|
+
code: `
|
|
2052
|
+
<EffectComposer enabled={postProcessingEnabled}>
|
|
2053
|
+
<DepthOfField
|
|
2054
|
+
focusDistance={0}
|
|
2055
|
+
focalLength={0.02}
|
|
2056
|
+
bokehScale={2}
|
|
2057
|
+
height={480}
|
|
2058
|
+
/>
|
|
2059
|
+
<Bloom luminanceThreshold={0} luminanceSmoothing={0.9} height={300} />
|
|
2060
|
+
</EffectComposer>
|
|
2061
|
+
`,
|
|
2062
|
+
import: 'import { Bloom, DepthOfField, EffectComposer } from "@react-three/postprocessing";',
|
|
2063
|
+
props: [
|
|
2064
|
+
{
|
|
2065
|
+
declaredPropDefaultValue: true,
|
|
2066
|
+
declaredPropName: "postProcessingEnabled",
|
|
2067
|
+
propName: "enabled",
|
|
2068
|
+
propValue: "postProcessingEnabled",
|
|
2069
|
+
declaredPropType: "boolean"
|
|
2070
|
+
}
|
|
2071
|
+
]
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
if (generator.options.rapier) {
|
|
2075
|
+
canvasProviders.push("rapier");
|
|
2076
|
+
}
|
|
2077
|
+
if (!!generator.options.postprocessing && !generator.options.xr) {
|
|
2078
|
+
canvasProviders.push("postprocessing");
|
|
2079
|
+
}
|
|
2080
|
+
if (generator.options.uikit) {
|
|
2081
|
+
globalProviders.push("uikit");
|
|
2082
|
+
}
|
|
2083
|
+
function generateProviderFunction(name, { jsdoc, providers }) {
|
|
2084
|
+
const resolvedProviders = providers.map((provider) => providerDefs[provider]);
|
|
2085
|
+
const providerProps = resolvedProviders.flatMap((provider) => provider.props || []);
|
|
2086
|
+
const providerImports = resolvedProviders.flatMap((provider) => provider.import);
|
|
2087
|
+
const wrappedComponents = resolvedProviders.filter(
|
|
2088
|
+
(provider) => provider.type === "wrapped-jsx"
|
|
2089
|
+
);
|
|
2090
|
+
const inlineComponents = resolvedProviders.filter((provider) => provider.type === "inline-jsx");
|
|
2091
|
+
const layoutEffects = resolvedProviders.filter((provider) => provider.type === "layout-effect");
|
|
2092
|
+
const declaredProps = providerProps.map((prop) => `${prop.declaredPropName} = ${prop.declaredPropDefaultValue}`).join(", ");
|
|
2093
|
+
const declaredTypes = providerProps.map((prop) => `${prop.declaredPropName}?: ${prop.declaredPropType}`).join("; ");
|
|
2094
|
+
const reactImports = ["type ReactNode"];
|
|
2095
|
+
if (layoutEffects.length) {
|
|
2096
|
+
reactImports.push("useLayoutEffect");
|
|
2097
|
+
}
|
|
2098
|
+
return {
|
|
2099
|
+
reactImports,
|
|
2100
|
+
imports: providerImports,
|
|
2101
|
+
code: `
|
|
2102
|
+
/**
|
|
2103
|
+
${jsdoc.split("\n").map((line) => ` * ${line}`).join("\n")}
|
|
2104
|
+
*/
|
|
2105
|
+
export function ${name}({ children, ${declaredProps} }: { children: ReactNode; ${declaredTypes} }) {
|
|
2106
|
+
${layoutEffects.length ? `
|
|
2107
|
+
useLayoutEffect(() => {
|
|
2108
|
+
${layoutEffects.map((effect) => effect.code).join("\n")}
|
|
2109
|
+
}, [${layoutEffects.map((effect) => effect.props?.[0]?.propValue)}]);
|
|
2110
|
+
` : ""}
|
|
2111
|
+
return (
|
|
2112
|
+
<>
|
|
2113
|
+
${inlineComponents.map((provider) => provider.code)}
|
|
2114
|
+
${wrappedComponents.reduce((acc, provider) => {
|
|
2115
|
+
const props = provider.props?.map((prop) => `${prop.propName}={${prop.propValue}}`).join(" ");
|
|
2116
|
+
return `<${provider.component} ${props}>${acc}</${provider.component}>`;
|
|
2117
|
+
}, "{children}")}
|
|
2118
|
+
</>
|
|
2119
|
+
);
|
|
2120
|
+
}`
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
const global = generateProviderFunction("GlobalProvider", {
|
|
2124
|
+
jsdoc: "The global provider is rendered at the root of your application,\nuse it to set up global configuration like themes.\nProps defined on this component appear as controls inside Triplex.\n\nSee: https://triplex.dev/docs/building-your-scene/providers#global-provider",
|
|
2125
|
+
providers: globalProviders
|
|
2126
|
+
});
|
|
2127
|
+
const canvas = generateProviderFunction("CanvasProvider", {
|
|
2128
|
+
jsdoc: "The canvas provider is rendered as a child inside the React Three Fiber canvas,\nuse it to set up canvas specific configuration like post-processing and physics.\nProps defined on this component appear as controls inside Triplex.\n\nSee: https://triplex.dev/docs/building-your-scene/providers#canvas-provider",
|
|
2129
|
+
providers: canvasProviders
|
|
2130
|
+
});
|
|
2131
|
+
return `
|
|
2132
|
+
import { ${unique(global.reactImports, canvas.reactImports).sort().join(", ")} } from "react";
|
|
2133
|
+
${unique(global.imports, canvas.imports).sort().join("\n")}
|
|
2134
|
+
|
|
2135
|
+
${global.code}
|
|
2136
|
+
${canvas.code}
|
|
2137
|
+
`;
|
|
2138
|
+
}
|
|
2139
|
+
function generateTriplex(generator, options) {
|
|
2140
|
+
if (options == null) {
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
generator.inject("vscode-extension-suggestion", "trytriplex.triplex-vsce");
|
|
2144
|
+
generator.inject(
|
|
2145
|
+
"readme-tools",
|
|
2146
|
+
`[Triplex](https://triplex.dev) - Your visual workspace for React / Three Fiber. Get started by installing [Triplex for VS Code](https://triplex.dev/docs/get-started/vscode). Don't use Visual Studio Code? Download [Triplex Standalone](https://triplex.dev/docs/get-started/standalone).`
|
|
2147
|
+
);
|
|
2148
|
+
generator.addFile(".triplex/providers.tsx", {
|
|
2149
|
+
content: generateProvidersModule(generator),
|
|
2150
|
+
type: "text"
|
|
2151
|
+
});
|
|
2152
|
+
generator.addFile(".triplex/config.json", {
|
|
2153
|
+
content: JSON.stringify(
|
|
2154
|
+
{
|
|
2155
|
+
$schema: "https://triplex.dev/config.schema.json",
|
|
2156
|
+
provider: "./providers.tsx"
|
|
2157
|
+
},
|
|
2158
|
+
null,
|
|
2159
|
+
2
|
|
2160
|
+
),
|
|
2161
|
+
type: "text"
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
function generateTsdown(generator) {
|
|
2166
|
+
generator.addDevDependency("tsdown", "^0.12.0");
|
|
2167
|
+
const template = generator.options.template ?? "vanilla";
|
|
2168
|
+
const baseTemplate = getBaseTemplate(template);
|
|
2169
|
+
const language = getLanguageFromTemplate(template);
|
|
2170
|
+
const isReact = baseTemplate === "react" || baseTemplate === "r3f";
|
|
2171
|
+
const ext = language === "typescript" ? "ts" : "js";
|
|
2172
|
+
const configLines = [
|
|
2173
|
+
`import { defineConfig } from "tsdown"`,
|
|
2174
|
+
``,
|
|
2175
|
+
`export default defineConfig({`,
|
|
2176
|
+
` entry: ["./src/index.${ext}${isReact ? "x" : ""}"],`,
|
|
2177
|
+
` format: ["esm", "cjs"],`,
|
|
2178
|
+
` dts: ${language === "typescript"},`,
|
|
2179
|
+
` clean: true,`
|
|
2180
|
+
];
|
|
2181
|
+
if (isReact) {
|
|
2182
|
+
configLines.push(` esbuild: {`);
|
|
2183
|
+
configLines.push(` jsx: "automatic",`);
|
|
2184
|
+
configLines.push(` },`);
|
|
2185
|
+
}
|
|
2186
|
+
configLines.push(`})`);
|
|
2187
|
+
generator.addFile(`tsdown.config.${ext}`, {
|
|
2188
|
+
type: "text",
|
|
2189
|
+
content: configLines.join("\n")
|
|
2190
|
+
});
|
|
2191
|
+
generator.addScript("build", "tsdown");
|
|
2192
|
+
generator.inject(
|
|
2193
|
+
"readme-libraries",
|
|
2194
|
+
"[tsdown](https://github.com/nicepkg/tsdown) - Fast TypeScript bundler powered by esbuild"
|
|
2195
|
+
);
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
function generateUikit(generator, options) {
|
|
2199
|
+
if (options == null) {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
generator.addDependency("@react-three/uikit", "^0.8.15");
|
|
2203
|
+
generator.inject(
|
|
2204
|
+
"readme-libraries",
|
|
2205
|
+
`[@react-three/uikit](https://pmndrs.github.io/uikit/docs/) - UI primitives for React Three Fiber`
|
|
2206
|
+
);
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
function generateUnbuild(generator) {
|
|
2210
|
+
generator.addDevDependency("unbuild", "^3.5.0");
|
|
2211
|
+
const template = generator.options.template ?? "vanilla";
|
|
2212
|
+
const baseTemplate = getBaseTemplate(template);
|
|
2213
|
+
const language = getLanguageFromTemplate(template);
|
|
2214
|
+
const isReact = baseTemplate === "react" || baseTemplate === "r3f";
|
|
2215
|
+
const ext = language === "typescript" ? "ts" : "js";
|
|
2216
|
+
const isMonorepo = generator.options.workspaceRoot != null;
|
|
2217
|
+
const buildConfigLines = [
|
|
2218
|
+
`import { defineBuildConfig } from "unbuild"`,
|
|
2219
|
+
``,
|
|
2220
|
+
`export default defineBuildConfig({`,
|
|
2221
|
+
` entries: ["./src/index"],`,
|
|
2222
|
+
` declaration: ${language === "typescript"},`,
|
|
2223
|
+
` clean: true,`,
|
|
2224
|
+
` rollup: {`,
|
|
2225
|
+
` emitCJS: true,`
|
|
2226
|
+
];
|
|
2227
|
+
if (isReact) {
|
|
2228
|
+
buildConfigLines.push(` esbuild: {`);
|
|
2229
|
+
buildConfigLines.push(` jsx: "automatic",`);
|
|
2230
|
+
buildConfigLines.push(` },`);
|
|
2231
|
+
}
|
|
2232
|
+
buildConfigLines.push(` },`);
|
|
2233
|
+
buildConfigLines.push(`})`);
|
|
2234
|
+
const isStealth = generator.isStealthConfig() && !isMonorepo;
|
|
2235
|
+
if (isStealth) {
|
|
2236
|
+
generator.addFile(`.config/build.config.${ext}`, {
|
|
2237
|
+
type: "text",
|
|
2238
|
+
content: buildConfigLines.join("\n")
|
|
2239
|
+
});
|
|
2240
|
+
generator.addScript("build", `unbuild --config .config/build.config.${ext}`);
|
|
2241
|
+
} else {
|
|
2242
|
+
generator.addFile(`build.config.${ext}`, {
|
|
2243
|
+
type: "text",
|
|
2244
|
+
content: buildConfigLines.join("\n")
|
|
2245
|
+
});
|
|
2246
|
+
generator.addScript("build", "unbuild");
|
|
2247
|
+
}
|
|
2248
|
+
generator.inject(
|
|
2249
|
+
"readme-libraries",
|
|
2250
|
+
"[unbuild](https://github.com/unjs/unbuild) - Unified JavaScript build system"
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
function generateVitest(generator) {
|
|
2255
|
+
const version = generator.versions.vitest ?? "4.0.0";
|
|
2256
|
+
generator.addDevDependency("vitest", `^${version}`);
|
|
2257
|
+
const template = generator.options.template ?? "vanilla";
|
|
2258
|
+
const baseTemplate = getBaseTemplate(template);
|
|
2259
|
+
const isReact = baseTemplate === "react" || baseTemplate === "r3f";
|
|
2260
|
+
if (isReact) {
|
|
2261
|
+
generator.addDevDependency("@testing-library/react", "^16.2.0");
|
|
2262
|
+
generator.addDevDependency("@testing-library/dom", "^10.4.0");
|
|
2263
|
+
generator.addDevDependency("jsdom", "^26.0.0");
|
|
2264
|
+
}
|
|
2265
|
+
if (isReact) {
|
|
2266
|
+
generator.configureVite({ test: { environment: "jsdom" } });
|
|
2267
|
+
}
|
|
2268
|
+
generator.addScript("test", "vitest");
|
|
2269
|
+
generator.inject(
|
|
2270
|
+
"readme-tools",
|
|
2271
|
+
"[Vitest](https://vitest.dev/) - Fast unit test framework powered by Vite"
|
|
2272
|
+
);
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
function generateViverse(generator, options) {
|
|
2276
|
+
if (options == null || (generator.options.packageManager ?? "npm") != "npm") {
|
|
2277
|
+
return;
|
|
2278
|
+
}
|
|
2279
|
+
generator.addFile(".github/workflows/viverse.yml", {
|
|
2280
|
+
type: "text",
|
|
2281
|
+
content: `name: Deploy to Viverse
|
|
2282
|
+
|
|
2283
|
+
on:
|
|
2284
|
+
push:
|
|
2285
|
+
branches:
|
|
2286
|
+
- main
|
|
2287
|
+
workflow_dispatch:
|
|
2288
|
+
|
|
2289
|
+
jobs:
|
|
2290
|
+
check-secrets:
|
|
2291
|
+
runs-on: ubuntu-latest
|
|
2292
|
+
outputs:
|
|
2293
|
+
secrets-available: \${{ steps.check.outputs.secrets-available }}
|
|
2294
|
+
steps:
|
|
2295
|
+
- id: check
|
|
2296
|
+
run: |
|
|
2297
|
+
if [[ -n "\${{ secrets.VIVERSE_EMAIL }}" && -n "\${{ secrets.VIVERSE_PASSWORD }}" ]]; then
|
|
2298
|
+
echo "secrets-available=true" >> $GITHUB_OUTPUT
|
|
2299
|
+
else
|
|
2300
|
+
echo "secrets-available=false" >> $GITHUB_OUTPUT
|
|
2301
|
+
fi
|
|
2302
|
+
|
|
2303
|
+
build-and-deploy:
|
|
2304
|
+
runs-on: ubuntu-latest
|
|
2305
|
+
needs: check-secrets
|
|
2306
|
+
# Only run if secrets are present
|
|
2307
|
+
if: needs.check-secrets.outputs.secrets-available == 'true'
|
|
2308
|
+
permissions:
|
|
2309
|
+
contents: read
|
|
2310
|
+
|
|
2311
|
+
steps:
|
|
2312
|
+
- name: Checkout code
|
|
2313
|
+
uses: actions/checkout@v3
|
|
2314
|
+
|
|
2315
|
+
- name: Setup Node
|
|
2316
|
+
uses: actions/setup-node@v3
|
|
2317
|
+
with:
|
|
2318
|
+
node-version: 22
|
|
2319
|
+
|
|
2320
|
+
- name: Install dependencies
|
|
2321
|
+
run: npm install
|
|
2322
|
+
|
|
2323
|
+
- name: Build project
|
|
2324
|
+
run: npm run build
|
|
2325
|
+
|
|
2326
|
+
- name: Viverse Login
|
|
2327
|
+
run: npx viverse-cli auth login -e \${{ secrets.VIVERSE_EMAIL }} -p \${{ secrets.VIVERSE_PASSWORD }}
|
|
2328
|
+
|
|
2329
|
+
- name: Deploy to Viverse
|
|
2330
|
+
run: npx viverse-cli app publish ./dist --auto-create-app --name ${generator.options.name}
|
|
2331
|
+
|
|
2332
|
+
`
|
|
2333
|
+
});
|
|
2334
|
+
generator.addDependency("@viverse/cli", "^0.9.5-beta.8");
|
|
2335
|
+
generator.inject(
|
|
2336
|
+
"readme-start",
|
|
2337
|
+
`A GitHub CI/CD workflow for publishing to Viverse is configured.
|
|
2338
|
+
|
|
2339
|
+
To use publish to viverse via the CI/CD workflow:
|
|
2340
|
+
1. Set \`VIVERSE_EMAIL\` and \`VIVERSE_PASSWORD\` secrets in your repository settings under \`Secrets and Variables\` > \`Actions\` > \`New repository secret\`
|
|
2341
|
+
2. Manually trigger the "Deploy to Viverse" workflow or push to the main branch
|
|
2342
|
+
|
|
2343
|
+
**Manual CLI Upload:**
|
|
2344
|
+
You can also upload your project manually using the Viverse CLI:
|
|
2345
|
+
\`\`\`bash
|
|
2346
|
+
viverse-cli auth login -e <email> -p <password>
|
|
2347
|
+
npm run build
|
|
2348
|
+
viverse-cli app publish ./dist --auto-create-app --name ${generator.options.name}
|
|
2349
|
+
\`\`\`
|
|
2350
|
+
`
|
|
2351
|
+
);
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
function generateXr(generator, options) {
|
|
2355
|
+
if (options == null || options === false) {
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
if (options === true) {
|
|
2359
|
+
options = {};
|
|
2360
|
+
}
|
|
2361
|
+
generator.addDependency("@react-three/xr", "^6.6.16");
|
|
2362
|
+
generator.addDependency("@vitejs/plugin-basic-ssl", "^2.0.0");
|
|
2363
|
+
generator.inject("import", "import { XR, createXRStore } from '@react-three/xr'");
|
|
2364
|
+
generator.inject(
|
|
2365
|
+
`global-start`,
|
|
2366
|
+
`const store = createXRStore(${JSON.stringify(options.storeOptions ?? {})})`
|
|
2367
|
+
);
|
|
2368
|
+
generator.inject("scene-start", "<XR store={store}>");
|
|
2369
|
+
generator.inject("scene-end", "</XR>");
|
|
2370
|
+
generator.inject("vite-config-import", "import basicSsl from '@vitejs/plugin-basic-ssl'");
|
|
2371
|
+
generator.configureVite({
|
|
2372
|
+
server: {
|
|
2373
|
+
host: true
|
|
2374
|
+
},
|
|
2375
|
+
plugins: ["$raw:basicSsl()"]
|
|
2376
|
+
});
|
|
2377
|
+
generator.inject(
|
|
2378
|
+
"dom-start",
|
|
2379
|
+
`<div style={{
|
|
2380
|
+
display: "flex",
|
|
2381
|
+
flexDirection: "row",
|
|
2382
|
+
gap: "1rem",
|
|
2383
|
+
position: 'absolute',
|
|
2384
|
+
zIndex: 10000,
|
|
2385
|
+
background: 'black',
|
|
2386
|
+
borderRadius: '0.5rem',
|
|
2387
|
+
border: 'none',
|
|
2388
|
+
fontWeight: 'bold',
|
|
2389
|
+
color: 'white',
|
|
2390
|
+
cursor: 'pointer',
|
|
2391
|
+
fontSize: '1.5rem',
|
|
2392
|
+
bottom: '1rem',
|
|
2393
|
+
left: '50%',
|
|
2394
|
+
boxShadow: '0px 0px 20px rgba(0,0,0,1)',
|
|
2395
|
+
transform: 'translate(-50%, 0)',
|
|
2396
|
+
}}><button
|
|
2397
|
+
style={{ cursor: "pointer", padding: '1rem 2rem', fontSize: "1rem", background: "none", color: "white", border: "none" }}
|
|
2398
|
+
onClick={() => store.enterAR()}
|
|
2399
|
+
>
|
|
2400
|
+
Enter AR
|
|
2401
|
+
</button>
|
|
2402
|
+
<button
|
|
2403
|
+
style={{ cursor: "pointer", padding: '1rem 2rem', fontSize: "1rem", background: "none", color: "white", border: "none" }}
|
|
2404
|
+
onClick={() => store.enterVR()}
|
|
2405
|
+
>
|
|
2406
|
+
Enter VR
|
|
2407
|
+
</button></div>`
|
|
2408
|
+
);
|
|
2409
|
+
generator.inject(
|
|
2410
|
+
"readme-libraries",
|
|
2411
|
+
`[@react-three/xr](https://pmndrs.github.io/xr/docs/) - VR/AR support for @react-three/fiber`
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
function generateZustand(generator, options) {
|
|
2416
|
+
if (options == null) {
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
generator.addDependency("zustand", "^5.0.3");
|
|
2420
|
+
generator.inject(
|
|
2421
|
+
"readme-libraries",
|
|
2422
|
+
`[zustand](https://zustand.docs.pmnd.rs/) - small, fast and scalable state-management solution`
|
|
2423
|
+
);
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
function merge(target, modification) {
|
|
2427
|
+
if (modification == null) {
|
|
2428
|
+
throw new Error(`Cannot merge "${modification}" modification into target "${target}"`);
|
|
2429
|
+
}
|
|
2430
|
+
if (target == null) {
|
|
2431
|
+
return modification;
|
|
2432
|
+
}
|
|
2433
|
+
if (Array.isArray(target)) {
|
|
2434
|
+
if (!Array.isArray(modification)) {
|
|
2435
|
+
throw new Error(
|
|
2436
|
+
`Cannot merge non-array modification "${modification}" into array target "${target}"`
|
|
2437
|
+
);
|
|
2438
|
+
}
|
|
2439
|
+
return [...target, ...modification];
|
|
2440
|
+
}
|
|
2441
|
+
if (typeof target === "object") {
|
|
2442
|
+
if (typeof modification != "object") {
|
|
2443
|
+
throw new Error(
|
|
2444
|
+
`Cannot merge non-object modification "${modification}" into object target "${target}"`
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
const result = { ...target };
|
|
2448
|
+
for (const modificationKey in modification) {
|
|
2449
|
+
result[modificationKey] = merge(target[modificationKey], modification[modificationKey]);
|
|
2450
|
+
}
|
|
2451
|
+
return result;
|
|
2452
|
+
}
|
|
2453
|
+
console.warn(`target "${target}" is overwritten with modification "${modification}"`);
|
|
2454
|
+
return modification;
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
async function getLatestNpmVersion(packageName, fallback) {
|
|
2458
|
+
try {
|
|
2459
|
+
const response = await fetch(
|
|
2460
|
+
`https://registry.npmjs.org/${packageName}/latest`
|
|
2461
|
+
);
|
|
2462
|
+
const data = await response.json();
|
|
2463
|
+
return data.version;
|
|
2464
|
+
} catch {
|
|
2465
|
+
return fallback;
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
async function getLatestPnpmVersion() {
|
|
2469
|
+
return getLatestNpmVersion("pnpm", "10.11.0");
|
|
2470
|
+
}
|
|
2471
|
+
async function getLatestYarnVersion() {
|
|
2472
|
+
return getLatestNpmVersion("yarn", "4.6.0");
|
|
2473
|
+
}
|
|
2474
|
+
async function getLatestNpmCliVersion() {
|
|
2475
|
+
return getLatestNpmVersion("npm", "11.0.0");
|
|
2476
|
+
}
|
|
2477
|
+
async function getLatestNodeVersion() {
|
|
2478
|
+
try {
|
|
2479
|
+
const response = await fetch("https://nodejs.org/dist/index.json");
|
|
2480
|
+
const data = await response.json();
|
|
2481
|
+
const latestVersion = data[0];
|
|
2482
|
+
if (latestVersion) {
|
|
2483
|
+
return latestVersion.version.replace(/^v/, "");
|
|
2484
|
+
}
|
|
2485
|
+
return "25.0.0";
|
|
2486
|
+
} catch {
|
|
2487
|
+
return "25.0.0";
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
function validateNameSegment(segment, label) {
|
|
2491
|
+
if (!segment.length) {
|
|
2492
|
+
return `${label} is required`;
|
|
2493
|
+
}
|
|
2494
|
+
if (!/^[a-z0-9-]+$/.test(segment)) {
|
|
2495
|
+
return `${label} must be lowercase and contain only letters, numbers, and hyphens`;
|
|
2496
|
+
}
|
|
2497
|
+
if (segment.startsWith("-") || segment.endsWith("-")) {
|
|
2498
|
+
return `${label} cannot start or end with a hyphen`;
|
|
2499
|
+
}
|
|
2500
|
+
if (segment.includes("--")) {
|
|
2501
|
+
return `${label} cannot contain consecutive hyphens`;
|
|
2502
|
+
}
|
|
2503
|
+
return void 0;
|
|
2504
|
+
}
|
|
2505
|
+
function validatePackageName(name) {
|
|
2506
|
+
if (!name.length) {
|
|
2507
|
+
return "Package name is required";
|
|
2508
|
+
}
|
|
2509
|
+
if (name.includes("..") || name.includes("\\")) {
|
|
2510
|
+
return "Package name cannot contain path traversal sequences";
|
|
2511
|
+
}
|
|
2512
|
+
if (name.startsWith("@")) {
|
|
2513
|
+
const slashIndex = name.indexOf("/");
|
|
2514
|
+
if (slashIndex === -1) {
|
|
2515
|
+
return "Scoped package name must include a package name after the scope (e.g., @scope/name)";
|
|
2516
|
+
}
|
|
2517
|
+
if (name.indexOf("/", slashIndex + 1) !== -1) {
|
|
2518
|
+
return "Package name can only have one slash for scoped packages";
|
|
2519
|
+
}
|
|
2520
|
+
const scope = name.slice(1, slashIndex);
|
|
2521
|
+
const packageName = name.slice(slashIndex + 1);
|
|
2522
|
+
const scopeError = validateNameSegment(scope, "Scope");
|
|
2523
|
+
if (scopeError) return scopeError;
|
|
2524
|
+
const nameError = validateNameSegment(packageName, "Package name");
|
|
2525
|
+
if (nameError) return nameError;
|
|
2526
|
+
return void 0;
|
|
2527
|
+
}
|
|
2528
|
+
if (name.includes("/")) {
|
|
2529
|
+
return "Unscoped package name cannot contain slashes. Use @scope/name format for scoped packages";
|
|
2530
|
+
}
|
|
2531
|
+
return validateNameSegment(name, "Package name");
|
|
2532
|
+
}
|
|
2533
|
+
function parseWorkspaceYamlContent(content) {
|
|
2534
|
+
const directories = [];
|
|
2535
|
+
let inPackagesSection = false;
|
|
2536
|
+
for (const line of content.split("\n")) {
|
|
2537
|
+
const trimmed = line.trim();
|
|
2538
|
+
if (trimmed === "packages:") {
|
|
2539
|
+
inPackagesSection = true;
|
|
2540
|
+
continue;
|
|
2541
|
+
}
|
|
2542
|
+
if (inPackagesSection && trimmed && !line.startsWith(" ") && !line.startsWith(" ") && !trimmed.startsWith("-")) {
|
|
2543
|
+
break;
|
|
2544
|
+
}
|
|
2545
|
+
if (inPackagesSection && trimmed.startsWith("-")) {
|
|
2546
|
+
const entry = trimmed.slice(1).trim().replace(/^["']|["']$/g, "").replace(/^\.\//, "").replace(/\/\*.*$/, "");
|
|
2547
|
+
if (entry && !entry.startsWith(".")) {
|
|
2548
|
+
directories.push(entry);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
return directories;
|
|
2553
|
+
}
|
|
2554
|
+
async function pathExists(path) {
|
|
2555
|
+
try {
|
|
2556
|
+
await access(path, constants.F_OK);
|
|
2557
|
+
return true;
|
|
2558
|
+
} catch {
|
|
2559
|
+
return false;
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
function detectLinterFromScript(script) {
|
|
2563
|
+
if (!script) return void 0;
|
|
2564
|
+
if (script.includes("oxlint")) return "oxlint";
|
|
2565
|
+
if (script.includes("eslint")) return "eslint";
|
|
2566
|
+
if (script.includes("biome check") || script.includes("biome lint")) return "biome";
|
|
2567
|
+
return void 0;
|
|
2568
|
+
}
|
|
2569
|
+
function detectFormatterFromScript(script) {
|
|
2570
|
+
if (!script) return void 0;
|
|
2571
|
+
if (script.includes("prettier")) return "prettier";
|
|
2572
|
+
if (script.includes("oxfmt")) return "oxfmt";
|
|
2573
|
+
if (script.includes("biome format")) return "biome";
|
|
2574
|
+
return void 0;
|
|
2575
|
+
}
|
|
2576
|
+
async function detectLinterFromConfig(root) {
|
|
2577
|
+
if (await pathExists(join(root, ".config/oxlint"))) return "oxlint";
|
|
2578
|
+
if (await pathExists(join(root, ".config/eslint"))) return "eslint";
|
|
2579
|
+
if (await pathExists(join(root, "biome.json"))) {
|
|
2580
|
+
try {
|
|
2581
|
+
const content = await readFile(join(root, "biome.json"), "utf-8");
|
|
2582
|
+
const config = JSON.parse(content);
|
|
2583
|
+
if (config.linter?.enabled !== false) return "biome";
|
|
2584
|
+
} catch {
|
|
2585
|
+
return "biome";
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
return void 0;
|
|
2589
|
+
}
|
|
2590
|
+
async function detectFormatterFromConfig(root) {
|
|
2591
|
+
if (await pathExists(join(root, ".config/prettier"))) return "prettier";
|
|
2592
|
+
if (await pathExists(join(root, ".config/oxfmt"))) return "oxfmt";
|
|
2593
|
+
if (await pathExists(join(root, "biome.json"))) {
|
|
2594
|
+
try {
|
|
2595
|
+
const content = await readFile(join(root, "biome.json"), "utf-8");
|
|
2596
|
+
const config = JSON.parse(content);
|
|
2597
|
+
if (config.formatter?.enabled !== false) return "biome";
|
|
2598
|
+
} catch {
|
|
2599
|
+
return "biome";
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
return void 0;
|
|
2603
|
+
}
|
|
2604
|
+
function detectLinterFromDeps(devDeps) {
|
|
2605
|
+
if (!devDeps) return void 0;
|
|
2606
|
+
if (devDeps["@biomejs/biome"]) return "biome";
|
|
2607
|
+
if (devDeps.eslint) return "eslint";
|
|
2608
|
+
if (devDeps.oxlint) return "oxlint";
|
|
2609
|
+
return void 0;
|
|
2610
|
+
}
|
|
2611
|
+
function detectFormatterFromDeps(devDeps) {
|
|
2612
|
+
if (!devDeps) return void 0;
|
|
2613
|
+
if (devDeps["@biomejs/biome"]) return "biome";
|
|
2614
|
+
if (devDeps.prettier) return "prettier";
|
|
2615
|
+
if (devDeps.oxfmt) return "oxfmt";
|
|
2616
|
+
return void 0;
|
|
2617
|
+
}
|
|
2618
|
+
async function detectTooling(root) {
|
|
2619
|
+
try {
|
|
2620
|
+
const pkgPath = join(root, "package.json");
|
|
2621
|
+
const content = await readFile(pkgPath, "utf-8");
|
|
2622
|
+
const pkg = JSON.parse(content);
|
|
2623
|
+
const linter = detectLinterFromScript(pkg.scripts?.lint) ?? await detectLinterFromConfig(root) ?? detectLinterFromDeps(pkg.devDependencies);
|
|
2624
|
+
const formatter = detectFormatterFromScript(pkg.scripts?.format) ?? await detectFormatterFromConfig(root) ?? detectFormatterFromDeps(pkg.devDependencies);
|
|
2625
|
+
return { linter, formatter };
|
|
2626
|
+
} catch {
|
|
2627
|
+
return { linter: void 0, formatter: void 0 };
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
function generateRandomName() {
|
|
2631
|
+
const adjectives = [
|
|
2632
|
+
"red",
|
|
2633
|
+
"blue",
|
|
2634
|
+
"green",
|
|
2635
|
+
"yellow",
|
|
2636
|
+
"purple",
|
|
2637
|
+
"orange",
|
|
2638
|
+
"pink",
|
|
2639
|
+
"black",
|
|
2640
|
+
"white",
|
|
2641
|
+
"tiny",
|
|
2642
|
+
"big",
|
|
2643
|
+
"small",
|
|
2644
|
+
"large",
|
|
2645
|
+
"huge",
|
|
2646
|
+
"giant",
|
|
2647
|
+
"mini",
|
|
2648
|
+
"mega",
|
|
2649
|
+
"super",
|
|
2650
|
+
"happy",
|
|
2651
|
+
"sad",
|
|
2652
|
+
"angry",
|
|
2653
|
+
"calm",
|
|
2654
|
+
"quiet",
|
|
2655
|
+
"loud",
|
|
2656
|
+
"silent",
|
|
2657
|
+
"noisy",
|
|
2658
|
+
"shiny",
|
|
2659
|
+
"dull",
|
|
2660
|
+
"bright",
|
|
2661
|
+
"dark",
|
|
2662
|
+
"fuzzy",
|
|
2663
|
+
"smooth",
|
|
2664
|
+
"rough",
|
|
2665
|
+
"soft"
|
|
2666
|
+
];
|
|
2667
|
+
const nouns = [
|
|
2668
|
+
"apple",
|
|
2669
|
+
"banana",
|
|
2670
|
+
"cherry",
|
|
2671
|
+
"date",
|
|
2672
|
+
"elderberry",
|
|
2673
|
+
"fig",
|
|
2674
|
+
"grape",
|
|
2675
|
+
"honeydew",
|
|
2676
|
+
"cat",
|
|
2677
|
+
"dog",
|
|
2678
|
+
"elephant",
|
|
2679
|
+
"fox",
|
|
2680
|
+
"giraffe",
|
|
2681
|
+
"horse",
|
|
2682
|
+
"iguana",
|
|
2683
|
+
"jaguar",
|
|
2684
|
+
"mountain",
|
|
2685
|
+
"river",
|
|
2686
|
+
"ocean",
|
|
2687
|
+
"desert",
|
|
2688
|
+
"forest",
|
|
2689
|
+
"jungle",
|
|
2690
|
+
"meadow",
|
|
2691
|
+
"valley",
|
|
2692
|
+
"star",
|
|
2693
|
+
"moon",
|
|
2694
|
+
"sun",
|
|
2695
|
+
"planet",
|
|
2696
|
+
"comet",
|
|
2697
|
+
"asteroid",
|
|
2698
|
+
"galaxy",
|
|
2699
|
+
"universe"
|
|
2700
|
+
];
|
|
2701
|
+
const randomAdjective = adjectives[Math.floor(Math.random() * adjectives.length)];
|
|
2702
|
+
const randomNoun = nouns[Math.floor(Math.random() * nouns.length)];
|
|
2703
|
+
return `${randomAdjective}-${randomNoun}`;
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
function generate(options) {
|
|
2707
|
+
const clonedOptions = structuredClone(options);
|
|
2708
|
+
const template = clonedOptions.template ?? "vanilla";
|
|
2709
|
+
const baseTemplate = getBaseTemplate(template);
|
|
2710
|
+
const language = getLanguageFromTemplate(template);
|
|
2711
|
+
const isVanilla = baseTemplate === "vanilla";
|
|
2712
|
+
const isReact = baseTemplate === "react";
|
|
2713
|
+
const isR3f = baseTemplate === "r3f";
|
|
2714
|
+
const isLibrary = clonedOptions.projectType === "library";
|
|
2715
|
+
const libraryBundler = clonedOptions.libraryBundler ?? "unbuild";
|
|
2716
|
+
const files = {
|
|
2717
|
+
...clonedOptions.files
|
|
2718
|
+
};
|
|
2719
|
+
const replacements = clonedOptions.replacements ?? [];
|
|
2720
|
+
const versions = clonedOptions.versions ?? {};
|
|
2721
|
+
const dependencies = {
|
|
2722
|
+
...clonedOptions.dependencies
|
|
2723
|
+
};
|
|
2724
|
+
const devDependencies = {};
|
|
2725
|
+
const peerDependencies = {};
|
|
2726
|
+
if (!isLibrary) {
|
|
2727
|
+
devDependencies.vite = versions.vite ? `^${versions.vite}` : "^6.3.4";
|
|
2728
|
+
}
|
|
2729
|
+
if (isReact || isR3f) {
|
|
2730
|
+
if (isLibrary) {
|
|
2731
|
+
peerDependencies["react"] = "^18.0.0 || ^19.0.0";
|
|
2732
|
+
peerDependencies["react-dom"] = "^18.0.0 || ^19.0.0";
|
|
2733
|
+
} else {
|
|
2734
|
+
dependencies["react"] = "^19.0.0";
|
|
2735
|
+
dependencies["react-dom"] = "^19.0.0";
|
|
2736
|
+
devDependencies["@vitejs/plugin-react"] = "^4.4.1";
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
if (isR3f) {
|
|
2740
|
+
if (isLibrary) {
|
|
2741
|
+
peerDependencies["three"] = ">=0.150.0";
|
|
2742
|
+
peerDependencies["@react-three/fiber"] = "^8.0.0 || ^9.0.0";
|
|
2743
|
+
} else {
|
|
2744
|
+
dependencies["three"] = "~0.175.0";
|
|
2745
|
+
dependencies["@react-three/fiber"] = "^9.0.0";
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
if (language === "typescript") {
|
|
2749
|
+
const tsResult = generateTypescriptConfig({
|
|
2750
|
+
baseTemplate,
|
|
2751
|
+
useConfigPackage: clonedOptions.workspaceRoot != null,
|
|
2752
|
+
configStrategy: clonedOptions.configStrategy,
|
|
2753
|
+
nodeVersion: clonedOptions.nodeVersion
|
|
2754
|
+
});
|
|
2755
|
+
Object.assign(files, tsResult.files);
|
|
2756
|
+
Object.assign(devDependencies, tsResult.devDependencies);
|
|
2757
|
+
}
|
|
2758
|
+
const codeSnippets = {};
|
|
2759
|
+
const vscodeSettings = {};
|
|
2760
|
+
const scripts = isLibrary ? {} : {
|
|
2761
|
+
dev: "vite",
|
|
2762
|
+
build: "vite build"
|
|
2763
|
+
};
|
|
2764
|
+
if (!isLibrary && (isReact || isR3f)) {
|
|
2765
|
+
codeSnippets["vite-config-import"] = [
|
|
2766
|
+
"import react from '@vitejs/plugin-react'"
|
|
2767
|
+
];
|
|
2768
|
+
}
|
|
2769
|
+
if (!isLibrary && isR3f) {
|
|
2770
|
+
codeSnippets["import"] = [`import { Canvas } from "@react-three/fiber"`];
|
|
2771
|
+
}
|
|
2772
|
+
const defaultName = isVanilla ? "vanilla-app" : isReact ? "react-app" : "react-three-app";
|
|
2773
|
+
const name = clonedOptions.name ?? defaultName;
|
|
2774
|
+
let viteConfig = {
|
|
2775
|
+
base: "./"
|
|
2776
|
+
};
|
|
2777
|
+
if (!isLibrary && (isReact || isR3f)) {
|
|
2778
|
+
viteConfig.plugins = ["$raw:react()"];
|
|
2779
|
+
}
|
|
2780
|
+
if (!isLibrary && isR3f) {
|
|
2781
|
+
viteConfig.resolve = { dedupe: ["three"] };
|
|
2782
|
+
}
|
|
2783
|
+
const isMonorepoPackage = clonedOptions.workspaceRoot != null;
|
|
2784
|
+
const generator = {
|
|
2785
|
+
options: clonedOptions,
|
|
2786
|
+
versions,
|
|
2787
|
+
isStealthConfig() {
|
|
2788
|
+
return (clonedOptions.configStrategy ?? "stealth") === "stealth";
|
|
2789
|
+
},
|
|
2790
|
+
addDependency(name2, semver) {
|
|
2791
|
+
dependencies[name2];
|
|
2792
|
+
dependencies[name2] = semver;
|
|
2793
|
+
},
|
|
2794
|
+
addDevDependency(name2, semver) {
|
|
2795
|
+
devDependencies[name2];
|
|
2796
|
+
devDependencies[name2] = semver;
|
|
2797
|
+
},
|
|
2798
|
+
addFile(path, content) {
|
|
2799
|
+
files[path] = content;
|
|
2800
|
+
},
|
|
2801
|
+
addScript(name2, command) {
|
|
2802
|
+
scripts[name2] = command;
|
|
2803
|
+
},
|
|
2804
|
+
inject(location, code) {
|
|
2805
|
+
let entries = codeSnippets[location];
|
|
2806
|
+
if (entries == null) {
|
|
2807
|
+
codeSnippets[location] = entries = [];
|
|
2808
|
+
}
|
|
2809
|
+
entries.push(code);
|
|
2810
|
+
},
|
|
2811
|
+
replace(search, replace) {
|
|
2812
|
+
replacements.push({ search, replace });
|
|
2813
|
+
},
|
|
2814
|
+
configureVite(config) {
|
|
2815
|
+
viteConfig = merge(viteConfig, config);
|
|
2816
|
+
},
|
|
2817
|
+
addVscodeSetting(key, value) {
|
|
2818
|
+
vscodeSettings[key] = value;
|
|
2819
|
+
}
|
|
2820
|
+
};
|
|
2821
|
+
if (isR3f) {
|
|
2822
|
+
generateDrei(generator, clonedOptions.drei);
|
|
2823
|
+
generateHandle(generator, clonedOptions.handle);
|
|
2824
|
+
generateKoota(generator, clonedOptions.koota);
|
|
2825
|
+
generateLeva(generator, clonedOptions.leva);
|
|
2826
|
+
generateOffscreen(generator, clonedOptions.offscreen);
|
|
2827
|
+
generatePostprocessing(generator, clonedOptions.postprocessing);
|
|
2828
|
+
generateRapier(generator, clonedOptions.rapier);
|
|
2829
|
+
generateUikit(generator, clonedOptions.uikit);
|
|
2830
|
+
generateXr(generator, clonedOptions.xr);
|
|
2831
|
+
generateZustand(generator, clonedOptions.zustand);
|
|
2832
|
+
generateFiber(generator, clonedOptions.fiber);
|
|
2833
|
+
generateTriplex(generator, clonedOptions.triplex);
|
|
2834
|
+
generateViverse(generator, clonedOptions.viverse);
|
|
2835
|
+
}
|
|
2836
|
+
if (!isLibrary) {
|
|
2837
|
+
generateGithubPages(generator, clonedOptions.githubPages);
|
|
2838
|
+
}
|
|
2839
|
+
if (isLibrary) {
|
|
2840
|
+
if (libraryBundler === "unbuild") {
|
|
2841
|
+
generateUnbuild(generator);
|
|
2842
|
+
} else if (libraryBundler === "tsdown") {
|
|
2843
|
+
generateTsdown(generator);
|
|
2844
|
+
}
|
|
2845
|
+
const packageManager2 = clonedOptions.packageManager ?? "pnpm";
|
|
2846
|
+
generator.addScript(
|
|
2847
|
+
"release",
|
|
2848
|
+
`${packageManager2} run build && ${packageManager2} publish`
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
const testing = clonedOptions.testing ?? (isLibrary ? "vitest" : "none");
|
|
2852
|
+
if (testing === "vitest") {
|
|
2853
|
+
generateVitest(generator);
|
|
2854
|
+
}
|
|
2855
|
+
const linter = clonedOptions.linter;
|
|
2856
|
+
const formatter = clonedOptions.formatter;
|
|
2857
|
+
if (linter === "eslint") {
|
|
2858
|
+
generateEslint(generator);
|
|
2859
|
+
generator.addVscodeSetting("biome.enabled", false);
|
|
2860
|
+
generator.addVscodeSetting("oxc.enable", false);
|
|
2861
|
+
} else if (linter === "oxlint") {
|
|
2862
|
+
generateOxlint(generator);
|
|
2863
|
+
generator.addVscodeSetting("eslint.enable", false);
|
|
2864
|
+
generator.addVscodeSetting("biome.enabled", false);
|
|
2865
|
+
} else if (linter === "biome") {
|
|
2866
|
+
generateBiome(generator, {
|
|
2867
|
+
linter: true,
|
|
2868
|
+
formatter: formatter === "biome"
|
|
2869
|
+
});
|
|
2870
|
+
generator.addVscodeSetting("eslint.enable", false);
|
|
2871
|
+
generator.addVscodeSetting("oxc.enable", false);
|
|
2872
|
+
}
|
|
2873
|
+
if (formatter === "prettier") {
|
|
2874
|
+
generatePrettier(generator);
|
|
2875
|
+
} else if (formatter === "oxfmt") {
|
|
2876
|
+
generateOxfmt(generator);
|
|
2877
|
+
} else if (formatter === "biome" && linter !== "biome") {
|
|
2878
|
+
generateBiome(generator, { linter: false, formatter: true });
|
|
2879
|
+
generator.addVscodeSetting("eslint.enable", false);
|
|
2880
|
+
generator.addVscodeSetting("oxc.enable", false);
|
|
2881
|
+
}
|
|
2882
|
+
for (const { code, location } of clonedOptions.injections ?? []) {
|
|
2883
|
+
generator.inject(location, code);
|
|
2884
|
+
}
|
|
2885
|
+
if (!isLibrary) {
|
|
2886
|
+
files["vite.config.ts"] = generateViteConfig({ viteConfig, codeSnippets });
|
|
2887
|
+
}
|
|
2888
|
+
const packageManager = options.packageManager ?? "pnpm";
|
|
2889
|
+
files["README.md"] = generateReadme({
|
|
2890
|
+
name,
|
|
2891
|
+
baseTemplate,
|
|
2892
|
+
isLibrary,
|
|
2893
|
+
libraryBundler,
|
|
2894
|
+
packageManager,
|
|
2895
|
+
codeSnippets
|
|
2896
|
+
});
|
|
2897
|
+
Object.assign(
|
|
2898
|
+
files,
|
|
2899
|
+
generateSourceFiles({
|
|
2900
|
+
name,
|
|
2901
|
+
baseTemplate,
|
|
2902
|
+
language,
|
|
2903
|
+
isLibrary,
|
|
2904
|
+
codeSnippets,
|
|
2905
|
+
replacements
|
|
2906
|
+
})
|
|
2907
|
+
);
|
|
2908
|
+
if (testing === "vitest") {
|
|
2909
|
+
Object.assign(
|
|
2910
|
+
files,
|
|
2911
|
+
generateTestFiles({
|
|
2912
|
+
baseTemplate,
|
|
2913
|
+
language,
|
|
2914
|
+
isLibrary
|
|
2915
|
+
})
|
|
2916
|
+
);
|
|
2917
|
+
}
|
|
2918
|
+
Object.assign(
|
|
2919
|
+
files,
|
|
2920
|
+
generatePackageJson({
|
|
2921
|
+
name,
|
|
2922
|
+
language,
|
|
2923
|
+
isLibrary,
|
|
2924
|
+
dependencies,
|
|
2925
|
+
devDependencies,
|
|
2926
|
+
peerDependencies,
|
|
2927
|
+
scripts,
|
|
2928
|
+
options: clonedOptions,
|
|
2929
|
+
workspaceDependencies: clonedOptions.workspaceDependencies
|
|
2930
|
+
}).files
|
|
2931
|
+
);
|
|
2932
|
+
if (!isMonorepoPackage) {
|
|
2933
|
+
Object.assign(files, generateVscodeFiles$1({ codeSnippets, vscodeSettings }));
|
|
2934
|
+
}
|
|
2935
|
+
if (!isMonorepoPackage) {
|
|
2936
|
+
files[".gitignore"] = generateGitignore("standalone");
|
|
2937
|
+
files[".gitattributes"] = { type: "text", content: GitAttributes };
|
|
2938
|
+
}
|
|
2939
|
+
if (!isMonorepoPackage && clonedOptions.aiPlatforms?.length) {
|
|
2940
|
+
generateAiFiles(files, {
|
|
2941
|
+
name,
|
|
2942
|
+
packageManager: clonedOptions.packageManager ?? "pnpm",
|
|
2943
|
+
linter: clonedOptions.linter ?? "oxlint",
|
|
2944
|
+
formatter: clonedOptions.formatter ?? "prettier",
|
|
2945
|
+
isMonorepo: false,
|
|
2946
|
+
configStrategy: clonedOptions.configStrategy,
|
|
2947
|
+
platforms: clonedOptions.aiPlatforms
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
return files;
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2953
|
+
export { detectTooling, generate, generateMonorepo, generateRandomName, getBaseTemplate, getLanguageFromTemplate, getLatestNodeVersion, getLatestNpmCliVersion, getLatestNpmVersion, getLatestPnpmVersion, getLatestYarnVersion, parseWorkspaceYamlContent, validatePackageName };
|