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 CHANGED
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export { };
package/lib/index.js CHANGED
@@ -1,566 +1,546 @@
1
- // src/index.ts
1
+ import { createRequire } from "node:module";
2
2
  import cac from "cac";
3
-
4
- // src/constants.ts
5
- var languageOptions = [
6
- { label: "English", value: "en-US" },
7
- { label: "\u7B80\u4F53\u4E2D\u6587", value: "zh-CN" }
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
- // src/generate.ts
29
- import fs2 from "node:fs";
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
- // src/utils/index.ts
39
- import path2 from "node:path";
40
- import { fileURLToPath } from "node:url";
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
- // src/utils/fs.ts
43
- import fs from "node:fs/promises";
44
- import path from "node:path";
65
+ //#endregion
66
+ //#region src/utils/fs.ts
45
67
  async function readFiles(root) {
46
- const filepaths = await fs.readdir(root, { recursive: true });
47
- const files = [];
48
- for (const file of filepaths) {
49
- const filepath = path.join(root, file);
50
- if ((await fs.stat(filepath)).isFile()) {
51
- files.push({
52
- filepath: file,
53
- content: await fs.readFile(filepath, "utf-8")
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
- for (const { filepath, content } of files) {
61
- let root = path.join(target, filepath).replace(/\.handlebars$/, "");
62
- if (rewrite)
63
- root = rewrite(root);
64
- await fs.mkdir(path.dirname(root), { recursive: true });
65
- await fs.writeFile(root, content);
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
- try {
70
- const content = await fs.readFile(filepath, "utf-8");
71
- return JSON.parse(content);
72
- } catch {
73
- return null;
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
- // src/utils/getPackageManager.ts
78
- import process from "node:process";
96
+ //#endregion
97
+ //#region src/utils/getPackageManager.ts
79
98
  function getPackageManager() {
80
- const name = process.env?.npm_config_user_agent || "npm";
81
- return name.split("/")[0];
99
+ const name = process.env?.npm_config_user_agent || "npm";
100
+ return name.split("/")[0];
82
101
  }
83
102
 
84
- // src/utils/index.ts
85
- var __dirname = path2.dirname(fileURLToPath(import.meta.url));
86
- var resolve = (...args) => path2.resolve(__dirname, "../", ...args);
87
- var getTemplate = (dir) => resolve("templates", dir);
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
- // src/packageJson.ts
90
- async function createPackageJson(mode, pkg, {
91
- packageManager,
92
- docsDir,
93
- siteName,
94
- siteDescription,
95
- bundler,
96
- injectNpmScripts,
97
- useTs
98
- }) {
99
- if (mode === 1 /* create */) {
100
- pkg.name = kebabCase(siteName);
101
- pkg.type = "module";
102
- pkg.version = "1.0.0";
103
- pkg.description = siteDescription;
104
- if (packageManager !== "npm") {
105
- let version = await getPackageManagerVersion(packageManager);
106
- if (version) {
107
- if (packageManager === "yarn" && version.startsWith("1"))
108
- version = "4.6.0";
109
- pkg.packageManager = `${packageManager}@${version}`;
110
- if (packageManager === "pnpm" && version.startsWith("10")) {
111
- pkg.pnpm = {
112
- onlyBuiltDependencies: ["@parcel/watcher", "esbuild"]
113
- };
114
- }
115
- }
116
- }
117
- const userInfo = await getUserInfo();
118
- if (userInfo) {
119
- pkg.author = userInfo.username + (userInfo.email ? ` <${userInfo.email}>` : "");
120
- }
121
- pkg.license = "MIT";
122
- pkg.engines = { node: "^20.6.0 || >=22.0.0" };
123
- }
124
- if (injectNpmScripts) {
125
- pkg.scripts ??= {};
126
- pkg.scripts = {
127
- ...pkg.scripts,
128
- "docs:dev": `vuepress dev ${docsDir}`,
129
- "docs:dev-clean": `vuepress dev ${docsDir} --clean-cache --clean-temp`,
130
- "docs:build": `vuepress build ${docsDir} --clean-cache --clean-temp`,
131
- "docs:preview": `http-server ${docsDir}/.vuepress/dist`
132
- };
133
- if (mode === 1 /* create */) {
134
- pkg.scripts["vp-update"] = `${packageManager === "npm" ? "npx" : `${packageManager} dlx`} vp-update`;
135
- }
136
- }
137
- pkg.devDependencies ??= {};
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
- try {
162
- const { stdout: username } = await execaCommand("git config --global user.name");
163
- const { stdout: email } = await execaCommand("git config --global user.email");
164
- return { username, email };
165
- } catch {
166
- return null;
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
- try {
171
- const { stdout } = await execaCommand(`${pkg} -v`);
172
- return stdout;
173
- } catch {
174
- return null;
175
- }
181
+ try {
182
+ const { output } = await spawn(pkg, ["--version"]);
183
+ return output;
184
+ } catch {
185
+ return null;
186
+ }
176
187
  }
177
188
 
178
- // src/render.ts
179
- import { kebabCase as kebabCase2 } from "@pengzhanbo/utils";
180
- import handlebars from "handlebars";
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
- const data = {
185
- ...result,
186
- name: kebabCase2(result.siteName),
187
- isEN: result.defaultLanguage === "en-US",
188
- locales: result.defaultLanguage === "en-US" ? [
189
- { path: "/", lang: "en-US", isEn: true, prefix: "en" },
190
- { path: "/zh/", lang: "zh-CN", isEn: false, prefix: "zh" }
191
- ] : [
192
- { path: "/", lang: "zh-CN", isEn: false, prefix: "zh" },
193
- { path: "/en/", lang: "en-US", isEn: true, prefix: "en" }
194
- ]
195
- };
196
- return function render(source) {
197
- try {
198
- const template = handlebars.compile(source);
199
- return template(data);
200
- } catch (e) {
201
- console.error(e);
202
- return source;
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
- // src/generate.ts
208
- async function generate(mode, data, cwd = process2.cwd()) {
209
- let userPkg = {};
210
- if (mode === 0 /* init */) {
211
- const pkgPath = path3.join(cwd, "package.json");
212
- if (fs2.existsSync(pkgPath)) {
213
- userPkg = await readJsonFile(pkgPath) || {};
214
- }
215
- }
216
- const fileList = [
217
- // add package.json
218
- await createPackageJson(mode, userPkg, data),
219
- // add docs files
220
- ...await createDocsFiles(data),
221
- // add vuepress and theme-plume configs
222
- ...updateFileListTarget(await readFiles(getTemplate(".vuepress")), `${data.docsDir}/.vuepress`)
223
- ];
224
- if (mode === 1 /* create */) {
225
- fileList.push(...await readFiles(getTemplate("common")));
226
- if (data.packageManager === "pnpm") {
227
- fileList.push({
228
- filepath: ".npmrc",
229
- content: "shamefully-hoist=true\nshell-emulator=true"
230
- });
231
- }
232
- if (data.packageManager === "yarn") {
233
- const { stdout: yarnVersion } = await execaCommand2("yarn --version");
234
- if (yarnVersion.startsWith("2")) {
235
- fileList.push({
236
- filepath: ".yarnrc.yml",
237
- content: "nodeLinker: 'node-modules'\n"
238
- });
239
- }
240
- }
241
- }
242
- if (data.git) {
243
- const gitFiles = await readFiles(getTemplate("git"));
244
- if (mode === 0 /* init */) {
245
- const gitignorePath = path3.join(cwd, ".gitignore");
246
- const docs = data.docsDir;
247
- if (fs2.existsSync(gitignorePath)) {
248
- const content = await fs2.promises.readFile(gitignorePath, "utf-8");
249
- fileList.push({
250
- filepath: ".gitignore",
251
- content: `${content}
252
- ${docs}/.vuepress/.cache
253
- ${docs}/.vuepress/.temp
254
- ${docs}/.vuepress/dist
255
- `
256
- });
257
- fileList.push(...gitFiles.filter(({ filepath }) => filepath !== ".gitignore"));
258
- } else {
259
- fileList.push(...gitFiles);
260
- }
261
- } else {
262
- fileList.push(...gitFiles);
263
- }
264
- }
265
- if (data.packageManager === "yarn") {
266
- fileList.push({
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
- const fileList = [];
293
- if (data.multiLanguage) {
294
- const enDocs = await readFiles(getTemplate("docs/en"));
295
- const zhDocs = await readFiles(getTemplate("docs/zh"));
296
- if (data.defaultLanguage === "en-US") {
297
- fileList.push(...enDocs);
298
- fileList.push(...updateFileListTarget(zhDocs, "zh"));
299
- } else {
300
- fileList.push(...zhDocs);
301
- fileList.push(...updateFileListTarget(enDocs, "en"));
302
- }
303
- } else {
304
- if (data.defaultLanguage === "en-US")
305
- fileList.push(...await readFiles(getTemplate("docs/en")));
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
- return fileList.map(({ filepath, content }) => ({
313
- filepath: path3.join(target, filepath),
314
- content
315
- }));
309
+ return fileList.map(({ filepath, content }) => ({
310
+ filepath: path.join(target, filepath),
311
+ content
312
+ }));
316
313
  }
317
314
 
318
- // src/prompt.ts
319
- import { createRequire } from "node:module";
320
- import process3 from "node:process";
321
- import { cancel, confirm, group, select, text } from "@clack/prompts";
322
- import { osLocale } from "os-locale";
323
-
324
- // src/locales/en.ts
325
- var en = {
326
- "question.root": "Where would you want to initialize VuePress?",
327
- "question.site.name": "Site Name:",
328
- "question.site.description": "Site Description:",
329
- "question.bundler": "Select a bundler",
330
- "question.multiLanguage": "Do you want to use multiple languages?",
331
- "question.defaultLanguage": "Select the default language of the site",
332
- "question.useTs": "Use TypeScript?",
333
- "question.injectNpmScripts": "Inject npm scripts?",
334
- "question.deploy": "Deploy type:",
335
- "question.git": "Initialize a git repository?",
336
- "question.installDeps": "Install dependencies?",
337
- "spinner.start": "\u{1F680} Creating...",
338
- "spinner.stop": "\u{1F389} Create success!",
339
- "spinner.git": "\u{1F4C4} Initializing git repository...",
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
- // src/locales/zh.ts
348
- var zh = {
349
- "question.root": "\u60A8\u60F3\u5728\u54EA\u91CC\u521D\u59CB\u5316 VuePress\uFF1F",
350
- "question.site.name": "\u7AD9\u70B9\u540D\u79F0\uFF1A",
351
- "question.site.description": "\u7AD9\u70B9\u63CF\u8FF0\u4FE1\u606F\uFF1A",
352
- "question.bundler": "\u8BF7\u9009\u62E9\u6253\u5305\u5DE5\u5177",
353
- "question.multiLanguage": "\u662F\u5426\u4F7F\u7528\u591A\u8BED\u8A00\uFF1F",
354
- "question.defaultLanguage": "\u8BF7\u9009\u62E9\u7AD9\u70B9\u9ED8\u8BA4\u8BED\u8A00",
355
- "question.useTs": "\u662F\u5426\u4F7F\u7528 TypeScript\uFF1F",
356
- "question.injectNpmScripts": "\u662F\u5426\u6CE8\u5165 npm \u811A\u672C\uFF1F",
357
- "question.deploy": "\u90E8\u7F72\u65B9\u5F0F\uFF1A",
358
- "question.git": "\u662F\u5426\u521D\u59CB\u5316 git \u4ED3\u5E93\uFF1F",
359
- "question.installDeps": "\u662F\u5426\u5B89\u88C5\u4F9D\u8D56\uFF1F",
360
- "spinner.start": "\u{1F680} \u6B63\u5728\u521B\u5EFA...",
361
- "spinner.stop": "\u{1F389} \u521B\u5EFA\u6210\u529F!",
362
- "spinner.git": "\u{1F4C4} \u521D\u59CB\u5316 git \u4ED3\u5E93...",
363
- "spinner.install": "\u{1F4E6} \u5B89\u88C5\u4F9D\u8D56...",
364
- "spinner.command": "\u{1F528} \u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u5373\u53EF\u542F\u52A8\uFF1A",
365
- "hint.cancel": "\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002",
366
- "hint.root": "\u6587\u4EF6\u8DEF\u5F84\u4E0D\u80FD\u662F\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u4E0D\u80FD\u5305\u542B\u7236\u8DEF\u5F84\u3002",
367
- "hint.root.illegal": "\u6587\u4EF6\u5939\u4E0D\u80FD\u5305\u542B\u7279\u6B8A\u5B57\u7B26\u3002"
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
- // src/locales/index.ts
371
- var locales = {
372
- "zh-CN": zh,
373
- "en-US": en
363
+ //#endregion
364
+ //#region src/locales/index.ts
365
+ const locales = {
366
+ "zh-CN": zh,
367
+ "en-US": en
374
368
  };
375
369
 
376
- // src/translate.ts
370
+ //#endregion
371
+ //#region src/translate.ts
377
372
  function createTranslate(lang) {
378
- let current = lang || "en-US";
379
- return {
380
- setLang: (lang2) => {
381
- current = lang2;
382
- },
383
- t: (key) => locales[current][key]
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
- var { t, setLang } = createTranslate();
381
+ const translate = createTranslate();
382
+ const t = translate.t;
383
+ const setLang = translate.setLang;
387
384
 
388
- // src/prompt.ts
389
- var require2 = createRequire(process3.cwd());
390
- var REG_DIR_CHAR = /[<>:"\\|?*[\]]/;
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
- let hasTs = false;
393
- if (mode === 0 /* init */) {
394
- try {
395
- hasTs = !!require2.resolve("typescript");
396
- } catch {
397
- }
398
- }
399
- const result = await group({
400
- displayLang: async () => {
401
- const locale = await osLocale();
402
- if (locale === "zh-CN" || locale === "zh-Hans") {
403
- setLang("zh-CN");
404
- return "zh-CN";
405
- }
406
- if (locale === "en-US") {
407
- setLang("en-US");
408
- return "en-US";
409
- }
410
- const lang = await select({
411
- message: "Select a language to display / \u9009\u62E9\u663E\u793A\u8BED\u8A00",
412
- options: languageOptions
413
- });
414
- if (typeof lang === "string")
415
- setLang(lang);
416
- return lang;
417
- },
418
- root: async () => {
419
- if (root)
420
- return root;
421
- const DEFAULT_ROOT = mode === 0 /* init */ ? "./docs" : "./my-project";
422
- return await text({
423
- message: t("question.root"),
424
- placeholder: DEFAULT_ROOT,
425
- validate(value) {
426
- if (value?.startsWith("/") || value?.startsWith(".."))
427
- return t("hint.root");
428
- if (value && REG_DIR_CHAR.test(value))
429
- return t("hint.root.illegal");
430
- return void 0;
431
- },
432
- defaultValue: DEFAULT_ROOT
433
- });
434
- },
435
- siteName: () => text({
436
- message: t("question.site.name"),
437
- placeholder: "My Vuepress Site",
438
- defaultValue: "My Vuepress Site"
439
- }),
440
- siteDescription: () => text({
441
- message: t("question.site.description")
442
- }),
443
- multiLanguage: () => confirm({
444
- message: t("question.multiLanguage"),
445
- initialValue: false
446
- }),
447
- defaultLanguage: () => select({
448
- message: t("question.defaultLanguage"),
449
- options: languageOptions
450
- }),
451
- useTs: async () => {
452
- if (mode === 0 /* init */)
453
- return hasTs;
454
- if (hasTs)
455
- return true;
456
- return await confirm({
457
- message: t("question.useTs"),
458
- initialValue: true
459
- });
460
- },
461
- injectNpmScripts: async () => {
462
- if (mode === 1 /* create */)
463
- return true;
464
- return await confirm({
465
- message: t("question.injectNpmScripts"),
466
- initialValue: true
467
- });
468
- },
469
- bundler: () => select({
470
- message: t("question.bundler"),
471
- options: bundlerOptions
472
- }),
473
- deploy: async () => {
474
- if (mode === 0 /* init */) {
475
- return "custom" /* custom */;
476
- }
477
- return await select({
478
- message: t("question.deploy"),
479
- options: deployOptions,
480
- initialValue: "custom" /* custom */
481
- });
482
- },
483
- git: async () => {
484
- if (mode === 0 /* init */)
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
- // src/run.ts
485
+ //#endregion
486
+ //#region src/run.ts
505
487
  async function run(mode, root) {
506
- intro(colors.cyan("Welcome to VuePress and vuepress-theme-plume !"));
507
- const result = await prompt(mode, root);
508
- const data = resolveData(result, mode);
509
- const progress = spinner();
510
- progress.start(t("spinner.start"));
511
- try {
512
- await generate(mode, data);
513
- } catch (e) {
514
- console.error(`${colors.red("generate files error: ")}
515
- `, e);
516
- process4.exit(1);
517
- }
518
- await sleep(200);
519
- const cwd = path4.join(process4.cwd(), data.root);
520
- if (data.git) {
521
- progress.message(t("spinner.git"));
522
- try {
523
- await execaCommand3("git init", { cwd });
524
- } catch (e) {
525
- console.error(`${colors.red("git init error: ")}
526
- `, e);
527
- process4.exit(1);
528
- }
529
- }
530
- const pm = data.packageManager;
531
- if (data.install) {
532
- progress.message(t("spinner.install"));
533
- try {
534
- await execaCommand3(`${pm} install`, { cwd });
535
- } catch (e) {
536
- console.error(`${colors.red("install dependencies error: ")}
537
- `, e);
538
- process4.exit(1);
539
- }
540
- }
541
- const cdCommand = mode === 1 /* create */ ? colors.green(`cd ${data.root}`) : "";
542
- const runCommand = colors.green(`${pm} run docs:dev`);
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
- return {
553
- ...result,
554
- packageManager: getPackageManager(),
555
- docsDir: mode === 1 /* create */ ? "docs" : result.root.replace(/^\.\//, "").replace(/\/$/, ""),
556
- siteDescription: result.siteDescription || ""
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
- // src/index.ts
561
- var cli = cac("create-vuepress-theme-plume");
562
- cli.command("[root]", "create a new vuepress-theme-plume project / \u521B\u5EFA\u65B0\u7684 vuepress-theme-plume \u9879\u76EE").action((root) => run(1 /* create */, root));
563
- cli.command("init [root]", "Initial vuepress-theme-plume in the existing project / \u5728\u73B0\u6709\u9879\u76EE\u4E2D\u521D\u59CB\u5316 vuepress-theme-plume").action((root) => run(0 /* init */, root));
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("1.0.0-rc.145");
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.146",
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.87.0",
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": "tsup"
47
+ "build": "tsdown"
48
48
  }
49
49
  }