create-vuepress-theme-hope 1.27.4 → 2.0.0-alpha.27

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 +26 -0
  2. package/LICENSE +1 -1
  3. package/lib/node/index.d.ts +1 -0
  4. package/lib/node/index.js +3 -0
  5. package/lib/node/index.js.map +1 -0
  6. package/package.json +10 -9
  7. package/readme.md +15 -3
  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,26 @@
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.27](https://github.com/vuepress-theme-hope/vuepress-theme-hope/compare/v2.0.0-alpha.26...v2.0.0-alpha.27) (2022-02-16)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **create:** fix template folder path ([3fcc980](https://github.com/vuepress-theme-hope/vuepress-theme-hope/commit/3fcc980865c14a74c54bc7950e93cadab3da2d00))
11
+
12
+ # [2.0.0-alpha.26](https://github.com/vuepress-theme-hope/vuepress-theme-hope/compare/v2.0.0-alpha.25...v2.0.0-alpha.26) (2022-02-16)
13
+
14
+ **Note:** Version bump only for package create-vuepress-theme-hope
15
+
16
+ # [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)
17
+
18
+ ### Bug Fixes
19
+
20
+ - **create:** fix command ([cc9cb54](https://github.com/vuepress-theme-hope/vuepress-theme-hope/commit/cc9cb54f5b274c2e186e50ec53353caa3d997d33))
21
+
22
+ # [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)
23
+
24
+ ### Features
25
+
26
+ - 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,3 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var e=require("fs"),s=require("path"),r=require("cac"),t=require("inquirer"),a=require("execa"),n=require("https");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(a);const c=(e,...s)=>{if(0===s.length)return e;const r=s.shift()||{};return Object.keys(r).forEach((s=>{"object"!=typeof e[s]||Array.isArray(e[s])||"object"!=typeof r[s]||Array.isArray(r[s])?"object"==typeof r[s]?Array.isArray(r[s])?e[s]=[...r[s]]:e[s]={...r[s]}:e[s]=r[s]:c(e[s],r[s])})),c(e,...s)},p=s=>{try{e.readdirSync(s)}catch(r){e.mkdirSync(s)}},l=(r,t)=>{const a=s.dirname(t);p(a);const n=e.createReadStream(r),o=e.createWriteStream(t);n.pipe(o)},u=(s,r)=>{p(r);e.readdirSync(s,{withFileTypes:!0}).forEach((e=>{e.isFile()?l(`${s}/${e.name}`,`${r}/${e.name}`):e.isDirectory()&&u(`${s}/${e.name}`,`${r}/${e.name}`)}))},d=e=>new Promise(((s,r)=>{n.get(`https://registry.npmjs.org/-/package/${e}/dist-tags`,(t=>{if(200===t.statusCode){let e="";t.on("data",(s=>e+=s)),t.on("end",(()=>{s(JSON.parse(e).next)}))}else r(new Error(`Get ${e} version failed, please check your network!`))})).on("error",(()=>{r(new Error(`Get ${e} version failed, please check your network!`))}))})),g={"zh-CN":{getVersion:"获取依赖的最新版本...",createPackage:"生成 package.json...",updatePackage:"更新 package.json...",template:"生成模板...",wait:"这可能需要数分钟,请耐心等待.\n我们无法正确输出子进程的进度条,所以进程可能会看似未响应",install:"安装依赖...",success:"模板已成功生成!",devServerAsk:"是否想要现在启动 Demo 查看?",devServer:"启动开发服务器...\n启动成功后,请在浏览器输入给出的开发服务器地址(默认为 'localhost:8080')",hint:'提示: 请使用 "yarn run docs:dev" 命令启动开发服务器',nameMessage:"设置应用名称",nameError:"应用名称应只包含小写字母、数字和连接线 (-)",versionMessage:"设置应用版本号",versionError:"此版本无效,版本号应为 'x.x.x'",descriptionMessage:"设置应用描述",licenseMessage:"设置协议"},"en-US":{getVersion:"Getting lastest version of deps...",createPackage:"Generating package.json...",updatePackage:"Updating package.json...",template:"Generating Template...",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.",install:"Installing Deps...",success:"Successful Generated!",devServerAsk:"Would you like to preview template now?",devServer:"Staring dev server...\nAfter the dev server starts running, please visit the given server link ('localhost:8080' by default)",hint:'Hint: You should execute "yarn run docs:dev" to start dev server.',nameMessage:"Your project name",nameError:"package name should only contain lowercase characters, numbers and dash",versionMessage:"Your project version",versionError:"This version is not a valid one. Version should be like 'x.x.x'",descriptionMessage:"Your project description",licenseMessage:"Your project lincense"}},m=async(e,s)=>{const r=(e=>a.sync(e?"yarn":"npm",["config","get","registry"]).stdout)(s);if("en-US"===e||"https://registry.npmmirror.com/"===r)return r;const{registry:n}=await t.prompt([{name:"registry",type:"list",message:"选择你想使用的源",choices:["国内镜像源","当前源"]}]);return"国内镜像源"===n?"https://registry.npmmirror.com/":r},v=r.cac("vuepress-theme-hope"),y=(()=>{try{return a.sync("yarn --version",{stdio:"ignore"}),!0}catch(e){return!1}})()?"yarn":"npm";v.command("[dir]","Generate a new vuepress-theme-hope project").action((async r=>{if(!r)return v.outputHelp();const{lang:a,message:n}=await(async()=>{const{language:e}=await t.prompt([{name:"language",type:"list",message:"Select a language to display",choices:["en-US","zh-CN"]}]);return{lang:e,message:g[e]}})(),o=s.resolve(process.cwd(),r),p=s.resolve(process.cwd(),"package.json"),h={"docs:build":`vuepress build ${r}`,"docs:clean-dev":`vuepress dev ${r} --no-cache`,"docs:dev":`vuepress dev ${r}`,"docs:eject-theme":`vuepress eject-hope ${r}`};console.log(n.getVersion);const f={vuepress:`^${await d("vuepress")}`,"vuepress-theme-hope":`^${await d("vuepress-theme-hope")}`};if(e.existsSync(o)||e.mkdirSync(o),e.existsSync(p)){console.log(n.updatePackage);const s=JSON.parse(e.readFileSync(p,{encoding:"utf-8"}));c(s,{scripts:h,devDependencies:f}),e.writeFileSync(p,`${JSON.stringify(s,null,2)}\n`,{encoding:"utf-8"})}else{console.log(n.createPackage);const s={...await t.prompt([{name:"name",type:"input",message:n.nameMessage,default:"vuepress-theme-hope-project",validate:e=>!!/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u.exec(e)||n.nameError},{name:"version",type:"input",message:n.versionMessage,default:"1.0.0",validate:e=>!!/^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u.exec(e)||n.versionError},{name:"description",type:"input",message:n.descriptionMessage,default:"A project of vuepress-theme-hope"},{name:"license",type:"input",message:n.licenseMessage,default:"MIT"}]),scripts:h,devDependencies:f};e.writeFileSync(p,`${JSON.stringify(s,null,2)}\n`,{encoding:"utf-8"})}var k,w;console.log(n.template),k=s.resolve(__dirname,"../../template"),w=s.resolve(process.cwd(),r),e.statSync(k).isDirectory()?u(k,w):e.statSync(k).isFile()&&l(k,w),console.log(n.install),console.warn(n.wait);const S=await m(a,y);i.default.sync(y,["install","--registry",S],{stdout:"inherit"}),console.log(n.success);const{choise:$}=await t.prompt([{name:"choise",type:"list",message:n.devServerAsk,choices:["Yes","No"]}]);"Yes"===$?(console.log(n.devServer),await i.default(y,["run","docs:dev"],{stdout:"inherit"})):console.log(n.hint)})),v.help((()=>[{title:"yarn create vuepress-theme-hope <dir> / npm init vuepress-theme-hope <dir>",body:"Create a vuepress-theme-hope template in <dir>"}])),v.parse();
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/node/deepAssign.ts","../../src/node/copy.ts","../../src/node/checkVersion.ts","../../src/node/i18n.ts","../../src/node/registry.ts","../../src/node/index.ts","../../src/node/hasYarn.ts"],"sourcesContent":[null,null,null,null,null,null,null],"names":["deepAssign","originObject","assignObjects","length","assignObject","shift","Object","keys","forEach","property","Array","isArray","ensureDirExistSync","dirPath","readdirSync","err","mkdirSync","copyFile","srcFile","targetFile","targetDir","dirname","rs","createReadStream","ws","createWriteStream","pipe","copyDir","srcDir","withFileTypes","file","isFile","name","isDirectory","checkForLatestVersion","packageName","Promise","resolve","reject","get","res","statusCode","body","on","data","JSON","parse","next","Error","i18n","getVersion","createPackage","updatePackage","template","wait","install","success","devServerAsk","devServer","hint","nameMessage","nameError","versionMessage","versionError","descriptionMessage","licenseMessage","getRegistry","async","lang","bin","userRegistry","sync","stdout","getUserRegistry","registry","prompt","type","message","choices","cli","cac","stdio","e","detectYarn","command","action","dir","outputHelp","language","getLanguage","targetFolder","process","cwd","packageJsonPath","scripts","console","log","devDependencies","vuepress","existsSync","packageContent","readFileSync","encoding","writeFileSync","stringify","default","validate","input","exec","src","target","__dirname","statSync","warn","execa","choise","help","title"],"mappings":";mNAIO,MAAMA,EAAa,CAKxBC,KACGC,KAEH,GAA6B,IAAzBA,EAAcC,OAAc,OAAOF,EAGvC,MAAMG,EAAgBF,EAAcG,SAA0B,GAyB9D,OAvBAC,OAAOC,KAAKH,GAAcI,SAASC,IAEG,iBAA3BR,EAAaQ,IACnBC,MAAMC,QAAQV,EAAaQ,KACM,iBAA3BL,EAAaK,IACnBC,MAAMC,QAAQP,EAAaK,IAGa,iBAA3BL,EAAaK,GACvBC,MAAMC,QAAQP,EAAaK,IAC5BR,EAA4BQ,GAAY,IACnCL,EAAaK,IAGlBR,EAA4BQ,GAAY,IACnCL,EAAaK,IAGpBR,EAA4BQ,GAAYL,EACvCK,GAZFT,EAAWC,EAAaQ,GAAWL,EAAaK,OAgB7CT,EAAWC,KAAiBC,IC/B/BU,EAAsBC,IAC1B,IACEC,cAAYD,GACZ,MAAOE,GACPC,YAAUH,KAIRI,EAAW,CAACC,EAAiBC,KACjC,MAAMC,EAAYC,UAAQF,GAE1BP,EAAmBQ,GAEnB,MAAME,EAAKC,mBAAiBL,GACtBM,EAAKC,oBAAkBN,GAE7BG,EAAGI,KAAKF,IAGJG,EAAU,CAACC,EAAgBR,KAC/BR,EAAmBQ,GAELN,cAAYc,EAAQ,CAA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vuepress-theme-hope",
3
- "version": "1.27.4",
4
- "description": "Theme create shortcut for yarn",
3
+ "version": "2.0.0-alpha.27",
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://vuepress-theme-hope.github.io/",
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.24.0",
34
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": "56601788fc722d4303cec25efc7e7eace8ddc4eb"
40
+ "gitHead": "24c8014ca9fb27dca52c4ca35b7dabdfc3686f31"
40
41
  }
package/readme.md CHANGED
@@ -1,15 +1,21 @@
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
9
  ```bash
10
- yarn create vuepress-theme-hope <dir>
10
+ npm init vuepress-theme-hope@next <dir>
11
11
  ```
12
12
 
13
+ <!-- Or
14
+
15
+ ```bash
16
+ yarn create vuepress-theme-hope <dir>
17
+ ``` -->
18
+
13
19
  ---
14
20
 
15
21
  快速创建 vuepress-theme-hope 模板捷径。
@@ -17,5 +23,11 @@ yarn create vuepress-theme-hope <dir>
17
23
  ## 使用
18
24
 
19
25
  ```bash
20
- yarn create vuepress-theme-hope <dir>
26
+ npm init vuepress-theme-hope@next <dir>
21
27
  ```
28
+
29
+ <!-- 或
30
+
31
+ ```bash
32
+ yarn create vuepress-theme-hope <dir>
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
+ };
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ import { deepAssign } from "./deepAssign";
5
+ import { cac } from "cac";
6
+ import { prompt } from "inquirer";
7
+ import execa from "execa";
8
+ import { copy } from "./copy";
9
+ import { checkForLatestVersion } from "./checkVersion";
10
+ import { detectYarn } from "./hasYarn";
11
+ import { getLanguage } from "./i18n";
12
+ import { getRegistry } from "./registry";
13
+ const cli = cac("vuepress-theme-hope");
14
+
15
+ const bin = detectYarn() ? "yarn" : "npm";
16
+
17
+ cli
18
+ .command("[dir]", "Generate a new vuepress-theme-hope project")
19
+ .action(async (dir: string) => {
20
+ if (!dir) return cli.outputHelp();
21
+
22
+ const { lang, message } = await getLanguage();
23
+
24
+ const targetFolder = resolve(process.cwd(), dir);
25
+ const packageJsonPath = resolve(process.cwd(), "package.json");
26
+ const scripts = {
27
+ "docs:build": `vuepress build ${dir}`,
28
+ "docs:clean-dev": `vuepress dev ${dir} --no-cache`,
29
+ "docs:dev": `vuepress dev ${dir}`,
30
+ "docs:eject-theme": `vuepress eject-hope ${dir}`,
31
+ };
32
+
33
+ console.log(message.getVersion);
34
+
35
+ const vuepressVersion = await checkForLatestVersion("vuepress");
36
+ const themeVersion = await checkForLatestVersion("vuepress-theme-hope");
37
+
38
+ const devDependencies = {
39
+ vuepress: `^${vuepressVersion}`,
40
+ "vuepress-theme-hope": `^${themeVersion}`,
41
+ };
42
+
43
+ if (!existsSync(targetFolder)) mkdirSync(targetFolder);
44
+
45
+ if (existsSync(packageJsonPath)) {
46
+ console.log(message.updatePackage);
47
+
48
+ // eslint-disable-next-line
49
+ const packageContent: any = JSON.parse(
50
+ readFileSync(packageJsonPath, { encoding: "utf-8" })
51
+ );
52
+
53
+ deepAssign(packageContent, { scripts, devDependencies });
54
+
55
+ writeFileSync(
56
+ packageJsonPath,
57
+ `${JSON.stringify(packageContent, null, 2)}\n`,
58
+ { encoding: "utf-8" }
59
+ );
60
+ } else {
61
+ console.log(message.createPackage);
62
+
63
+ interface PackageJsonAnswer {
64
+ name: string;
65
+ version: string;
66
+ description: string;
67
+ license: string;
68
+ }
69
+
70
+ const result = await prompt<PackageJsonAnswer>([
71
+ {
72
+ name: "name",
73
+ type: "input",
74
+ message: message.nameMessage,
75
+ default: "vuepress-theme-hope-project",
76
+ validate: (input: string): true | string =>
77
+ /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u.exec(
78
+ input
79
+ )
80
+ ? true
81
+ : message.nameError,
82
+ },
83
+ {
84
+ name: "version",
85
+ type: "input",
86
+ message: message.versionMessage,
87
+ default: "1.0.0",
88
+ validate: (input: string): true | string =>
89
+ /^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u.exec(input)
90
+ ? true
91
+ : message.versionError,
92
+ },
93
+ {
94
+ name: "description",
95
+ type: "input",
96
+ message: message.descriptionMessage,
97
+ default: "A project of vuepress-theme-hope",
98
+ },
99
+ {
100
+ name: "license",
101
+ type: "input",
102
+ message: message.licenseMessage,
103
+ default: "MIT",
104
+ },
105
+ ]);
106
+
107
+ const packageContent = { ...result, scripts, devDependencies };
108
+
109
+ writeFileSync(
110
+ packageJsonPath,
111
+ `${JSON.stringify(packageContent, null, 2)}\n`,
112
+ { encoding: "utf-8" }
113
+ );
114
+ }
115
+
116
+ console.log(message.template);
117
+
118
+ copy(resolve(__dirname, "../../template"), resolve(process.cwd(), dir));
119
+
120
+ console.log(message.install);
121
+ console.warn(message.wait);
122
+
123
+ const registry = await getRegistry(lang, bin);
124
+
125
+ execa.sync(bin, ["install", "--registry", registry], {
126
+ stdout: "inherit",
127
+ });
128
+
129
+ console.log(message.success);
130
+
131
+ const { choise } = await prompt<{ choise: "Yes" | "No" }>([
132
+ {
133
+ name: "choise",
134
+ type: "list",
135
+ message: message.devServerAsk,
136
+ choices: ["Yes", "No"],
137
+ },
138
+ ]);
139
+
140
+ if (choise === "Yes") {
141
+ console.log(message.devServer);
142
+
143
+ await execa(bin, ["run", "docs:dev"], {
144
+ stdout: "inherit",
145
+ });
146
+ } else console.log(message.hint);
147
+ });
148
+
149
+ cli.help(() => [
150
+ {
151
+ title:
152
+ "yarn create vuepress-theme-hope <dir> / npm init vuepress-theme-hope <dir>",
153
+ body: "Create a vuepress-theme-hope template in <dir>",
154
+ },
155
+ ]);
156
+
157
+ cli.parse();
@@ -0,0 +1,31 @@
1
+ import { sync } from "execa";
2
+ import { prompt } from "inquirer";
3
+
4
+ import type { Lang } from "./i18n";
5
+
6
+ export interface RegistryAnswer {
7
+ registry: "国内镜像源" | "当前源";
8
+ }
9
+
10
+ const npmmirrorRegistry = "https://registry.npmmirror.com/";
11
+
12
+ const getUserRegistry = (bin: string): string =>
13
+ sync(bin ? "yarn" : "npm", ["config", "get", "registry"]).stdout;
14
+
15
+ export const getRegistry = async (lang: Lang, bin: string): Promise<string> => {
16
+ const userRegistry = getUserRegistry(bin);
17
+
18
+ if (lang === "en-US" || userRegistry === npmmirrorRegistry)
19
+ return userRegistry;
20
+
21
+ const { registry } = await prompt<RegistryAnswer>([
22
+ {
23
+ name: "registry",
24
+ type: "list",
25
+ message: "选择你想使用的源",
26
+ choices: ["国内镜像源", "当前源"],
27
+ },
28
+ ]);
29
+
30
+ return registry === "国内镜像源" ? npmmirrorRegistry : userRegistry;
31
+ };