create-vuepress-theme-hope 2.0.0-beta.250 → 2.0.0-beta.252
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 +5 -5
- package/package.json +1 -1
- package/template/blog/config/en/theme.ts +1 -1
- package/template/blog/config/multi/theme.ts +1 -1
- package/template/blog/config/zh/theme.ts +1 -1
- package/template/docs/config/en/theme.ts +1 -1
- package/template/docs/config/multi/theme.ts +1 -1
- package/template/docs/config/zh/theme.ts +1 -1
- package/template/docs/en/README.md +2 -1
- package/template/docs/zh/README.md +2 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{existsSync as f,readFileSync as
|
|
2
|
+
import{existsSync as f,readFileSync as S,writeFileSync as v,readdirSync as w,mkdirSync as A,statSync as j,createReadStream as C,createWriteStream as I}from"node:fs";import{resolve as o,join as x,dirname as D}from"node:path";import{cac as O}from"cac";import{execaCommandSync as c,execaCommand as R}from"execa";import m from"inquirer";import{createRequire as F}from"node:module";import{fileURLToPath as W}from"node:url";const H={简体中文:{flow:{getVersion:"获取依赖的最新版本...",createPackage:"生成 package.json...",updatePackage:"更新 package.json...",generateTemplate:"生成模板...",install:"安装依赖...",devServer:`启动开发服务器...
|
|
3
3
|
启动成功后,请在浏览器输入给出的开发服务器地址(默认为 'localhost:8080')`},question:{packageManager:"选择包管理器",i18n:"项目需要用到多语言么?",git:"是否初始化 Git 仓库?",workflow:"是否需要一个自动部署文档到 GitHub Pages 的工作流?",preset:"你想要创建什么类型的项目?",devServer:"是否想要现在启动 Demo 查看?",name:"设置应用名称",version:"设置应用版本号",description:"设置应用描述",license:"设置协议"},hint:{install:`这可能需要数分钟,请耐心等待.
|
|
4
4
|
我们无法正确输出子进程的进度条,所以进程可能会看似未响应`,finish:"模板已成功生成!",devServer:e=>`提示: 请使用 "${e} run docs:dev" 命令启动开发服务器`},error:{name:"应用名称应只包含小写字母、数字和连接线 (-)",version:"此版本无效,版本号应为 'x.x.x'",preset:"预设 (--preset) 仅支持 doc 或 blog",outputDirMissing:e=>`"[dir]" 的方括号表示此处为一个参数,你应该替换为自己想使用的文件夹名称,如 "my-blog", "project-docs" 等!
|
|
5
5
|
例如: "${e} init vuepress-theme-hope project-docs"`,updateDirMissing:e=>`"[dir]" 的方括号表示此处为一个参数,你应该替换为自己想使用的文件夹名称,如 "src", "docs" 等!
|
|
@@ -12,7 +12,7 @@ node_modules/
|
|
|
12
12
|
${e}/.vuepress/.cache/
|
|
13
13
|
${e}/.vuepress/.temp/
|
|
14
14
|
${e}/.vuepress/dist/
|
|
15
|
-
`,M=(e,t=process.cwd())=>{const s=
|
|
15
|
+
`,M=(e,t=process.cwd())=>{const s=o(t,".gitignore"),r=f(s)?S(s,{encoding:"utf-8"}):"";v(s,`${r}${Y(e)}`,{encoding:"utf-8"})},U=(e,t,s)=>`
|
|
16
16
|
name: ${s==="简体中文"?"部署文档":"Deploy Docs"}
|
|
17
17
|
|
|
18
18
|
on:
|
|
@@ -64,6 +64,6 @@ ${e!=="pnpm"?` - name: ${s==="简体中文"?"安装依赖":"Install Deps"}
|
|
|
64
64
|
# ${s==="简体中文"?"这是文档部署到的分支名称":"This is the branch where the docs are deployed to"}
|
|
65
65
|
branch: gh-pages
|
|
66
66
|
folder: ${x(t,".vuepress/dist").replace(/\\/g,"/")}
|
|
67
|
-
`,V=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u,L=/^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u,B=Array.isArray,$=e=>Object.prototype.toString.call(e)==="[object Object]",k=(e,...t)=>{if(t.length===0)return e;const s=t.shift()||null;return s&&Object.entries(s).forEach(([a
|
|
68
|
-
`,{encoding:"utf-8"})}else{console.log(t.flow.createPackage);const d={...await m.prompt([{name:"name",type:"input",message:t.question.name,default:"vuepress-theme-hope-template",validate:i=>V.exec(i)?!0:t.error.name},{name:"version",type:"input",message:t.question.version,default:"2.0.0",validate:i=>L.exec(i)?!0:t.error.version},{name:"description",type:"input",message:t.question.description,default:"A project of vuepress-theme-hope"},{name:"license",type:"input",message:t.question.license,default:"MIT"}]),type:"module",scripts:n,devDependencies:
|
|
69
|
-
`,{encoding:"utf-8"})}},P="https://registry.npmmirror.com/",
|
|
67
|
+
`,V=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u,L=/^[0-9]+\.[0-9]+\.(?:[0=9]+|[0-9]+-[a-z]+\.[0-9])$/u,B=Array.isArray,$=e=>Object.prototype.toString.call(e)==="[object Object]",k=(e,...t)=>{if(t.length===0)return e;const s=t.shift()||null;return s&&Object.entries(s).forEach(([r,a])=>{r==="__proto__"||r==="constructor"||($(e[r])&&$(a)?k(e[r],a):B(a)?e[r]=[...a]:$(a)?e[r]={...a}:e[r]=s[r])}),k(e,...t)},y=e=>{try{w(e)}catch{try{A(e,{recursive:!0})}catch{}}},G=(e,t)=>{const s=D(t);y(s);const r=C(e),a=I(t);r.pipe(a)},T=(e,t)=>{y(t),w(e,{withFileTypes:!0}).forEach(s=>{s.isFile()?G(`${e}/${s.name}`,`${t}/${s.name}`):s.isDirectory()&&T(`${e}/${s.name}`,`${t}/${s.name}`)})},p=(e,t)=>{j(e).isDirectory()?T(e,t):j(e).isFile()&&G(e,t)},K=(e=process.cwd())=>{try{return c("git status",{cwd:e}),!0}catch{return!1}},Q=()=>{try{return c("git --version"),!0}catch{return!1}},X=()=>{try{return c("pnpm --version",{stdio:"ignore"}).exitCode===0}catch{return!1}},Z=()=>{try{return c("yarn --version",{stdio:"ignore"}).exitCode===0}catch{return!1}},b=["npm"];Z()&&b.push("yarn"),X()&&b.push("pnpm");const ee=async e=>(await m.prompt([{name:"packageManager",type:"list",message:e,choices:b}])).packageManager,te=W(import.meta.url),l=D(te),_=async(e,{cwd:t=process.cwd(),packageManager:s,lang:r,message:a,preset:n})=>{const{i18n:u,workflow:d}=await m.prompt([{name:"i18n",type:"confirm",message:a.question.i18n,default:!1},{name:"workflow",type:"confirm",message:a.question.workflow,default:!0}]);n||(n=(await m.prompt([{name:"preset",type:"list",message:a.question.preset,choices:["blog","docs"]}])).preset),console.log(a.flow.generateTemplate);const i=n;if(p(o(l,"../template/public"),o(t,e,"./.vuepress/public")),p(o(l,"../template",i,"config/base"),o(t,e,".vuepress")),u?(p(o(l,"../template",i,"en"),o(t,e)),p(o(l,"../template",i,"zh"),o(t,e,"zh")),p(o(l,"../template",i,"config/multi"),o(t,e,".vuepress"))):r==="简体中文"?(p(o(l,"../template",i,"zh"),o(t,e)),p(o(l,"../template",i,"config/zh"),o(t,e,".vuepress"))):(p(o(l,"../template",i,"en"),o(t,e)),p(o(l,"../template",i,"config/en"),o(t,e,".vuepress"))),d){const h=o(t,".github/workflows");y(h),v(o(h,"deploy-docs.yml"),U(s,e,r),{encoding:"utf-8"})}if(K(t))M(e,t);else if(Q()){const{git:h}=await m.prompt([{name:"git",type:"confirm",message:a.question.git,default:!0}]);h&&(c("git init",{cwd:t}),M(e,t))}},E=F(import.meta.url)("create-vuepress-theme-hope/package.json").version,se=(e,t)=>({"docs:build":`vuepress build ${t}`,"docs:clean-dev":`vuepress dev ${t} --clean-cache`,"docs:dev":`vuepress dev ${t}`,"docs:update-package":`${e==="npm"?"npx":`${e} dlx`} vp-update`}),q=async(e,t,s,r=process.cwd())=>{const a=o(r,"package.json"),n=se(e,s),u={"@vuepress/client":"2.0.0-beta.68",vue:"^3.3.8",vuepress:"2.0.0-beta.68","vuepress-theme-hope":E};if(f(a)){console.log(t.flow.updatePackage);const d=JSON.parse(S(a,{encoding:"utf-8"}));k(d,{scripts:n,devDependencies:u}),v(a,`${JSON.stringify(d,null,2)}
|
|
68
|
+
`,{encoding:"utf-8"})}else{console.log(t.flow.createPackage);const d={...await m.prompt([{name:"name",type:"input",message:t.question.name,default:"vuepress-theme-hope-template",validate:i=>V.exec(i)?!0:t.error.name},{name:"version",type:"input",message:t.question.version,default:"2.0.0",validate:i=>L.exec(i)?!0:t.error.version},{name:"description",type:"input",message:t.question.description,default:"A project of vuepress-theme-hope"},{name:"license",type:"input",message:t.question.license,default:"MIT"}]),type:"module",scripts:n,devDependencies:u};v(a,`${JSON.stringify(d,null,2)}
|
|
69
|
+
`,{encoding:"utf-8"})}},P="https://registry.npmmirror.com/",re=(e,t)=>c(`${e} config get ${t?"npmRegistryServer":"registry"}}`).stdout,ae=async(e,t)=>{const s=e==="yarn"&&!c("yarn --version").stdout.startsWith("1"),r=re(e,s);if(/https:\/\/registry\.npm\.taobao\.org\/?/.test(r)&&(console.error("npm.taobao.org is no longer available, resetting it to npmmirror.com"),c(`${e} config set ${s?"npmRegistryServer":"registry"}} ${P}`)),t==="简体中文"){const{registry:a}=await m.prompt([{name:"registry",type:"list",message:"选择你想使用的源",choices:["国内镜像源","当前源"]}]);return a==="国内镜像源"?P:r}return r},z=async(e,t)=>{if(!e)return g.outputHelp();const{lang:s,message:r}=await J();if(t&&!["docs","blog"].includes(t))return console.log(r.error.preset);const a=await ee(r.question.packageManager);if(e.startsWith("[")&&e.endsWith("]"))return console.log(r.error.updateDirMissing(a));const n=o(process.cwd(),e);return f(n)&&w(n).length?console.error(r.error.dirNotEmpty(e)):(y(n),{lang:s,message:r,packageManager:a})},N=async({cwd:e=process.cwd(),lang:t,message:s,packageManager:r})=>{const a=r==="pnpm"?"":await ae(r,t);console.log(s.flow.install),console.warn(s.hint.install),c(`${r} install ${a?`--registry ${a}`:""}`,{cwd:e,stdout:"inherit"}),console.log(s.hint.finish);const{choice:n}=await m.prompt([{name:"choice",type:"confirm",message:s.question.devServer,default:!0}]);n?(console.log(s.flow.devServer),await R(`${r} run docs:dev`,{cwd:e,stdout:"inherit"})):console.log(s.hint.devServer(r))},g=O("vuepress-theme-hope");g.command("[dir]","Generate a new vuepress-theme-hope project").option("-p, --preset <preset>","Choose preset to use").usage("pnpm create vuepress-theme-hope [dir] / yarn create vuepress-theme-hope [dir] / npm init vuepress-theme-hope [dir]").example("docs").action(async(e,{preset:t=null})=>{const s=o(process.cwd(),e),r=await z(e,t);if(r){const{lang:a,message:n,packageManager:u}=r;await q(u,n,"src",e),await _("src",{cwd:s,packageManager:u,lang:a,message:n,preset:t}),await N({cwd:s,lang:a,message:n,packageManager:u})}}),g.command("add [dir]","Add vuepress template to dir").alias("inject").option("-p, --preset <preset>","Choose preset to use").usage("pnpm create vuepress-theme-hope add [dir] / yarn create vuepress-theme-hope add [dir] / npm init vuepress-theme-hope add [dir]").example("docs").action(async(e,{preset:t=null})=>{const s=await z(e,t);if(s){const{lang:r,message:a,packageManager:n}=s;await q(n,a,e),await _(e,{packageManager:n,lang:r,message:a,preset:t}),await N({message:a,lang:r,packageManager:n})}}),g.help(()=>[{title:"pnpm create vuepress-theme-hope [dir] / yarn create vuepress-theme-hope [dir] / npm init vuepress-theme-hope [dir]",body:"Create a vuepress-theme-hope template in [dir]"},{title:"pnpm create vuepress-theme-hope inject [dir] / yarn create vuepress-theme-hope add [dir] / npm init vuepress-theme-hope inject [dir]",body:"Add vuepress-theme-hope template in [dir] under current project"}]),g.version(E),g.parse();
|
package/package.json
CHANGED