create-fumapress 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +282 -0
- package/package.json +1 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, readdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { cancel, confirm, intro, isCancel, log, outro, text } from "@clack/prompts";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { x } from "tinyexec";
|
|
7
|
+
//#region ../create-fumapress-versions/package.json
|
|
8
|
+
var dependencies = {
|
|
9
|
+
"fumadocs-core": "^16.8.10",
|
|
10
|
+
"fumadocs-mdx": "^15.0.4",
|
|
11
|
+
"fumadocs-ui": "^16.8.10",
|
|
12
|
+
"fumapress": "workspace:*",
|
|
13
|
+
"react": "^19.2.6",
|
|
14
|
+
"react-dom": "^19.2.6",
|
|
15
|
+
"react-server-dom-webpack": "^19.2.6",
|
|
16
|
+
"waku": "1.0.0-alpha.10"
|
|
17
|
+
};
|
|
18
|
+
var devDependencies = {
|
|
19
|
+
"@tailwindcss/vite": "^4.3.0",
|
|
20
|
+
"@types/mdx": "^2.0.13",
|
|
21
|
+
"@types/node": "^25.7.0",
|
|
22
|
+
"@types/react": "^19.2.14",
|
|
23
|
+
"@types/react-dom": "^19.2.3",
|
|
24
|
+
"tailwindcss": "^4.3.0",
|
|
25
|
+
"typescript": "^6.0.3"
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region ../press-core/package.json
|
|
29
|
+
var version = "0.2.4";
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/index.ts
|
|
32
|
+
const packageManagers = [
|
|
33
|
+
"npm",
|
|
34
|
+
"pnpm",
|
|
35
|
+
"yarn",
|
|
36
|
+
"bun"
|
|
37
|
+
];
|
|
38
|
+
const program = new Command().name("create-fumapress").description("Initialize a Fumapress app").argument("[directory]", "directory to create the app in").option("-y, --yes", "use defaults and install dependencies").option("--force", "write files even when the target directory is not empty").option("--install", "install dependencies after scaffolding").option("--no-install", "skip dependency installation").option("--package-manager <name>", "package manager to use: npm, pnpm, yarn, or bun").parse(process.argv);
|
|
39
|
+
const [directory] = program.args;
|
|
40
|
+
const options = program.opts();
|
|
41
|
+
intro("create-fumapress");
|
|
42
|
+
const projectDirectory = options.yes ? directory ?? "my-fumapress-app" : await promptProjectDirectory(directory);
|
|
43
|
+
const packageManager = getPackageManager(options.packageManager);
|
|
44
|
+
const shouldInstall = options.yes ? options.install !== false : options.install ?? await promptInstall(packageManager);
|
|
45
|
+
const root = path.resolve(projectDirectory);
|
|
46
|
+
const name = toPackageName(path.basename(root));
|
|
47
|
+
await assertCanInitialize(root, Boolean(options.force));
|
|
48
|
+
await writeProject(root, name);
|
|
49
|
+
log.success(`Created ${path.relative(process.cwd(), root) || "."}`);
|
|
50
|
+
if (shouldInstall) await installDependencies(root, packageManager);
|
|
51
|
+
printNextSteps(root, packageManager, shouldInstall);
|
|
52
|
+
async function promptProjectDirectory(initialValue) {
|
|
53
|
+
return unwrapPrompt(await text({
|
|
54
|
+
message: "Where should the Fumapress app be created?",
|
|
55
|
+
placeholder: "my-fumapress-app",
|
|
56
|
+
initialValue,
|
|
57
|
+
validate(value) {
|
|
58
|
+
if (!value?.trim()) return "Enter a directory name.";
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
async function promptInstall(packageManager) {
|
|
63
|
+
return unwrapPrompt(await confirm({
|
|
64
|
+
message: `Install dependencies with ${packageManager}?`,
|
|
65
|
+
initialValue: true
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
function unwrapPrompt(value) {
|
|
69
|
+
if (isCancel(value)) {
|
|
70
|
+
cancel("Operation cancelled.");
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
function getPackageManager(value) {
|
|
76
|
+
if (value) {
|
|
77
|
+
if (isPackageManager(value)) return value;
|
|
78
|
+
cancel(`Unsupported package manager: ${value}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
const detected = process.env.npm_config_user_agent?.split("/")[0];
|
|
82
|
+
if (detected && isPackageManager(detected)) return detected;
|
|
83
|
+
return "npm";
|
|
84
|
+
}
|
|
85
|
+
function isPackageManager(value) {
|
|
86
|
+
return packageManagers.includes(value);
|
|
87
|
+
}
|
|
88
|
+
async function assertCanInitialize(root, force) {
|
|
89
|
+
if (force) return;
|
|
90
|
+
let entries;
|
|
91
|
+
try {
|
|
92
|
+
entries = await readdir(root);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (isNodeError(error) && error.code === "ENOENT") return;
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
if (entries.length > 0) {
|
|
98
|
+
cancel(`Target directory is not empty: ${path.relative(process.cwd(), root) || "."}`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function writeProject(root, name) {
|
|
103
|
+
await Promise.all(Object.entries(getFiles(name)).map(async ([file, content]) => {
|
|
104
|
+
const target = path.join(root, file);
|
|
105
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
106
|
+
await writeFile(target, content);
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
function getFiles(name) {
|
|
110
|
+
return {
|
|
111
|
+
".gitignore": `.DS_Store
|
|
112
|
+
/node_modules/
|
|
113
|
+
|
|
114
|
+
dist
|
|
115
|
+
.source
|
|
116
|
+
src/pages.gen.ts
|
|
117
|
+
`,
|
|
118
|
+
"README.md": `# ${name}
|
|
119
|
+
|
|
120
|
+
This is a Fumapress app powered by Waku and Fumadocs.
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
\`\`\`sh
|
|
125
|
+
npm run dev
|
|
126
|
+
\`\`\`
|
|
127
|
+
`,
|
|
128
|
+
"content/index.mdx": `---
|
|
129
|
+
title: My Page
|
|
130
|
+
description: Hello World
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
# Overview
|
|
134
|
+
|
|
135
|
+
This is my first document.
|
|
136
|
+
`,
|
|
137
|
+
"package.json": `${JSON.stringify(getPackageJson(name), null, 2)}\n`,
|
|
138
|
+
"press.config.tsx": `import { defineConfig } from "fumapress";
|
|
139
|
+
import { fumadocsMdx } from "fumapress/adapters/mdx";
|
|
140
|
+
import { flexsearchPlugin } from "fumapress/plugins/flexsearch";
|
|
141
|
+
import { llmsPlugin } from "fumapress/plugins/llms.txt";
|
|
142
|
+
import { takumiPlugin } from "fumapress/plugins/takumi";
|
|
143
|
+
import { loader } from "fumadocs-core/source";
|
|
144
|
+
import { docs } from "./.source/server";
|
|
145
|
+
|
|
146
|
+
export default defineConfig({
|
|
147
|
+
loader: loader(docs.toFumadocsSource(), {
|
|
148
|
+
baseUrl: "/",
|
|
149
|
+
}),
|
|
150
|
+
site: {
|
|
151
|
+
name: "Fumapress",
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
.usePlugins(flexsearchPlugin(), llmsPlugin(), takumiPlugin())
|
|
155
|
+
.useAdapters(fumadocsMdx());
|
|
156
|
+
`,
|
|
157
|
+
"source.config.ts": `import { defineDocs } from "fumadocs-mdx/config";
|
|
158
|
+
import { metaSchema, pageSchema } from "fumadocs-core/source/schema";
|
|
159
|
+
|
|
160
|
+
export const docs = defineDocs({
|
|
161
|
+
dir: "content",
|
|
162
|
+
docs: {
|
|
163
|
+
async: true,
|
|
164
|
+
schema: pageSchema,
|
|
165
|
+
postprocess: {
|
|
166
|
+
includeProcessedMarkdown: true,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
meta: {
|
|
170
|
+
schema: metaSchema,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
`,
|
|
174
|
+
"src/app.css": `@import "tailwindcss";
|
|
175
|
+
@import "fumadocs-ui/css/neutral.css";
|
|
176
|
+
@import "fumadocs-ui/css/preset.css";
|
|
177
|
+
@import "fumapress/css/preset.css";
|
|
178
|
+
`,
|
|
179
|
+
"tsconfig.json": `${JSON.stringify(getTsConfig(), null, 2)}\n`,
|
|
180
|
+
"waku.config.ts": `import { defineConfig } from "waku/config";
|
|
181
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
182
|
+
import press from "fumapress/vite";
|
|
183
|
+
import mdx from "fumadocs-mdx/vite";
|
|
184
|
+
|
|
185
|
+
export default defineConfig({
|
|
186
|
+
vite: {
|
|
187
|
+
plugins: [press(), mdx(), tailwindcss()],
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
`
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function getPackageJson(name) {
|
|
194
|
+
return {
|
|
195
|
+
name,
|
|
196
|
+
private: true,
|
|
197
|
+
type: "module",
|
|
198
|
+
sideEffects: false,
|
|
199
|
+
scripts: {
|
|
200
|
+
dev: "waku dev",
|
|
201
|
+
build: "waku build",
|
|
202
|
+
start: "waku start",
|
|
203
|
+
"types:check": "fumadocs-mdx && tsc --noEmit"
|
|
204
|
+
},
|
|
205
|
+
dependencies: {
|
|
206
|
+
...dependencies,
|
|
207
|
+
fumapress: version
|
|
208
|
+
},
|
|
209
|
+
devDependencies
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function getTsConfig() {
|
|
213
|
+
return {
|
|
214
|
+
compilerOptions: {
|
|
215
|
+
target: "ES2023",
|
|
216
|
+
lib: [
|
|
217
|
+
"dom",
|
|
218
|
+
"dom.iterable",
|
|
219
|
+
"ES2023"
|
|
220
|
+
],
|
|
221
|
+
jsx: "react-jsx",
|
|
222
|
+
module: "ESNext",
|
|
223
|
+
moduleResolution: "bundler",
|
|
224
|
+
resolveJsonModule: true,
|
|
225
|
+
allowJs: true,
|
|
226
|
+
checkJs: true,
|
|
227
|
+
esModuleInterop: true,
|
|
228
|
+
forceConsistentCasingInFileNames: true,
|
|
229
|
+
strict: true,
|
|
230
|
+
skipLibCheck: true,
|
|
231
|
+
noUncheckedIndexedAccess: true,
|
|
232
|
+
noEmit: true
|
|
233
|
+
},
|
|
234
|
+
exclude: ["node_modules", "dist"]
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
async function installDependencies(root, packageManager) {
|
|
238
|
+
const { command, args } = getInstallCommand(packageManager);
|
|
239
|
+
log.step(`Installing dependencies with ${packageManager}...`);
|
|
240
|
+
await x(command, args, { nodeOptions: { cwd: root } });
|
|
241
|
+
}
|
|
242
|
+
function getInstallCommand(packageManager) {
|
|
243
|
+
switch (packageManager) {
|
|
244
|
+
case "bun": return {
|
|
245
|
+
command: "bun",
|
|
246
|
+
args: ["install"]
|
|
247
|
+
};
|
|
248
|
+
case "pnpm": return {
|
|
249
|
+
command: "pnpm",
|
|
250
|
+
args: ["install"]
|
|
251
|
+
};
|
|
252
|
+
case "yarn": return {
|
|
253
|
+
command: "yarn",
|
|
254
|
+
args: ["install"]
|
|
255
|
+
};
|
|
256
|
+
case "npm": return {
|
|
257
|
+
command: "npm",
|
|
258
|
+
args: ["install"]
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function printNextSteps(root, packageManager, installed) {
|
|
263
|
+
const relativeRoot = path.relative(process.cwd(), root);
|
|
264
|
+
const lines = ["Next steps:"];
|
|
265
|
+
if (relativeRoot) lines.push(` cd ${relativeRoot}`);
|
|
266
|
+
if (!installed) lines.push(` ${packageManager} install`);
|
|
267
|
+
lines.push(` ${getRunCommand(packageManager, "dev")}`);
|
|
268
|
+
outro(lines.join("\n"));
|
|
269
|
+
}
|
|
270
|
+
function getRunCommand(packageManager, script) {
|
|
271
|
+
if (packageManager === "npm") return `npm run ${script}`;
|
|
272
|
+
if (packageManager === "bun") return `bun run ${script}`;
|
|
273
|
+
return `${packageManager} ${script}`;
|
|
274
|
+
}
|
|
275
|
+
function toPackageName(value) {
|
|
276
|
+
return value.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "fumapress-app";
|
|
277
|
+
}
|
|
278
|
+
function isNodeError(error) {
|
|
279
|
+
return error instanceof Error && "code" in error;
|
|
280
|
+
}
|
|
281
|
+
//#endregion
|
|
282
|
+
export {};
|