create-vuepress-theme-hope 1.21.0 → 2.0.0-alpha.24

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 (86) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +1 -1
  3. package/lib/node/index.d.ts +1 -0
  4. package/lib/node/index.js +2 -0
  5. package/lib/node/index.js.map +1 -0
  6. package/package.json +13 -10
  7. package/readme.md +13 -1
  8. package/rollup.config.js +5 -0
  9. package/src/node/checkVersion.ts +31 -0
  10. package/src/node/copy.ts +30 -0
  11. package/src/node/hasYarn.ts +10 -0
  12. package/src/node/i18n.ts +86 -0
  13. package/src/node/index.ts +156 -0
  14. package/src/node/registry.ts +31 -0
  15. package/template/.vuepress/config.ts +212 -0
  16. package/template/.vuepress/configs/index.ts +2 -0
  17. package/template/.vuepress/configs/navbar/en.ts +52 -0
  18. package/template/.vuepress/configs/navbar/index.ts +2 -0
  19. package/template/.vuepress/configs/navbar/zh.ts +52 -0
  20. package/template/.vuepress/configs/sidebar/en.ts +64 -0
  21. package/template/.vuepress/configs/sidebar/index.ts +2 -0
  22. package/template/.vuepress/configs/sidebar/zh.ts +67 -0
  23. package/template/.vuepress/styles/index.scss +0 -0
  24. package/template/.vuepress/styles/palette.scss +0 -0
  25. package/template/{readme.md → README.md} +3 -3
  26. package/template/guide/{readme.md → README.md} +2 -1
  27. package/template/guide/disable.md +5 -2
  28. package/template/guide/encrypt.md +2 -2
  29. package/template/guide/markdown.md +140 -391
  30. package/template/guide/page.md +4 -3
  31. package/template/home.md +44 -36
  32. package/template/posts/article/article1.md +19 -0
  33. package/template/posts/article/article2.md +20 -0
  34. package/template/posts/article/article3.md +20 -0
  35. package/template/posts/article/article4.md +20 -0
  36. package/template/posts/article/article5.md +20 -0
  37. package/template/posts/article/article6.md +21 -0
  38. package/template/posts/article/article7.md +20 -0
  39. package/template/posts/article/article8.md +20 -0
  40. package/template/posts/article10.md +20 -0
  41. package/template/posts/article11.md +20 -0
  42. package/template/posts/article12.md +21 -0
  43. package/template/posts/article9.md +20 -0
  44. package/template/zh/{readme.md → README.md} +3 -3
  45. package/template/zh/guide/{readme.md → README.md} +2 -1
  46. package/template/zh/guide/disable.md +5 -2
  47. package/template/zh/guide/encrypt.md +2 -2
  48. package/template/zh/guide/markdown.md +141 -394
  49. package/template/zh/guide/page.md +5 -4
  50. package/template/zh/home.md +41 -33
  51. package/template/zh/posts/article/article1.md +19 -0
  52. package/template/zh/posts/article/article2.md +20 -0
  53. package/template/zh/posts/article/article3.md +20 -0
  54. package/template/zh/posts/article/article4.md +20 -0
  55. package/template/zh/posts/article/article5.md +20 -0
  56. package/template/zh/posts/article/article6.md +21 -0
  57. package/template/zh/posts/article/article7.md +20 -0
  58. package/template/zh/posts/article/article8.md +20 -0
  59. package/template/zh/posts/article10.md +20 -0
  60. package/template/zh/posts/article11.md +20 -0
  61. package/template/zh/posts/article12.md +21 -0
  62. package/template/zh/posts/article9.md +20 -0
  63. package/tsconfig.build.json +10 -0
  64. package/tsconfig.json +8 -0
  65. package/lib/checkVersion.d.ts +0 -1
  66. package/lib/checkVersion.js +0 -23
  67. package/lib/checkVersion.js.map +0 -1
  68. package/lib/copy.d.ts +0 -1
  69. package/lib/copy.js +0 -38
  70. package/lib/copy.js.map +0 -1
  71. package/lib/hasYarn.d.ts +0 -1
  72. package/lib/hasYarn.js +0 -15
  73. package/lib/hasYarn.js.map +0 -1
  74. package/lib/i18n.d.ts +0 -26
  75. package/lib/i18n.js +0 -58
  76. package/lib/i18n.js.map +0 -1
  77. package/lib/index.d.ts +0 -2
  78. package/lib/index.js +0 -118
  79. package/lib/index.js.map +0 -1
  80. package/lib/registry.d.ts +0 -5
  81. package/lib/registry.js +0 -23
  82. package/lib/registry.js.map +0 -1
  83. package/template/.vuepress/config.js +0 -211
  84. package/template/.vuepress/styles/index.styl +0 -2
  85. package/template/layout.md +0 -98
  86. package/template/zh/layout.md +0 -98
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
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.24](https://github.com/vuepress-theme-hope/vuepress-theme-hope/compare/v2.0.0-alpha.23...v2.0.0-alpha.24) (2022-02-16)
7
+
8
+ ### Features
9
+
10
+ - 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,2 @@
1
+ "use strict";var e=require("fs"),s=require("path"),r=require("@mr-hope/vuepress-shared"),t=require("cac"),a=require("inquirer"),n=require("execa"),o=require("@vuepress/utils"),i=require("https");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=c(n);const l=(e,s)=>{const r=o.path.dirname(s);o.fs.ensureDirSync(r);const t=o.fs.createReadStream(e),a=o.fs.createWriteStream(s);t.pipe(a)},u=(e,s)=>{o.fs.ensureDirSync(s);o.fs.readdirSync(e,{withFileTypes:!0}).forEach((r=>{r.isFile()?l(`${e}/${r.name}`,`${s}/${r.name}`):r.isDirectory()&&u(`${e}/${r.name}`,`${s}/${r.name}`)}))},d=e=>new Promise(((s,r)=>{i.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=>n.sync(e?"yarn":"npm",["config","get","registry"]).stdout)(s);if("en-US"===e||"https://registry.npmmirror.com/"===r)return r;const{registry:t}=await a.prompt([{name:"registry",type:"list",message:"选择你想使用的源",choices:["国内镜像源","当前源"]}]);return"国内镜像源"===t?"https://registry.npmmirror.com/":r},v=t.cac("vuepress-theme-hope"),h=(()=>{try{return n.sync("yarn --version",{stdio:"ignore"}),!0}catch(e){return!1}})()?"yarn":"npm";v.command("[dir]","Generate a new vuepress-theme-hope project").action((async t=>{if(!t)return v.outputHelp();const{lang:n,message:i}=await(async()=>{const{language:e}=await a.prompt([{name:"language",type:"list",message:"Select a language to display",choices:["en-US","zh-CN"]}]);return{lang:e,message:g[e]}})(),c=s.resolve(process.cwd(),t),y=s.resolve(process.cwd(),"package.json"),f={"docs:build":`vuepress build ${t}`,"docs:clean-dev":`vuepress dev ${t} --no-cache`,"docs:dev":`vuepress dev ${t}`,"docs:eject-theme":`vuepress eject-hope ${t}`};console.log(i.getVersion);const w={vuepress:`^${await d("vuepress")}`,"vuepress-theme-hope":`^${await d("vuepress-theme-hope")}`};if(e.existsSync(c)||e.mkdirSync(c),e.existsSync(y)){console.log(i.updatePackage);const s=JSON.parse(e.readFileSync(y,{encoding:"utf-8"}));r.deepAssign(s,{scripts:f,devDependencies:w}),e.writeFileSync(y,`${JSON.stringify(s,null,2)}\n`,{encoding:"utf-8"})}else{console.log(i.createPackage);const s={...await a.prompt([{name:"name",type:"input",message:i.nameMessage,default:"vuepress-theme-hope-project",validate:e=>!!/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u.exec(e)||i.nameError},{name:"version",type:"input",message:i.versionMessage,default:"1.0.0",validate:e=>!!/^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u.exec(e)||i.versionError},{name:"description",type:"input",message:i.descriptionMessage,default:"A project of vuepress-theme-hope"},{name:"license",type:"input",message:i.licenseMessage,default:"MIT"}]),scripts:f,devDependencies:w};e.writeFileSync(y,`${JSON.stringify(s,null,2)}\n`,{encoding:"utf-8"})}var S,k;console.log(i.template),S=s.resolve(__dirname,"../template"),k=s.resolve(process.cwd(),t),o.fs.statSync(S).isDirectory()?u(S,k):o.fs.statSync(S).isFile()&&l(S,k),console.log(i.install),console.warn(i.wait);const $=await m(n,h);p.default.sync(h,["install","--registry",$],{stdout:"inherit"}),console.log(i.success);const{choise:j}=await a.prompt([{name:"choise",type:"list",message:i.devServerAsk,choices:["Yes","No"]}]);"Yes"===j?(console.log(i.devServer),await p.default(h,["run","docs:dev"],{stdout:"inherit"})):console.log(i.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();
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../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],"names":["copyFile","srcFile","targetFile","targetDir","path","dirname","fs","ensureDirSync","rs","createReadStream","ws","createWriteStream","pipe","copyDir","srcDir","readdirSync","withFileTypes","forEach","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","mkdirSync","packageContent","readFileSync","encoding","deepAssign","writeFileSync","stringify","default","validate","input","exec","src","target","__dirname","statSync","warn","execa","choise","help","title"],"mappings":"sRAEA,MAAMA,EAAW,CAACC,EAAiBC,KACjC,MAAMC,EAAYC,OAAKC,QAAQH,GAE/BI,KAAGC,cAAcJ,GAEjB,MAAMK,EAAKF,KAAGG,iBAAiBR,GACzBS,EAAKJ,KAAGK,kBAAkBT,GAEhCM,EAAGI,KAAKF,IAGJG,EAAU,CAACC,EAAgBX,KAC/BG,KAAGC,cAAcJ,GAEHG,KAAGS,YAAYD,EAAQ,CAAEE,eAAe,IAEhDC,SAASC,IACTA,EAAKC,SACPnB,EAAS,GAAGc,KAAUI,EAAKE,OAAQ,GAAGjB,KAAae,EAAKE,QACjDF,EAAKG,eACZR,EAAQ,GAAGC,KAAUI,EAAKE,OAAQ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C,EAAQd,cAEhB,CACE/B,KAAM,cACN4C,KAAM,QACNC,QAASA,EAAQb,mBACjB2C,QAAS,oCAEX,CACE3E,KAAM,UACN4C,KAAM,QACNC,QAASA,EAAQZ,eACjB0C,QAAS,SAIuBb,QAAAA,EAASG,gBAAAA,GAE7CQ,gBACEZ,EACA,GAAGhD,KAAK6D,UAAUL,EAAgB,KAAM,OACxC,CAAEE,SAAU,UJpFA,IAACQ,EAAaC,EIwF9BjB,QAAQC,IAAInB,EAAQxB,UJxFH0D,EI0FZ1E,UAAQ4E,UAAW,eJ1FMD,EI0FU3E,UAAQsD,QAAQC,MAAON,GJzF7DpE,KAAGgG,SAASH,GAAK9E,cAAeR,EAAQsF,EAAKC,GACxC9F,KAAGgG,SAASH,GAAKhF,UAAUnB,EAASmG,EAAKC,GI0FhDjB,QAAQC,IAAInB,EAAQtB,SACpBwC,QAAQoB,KAAKtC,EAAQvB,MAErB,MAAMoB,QAAiBR,EAAYE,EAAMC,GAEzC+C,UAAM7C,KAAKF,EAAK,CAAC,UAAW,aAAcK,GAAW,CACnDF,OAAQ,YAGVuB,QAAQC,IAAInB,EAAQrB,SAEpB,MAAM6D,OAAEA,SAAiB1C,SAAiC,CACxD,CACE3C,KAAM,SACN4C,KAAM,OACNC,QAASA,EAAQpB,aACjBqB,QAAS,CAAC,MAAO,SAIN,QAAXuC,GACFtB,QAAQC,IAAInB,EAAQnB,iBAEd0D,UAAM/C,EAAK,CAAC,MAAO,YAAa,CACpCG,OAAQ,aAELuB,QAAQC,IAAInB,EAAQlB,SAG/BoB,EAAIuC,MAAK,IAAM,CACb,CACEC,MACE,6EACF7E,KAAM,qDAIVqC,EAAIjC"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "create-vuepress-theme-hope",
3
- "version": "1.21.0",
4
- "description": "Theme create shortcut for yarn",
3
+ "version": "2.0.0-alpha.24",
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,25 @@
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.21.0",
34
- "@types/inquirer": "^8.1.3",
35
+ "@mr-hope/vuepress-shared": "2.0.0-alpha.24",
36
+ "@types/inquirer": "^8.2.0",
37
+ "@vuepress/utils": "2.0.0-beta.35",
35
38
  "cac": "^6.7.12",
36
39
  "execa": "^5.1.1",
37
40
  "inquirer": "^8.2.0"
38
41
  },
39
- "gitHead": "f67eff4870c5b352177bf65b8361e8d2514d9619"
42
+ "gitHead": "095aa332146400730b697b08063c45e72f514160"
40
43
  }
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,5 @@
1
+ import { rollupTypescript } from "../../scripts/rollup";
2
+
3
+ export default rollupTypescript("node/index", {
4
+ external: ["@mr-hope/vuepress-shared", "@vuepress/utils", "https"],
5
+ });
@@ -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,30 @@
1
+ import { fs, path } from "@vuepress/utils";
2
+
3
+ const copyFile = (srcFile: string, targetFile: string): void => {
4
+ const targetDir = path.dirname(targetFile);
5
+
6
+ fs.ensureDirSync(targetDir);
7
+
8
+ const rs = fs.createReadStream(srcFile); // create read stream
9
+ const ws = fs.createWriteStream(targetFile); // create write stream
10
+
11
+ rs.pipe(ws);
12
+ };
13
+
14
+ const copyDir = (srcDir: string, targetDir: string): void => {
15
+ fs.ensureDirSync(targetDir);
16
+
17
+ const files = fs.readdirSync(srcDir, { withFileTypes: true });
18
+
19
+ files.forEach((file) => {
20
+ if (file.isFile())
21
+ copyFile(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`);
22
+ else if (file.isDirectory())
23
+ copyDir(`${srcDir}/${file.name}`, `${targetDir}/${file.name}`);
24
+ });
25
+ };
26
+
27
+ export const copy = (src: string, target: string): void => {
28
+ if (fs.statSync(src).isDirectory()) copyDir(src, target);
29
+ else if (fs.statSync(src).isFile()) copyFile(src, target);
30
+ };
@@ -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,156 @@
1
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs";
2
+ import { resolve } from "path";
3
+ import { deepAssign } from "@mr-hope/vuepress-shared";
4
+ import { cac } from "cac";
5
+ import { prompt } from "inquirer";
6
+ import execa from "execa";
7
+ import { copy } from "./copy";
8
+ import { checkForLatestVersion } from "./checkVersion";
9
+ import { detectYarn } from "./hasYarn";
10
+ import { getLanguage } from "./i18n";
11
+ import { getRegistry } from "./registry";
12
+ const cli = cac("vuepress-theme-hope");
13
+
14
+ const bin = detectYarn() ? "yarn" : "npm";
15
+
16
+ cli
17
+ .command("[dir]", "Generate a new vuepress-theme-hope project")
18
+ .action(async (dir: string) => {
19
+ if (!dir) return cli.outputHelp();
20
+
21
+ const { lang, message } = await getLanguage();
22
+
23
+ const targetFolder = resolve(process.cwd(), dir);
24
+ const packageJsonPath = resolve(process.cwd(), "package.json");
25
+ const scripts = {
26
+ "docs:build": `vuepress build ${dir}`,
27
+ "docs:clean-dev": `vuepress dev ${dir} --no-cache`,
28
+ "docs:dev": `vuepress dev ${dir}`,
29
+ "docs:eject-theme": `vuepress eject-hope ${dir}`,
30
+ };
31
+
32
+ console.log(message.getVersion);
33
+
34
+ const vuepressVersion = await checkForLatestVersion("vuepress");
35
+ const themeVersion = await checkForLatestVersion("vuepress-theme-hope");
36
+
37
+ const devDependencies = {
38
+ vuepress: `^${vuepressVersion}`,
39
+ "vuepress-theme-hope": `^${themeVersion}`,
40
+ };
41
+
42
+ if (!existsSync(targetFolder)) mkdirSync(targetFolder);
43
+
44
+ if (existsSync(packageJsonPath)) {
45
+ console.log(message.updatePackage);
46
+
47
+ // eslint-disable-next-line
48
+ const packageContent: any = JSON.parse(
49
+ readFileSync(packageJsonPath, { encoding: "utf-8" })
50
+ );
51
+
52
+ deepAssign(packageContent, { scripts, devDependencies });
53
+
54
+ writeFileSync(
55
+ packageJsonPath,
56
+ `${JSON.stringify(packageContent, null, 2)}\n`,
57
+ { encoding: "utf-8" }
58
+ );
59
+ } else {
60
+ console.log(message.createPackage);
61
+
62
+ interface PackageJsonAnswer {
63
+ name: string;
64
+ version: string;
65
+ description: string;
66
+ license: string;
67
+ }
68
+
69
+ const result = await prompt<PackageJsonAnswer>([
70
+ {
71
+ name: "name",
72
+ type: "input",
73
+ message: message.nameMessage,
74
+ default: "vuepress-theme-hope-project",
75
+ validate: (input: string): true | string =>
76
+ /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u.exec(
77
+ input
78
+ )
79
+ ? true
80
+ : message.nameError,
81
+ },
82
+ {
83
+ name: "version",
84
+ type: "input",
85
+ message: message.versionMessage,
86
+ default: "1.0.0",
87
+ validate: (input: string): true | string =>
88
+ /^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u.exec(input)
89
+ ? true
90
+ : message.versionError,
91
+ },
92
+ {
93
+ name: "description",
94
+ type: "input",
95
+ message: message.descriptionMessage,
96
+ default: "A project of vuepress-theme-hope",
97
+ },
98
+ {
99
+ name: "license",
100
+ type: "input",
101
+ message: message.licenseMessage,
102
+ default: "MIT",
103
+ },
104
+ ]);
105
+
106
+ const packageContent = { ...result, scripts, devDependencies };
107
+
108
+ writeFileSync(
109
+ packageJsonPath,
110
+ `${JSON.stringify(packageContent, null, 2)}\n`,
111
+ { encoding: "utf-8" }
112
+ );
113
+ }
114
+
115
+ console.log(message.template);
116
+
117
+ copy(resolve(__dirname, "../template"), resolve(process.cwd(), dir));
118
+
119
+ console.log(message.install);
120
+ console.warn(message.wait);
121
+
122
+ const registry = await getRegistry(lang, bin);
123
+
124
+ execa.sync(bin, ["install", "--registry", registry], {
125
+ stdout: "inherit",
126
+ });
127
+
128
+ console.log(message.success);
129
+
130
+ const { choise } = await prompt<{ choise: "Yes" | "No" }>([
131
+ {
132
+ name: "choise",
133
+ type: "list",
134
+ message: message.devServerAsk,
135
+ choices: ["Yes", "No"],
136
+ },
137
+ ]);
138
+
139
+ if (choise === "Yes") {
140
+ console.log(message.devServer);
141
+
142
+ await execa(bin, ["run", "docs:dev"], {
143
+ stdout: "inherit",
144
+ });
145
+ } else console.log(message.hint);
146
+ });
147
+
148
+ cli.help(() => [
149
+ {
150
+ title:
151
+ "yarn create vuepress-theme-hope <dir> / npm init vuepress-theme-hope <dir>",
152
+ body: "Create a vuepress-theme-hope template in <dir>",
153
+ },
154
+ ]);
155
+
156
+ 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
+ };