@tomjs/create-app 0.1.0 → 0.1.2
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/README.md +2 -2
- package/README.zh_CN.md +2 -2
- package/dist/index.mjs +4 -4
- package/package.json +1 -1
- package/template-node-github/README.md +2 -2
- package/template-node-github/README.zh_CN.md +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @tomjs/create-app
|
|
2
2
|
|
|
3
|
-
   
|
|
4
4
|
|
|
5
|
-
Create a web application based on [vite](https://github.com/vitejs/vite) + [tomjs](https://github.com/tomgao365/tomjs)
|
|
5
|
+
Create a web application based on [vite](https://github.com/vitejs/vite) + [tomjs](https://github.com/tomgao365/tomjs).
|
|
6
6
|
|
|
7
7
|
**English** | [中文](./README.zh_CN.md)
|
|
8
8
|
|
package/README.zh_CN.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @tomjs/create-app
|
|
2
2
|
|
|
3
|
-
   
|
|
4
4
|
|
|
5
|
-
创建基于 [vite](https://github.com/vitejs/vite) + [tomjs](https://github.com/tomgao365/tomjs) 的 web
|
|
5
|
+
创建基于 [vite](https://github.com/vitejs/vite) + [tomjs](https://github.com/tomgao365/tomjs) 的 web 应用。
|
|
6
6
|
|
|
7
7
|
[English](./README.md) | **中文**
|
|
8
8
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
Scaffolding project in ${i}...`);let y=
|
|
4
|
-
`),
|
|
2
|
+
import c from"fs";import X from"os";import s from"path";import{fileURLToPath as Y}from"url";import{blue as h,cyan as Z,green as ee,red as I,reset as d,yellow as j}from"kolorist";import te from"minimist";import ne from"prompts";import k from"shelljs";import m from"fs";import E from"path";function T(e){return[["t","template"]].forEach(([t,r])=>{e[r]=e[r]??e[t]}),e}function M(e){let t=m.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function N(e){return e?.trim().replace(/\/+$/g,"")}function Q(e,t){m.mkdirSync(t,{recursive:!0});for(let r of m.readdirSync(e)){let p=E.resolve(e,r),f=E.resolve(t,r);F(p,f)}}function F(e,t){m.statSync(e).isDirectory()?Q(e,t):m.copyFileSync(e,t)}function O(e){if(m.existsSync(e))for(let t of m.readdirSync(e))t!==".git"&&m.rmSync(E.resolve(e,t),{recursive:!0,force:!0})}function b(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function V(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function z(e){if(!e)return;let r=e.split(" ")[0].split("/");return{name:r[0],version:r[1]}}var $=T(te(process.argv.slice(2),{string:["_"]})),P=process.cwd(),L=[{name:"vue",display:"Vue",color:ee,variants:[{name:"vue",display:"Web",color:h},{name:"electron-vue",display:"Electron",color:j}]},{name:"react",display:"React",color:Z,variants:[{name:"react",display:"Web",color:h},{name:"electron-react",display:"Electron",color:j}]},{name:"node",display:"Node",color:h,variants:[{name:"node",display:"base",color:h},{name:"node-github",display:"Github + NPM",color:j}]}],W=L.map(e=>e.variants&&e.variants.map(t=>t.name)||[e.name]).reduce((e,t)=>e.concat(t),[]),re={_gitignore:".gitignore","_lintstagedrc.cjs":".lintstagedrc.cjs"},R="my-app";function G(e){let t=k.exec(`git config --get ${e}`,{silent:!0});if(t.code===0)return t.stdout.trim()}async function oe(){let e=N($._[0]),t=$.template||$.t,r=e||R,p=()=>r==="."?s.basename(s.resolve()):r,f={};f=await ne([{type:e?null:"text",name:"projectName",message:d("Project name:"),initial:R,onState:n=>{r=N(n.value)||R}},{type:()=>!c.existsSync(r)||M(r)?null:"toggle",name:"overwrite",message:()=>(r==="."?"Current directory":`Target directory "${r}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"yes",inactive:"no"},{type:(n,{overwrite:o})=>{if(o===!1)throw console.log(I("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>b(p())?null:"text",name:"packageName",message:d("Package name:"),initial:()=>V(p()),validate:n=>b(n)||"Invalid package.json name"},{type:t&&W.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!W.includes(t)?d(`"${t}" isn't a valid template. Please choose from below: `):d("Select a framework:"),initial:0,choices:L.map(n=>{let o=n.color;return{title:o(n.display||n.name),value:n}})},{type:n=>n&&n.variants?"select":null,name:"variant",message:d("Select a variant:"),choices:n=>n?.variants?.map(o=>{let a=o.color;return{title:a(o.display||o.name),value:o.name}})}],{onCancel:()=>{throw console.log(I("\u2716")+" Operation cancelled"),new Error}});let{framework:U,overwrite:J,packageName:H,variant:K}=f,i=s.join(P,r.substring(r.indexOf("/")+1));J?O(i):c.existsSync(i)||c.mkdirSync(i,{recursive:!0}),console.log(`
|
|
3
|
+
Scaffolding project in ${i}...`);let y=K||U?.name||t||"",A=n=>s.join(Y(import.meta.url),"../..",`template-${n}`),C=A(y),q=y.includes("node");[C,A("config")].forEach(n=>{let o=c.readdirSync(n);for(let a of o){let v=re[a]??a;if(q&&a.includes("stylelint"))continue;let x=s.join(i,v);F(s.join(n,a),x)}});let D=y.includes("github"),B=`template-${y}`,u=JSON.parse(c.readFileSync(s.join(C,"package.json"),"utf-8")),l=H||p();u.name=l;let g={name:"Tom Gao",email:"tom@tomgao.cc"};if(D){k.which("git")&&(g.name=G("user.name")||X.userInfo().username,g.email=G("user.email")||"",u.author=Object.assign(u.author,g));let n=l.startsWith("@")?l.split("/")[0].substring(1):g.name;u.repository.url=`https://github.com/${n}/${l.substring(l.indexOf("/")+1)}.git`}c.writeFileSync(s.join(i,"package.json"),JSON.stringify(u,null,2)+`
|
|
4
|
+
`),D&&["LICENSE","README.md","README.zh_CN.md"].forEach(n=>{let o=s.join(i,n);if(!c.existsSync(o))return;let a=c.readFileSync(o,"utf-8").replace(new RegExp(B,"g"),l).replace(new RegExp("{{user.name}}","g"),g.name).replace(new RegExp("{{user.email}}","g"),g.email);if(n.startsWith("README")){let v=l.replace("@","%40"),x=l.replace("@","%40").replace(new RegExp("/","g"),"%2F");a=a.replace("{{badges}}",[``,``,``].join(" "))}c.writeFileSync(o,a)});let _=z(process.env.npm_config_user_agent),w=_?_.name:"npm";k.which("git")&&k.exec(`cd ${i} && git init`);let S=s.relative(P,i);switch(console.log(`
|
|
5
5
|
Done. Now run:
|
|
6
|
-
`),i!==
|
|
6
|
+
`),i!==P&&console.log(` cd ${S.includes(" ")?`"${S}"`:S}`),w){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${w} install`),console.log(` ${w} run dev`);break}}oe().catch(e=>{e.message&&console.error(e)});
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# template-node-github
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
{{badges}}
|
|
4
4
|
|
|
5
|
-
Basic node template
|
|
5
|
+
> Basic node template
|
|
6
6
|
|
|
7
7
|
**English** | [中文](./README.zh_CN.md)
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# template-node-github
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
{{badges}}
|
|
4
4
|
|
|
5
|
-
基础 node 模板
|
|
5
|
+
> 基础 node 模板
|
|
6
6
|
|
|
7
7
|
[English](./README.md) | **中文**
|
|
8
8
|
|