create-vuepress-theme-plume 1.0.0-rc.146 → 1.0.0-rc.148
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/lib/index.d.ts +1 -2
- package/lib/index.js +493 -513
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
1
|
+
export { };
|
package/lib/index.js
CHANGED
|
@@ -1,566 +1,546 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
import cac from "cac";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
];
|
|
9
|
-
var bundlerOptions = [
|
|
10
|
-
{ label: "Vite", value: "vite" },
|
|
11
|
-
{ label: "Webpack", value: "webpack" }
|
|
12
|
-
];
|
|
13
|
-
var deployOptions = [
|
|
14
|
-
{ label: "Custom", value: "custom" /* custom */ },
|
|
15
|
-
{ label: "GitHub Pages", value: "github" /* github */ },
|
|
16
|
-
{ label: "Vercel", value: "vercel" /* vercel */ },
|
|
17
|
-
{ label: "Netlify", value: "netlify" /* netlify */ }
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
// src/run.ts
|
|
21
|
-
import path4 from "node:path";
|
|
22
|
-
import process4 from "node:process";
|
|
23
|
-
import { intro, outro, spinner } from "@clack/prompts";
|
|
24
|
-
import { sleep } from "@pengzhanbo/utils";
|
|
25
|
-
import { execaCommand as execaCommand3 } from "execa";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { cancel, confirm, group, intro, outro, select, spinner, text } from "@clack/prompts";
|
|
6
|
+
import { kebabCase, sleep } from "@pengzhanbo/utils";
|
|
7
|
+
import spawn from "nano-spawn";
|
|
26
8
|
import colors from "picocolors";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import fs$1 from "node:fs/promises";
|
|
12
|
+
import handlebars from "handlebars";
|
|
13
|
+
import { osLocale } from "os-locale";
|
|
27
14
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
import path3 from "node:path";
|
|
31
|
-
import process2 from "node:process";
|
|
32
|
-
import { execaCommand as execaCommand2 } from "execa";
|
|
33
|
-
|
|
34
|
-
// src/packageJson.ts
|
|
35
|
-
import { kebabCase } from "@pengzhanbo/utils";
|
|
36
|
-
import { execaCommand } from "execa";
|
|
15
|
+
//#region package.json
|
|
16
|
+
var version = "1.0.0-rc.147";
|
|
37
17
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/constants.ts
|
|
20
|
+
const languageOptions = [{
|
|
21
|
+
label: "English",
|
|
22
|
+
value: "en-US"
|
|
23
|
+
}, {
|
|
24
|
+
label: "简体中文",
|
|
25
|
+
value: "zh-CN"
|
|
26
|
+
}];
|
|
27
|
+
const bundlerOptions = [{
|
|
28
|
+
label: "Vite",
|
|
29
|
+
value: "vite"
|
|
30
|
+
}, {
|
|
31
|
+
label: "Webpack",
|
|
32
|
+
value: "webpack"
|
|
33
|
+
}];
|
|
34
|
+
let Mode = /* @__PURE__ */ function(Mode$1) {
|
|
35
|
+
Mode$1[Mode$1["init"] = 0] = "init";
|
|
36
|
+
Mode$1[Mode$1["create"] = 1] = "create";
|
|
37
|
+
return Mode$1;
|
|
38
|
+
}({});
|
|
39
|
+
let DeployType = /* @__PURE__ */ function(DeployType$1) {
|
|
40
|
+
DeployType$1["github"] = "github";
|
|
41
|
+
DeployType$1["vercel"] = "vercel";
|
|
42
|
+
DeployType$1["netlify"] = "netlify";
|
|
43
|
+
DeployType$1["custom"] = "custom";
|
|
44
|
+
return DeployType$1;
|
|
45
|
+
}({});
|
|
46
|
+
const deployOptions = [
|
|
47
|
+
{
|
|
48
|
+
label: "Custom",
|
|
49
|
+
value: DeployType.custom
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: "GitHub Pages",
|
|
53
|
+
value: DeployType.github
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
label: "Vercel",
|
|
57
|
+
value: DeployType.vercel
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
label: "Netlify",
|
|
61
|
+
value: DeployType.netlify
|
|
62
|
+
}
|
|
63
|
+
];
|
|
41
64
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
import path from "node:path";
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/utils/fs.ts
|
|
45
67
|
async function readFiles(root) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
return files;
|
|
68
|
+
const filepaths = await fs$1.readdir(root, { recursive: true });
|
|
69
|
+
const files = [];
|
|
70
|
+
for (const file of filepaths) {
|
|
71
|
+
const filepath = path.join(root, file);
|
|
72
|
+
if ((await fs$1.stat(filepath)).isFile()) files.push({
|
|
73
|
+
filepath: file,
|
|
74
|
+
content: await fs$1.readFile(filepath, "utf-8")
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return files;
|
|
58
78
|
}
|
|
59
79
|
async function writeFiles(files, target, rewrite) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
80
|
+
for (const { filepath, content } of files) {
|
|
81
|
+
let root = path.join(target, filepath).replace(/\.handlebars$/, "");
|
|
82
|
+
if (rewrite) root = rewrite(root);
|
|
83
|
+
await fs$1.mkdir(path.dirname(root), { recursive: true });
|
|
84
|
+
await fs$1.writeFile(root, content);
|
|
85
|
+
}
|
|
67
86
|
}
|
|
68
87
|
async function readJsonFile(filepath) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
try {
|
|
89
|
+
const content = await fs$1.readFile(filepath, "utf-8");
|
|
90
|
+
return JSON.parse(content);
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/utils/getPackageManager.ts
|
|
79
98
|
function getPackageManager() {
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
const name = process.env?.npm_config_user_agent || "npm";
|
|
100
|
+
return name.split("/")[0];
|
|
82
101
|
}
|
|
83
102
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/utils/index.ts
|
|
105
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
106
|
+
const resolve = (...args) => path.resolve(__dirname, "../", ...args);
|
|
107
|
+
const getTemplate = (dir) => resolve("templates", dir);
|
|
88
108
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const hasDep = (dep) => pkg.devDependencies?.[dep] || pkg.dependencies?.[dep];
|
|
139
|
-
const context = await readJsonFile(resolve("package.json"));
|
|
140
|
-
const meta = context["plume-deps"];
|
|
141
|
-
pkg.devDependencies[`@vuepress/bundler-${bundler}`] = `${meta.vuepress}`;
|
|
142
|
-
pkg.devDependencies.vuepress = `${meta.vuepress}`;
|
|
143
|
-
pkg.devDependencies["vuepress-theme-plume"] = `${context.version}`;
|
|
144
|
-
const deps = ["http-server"];
|
|
145
|
-
if (!hasDep("vue"))
|
|
146
|
-
deps.push("vue");
|
|
147
|
-
if (bundler === "webpack" && !hasDep("sass-loader"))
|
|
148
|
-
deps.push("sass-loader");
|
|
149
|
-
if (!hasDep("sass-embedded"))
|
|
150
|
-
deps.push("sass-embedded");
|
|
151
|
-
if (useTs)
|
|
152
|
-
deps.push("typescript");
|
|
153
|
-
for (const dep of deps)
|
|
154
|
-
pkg.devDependencies[dep] = meta[dep];
|
|
155
|
-
return {
|
|
156
|
-
filepath: "package.json",
|
|
157
|
-
content: JSON.stringify(pkg, null, 2)
|
|
158
|
-
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/packageJson.ts
|
|
111
|
+
async function createPackageJson(mode, pkg, { packageManager, docsDir, siteName, siteDescription, bundler, injectNpmScripts, useTs }) {
|
|
112
|
+
if (mode === Mode.create) {
|
|
113
|
+
pkg.name = kebabCase(siteName);
|
|
114
|
+
pkg.type = "module";
|
|
115
|
+
pkg.version = "1.0.0";
|
|
116
|
+
pkg.description = siteDescription;
|
|
117
|
+
if (packageManager !== "npm") {
|
|
118
|
+
let version$1 = await getPackageManagerVersion(packageManager);
|
|
119
|
+
if (version$1) {
|
|
120
|
+
if (packageManager === "yarn" && version$1.startsWith("1")) version$1 = "4.6.0";
|
|
121
|
+
pkg.packageManager = `${packageManager}@${version$1}`;
|
|
122
|
+
if (packageManager === "pnpm" && version$1.startsWith("10")) pkg.pnpm = { onlyBuiltDependencies: ["@parcel/watcher", "esbuild"] };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const userInfo = await getUserInfo();
|
|
126
|
+
if (userInfo) pkg.author = userInfo.username + (userInfo.email ? ` <${userInfo.email}>` : "");
|
|
127
|
+
pkg.license = "MIT";
|
|
128
|
+
pkg.engines = { node: "^20.6.0 || >=22.0.0" };
|
|
129
|
+
}
|
|
130
|
+
if (injectNpmScripts) {
|
|
131
|
+
pkg.scripts ??= {};
|
|
132
|
+
pkg.scripts = {
|
|
133
|
+
...pkg.scripts,
|
|
134
|
+
"docs:dev": `vuepress dev ${docsDir}`,
|
|
135
|
+
"docs:dev-clean": `vuepress dev ${docsDir} --clean-cache --clean-temp`,
|
|
136
|
+
"docs:build": `vuepress build ${docsDir} --clean-cache --clean-temp`,
|
|
137
|
+
"docs:preview": `http-server ${docsDir}/.vuepress/dist`
|
|
138
|
+
};
|
|
139
|
+
if (mode === Mode.create) pkg.scripts["vp-update"] = `${packageManager === "npm" ? "npx" : `${packageManager} dlx`} vp-update`;
|
|
140
|
+
}
|
|
141
|
+
pkg.devDependencies ??= {};
|
|
142
|
+
const hasDep = (dep) => pkg.devDependencies?.[dep] || pkg.dependencies?.[dep];
|
|
143
|
+
const context = await readJsonFile(resolve("package.json"));
|
|
144
|
+
const meta = context["plume-deps"];
|
|
145
|
+
pkg.devDependencies[`@vuepress/bundler-${bundler}`] = `${meta.vuepress}`;
|
|
146
|
+
pkg.devDependencies.vuepress = `${meta.vuepress}`;
|
|
147
|
+
pkg.devDependencies["vuepress-theme-plume"] = `${context.version}`;
|
|
148
|
+
const deps = ["http-server"];
|
|
149
|
+
if (!hasDep("vue")) deps.push("vue");
|
|
150
|
+
if (bundler === "webpack" && !hasDep("sass-loader")) deps.push("sass-loader");
|
|
151
|
+
if (!hasDep("sass-embedded")) deps.push("sass-embedded");
|
|
152
|
+
if (useTs) deps.push("typescript");
|
|
153
|
+
for (const dep of deps) pkg.devDependencies[dep] = meta[dep];
|
|
154
|
+
return {
|
|
155
|
+
filepath: "package.json",
|
|
156
|
+
content: JSON.stringify(pkg, null, 2)
|
|
157
|
+
};
|
|
159
158
|
}
|
|
160
159
|
async function getUserInfo() {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
160
|
+
try {
|
|
161
|
+
const { output: username } = await spawn("git", [
|
|
162
|
+
"config",
|
|
163
|
+
"--global",
|
|
164
|
+
"user.name"
|
|
165
|
+
]);
|
|
166
|
+
const { output: email } = await spawn("git", [
|
|
167
|
+
"config",
|
|
168
|
+
"--global",
|
|
169
|
+
"user.email"
|
|
170
|
+
]);
|
|
171
|
+
console.log("userInfo", username, email);
|
|
172
|
+
return {
|
|
173
|
+
username,
|
|
174
|
+
email
|
|
175
|
+
};
|
|
176
|
+
} catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
168
179
|
}
|
|
169
180
|
async function getPackageManagerVersion(pkg) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
181
|
+
try {
|
|
182
|
+
const { output } = await spawn(pkg, ["--version"]);
|
|
183
|
+
return output;
|
|
184
|
+
} catch {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
176
187
|
}
|
|
177
188
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
handlebars.registerHelper("removeLeadingSlash", (path5) => path5.replace(/^\//, ""));
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/render.ts
|
|
191
|
+
handlebars.registerHelper("removeLeadingSlash", (path$1) => path$1.replace(/^\//, ""));
|
|
182
192
|
handlebars.registerHelper("equal", (a, b) => a === b);
|
|
183
193
|
function createRender(result) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
194
|
+
const data = {
|
|
195
|
+
...result,
|
|
196
|
+
name: kebabCase(result.siteName),
|
|
197
|
+
isEN: result.defaultLanguage === "en-US",
|
|
198
|
+
locales: result.defaultLanguage === "en-US" ? [{
|
|
199
|
+
path: "/",
|
|
200
|
+
lang: "en-US",
|
|
201
|
+
isEn: true,
|
|
202
|
+
prefix: "en"
|
|
203
|
+
}, {
|
|
204
|
+
path: "/zh/",
|
|
205
|
+
lang: "zh-CN",
|
|
206
|
+
isEn: false,
|
|
207
|
+
prefix: "zh"
|
|
208
|
+
}] : [{
|
|
209
|
+
path: "/",
|
|
210
|
+
lang: "zh-CN",
|
|
211
|
+
isEn: false,
|
|
212
|
+
prefix: "zh"
|
|
213
|
+
}, {
|
|
214
|
+
path: "/en/",
|
|
215
|
+
lang: "en-US",
|
|
216
|
+
isEn: true,
|
|
217
|
+
prefix: "en"
|
|
218
|
+
}]
|
|
219
|
+
};
|
|
220
|
+
return function render(source) {
|
|
221
|
+
try {
|
|
222
|
+
const template = handlebars.compile(source);
|
|
223
|
+
return template(data);
|
|
224
|
+
} catch (e) {
|
|
225
|
+
console.error(e);
|
|
226
|
+
return source;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
205
229
|
}
|
|
206
230
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
filepath: ".yarnrc.yml",
|
|
268
|
-
content: "nodeLinker: 'node-modules'\n"
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
if (data.deploy !== "custom" /* custom */) {
|
|
272
|
-
fileList.push(...await readFiles(getTemplate(`deploy/${data.deploy}`)));
|
|
273
|
-
}
|
|
274
|
-
const render = createRender(data);
|
|
275
|
-
const renderedFiles = fileList.map((file) => {
|
|
276
|
-
if (file.filepath.endsWith(".handlebars"))
|
|
277
|
-
file.content = render(file.content);
|
|
278
|
-
return file;
|
|
279
|
-
});
|
|
280
|
-
const ext = data.useTs ? "" : userPkg.type !== "module" ? ".mjs" : ".js";
|
|
281
|
-
const REG_EXT = /\.ts$/;
|
|
282
|
-
const output = mode === 1 /* create */ ? path3.join(cwd, data.root) : cwd;
|
|
283
|
-
await writeFiles(renderedFiles, output, (filepath) => {
|
|
284
|
-
if (filepath.endsWith(".d.ts"))
|
|
285
|
-
return filepath;
|
|
286
|
-
if (ext)
|
|
287
|
-
return filepath.replace(REG_EXT, ext);
|
|
288
|
-
return filepath;
|
|
289
|
-
});
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/generate.ts
|
|
233
|
+
async function generate(mode, data, cwd = process.cwd()) {
|
|
234
|
+
let userPkg = {};
|
|
235
|
+
if (mode === Mode.init) {
|
|
236
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
237
|
+
if (fs.existsSync(pkgPath)) userPkg = await readJsonFile(pkgPath) || {};
|
|
238
|
+
}
|
|
239
|
+
const fileList = [
|
|
240
|
+
await createPackageJson(mode, userPkg, data),
|
|
241
|
+
...await createDocsFiles(data),
|
|
242
|
+
...updateFileListTarget(await readFiles(getTemplate(".vuepress")), `${data.docsDir}/.vuepress`)
|
|
243
|
+
];
|
|
244
|
+
if (mode === Mode.create) {
|
|
245
|
+
fileList.push(...await readFiles(getTemplate("common")));
|
|
246
|
+
if (data.packageManager === "pnpm") fileList.push({
|
|
247
|
+
filepath: ".npmrc",
|
|
248
|
+
content: "shamefully-hoist=true\nshell-emulator=true"
|
|
249
|
+
});
|
|
250
|
+
if (data.packageManager === "yarn") {
|
|
251
|
+
const { output: output$1 } = await spawn("yarn", ["--version"]);
|
|
252
|
+
if (output$1.startsWith("2")) fileList.push({
|
|
253
|
+
filepath: ".yarnrc.yml",
|
|
254
|
+
content: "nodeLinker: 'node-modules'\n"
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (data.git) {
|
|
259
|
+
const gitFiles = await readFiles(getTemplate("git"));
|
|
260
|
+
if (mode === Mode.init) {
|
|
261
|
+
const gitignorePath = path.join(cwd, ".gitignore");
|
|
262
|
+
const docs = data.docsDir;
|
|
263
|
+
if (fs.existsSync(gitignorePath)) {
|
|
264
|
+
const content = await fs.promises.readFile(gitignorePath, "utf-8");
|
|
265
|
+
fileList.push({
|
|
266
|
+
filepath: ".gitignore",
|
|
267
|
+
content: `${content}\n${docs}/.vuepress/.cache\n${docs}/.vuepress/.temp\n${docs}/.vuepress/dist\n`
|
|
268
|
+
});
|
|
269
|
+
fileList.push(...gitFiles.filter(({ filepath }) => filepath !== ".gitignore"));
|
|
270
|
+
} else fileList.push(...gitFiles);
|
|
271
|
+
} else fileList.push(...gitFiles);
|
|
272
|
+
}
|
|
273
|
+
if (data.packageManager === "yarn") fileList.push({
|
|
274
|
+
filepath: ".yarnrc.yml",
|
|
275
|
+
content: "nodeLinker: 'node-modules'\n"
|
|
276
|
+
});
|
|
277
|
+
if (data.deploy !== DeployType.custom) fileList.push(...await readFiles(getTemplate(`deploy/${data.deploy}`)));
|
|
278
|
+
const render = createRender(data);
|
|
279
|
+
const renderedFiles = fileList.map((file) => {
|
|
280
|
+
if (file.filepath.endsWith(".handlebars")) file.content = render(file.content);
|
|
281
|
+
return file;
|
|
282
|
+
});
|
|
283
|
+
const ext = data.useTs ? "" : userPkg.type !== "module" ? ".mjs" : ".js";
|
|
284
|
+
const REG_EXT = /\.ts$/;
|
|
285
|
+
const output = mode === Mode.create ? path.join(cwd, data.root) : cwd;
|
|
286
|
+
await writeFiles(renderedFiles, output, (filepath) => {
|
|
287
|
+
if (filepath.endsWith(".d.ts")) return filepath;
|
|
288
|
+
if (ext) return filepath.replace(REG_EXT, ext);
|
|
289
|
+
return filepath;
|
|
290
|
+
});
|
|
290
291
|
}
|
|
291
292
|
async function createDocsFiles(data) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
else
|
|
307
|
-
fileList.push(...await readFiles(getTemplate("docs/zh")));
|
|
308
|
-
}
|
|
309
|
-
return updateFileListTarget(fileList, data.docsDir);
|
|
293
|
+
const fileList = [];
|
|
294
|
+
if (data.multiLanguage) {
|
|
295
|
+
const enDocs = await readFiles(getTemplate("docs/en"));
|
|
296
|
+
const zhDocs = await readFiles(getTemplate("docs/zh"));
|
|
297
|
+
if (data.defaultLanguage === "en-US") {
|
|
298
|
+
fileList.push(...enDocs);
|
|
299
|
+
fileList.push(...updateFileListTarget(zhDocs, "zh"));
|
|
300
|
+
} else {
|
|
301
|
+
fileList.push(...zhDocs);
|
|
302
|
+
fileList.push(...updateFileListTarget(enDocs, "en"));
|
|
303
|
+
}
|
|
304
|
+
} else if (data.defaultLanguage === "en-US") fileList.push(...await readFiles(getTemplate("docs/en")));
|
|
305
|
+
else fileList.push(...await readFiles(getTemplate("docs/zh")));
|
|
306
|
+
return updateFileListTarget(fileList, data.docsDir);
|
|
310
307
|
}
|
|
311
308
|
function updateFileListTarget(fileList, target) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
309
|
+
return fileList.map(({ filepath, content }) => ({
|
|
310
|
+
filepath: path.join(target, filepath),
|
|
311
|
+
content
|
|
312
|
+
}));
|
|
316
313
|
}
|
|
317
314
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
"spinner.install": "\u{1F4E6} Installing dependencies...",
|
|
341
|
-
"spinner.command": "\u{1F528} Execute the following command to start:",
|
|
342
|
-
"hint.cancel": "Operation cancelled.",
|
|
343
|
-
"hint.root": "The path cannot be an absolute path, and cannot contain the parent path.",
|
|
344
|
-
"hint.root.illegal": "Project names cannot contain special characters."
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/locales/en.ts
|
|
317
|
+
const en = {
|
|
318
|
+
"question.root": "Where would you want to initialize VuePress?",
|
|
319
|
+
"question.site.name": "Site Name:",
|
|
320
|
+
"question.site.description": "Site Description:",
|
|
321
|
+
"question.bundler": "Select a bundler",
|
|
322
|
+
"question.multiLanguage": "Do you want to use multiple languages?",
|
|
323
|
+
"question.defaultLanguage": "Select the default language of the site",
|
|
324
|
+
"question.useTs": "Use TypeScript?",
|
|
325
|
+
"question.injectNpmScripts": "Inject npm scripts?",
|
|
326
|
+
"question.deploy": "Deploy type:",
|
|
327
|
+
"question.git": "Initialize a git repository?",
|
|
328
|
+
"question.installDeps": "Install dependencies?",
|
|
329
|
+
"spinner.start": "🚀 Creating...",
|
|
330
|
+
"spinner.stop": "🎉 Create success!",
|
|
331
|
+
"spinner.git": "📄 Initializing git repository...",
|
|
332
|
+
"spinner.install": "📦 Installing dependencies...",
|
|
333
|
+
"spinner.command": "🔨 Execute the following command to start:",
|
|
334
|
+
"hint.cancel": "Operation cancelled.",
|
|
335
|
+
"hint.root": "The path cannot be an absolute path, and cannot contain the parent path.",
|
|
336
|
+
"hint.root.illegal": "Project names cannot contain special characters."
|
|
345
337
|
};
|
|
346
338
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/locales/zh.ts
|
|
341
|
+
const zh = {
|
|
342
|
+
"question.root": "您想在哪里初始化 VuePress?",
|
|
343
|
+
"question.site.name": "站点名称:",
|
|
344
|
+
"question.site.description": "站点描述信息:",
|
|
345
|
+
"question.bundler": "请选择打包工具",
|
|
346
|
+
"question.multiLanguage": "是否使用多语言?",
|
|
347
|
+
"question.defaultLanguage": "请选择站点默认语言",
|
|
348
|
+
"question.useTs": "是否使用 TypeScript?",
|
|
349
|
+
"question.injectNpmScripts": "是否注入 npm 脚本?",
|
|
350
|
+
"question.deploy": "部署方式:",
|
|
351
|
+
"question.git": "是否初始化 git 仓库?",
|
|
352
|
+
"question.installDeps": "是否安装依赖?",
|
|
353
|
+
"spinner.start": "🚀 正在创建...",
|
|
354
|
+
"spinner.stop": "🎉 创建成功!",
|
|
355
|
+
"spinner.git": "📄 初始化 git 仓库...",
|
|
356
|
+
"spinner.install": "📦 安装依赖...",
|
|
357
|
+
"spinner.command": "🔨 执行以下命令即可启动:",
|
|
358
|
+
"hint.cancel": "操作已取消。",
|
|
359
|
+
"hint.root": "文件路径不能是绝对路径,不能包含父路径。",
|
|
360
|
+
"hint.root.illegal": "文件夹不能包含特殊字符。"
|
|
368
361
|
};
|
|
369
362
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/locales/index.ts
|
|
365
|
+
const locales = {
|
|
366
|
+
"zh-CN": zh,
|
|
367
|
+
"en-US": en
|
|
374
368
|
};
|
|
375
369
|
|
|
376
|
-
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/translate.ts
|
|
377
372
|
function createTranslate(lang) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
373
|
+
let current = lang || "en-US";
|
|
374
|
+
return {
|
|
375
|
+
setLang: (lang$1) => {
|
|
376
|
+
current = lang$1;
|
|
377
|
+
},
|
|
378
|
+
t: (key) => locales[current][key]
|
|
379
|
+
};
|
|
385
380
|
}
|
|
386
|
-
|
|
381
|
+
const translate = createTranslate();
|
|
382
|
+
const t = translate.t;
|
|
383
|
+
const setLang = translate.setLang;
|
|
387
384
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/prompt.ts
|
|
387
|
+
const require = createRequire(process.cwd());
|
|
388
|
+
const REG_DIR_CHAR = /[<>:"\\|?*[\]]/;
|
|
391
389
|
async function prompt(mode, root) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
return false;
|
|
486
|
-
return confirm({
|
|
487
|
-
message: t("question.git"),
|
|
488
|
-
initialValue: true
|
|
489
|
-
});
|
|
490
|
-
},
|
|
491
|
-
install: () => confirm({
|
|
492
|
-
message: t("question.installDeps"),
|
|
493
|
-
initialValue: true
|
|
494
|
-
})
|
|
495
|
-
}, {
|
|
496
|
-
onCancel: () => {
|
|
497
|
-
cancel(t("hint.cancel"));
|
|
498
|
-
process3.exit(0);
|
|
499
|
-
}
|
|
500
|
-
});
|
|
501
|
-
return result;
|
|
390
|
+
let hasTs = false;
|
|
391
|
+
if (mode === Mode.init) try {
|
|
392
|
+
hasTs = !!require.resolve("typescript");
|
|
393
|
+
} catch {}
|
|
394
|
+
const result = await group({
|
|
395
|
+
displayLang: async () => {
|
|
396
|
+
const locale = await osLocale();
|
|
397
|
+
if (locale === "zh-CN" || locale === "zh-Hans") {
|
|
398
|
+
setLang("zh-CN");
|
|
399
|
+
return "zh-CN";
|
|
400
|
+
}
|
|
401
|
+
if (locale === "en-US") {
|
|
402
|
+
setLang("en-US");
|
|
403
|
+
return "en-US";
|
|
404
|
+
}
|
|
405
|
+
const lang = await select({
|
|
406
|
+
message: "Select a language to display / 选择显示语言",
|
|
407
|
+
options: languageOptions
|
|
408
|
+
});
|
|
409
|
+
if (typeof lang === "string") setLang(lang);
|
|
410
|
+
return lang;
|
|
411
|
+
},
|
|
412
|
+
root: async () => {
|
|
413
|
+
if (root) return root;
|
|
414
|
+
const DEFAULT_ROOT = mode === Mode.init ? "./docs" : "./my-project";
|
|
415
|
+
return await text({
|
|
416
|
+
message: t("question.root"),
|
|
417
|
+
placeholder: DEFAULT_ROOT,
|
|
418
|
+
validate(value) {
|
|
419
|
+
if (value?.startsWith("/") || value?.startsWith("..")) return t("hint.root");
|
|
420
|
+
if (value && REG_DIR_CHAR.test(value)) return t("hint.root.illegal");
|
|
421
|
+
return void 0;
|
|
422
|
+
},
|
|
423
|
+
defaultValue: DEFAULT_ROOT
|
|
424
|
+
});
|
|
425
|
+
},
|
|
426
|
+
siteName: () => text({
|
|
427
|
+
message: t("question.site.name"),
|
|
428
|
+
placeholder: "My Vuepress Site",
|
|
429
|
+
defaultValue: "My Vuepress Site"
|
|
430
|
+
}),
|
|
431
|
+
siteDescription: () => text({ message: t("question.site.description") }),
|
|
432
|
+
multiLanguage: () => confirm({
|
|
433
|
+
message: t("question.multiLanguage"),
|
|
434
|
+
initialValue: false
|
|
435
|
+
}),
|
|
436
|
+
defaultLanguage: () => select({
|
|
437
|
+
message: t("question.defaultLanguage"),
|
|
438
|
+
options: languageOptions
|
|
439
|
+
}),
|
|
440
|
+
useTs: async () => {
|
|
441
|
+
if (mode === Mode.init) return hasTs;
|
|
442
|
+
if (hasTs) return true;
|
|
443
|
+
return await confirm({
|
|
444
|
+
message: t("question.useTs"),
|
|
445
|
+
initialValue: true
|
|
446
|
+
});
|
|
447
|
+
},
|
|
448
|
+
injectNpmScripts: async () => {
|
|
449
|
+
if (mode === Mode.create) return true;
|
|
450
|
+
return await confirm({
|
|
451
|
+
message: t("question.injectNpmScripts"),
|
|
452
|
+
initialValue: true
|
|
453
|
+
});
|
|
454
|
+
},
|
|
455
|
+
bundler: () => select({
|
|
456
|
+
message: t("question.bundler"),
|
|
457
|
+
options: bundlerOptions
|
|
458
|
+
}),
|
|
459
|
+
deploy: async () => {
|
|
460
|
+
if (mode === Mode.init) return DeployType.custom;
|
|
461
|
+
return await select({
|
|
462
|
+
message: t("question.deploy"),
|
|
463
|
+
options: deployOptions,
|
|
464
|
+
initialValue: DeployType.custom
|
|
465
|
+
});
|
|
466
|
+
},
|
|
467
|
+
git: async () => {
|
|
468
|
+
if (mode === Mode.init) return false;
|
|
469
|
+
return confirm({
|
|
470
|
+
message: t("question.git"),
|
|
471
|
+
initialValue: true
|
|
472
|
+
});
|
|
473
|
+
},
|
|
474
|
+
install: () => confirm({
|
|
475
|
+
message: t("question.installDeps"),
|
|
476
|
+
initialValue: true
|
|
477
|
+
})
|
|
478
|
+
}, { onCancel: () => {
|
|
479
|
+
cancel(t("hint.cancel"));
|
|
480
|
+
process.exit(0);
|
|
481
|
+
} });
|
|
482
|
+
return result;
|
|
502
483
|
}
|
|
503
484
|
|
|
504
|
-
|
|
485
|
+
//#endregion
|
|
486
|
+
//#region src/run.ts
|
|
505
487
|
async function run(mode, root) {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const installCommand = colors.green(`${pm} install`);
|
|
544
|
-
progress.stop(t("spinner.stop"));
|
|
545
|
-
if (mode === 1 /* create */) {
|
|
546
|
-
outro(`${t("spinner.command")}
|
|
488
|
+
intro(colors.cyan("Welcome to VuePress and vuepress-theme-plume !"));
|
|
489
|
+
const result = await prompt(mode, root);
|
|
490
|
+
const data = resolveData(result, mode);
|
|
491
|
+
const progress = spinner();
|
|
492
|
+
progress.start(t("spinner.start"));
|
|
493
|
+
try {
|
|
494
|
+
await generate(mode, data);
|
|
495
|
+
} catch (e) {
|
|
496
|
+
console.error(`${colors.red("generate files error: ")}\n`, e);
|
|
497
|
+
process.exit(1);
|
|
498
|
+
}
|
|
499
|
+
await sleep(200);
|
|
500
|
+
const cwd = path.join(process.cwd(), data.root);
|
|
501
|
+
if (data.git) {
|
|
502
|
+
progress.message(t("spinner.git"));
|
|
503
|
+
try {
|
|
504
|
+
await spawn("git", ["init"], { cwd });
|
|
505
|
+
} catch (e) {
|
|
506
|
+
console.error(`${colors.red("git init error: ")}\n`, e);
|
|
507
|
+
process.exit(1);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const pm = data.packageManager;
|
|
511
|
+
if (data.install) {
|
|
512
|
+
progress.message(t("spinner.install"));
|
|
513
|
+
try {
|
|
514
|
+
await spawn(pm, ["install"], { cwd });
|
|
515
|
+
} catch (e) {
|
|
516
|
+
console.error(`${colors.red("install dependencies error: ")}\n`, e);
|
|
517
|
+
process.exit(1);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const cdCommand = mode === Mode.create ? colors.green(`cd ${data.root}`) : "";
|
|
521
|
+
const runCommand = colors.green(`${pm} run docs:dev`);
|
|
522
|
+
const installCommand = colors.green(`${pm} install`);
|
|
523
|
+
progress.stop(t("spinner.stop"));
|
|
524
|
+
if (mode === Mode.create) outro(`${t("spinner.command")}
|
|
547
525
|
${cdCommand}
|
|
548
526
|
${data.install ? "" : `${installCommand} && `}${runCommand}`);
|
|
549
|
-
}
|
|
550
527
|
}
|
|
551
528
|
function resolveData(result, mode) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
529
|
+
return {
|
|
530
|
+
...result,
|
|
531
|
+
packageManager: getPackageManager(),
|
|
532
|
+
docsDir: mode === Mode.create ? "docs" : result.root.replace(/^\.\//, "").replace(/\/$/, ""),
|
|
533
|
+
siteDescription: result.siteDescription || ""
|
|
534
|
+
};
|
|
558
535
|
}
|
|
559
536
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
cli
|
|
563
|
-
cli.command("
|
|
537
|
+
//#endregion
|
|
538
|
+
//#region src/index.ts
|
|
539
|
+
const cli = cac("create-vuepress-theme-plume");
|
|
540
|
+
cli.command("[root]", "create a new vuepress-theme-plume project / 创建新的 vuepress-theme-plume 项目").action((root) => run(Mode.create, root));
|
|
541
|
+
cli.command("init [root]", "Initial vuepress-theme-plume in the existing project / 在现有项目中初始化 vuepress-theme-plume").action((root) => run(Mode.init, root));
|
|
564
542
|
cli.help();
|
|
565
|
-
cli.version(
|
|
543
|
+
cli.version(version);
|
|
566
544
|
cli.parse();
|
|
545
|
+
|
|
546
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-vuepress-theme-plume",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.148",
|
|
5
5
|
"description": "The cli for create vuepress-theme-plume's project",
|
|
6
6
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo/)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,20 +30,20 @@
|
|
|
30
30
|
"@clack/prompts": "^0.10.1",
|
|
31
31
|
"@pengzhanbo/utils": "^2.1.0",
|
|
32
32
|
"cac": "^6.7.14",
|
|
33
|
-
"execa": "^9.5.2",
|
|
34
33
|
"handlebars": "^4.7.8",
|
|
34
|
+
"nano-spawn": "^1.0.1",
|
|
35
35
|
"os-locale": "^6.0.2",
|
|
36
36
|
"picocolors": "^1.1.1"
|
|
37
37
|
},
|
|
38
38
|
"plume-deps": {
|
|
39
39
|
"vuepress": "2.0.0-rc.22",
|
|
40
40
|
"vue": "^3.5.13",
|
|
41
|
-
"sass-embedded": "^1.
|
|
41
|
+
"sass-embedded": "^1.88.0",
|
|
42
42
|
"sass-loader": "^16.0.5",
|
|
43
43
|
"http-server": "^14.1.1",
|
|
44
44
|
"typescript": "^5.8.3"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "
|
|
47
|
+
"build": "tsdown"
|
|
48
48
|
}
|
|
49
49
|
}
|