create-vuepress-theme-hope 1.23.0 → 2.0.0-alpha.25

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +1 -1
  3. package/lib/node/index.d.ts +1 -0
  4. package/lib/node/index.js +241 -0
  5. package/lib/node/index.js.map +1 -0
  6. package/package.json +11 -10
  7. package/readme.md +13 -1
  8. package/rollup.config.js +14 -0
  9. package/src/node/checkVersion.ts +31 -0
  10. package/src/node/copy.ts +45 -0
  11. package/src/node/deepAssign.ts +42 -0
  12. package/src/node/hasYarn.ts +10 -0
  13. package/src/node/i18n.ts +86 -0
  14. package/src/node/index.ts +157 -0
  15. package/src/node/registry.ts +31 -0
  16. package/template/.vuepress/config.ts +212 -0
  17. package/template/.vuepress/configs/index.ts +2 -0
  18. package/template/.vuepress/configs/navbar/en.ts +52 -0
  19. package/template/.vuepress/configs/navbar/index.ts +2 -0
  20. package/template/.vuepress/configs/navbar/zh.ts +52 -0
  21. package/template/.vuepress/configs/sidebar/en.ts +64 -0
  22. package/template/.vuepress/configs/sidebar/index.ts +2 -0
  23. package/template/.vuepress/configs/sidebar/zh.ts +67 -0
  24. package/template/.vuepress/styles/index.scss +0 -0
  25. package/template/.vuepress/styles/palette.scss +0 -0
  26. package/template/{readme.md → README.md} +3 -3
  27. package/template/guide/{readme.md → README.md} +2 -1
  28. package/template/guide/disable.md +5 -2
  29. package/template/guide/encrypt.md +2 -2
  30. package/template/guide/markdown.md +140 -391
  31. package/template/guide/page.md +4 -3
  32. package/template/home.md +44 -36
  33. package/template/posts/article/article1.md +19 -0
  34. package/template/posts/article/article2.md +20 -0
  35. package/template/posts/article/article3.md +20 -0
  36. package/template/posts/article/article4.md +20 -0
  37. package/template/posts/article/article5.md +20 -0
  38. package/template/posts/article/article6.md +21 -0
  39. package/template/posts/article/article7.md +20 -0
  40. package/template/posts/article/article8.md +20 -0
  41. package/template/posts/article10.md +20 -0
  42. package/template/posts/article11.md +20 -0
  43. package/template/posts/article12.md +21 -0
  44. package/template/posts/article9.md +20 -0
  45. package/template/zh/{readme.md → README.md} +3 -3
  46. package/template/zh/guide/{readme.md → README.md} +2 -1
  47. package/template/zh/guide/disable.md +5 -2
  48. package/template/zh/guide/encrypt.md +2 -2
  49. package/template/zh/guide/markdown.md +141 -394
  50. package/template/zh/guide/page.md +5 -4
  51. package/template/zh/home.md +41 -33
  52. package/template/zh/posts/article/article1.md +19 -0
  53. package/template/zh/posts/article/article2.md +20 -0
  54. package/template/zh/posts/article/article3.md +20 -0
  55. package/template/zh/posts/article/article4.md +20 -0
  56. package/template/zh/posts/article/article5.md +20 -0
  57. package/template/zh/posts/article/article6.md +21 -0
  58. package/template/zh/posts/article/article7.md +20 -0
  59. package/template/zh/posts/article/article8.md +20 -0
  60. package/template/zh/posts/article10.md +20 -0
  61. package/template/zh/posts/article11.md +20 -0
  62. package/template/zh/posts/article12.md +21 -0
  63. package/template/zh/posts/article9.md +20 -0
  64. package/tsconfig.build.json +10 -0
  65. package/tsconfig.json +8 -0
  66. package/lib/checkVersion.d.ts +0 -1
  67. package/lib/checkVersion.js +0 -23
  68. package/lib/checkVersion.js.map +0 -1
  69. package/lib/copy.d.ts +0 -1
  70. package/lib/copy.js +0 -38
  71. package/lib/copy.js.map +0 -1
  72. package/lib/hasYarn.d.ts +0 -1
  73. package/lib/hasYarn.js +0 -15
  74. package/lib/hasYarn.js.map +0 -1
  75. package/lib/i18n.d.ts +0 -26
  76. package/lib/i18n.js +0 -58
  77. package/lib/i18n.js.map +0 -1
  78. package/lib/index.d.ts +0 -2
  79. package/lib/index.js +0 -118
  80. package/lib/index.js.map +0 -1
  81. package/lib/registry.d.ts +0 -5
  82. package/lib/registry.js +0 -23
  83. package/lib/registry.js.map +0 -1
  84. package/template/.vuepress/config.js +0 -211
  85. package/template/.vuepress/styles/index.styl +0 -2
  86. package/template/layout.md +0 -98
  87. package/template/zh/layout.md +0 -98
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [2.0.0-alpha.25](https://github.com/vuepress-theme-hope/vuepress-theme-hope/compare/v2.0.0-alpha.24...v2.0.0-alpha.25) (2022-02-16)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **create:** fix command ([cc9cb54](https://github.com/vuepress-theme-hope/vuepress-theme-hope/commit/cc9cb54f5b274c2e186e50ec53353caa3d997d33))
11
+
12
+ # [2.0.0-alpha.24](https://github.com/vuepress-theme-hope/vuepress-theme-hope/compare/v2.0.0-alpha.23...v2.0.0-alpha.24) (2022-02-16)
13
+
14
+ ### Features
15
+
16
+ - add create-vuepress-theme-hope helper ([92333cf](https://github.com/vuepress-theme-hope/vuepress-theme-hope/commit/92333cfa468571887e285e6d545cdbc97e79bf26))
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (C) 2021 by MrHope
3
+ Copyright (C) 2020 - PRESENT by MrHope
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,241 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+ var vuepressShared = require('@mr-hope/vuepress-shared');
7
+ var cac = require('cac');
8
+ var inquirer = require('inquirer');
9
+ var execa = require('execa');
10
+ var utils = require('@vuepress/utils');
11
+ var https = require('https');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
16
+
17
+ const copyFile = (srcFile, targetFile) => {
18
+ const targetDir = utils.path.dirname(targetFile);
19
+ utils.fs.ensureDirSync(targetDir);
20
+ const rs = utils.fs.createReadStream(srcFile); // create read stream
21
+ const ws = utils.fs.createWriteStream(targetFile); // create write stream
22
+ rs.pipe(ws);
23
+ };
24
+ const copyDir = (srcDir, targetDir) => {
25
+ utils.fs.ensureDirSync(targetDir);
26
+ const files = utils.fs.readdirSync(srcDir, { withFileTypes: true });
27
+ files.forEach((file) => {
28
+ if (file.isFile())
29
+ copyFile(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`);
30
+ else if (file.isDirectory())
31
+ copyDir(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`);
32
+ });
33
+ };
34
+ const copy = (src, target) => {
35
+ if (utils.fs.statSync(src).isDirectory())
36
+ copyDir(src, target);
37
+ else if (utils.fs.statSync(src).isFile())
38
+ copyFile(src, target);
39
+ };
40
+
41
+ const checkForLatestVersion = (packageName) => new Promise((resolve, reject) => {
42
+ https.get(`https://registry.npmjs.org/-/package/${packageName}/dist-tags`, (res) => {
43
+ if (res.statusCode === 200) {
44
+ let body = "";
45
+ res.on("data", (data) => (body += data));
46
+ res.on("end", () => {
47
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
48
+ resolve(JSON.parse(body).next);
49
+ });
50
+ }
51
+ else {
52
+ reject(new Error(`Get ${packageName} version failed, please check your network!`));
53
+ }
54
+ }).on("error", () => {
55
+ reject(new Error(`Get ${packageName} version failed, please check your network!`));
56
+ });
57
+ });
58
+
59
+ const detectYarn = () => {
60
+ try {
61
+ execa.sync("yarn --version", { stdio: "ignore" });
62
+ return true;
63
+ }
64
+ catch (e) {
65
+ return false;
66
+ }
67
+ };
68
+
69
+ const i18n = {
70
+ "zh-CN": {
71
+ getVersion: "获取依赖的最新版本...",
72
+ createPackage: "生成 package.json...",
73
+ updatePackage: "更新 package.json...",
74
+ template: "生成模板...",
75
+ wait: "这可能需要数分钟,请耐心等待.\n我们无法正确输出子进程的进度条,所以进程可能会看似未响应",
76
+ install: "安装依赖...",
77
+ success: "模板已成功生成!",
78
+ devServerAsk: "是否想要现在启动 Demo 查看?",
79
+ devServer: "启动开发服务器...\n启动成功后,请在浏览器输入给出的开发服务器地址(默认为 'localhost:8080')",
80
+ hint: '提示: 请使用 "yarn run docs:dev" 命令启动开发服务器',
81
+ nameMessage: "设置应用名称",
82
+ nameError: "应用名称应只包含小写字母、数字和连接线 (-)",
83
+ versionMessage: "设置应用版本号",
84
+ versionError: "此版本无效,版本号应为 'x.x.x'",
85
+ descriptionMessage: "设置应用描述",
86
+ licenseMessage: "设置协议",
87
+ },
88
+ "en-US": {
89
+ getVersion: "Getting lastest version of deps...",
90
+ createPackage: "Generating package.json...",
91
+ updatePackage: "Updating package.json...",
92
+ template: "Generating Template...",
93
+ wait: "This may take a few minutes, please be patient.\nWe can not correctly output progress bar from child process, so the process may look stuck.",
94
+ install: "Installing Deps...",
95
+ success: "Successful Generated!",
96
+ devServerAsk: "Would you like to preview template now?",
97
+ devServer: "Staring dev server...\nAfter the dev server starts running, please visit the given server link ('localhost:8080' by default)",
98
+ hint: 'Hint: You should execute "yarn run docs:dev" to start dev server.',
99
+ nameMessage: "Your project name",
100
+ nameError: "package name should only contain lowercase characters, numbers and dash",
101
+ versionMessage: "Your project version",
102
+ versionError: "This version is not a valid one. Version should be like 'x.x.x'",
103
+ descriptionMessage: "Your project description",
104
+ licenseMessage: "Your project lincense",
105
+ },
106
+ };
107
+ const getLanguage = async () => {
108
+ const { language } = await inquirer.prompt([
109
+ {
110
+ name: "language",
111
+ type: "list",
112
+ message: "Select a language to display",
113
+ choices: ["en-US", "zh-CN"],
114
+ },
115
+ ]);
116
+ return {
117
+ lang: language,
118
+ message: i18n[language],
119
+ };
120
+ };
121
+
122
+ const npmmirrorRegistry = "https://registry.npmmirror.com/";
123
+ const getUserRegistry = (bin) => execa.sync(bin ? "yarn" : "npm", ["config", "get", "registry"]).stdout;
124
+ const getRegistry = async (lang, bin) => {
125
+ const userRegistry = getUserRegistry(bin);
126
+ if (lang === "en-US" || userRegistry === npmmirrorRegistry)
127
+ return userRegistry;
128
+ const { registry } = await inquirer.prompt([
129
+ {
130
+ name: "registry",
131
+ type: "list",
132
+ message: "选择你想使用的源",
133
+ choices: ["国内镜像源", "当前源"],
134
+ },
135
+ ]);
136
+ return registry === "国内镜像源" ? npmmirrorRegistry : userRegistry;
137
+ };
138
+
139
+ const cli = cac.cac("vuepress-theme-hope");
140
+ const bin = detectYarn() ? "yarn" : "npm";
141
+ cli
142
+ .command("[dir]", "Generate a new vuepress-theme-hope project")
143
+ .action(async (dir) => {
144
+ if (!dir)
145
+ return cli.outputHelp();
146
+ const { lang, message } = await getLanguage();
147
+ const targetFolder = path.resolve(process.cwd(), dir);
148
+ const packageJsonPath = path.resolve(process.cwd(), "package.json");
149
+ const scripts = {
150
+ "docs:build": `vuepress build ${dir}`,
151
+ "docs:clean-dev": `vuepress dev ${dir} --no-cache`,
152
+ "docs:dev": `vuepress dev ${dir}`,
153
+ "docs:eject-theme": `vuepress eject-hope ${dir}`,
154
+ };
155
+ console.log(message.getVersion);
156
+ const vuepressVersion = await checkForLatestVersion("vuepress");
157
+ const themeVersion = await checkForLatestVersion("vuepress-theme-hope");
158
+ const devDependencies = {
159
+ vuepress: `^${vuepressVersion}`,
160
+ "vuepress-theme-hope": `^${themeVersion}`,
161
+ };
162
+ if (!fs.existsSync(targetFolder))
163
+ fs.mkdirSync(targetFolder);
164
+ if (fs.existsSync(packageJsonPath)) {
165
+ console.log(message.updatePackage);
166
+ // eslint-disable-next-line
167
+ const packageContent = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: "utf-8" }));
168
+ vuepressShared.deepAssign(packageContent, { scripts, devDependencies });
169
+ fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageContent, null, 2)}\n`, { encoding: "utf-8" });
170
+ }
171
+ else {
172
+ console.log(message.createPackage);
173
+ const result = await inquirer.prompt([
174
+ {
175
+ name: "name",
176
+ type: "input",
177
+ message: message.nameMessage,
178
+ default: "vuepress-theme-hope-project",
179
+ validate: (input) => /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u.exec(input)
180
+ ? true
181
+ : message.nameError,
182
+ },
183
+ {
184
+ name: "version",
185
+ type: "input",
186
+ message: message.versionMessage,
187
+ default: "1.0.0",
188
+ validate: (input) => /^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u.exec(input)
189
+ ? true
190
+ : message.versionError,
191
+ },
192
+ {
193
+ name: "description",
194
+ type: "input",
195
+ message: message.descriptionMessage,
196
+ default: "A project of vuepress-theme-hope",
197
+ },
198
+ {
199
+ name: "license",
200
+ type: "input",
201
+ message: message.licenseMessage,
202
+ default: "MIT",
203
+ },
204
+ ]);
205
+ const packageContent = { ...result, scripts, devDependencies };
206
+ fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageContent, null, 2)}\n`, { encoding: "utf-8" });
207
+ }
208
+ console.log(message.template);
209
+ copy(path.resolve(__dirname, "../template"), path.resolve(process.cwd(), dir));
210
+ console.log(message.install);
211
+ console.warn(message.wait);
212
+ const registry = await getRegistry(lang, bin);
213
+ execa__default["default"].sync(bin, ["install", "--registry", registry], {
214
+ stdout: "inherit",
215
+ });
216
+ console.log(message.success);
217
+ const { choise } = await inquirer.prompt([
218
+ {
219
+ name: "choise",
220
+ type: "list",
221
+ message: message.devServerAsk,
222
+ choices: ["Yes", "No"],
223
+ },
224
+ ]);
225
+ if (choise === "Yes") {
226
+ console.log(message.devServer);
227
+ await execa__default["default"](bin, ["run", "docs:dev"], {
228
+ stdout: "inherit",
229
+ });
230
+ }
231
+ else
232
+ console.log(message.hint);
233
+ });
234
+ cli.help(() => [
235
+ {
236
+ title: "yarn create vuepress-theme-hope <dir> / npm init vuepress-theme-hope <dir>",
237
+ body: "Create a vuepress-theme-hope template in <dir>",
238
+ },
239
+ ]);
240
+ cli.parse();
241
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/node/copy.ts","../../src/node/checkVersion.ts","../../src/node/hasYarn.ts","../../src/node/i18n.ts","../../src/node/registry.ts","../../src/node/index.ts"],"sourcesContent":[null,null,null,null,null,null],"names":["path","fs","get","sync","prompt","cac","resolve","existsSync","mkdirSync","readFileSync","deepAssign","writeFileSync","execa"],"mappings":";;;;;;;;;;;;;;;;AAEA,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,UAAkB;IACnD,MAAM,SAAS,GAAGA,UAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3CC,QAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAE5B,MAAM,EAAE,GAAGA,QAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,EAAE,GAAGA,QAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAE5C,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,SAAiB;IAChDA,QAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAE5B,MAAM,KAAK,GAAGA,QAAE,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAE9D,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI;QACjB,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,QAAQ,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;aAC7D,IAAI,IAAI,CAAC,WAAW,EAAE;YACzB,OAAO,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;KAClE,CAAC,CAAC;AACL,CAAC,CAAC;AAEK,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,MAAc;IAC9C,IAAIA,QAAE,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AAE,CAAC,SAAS,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE;QACnD,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAMR,eAAM,CAA2B;QACxD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,OAAO,CAAC,YAAY;YAC7B,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC;SACvB;KACF,CAAC,CAAC;IAEH,IAAI,MAAM,KAAK,KAAK,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE/B,MAAMQ,yBAAK,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE;YACpC,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC;KACJ;;QAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEL,GAAG,CAAC,IAAI,CAAC,MAAM;IACb;QACE,KAAK,EACH,4EAA4E;QAC9E,IAAI,EAAE,gDAAgD;KACvD;CACF,CAAC,CAAC;AAEH,GAAG,CAAC,KAAK,EAAE"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "create-vuepress-theme-hope",
3
- "version": "1.23.0",
4
- "description": "Theme create shortcut for yarn",
3
+ "version": "2.0.0-alpha.25",
4
+ "description": "Create vuepress-theme-hope demo project helper",
5
5
  "keywords": [
6
6
  "create",
7
7
  "vuepress",
8
8
  "vuepress-theme-hope"
9
9
  ],
10
- "homepage": "https://github.com/vuepress-theme-hope/vuepress-theme-hope/tree/v1/packages/create#readme",
10
+ "homepage": "https://vuepress-theme-hope.github.io/v2/",
11
11
  "bugs": {
12
12
  "url": "https://github.com/vuepress-theme-hope/vuepress-theme-hope/issues"
13
13
  },
@@ -19,22 +19,23 @@
19
19
  "license": "MIT",
20
20
  "author": {
21
21
  "name": "Mr.Hope",
22
- "email": "zhangbowang1998@gmail.com",
22
+ "email": "mister-hope@outlook.com",
23
23
  "url": "https://mrhope.site"
24
24
  },
25
25
  "bin": {
26
- "create-vuepress-theme-hope": "lib/index.js"
26
+ "create-vuepress-theme-hope": "./lib/node/index.js"
27
27
  },
28
28
  "scripts": {
29
- "build": "tsc -b tsconfig.json",
30
- "clean": "rimraf lib *.tsbuildinfo"
29
+ "build": "rollup -c",
30
+ "clean": "rimraf ./lib ./*.tsbuildinfo",
31
+ "dev": "yarn dev:ts",
32
+ "dev:ts": "tsc -b tsconfig.build.json --watch"
31
33
  },
32
34
  "dependencies": {
33
- "@mr-hope/vuepress-shared": "1.23.0",
34
- "@types/inquirer": "^8.1.3",
35
+ "@types/inquirer": "^8.2.0",
35
36
  "cac": "^6.7.12",
36
37
  "execa": "^5.1.1",
37
38
  "inquirer": "^8.2.0"
38
39
  },
39
- "gitHead": "25d3718d5f17ffe15794be99766167a8497c1a5a"
40
+ "gitHead": "e45e15e98fd916c84d0e0efc3edeadbc060ef27d"
40
41
  }
package/readme.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # create-vuepress-theme-hope
2
2
 
3
- [![Version](https://img.shields.io/npm/v/create-vuepress-theme-hope.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/create-vuepress-theme-hope.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/create-vuepress-theme-hope?style=flat-square&logo=npm)](https://www.npmjs.com/package/create-vuepress-theme-hope)
3
+ [![Version](https://img.shields.io/npm/v/create-vuepress-theme-hope/next.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/create-vuepress-theme-hope.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/create-vuepress-theme-hope?style=flat-square&logo=npm)](https://www.npmjs.com/package/create-vuepress-theme-hope)
4
4
 
5
5
  Create template shortcut for vuepress-theme-hope.
6
6
 
7
7
  ## Usage
8
8
 
9
+ ```bash
10
+ npm init vuepress-theme-hope <dir>
11
+ ```
12
+
13
+ Or
14
+
9
15
  ```bash
10
16
  yarn create vuepress-theme-hope <dir>
11
17
  ```
@@ -16,6 +22,12 @@ yarn create vuepress-theme-hope <dir>
16
22
 
17
23
  ## 使用
18
24
 
25
+ ```bash
26
+ npm init vuepress-theme-hope <dir>
27
+ ```
28
+
29
+ 或
30
+
19
31
  ```bash
20
32
  yarn create vuepress-theme-hope <dir>
21
33
  ```
@@ -0,0 +1,14 @@
1
+ import { rollupTypescript } from "../../scripts/rollup";
2
+
3
+ export default rollupTypescript("node/index", {
4
+ external: [
5
+ "@mr-hope/vuepress-shared",
6
+ "cac",
7
+ "execa",
8
+ "fs",
9
+ "https",
10
+ "inquirer",
11
+ "path",
12
+ ],
13
+ preserveShebang: true,
14
+ });
@@ -0,0 +1,31 @@
1
+ import { get } from "https";
2
+
3
+ export const checkForLatestVersion = (packageName: string): Promise<string> =>
4
+ new Promise((resolve, reject) => {
5
+ get(
6
+ `https://registry.npmjs.org/-/package/${packageName}/dist-tags`,
7
+ (res) => {
8
+ if (res.statusCode === 200) {
9
+ let body = "";
10
+
11
+ res.on("data", (data) => (body += data));
12
+ res.on("end", () => {
13
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
14
+ resolve(JSON.parse(body).next as string);
15
+ });
16
+ } else {
17
+ reject(
18
+ new Error(
19
+ `Get ${packageName} version failed, please check your network!`
20
+ )
21
+ );
22
+ }
23
+ }
24
+ ).on("error", () => {
25
+ reject(
26
+ new Error(
27
+ `Get ${packageName} version failed, please check your network!`
28
+ )
29
+ );
30
+ });
31
+ });
@@ -0,0 +1,45 @@
1
+ import {
2
+ createReadStream,
3
+ createWriteStream,
4
+ mkdirSync,
5
+ readdirSync,
6
+ statSync,
7
+ } from "fs";
8
+ import { dirname } from "path";
9
+
10
+ const ensureDirExistSync = (dirPath: string): void => {
11
+ try {
12
+ readdirSync(dirPath);
13
+ } catch (err) {
14
+ mkdirSync(dirPath);
15
+ }
16
+ };
17
+
18
+ const copyFile = (srcFile: string, targetFile: string): void => {
19
+ const targetDir = dirname(targetFile);
20
+
21
+ ensureDirExistSync(targetDir);
22
+
23
+ const rs = createReadStream(srcFile); // create read stream
24
+ const ws = createWriteStream(targetFile); // create write stream
25
+
26
+ rs.pipe(ws);
27
+ };
28
+
29
+ const copyDir = (srcDir: string, targetDir: string): void => {
30
+ ensureDirExistSync(targetDir);
31
+
32
+ const files = readdirSync(srcDir, { withFileTypes: true });
33
+
34
+ files.forEach((file) => {
35
+ if (file.isFile())
36
+ copyFile(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`);
37
+ else if (file.isDirectory())
38
+ copyDir(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`);
39
+ });
40
+ };
41
+
42
+ export const copy = (src: string, target: string): void => {
43
+ if (statSync(src).isDirectory()) copyDir(src, target);
44
+ else if (statSync(src).isFile()) copyFile(src, target);
45
+ };
@@ -0,0 +1,42 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ type IAnyObject = Record<string, any>;
3
+
4
+ /** Deep merge objects to the first one */
5
+ export const deepAssign = <
6
+ T extends IAnyObject,
7
+ U extends IAnyObject = T,
8
+ V extends IAnyObject = T
9
+ >(
10
+ originObject: T,
11
+ ...assignObjects: U[]
12
+ ): V => {
13
+ if (assignObjects.length === 0) return originObject as V;
14
+
15
+ /** Object being merged */
16
+ const assignObject = (assignObjects.shift() as IAnyObject) || {};
17
+
18
+ Object.keys(assignObject).forEach((property) => {
19
+ if (
20
+ typeof originObject[property] === "object" &&
21
+ !Array.isArray(originObject[property]) &&
22
+ typeof assignObject[property] === "object" &&
23
+ !Array.isArray(assignObject[property])
24
+ )
25
+ deepAssign(originObject[property], assignObject[property]);
26
+ else if (typeof assignObject[property] === "object")
27
+ if (Array.isArray(assignObject[property]))
28
+ (originObject as IAnyObject)[property] = [
29
+ ...(assignObject[property] as unknown[]),
30
+ ];
31
+ else
32
+ (originObject as IAnyObject)[property] = {
33
+ ...(assignObject[property] as Record<string, unknown>),
34
+ };
35
+ else
36
+ (originObject as IAnyObject)[property] = assignObject[
37
+ property
38
+ ] as unknown;
39
+ });
40
+
41
+ return deepAssign(originObject, ...assignObjects);
42
+ };
@@ -0,0 +1,10 @@
1
+ import { sync } from "execa";
2
+
3
+ export const detectYarn = (): boolean => {
4
+ try {
5
+ sync("yarn --version", { stdio: "ignore" });
6
+ return true;
7
+ } catch (e) {
8
+ return false;
9
+ }
10
+ };
@@ -0,0 +1,86 @@
1
+ import { prompt } from "inquirer";
2
+
3
+ export type Lang = "zh-CN" | "en-US";
4
+
5
+ export interface CreateI18n {
6
+ getVersion: string;
7
+ createPackage: string;
8
+ updatePackage: string;
9
+ template: string;
10
+ install: string;
11
+ wait: string;
12
+ success: string;
13
+ devServerAsk: string;
14
+ devServer: string;
15
+ hint: string;
16
+ nameMessage: string;
17
+ nameError: string;
18
+ versionMessage: string;
19
+ versionError: string;
20
+ descriptionMessage: string;
21
+ licenseMessage: string;
22
+ }
23
+
24
+ export const i18n: Record<Lang, CreateI18n> = {
25
+ "zh-CN": {
26
+ getVersion: "获取依赖的最新版本...",
27
+ createPackage: "生成 package.json...",
28
+ updatePackage: "更新 package.json...",
29
+ template: "生成模板...",
30
+ wait: "这可能需要数分钟,请耐心等待.\n我们无法正确输出子进程的进度条,所以进程可能会看似未响应",
31
+ install: "安装依赖...",
32
+ success: "模板已成功生成!",
33
+ devServerAsk: "是否想要现在启动 Demo 查看?",
34
+ devServer:
35
+ "启动开发服务器...\n启动成功后,请在浏览器输入给出的开发服务器地址(默认为 'localhost:8080')",
36
+ hint: '提示: 请使用 "yarn run docs:dev" 命令启动开发服务器',
37
+ nameMessage: "设置应用名称",
38
+ nameError: "应用名称应只包含小写字母、数字和连接线 (-)",
39
+ versionMessage: "设置应用版本号",
40
+ versionError: "此版本无效,版本号应为 'x.x.x'",
41
+ descriptionMessage: "设置应用描述",
42
+ licenseMessage: "设置协议",
43
+ },
44
+ "en-US": {
45
+ getVersion: "Getting lastest version of deps...",
46
+ createPackage: "Generating package.json...",
47
+ updatePackage: "Updating package.json...",
48
+ template: "Generating Template...",
49
+ wait: "This may take a few minutes, please be patient.\nWe can not correctly output progress bar from child process, so the process may look stuck.",
50
+ install: "Installing Deps...",
51
+ success: "Successful Generated!",
52
+ devServerAsk: "Would you like to preview template now?",
53
+ devServer:
54
+ "Staring dev server...\nAfter the dev server starts running, please visit the given server link ('localhost:8080' by default)",
55
+ hint: 'Hint: You should execute "yarn run docs:dev" to start dev server.',
56
+ nameMessage: "Your project name",
57
+ nameError:
58
+ "package name should only contain lowercase characters, numbers and dash",
59
+ versionMessage: "Your project version",
60
+ versionError:
61
+ "This version is not a valid one. Version should be like 'x.x.x'",
62
+ descriptionMessage: "Your project description",
63
+ licenseMessage: "Your project lincense",
64
+ },
65
+ };
66
+
67
+ interface LanguageResult {
68
+ lang: Lang;
69
+ message: CreateI18n;
70
+ }
71
+
72
+ export const getLanguage = async (): Promise<LanguageResult> => {
73
+ const { language } = await prompt<{ language: Lang }>([
74
+ {
75
+ name: "language",
76
+ type: "list",
77
+ message: "Select a language to display",
78
+ choices: ["en-US", "zh-CN"],
79
+ },
80
+ ]);
81
+
82
+ return {
83
+ lang: language,
84
+ message: i18n[language],
85
+ };
86
+ };