create-vuepress-theme-hope 2.0.0-beta.101 → 2.0.0-beta.102
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.js +65 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,2 +1,66 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{readdirSync as m,mkdirSync as b,statSync as E,createReadStream as S,createWriteStream as x,writeFileSync as l,existsSync as d,readFileSync as v}from"node:fs";import{dirname as y,resolve as a,join as D}from"node:path";import{cac as j}from"cac";import{execaCommandSync as c,execaCommand as T}from"execa";import i from"inquirer";import{fileURLToPath as q}from"node:url";import"node:https";import{createRequire as G}from"node:module";const P={\u7B80\u4F53\u4E2D\u6587:{flow:{getVersion:"\u83B7\u53D6\u4F9D\u8D56\u7684\u6700\u65B0\u7248\u672C...",createPackage:"\u751F\u6210 package.json...",updatePackage:"\u66F4\u65B0 package.json...",generateTemplate:"\u751F\u6210\u6A21\u677F...",install:"\u5B89\u88C5\u4F9D\u8D56...",devServer:`\u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668...
|
|
3
|
+
\u542F\u52A8\u6210\u529F\u540E\uFF0C\u8BF7\u5728\u6D4F\u89C8\u5668\u8F93\u5165\u7ED9\u51FA\u7684\u5F00\u53D1\u670D\u52A1\u5668\u5730\u5740(\u9ED8\u8BA4\u4E3A 'localhost:8080')`},question:{packageManager:"\u9009\u62E9\u5305\u7BA1\u7406\u5668",i18n:"\u9879\u76EE\u9700\u8981\u7528\u5230\u591A\u8BED\u8A00\u4E48?",git:"\u662F\u5426\u521D\u59CB\u5316 Git \u4ED3\u5E93?",workflow:"\u662F\u5426\u9700\u8981\u4E00\u4E2A\u81EA\u52A8\u90E8\u7F72\u6587\u6863\u5230 GitHub Pages \u7684\u5DE5\u4F5C\u6D41\uFF1F",preset:"\u4F60\u60F3\u8981\u521B\u5EFA\u4EC0\u4E48\u7C7B\u578B\u7684\u9879\u76EE\uFF1F",devServer:"\u662F\u5426\u60F3\u8981\u73B0\u5728\u542F\u52A8 Demo \u67E5\u770B?",name:"\u8BBE\u7F6E\u5E94\u7528\u540D\u79F0",version:"\u8BBE\u7F6E\u5E94\u7528\u7248\u672C\u53F7",description:"\u8BBE\u7F6E\u5E94\u7528\u63CF\u8FF0",license:"\u8BBE\u7F6E\u534F\u8BAE"},hint:{install:`\u8FD9\u53EF\u80FD\u9700\u8981\u6570\u5206\u949F\uFF0C\u8BF7\u8010\u5FC3\u7B49\u5F85.
|
|
4
|
+
\u6211\u4EEC\u65E0\u6CD5\u6B63\u786E\u8F93\u51FA\u5B50\u8FDB\u7A0B\u7684\u8FDB\u5EA6\u6761\uFF0C\u6240\u4EE5\u8FDB\u7A0B\u53EF\u80FD\u4F1A\u770B\u4F3C\u672A\u54CD\u5E94`,finish:"\u6A21\u677F\u5DF2\u6210\u529F\u751F\u6210!",devServer:e=>`\u63D0\u793A: \u8BF7\u4F7F\u7528 "${e} run docs:dev" \u547D\u4EE4\u542F\u52A8\u5F00\u53D1\u670D\u52A1\u5668`},error:{name:"\u5E94\u7528\u540D\u79F0\u5E94\u53EA\u5305\u542B\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u63A5\u7EBF (-)",version:"\u6B64\u7248\u672C\u65E0\u6548\uFF0C\u7248\u672C\u53F7\u5E94\u4E3A 'x.x.x'",preset:"\u9884\u8BBE (--preset) \u4EC5\u652F\u6301 doc \u6216 blog",dir:e=>`"[dir]" \u7684\u65B9\u62EC\u53F7\u8868\u793A\u6B64\u5904\u4E3A\u4E00\u4E2A\u53C2\u6570\uFF0C\u4F60\u5E94\u8BE5\u66FF\u6362\u4E3A\u81EA\u5DF1\u60F3\u4F7F\u7528\u7684\u6587\u4EF6\u5939\u540D\u79F0\uFF0C\u5982 "src", "docs" \u7B49!
|
|
5
|
+
\u4F8B\u5982: "${e} init vuepress-theme-hope@next docs"`,empty:e=>`\u76EE\u6807\u6587\u4EF6\u5939 "${e}" \u4E0D\u4E3A\u7A7A\uFF0C\u8BF7\u9009\u62E9\u4E00\u4E2A\u7A7A\u6587\u4EF6\u5939\u6216\u8005\u624B\u52A8\u5220\u9664\u6587\u4EF6\u5939\u4E2D\u7684\u6587\u4EF6`}},"english (US)":{flow:{getVersion:"Getting lastest version of deps...",createPackage:"Generating package.json...",updatePackage:"Updating package.json...",generateTemplate:"Generating Template...",install:"Installing Deps...",devServer:`Staring dev server...
|
|
6
|
+
After the dev server starts running, please visit the given server link ('localhost:8080' by default)`},question:{i18n:"Does the project need multiple languages?",git:"Initialize a git repository?",workflow:"Do you need a GitHub workflow to deploy docs on GitHub pages?",preset:"What type of project do you want to create?",packageManager:"Choose package manager",devServer:"Would you like to preview template now?",name:"Your project name",version:"Your project version",description:"Your project description",license:"Your project lincense"},hint:{install:`This may take a few minutes, please be patient.
|
|
7
|
+
We can not correctly output progress bar from child process, so the process may look stuck.`,finish:"Successful Generated!",devServer:e=>`Hint: You should execute "${e} run docs:dev" to start dev server.`},error:{name:"package name should only contain lowercase characters, numbers and dash",version:"This version is not a valid one. Version should be like 'x.x.x'",preset:'preset (--preset) only support "doc" or "blog"',dir:e=>`The brackets in "[dir]" means it is an argument, you should replace it with folder name you want to use! E.g.: "src", "docs"
|
|
8
|
+
For example: "${e} init vuepress-theme-hope@next docs"`,empty:e=>`Target folder "${e}" is not empty, please choose an empty folder or delete files in it.`}}},I=async()=>{const{language:e}=await i.prompt([{name:"language",type:"list",message:"Select a language to display / \u9009\u62E9\u663E\u793A\u8BED\u8A00",choices:["english (US)","\u7B80\u4F53\u4E2D\u6587"]}]);return{lang:e,message:P[e]}},F=(e,...s)=>{if(s.length===0)return e;const u=s.shift()||{};return Object.keys(u).forEach(t=>{typeof e[t]=="object"&&!Array.isArray(e[t])&&typeof u[t]=="object"&&!Array.isArray(u[t])?F(e[t],u[t]):typeof u[t]=="object"?Array.isArray(u[t])?e[t]=[...u[t]]:e[t]={...u[t]}:e[t]=u[t]}),F(e,...s)},g=e=>{try{m(e)}catch{b(e,{recursive:!0})}},f=(e,s)=>{const u=y(s);g(u);const t=S(e),r=x(s);t.pipe(r)},B=(e,s)=>{g(s),m(e,{withFileTypes:!0}).forEach(u=>{u.isFile()?f(`${e}/${u.name}`,`${s}/${u.name}`):u.isDirectory()&&B(`${e}/${u.name}`,`${s}/${u.name}`)})},w=(e,s)=>{E(e).isDirectory()?B(e,s):E(e).isFile()&&f(e,s)},M=()=>{try{return c("git log"),!0}catch{return!1}},_=()=>{try{return c("git log"),!0}catch{return!1}},z=()=>{try{return c("pnpm --version",{stdio:"ignore"}).exitCode===0}catch{return!1}},N=()=>{try{return c("yarn --version",{stdio:"ignore"}).exitCode===0}catch{return!1}},h=["npm"];N()&&h.push("yarn"),z()&&h.push("pnpm");const O=async e=>(await i.prompt([{name:"packageManager",type:"list",message:e,choices:h}])).packageManager,W=q(import.meta.url),A=y(W),H=(e,s,u)=>`
|
|
9
|
+
name: ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u90E8\u7F72\u6587\u6863":"Deploy Docs"}
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
push:
|
|
13
|
+
branches:
|
|
14
|
+
# ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u786E\u4FDD\u8FD9\u662F\u4F60\u6B63\u5728\u4F7F\u7528\u7684\u5206\u652F\u540D\u79F0":"make sure this is the branch you are using"}
|
|
15
|
+
- main
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
deploy-gh-pages:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout
|
|
22
|
+
uses: actions/checkout@v3
|
|
23
|
+
with:
|
|
24
|
+
fetch-depth: 0
|
|
25
|
+
# ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u5982\u679C\u4F60\u6587\u6863\u9700\u8981 Git \u5B50\u6A21\u5757\uFF0C\u53D6\u6D88\u6CE8\u91CA\u4E0B\u4E00\u884C":"if your docs needs submodules, uncomment the following line"}
|
|
26
|
+
# submodules: true
|
|
27
|
+
|
|
28
|
+
${e==="pnpm"?`
|
|
29
|
+
- name: ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u5B89\u88C5 pnpm":"Install pnpm"}
|
|
30
|
+
uses: pnpm/action-setup@v2
|
|
31
|
+
with:
|
|
32
|
+
version: 7
|
|
33
|
+
run_install: true
|
|
34
|
+
`:""}
|
|
35
|
+
|
|
36
|
+
- name: ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u8BBE\u7F6E Node.js":"Setup Node.js"}
|
|
37
|
+
uses: actions/setup-node@v3
|
|
38
|
+
with:
|
|
39
|
+
node-version: 16
|
|
40
|
+
cache: ${e}
|
|
41
|
+
|
|
42
|
+
- name: ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u5B89\u88C5\u4F9D\u8D56":"Install Deps"}
|
|
43
|
+
run: ${e==="npm"?"npm install":`${e} install --frozen-lockfile`}
|
|
44
|
+
|
|
45
|
+
- name: ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u6784\u5EFA\u6587\u6863":"Build Docs"}
|
|
46
|
+
env:
|
|
47
|
+
NODE_OPTIONS: --max_old_space_size=8192
|
|
48
|
+
run: |-
|
|
49
|
+
${e} run docs:build
|
|
50
|
+
> ${D(s,".vuepress/dist/.nojekyll").replace(/\\/g,"/")}
|
|
51
|
+
|
|
52
|
+
- name: ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u90E8\u7F72\u6587\u6863":"Deploy Docs"}
|
|
53
|
+
uses: JamesIves/github-pages-deploy-action@v4
|
|
54
|
+
with:
|
|
55
|
+
# ${u==="\u7B80\u4F53\u4E2D\u6587"?"\u8FD9\u662F\u6587\u6863\u90E8\u7F72\u5230\u7684\u5206\u652F\u540D\u79F0":"This is the branch where the docs are deployed to"}
|
|
56
|
+
branch: gh-pages
|
|
57
|
+
folder: ${D(s,".vuepress/dist").replace(/\\/g,"/")}
|
|
58
|
+
|
|
59
|
+
`,J=e=>`
|
|
60
|
+
node_modules/
|
|
61
|
+
${e}/.vuepress/.cache/
|
|
62
|
+
${e}/.vuepress/.temp/
|
|
63
|
+
${e}/.vuepress/dist/
|
|
64
|
+
`,$=e=>{const s=a(process.cwd(),".gitignore"),u=d(s)?v(s,{encoding:"utf-8"}):"";l(s,`${u}${J(e)}`,{encoding:"utf-8"})},R=async(e,{packageManager:s,lang:u,message:t,preset:r})=>{const{workflow:n}=await i.prompt([{name:"workflow",type:"confirm",message:t.question.workflow,default:!0}]);if(r||(r=(await i.prompt([{name:"preset",type:"list",message:t.question.preset,choices:["blog","docs"]}])).preset),console.log(t.flow.generateTemplate),w(a(A,"../template/public"),a(process.cwd(),e,"./vuepress/public")),w(a(A,"../template",r),a(process.cwd(),e)),n){const o=a(process.cwd(),".github/workflows");g(o),l(a(o,"deploy-docs.yml"),H(s,e,u),{encoding:"utf-8"})}if(M())$(e);else if(_()){const{git:o}=await i.prompt([{name:"git",type:"confirm",message:t.question.git,default:!0}]);o&&(c("git init"),$(e))}},C=G(import.meta.url)("create-vuepress-theme-hope/package.json").version,Y=e=>({"docs:build":`vuepress build ${e}`,"docs:clean-dev":`vuepress dev ${e} --clean-cache`,"docs:dev":`vuepress dev ${e}`}),U=async(e,s)=>{const u=a(process.cwd(),"package.json"),t=Y(e),r={"@vuepress/client":"2.0.0-beta.51",vue:"^3.2.29",vuepress:"2.0.0-beta.51","vuepress-theme-hope":C};if(d(u)){console.log(s.flow.updatePackage);const n=JSON.parse(v(u,{encoding:"utf-8"}));F(n,{scripts:t,devDependencies:r}),l(u,`${JSON.stringify(n,null,2)}
|
|
65
|
+
`,{encoding:"utf-8"})}else{console.log(s.flow.createPackage);const n={...await i.prompt([{name:"name",type:"input",message:s.question.name,default:"vuepress-theme-hope-template",validate:o=>/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u.exec(o)?!0:s.error.name},{name:"version",type:"input",message:s.question.version,default:"2.0.0",validate:o=>/^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u.exec(o)?!0:s.error.version},{name:"description",type:"input",message:s.question.description,default:"A project of vuepress-theme-hope"},{name:"license",type:"input",message:s.question.license,default:"MIT"}]),type:"module",scripts:t,devDependencies:r};l(u,`${JSON.stringify(n,null,2)}
|
|
66
|
+
`,{encoding:"utf-8"})}},V="https://registry.npmmirror.com/",L=e=>c(`${e} config get registry`).stdout,K=async(e,s)=>{const u=L(e);if(s==="\u7B80\u4F53\u4E2D\u6587"){const{registry:t}=await i.prompt([{name:"registry",type:"list",message:"\u9009\u62E9\u4F60\u60F3\u4F7F\u7528\u7684\u6E90",choices:["\u56FD\u5185\u955C\u50CF\u6E90","\u5F53\u524D\u6E90"]}]);return t==="\u56FD\u5185\u955C\u50CF\u6E90"?V:u}return u},p=j("vuepress-theme-hope");p.command("[dir]","Generate a new vuepress-theme-hope project").option("-p, --preset <preset>","Choose preset to use").usage("pnpm create vuepress-theme-hope@next [dir] / npm init vuepress-theme-hope@next [dir]").example("docs").action(async(e,{preset:s=null})=>{if(!e)return p.outputHelp();const{lang:u,message:t}=await I();if(s&&!["doc","blog"].includes(s))return console.log(t.error.preset);const r=await O(t.question.packageManager);if(e.startsWith("[")&&e.endsWith("]"))return console.log(t.error.dir(r));const n=a(process.cwd(),e);if(d(n)&&m(n).length)return console.error(t.error.empty(e));await U(e,t),await R(e,{packageManager:r,lang:u,message:t,preset:s});const o=r==="pnpm"?"":await K(r,u);console.log(t.flow.install),console.warn(t.hint.install),c(`${r} install ${o?"":`--registry ${o}`}`,{stdout:"inherit"}),console.log(t.hint.finish);const{choice:k}=await i.prompt([{name:"choice",type:"confirm",message:t.question.devServer,default:!0}]);k?(console.log(t.flow.devServer),await T(`${r} run docs:dev`,{stdout:"inherit"})):console.log(t.hint.devServer(r))}),p.help(()=>[{title:"pnpm create vuepress-theme-hope@next [dir] / npm init vuepress-theme-hope@next [dir]",body:"Create a vuepress-theme-hope template in [dir]"}]),p.version(C),p.parse();
|