@tomjs/create-app 0.2.2 → 0.2.3
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/dist/index.mjs +5 -5
- package/package.json +9 -11
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import a from"fs";import
|
|
3
|
-
Scaffolding project in ${
|
|
4
|
-
`),_&&["LICENSE","README.md","README.zh_CN.md"].forEach(n=>{let o=l.join(s,n);if(!C&&a.existsSync(o)){a.rmSync(o),n==="README.md"&&a.writeFileSync(o,`# ${m}
|
|
5
|
-
`,{encoding:"utf-8"});return}if(!a.existsSync(o))return;let i=a.readFileSync(o,"utf-8").replace(new RegExp(Q,"g"),m).replace(new RegExp("{{user.name}}","g"),g.name).replace(new RegExp("{{user.email}}","g"),g.email);if(n.startsWith("README")){let u=m.replace("@","%40"),y=m.replace("@","%40").replace(new RegExp("/","g"),"%2F");i=i.replace("{{badges}}",[``,``,``].join(" "))}a.writeFileSync(o,i)});let T=I(process.env.npm_config_user_agent),b=T?T.name:"npm";w.which("git")&&w.exec(`cd ${s} && git init`);let S=l.relative(R,s);switch(console.log(`
|
|
2
|
+
import a,{rmSync as te}from"fs";import ne from"os";import l from"path";import{fileURLToPath as re}from"url";import{blue as v,cyan as oe,green as ie,red as L,reset as d,yellow as N}from"kolorist";import{camelCase as se}from"lodash-es";import ae from"minimist";import ce from"prompts";import k from"shelljs";import p from"fs";import b from"path";function W(e){return[["t","template"]].forEach(([t,o])=>{e[o]=e[o]??e[t]}),e}function z(e){let t=p.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function j(e){return e?.trim().replace(/\/+$/g,"")}function ee(e,t){p.mkdirSync(t,{recursive:!0});for(let o of p.readdirSync(e)){let g=b.resolve(e,o),u=b.resolve(t,o);P(g,u)}}function P(e,t){p.statSync(e).isDirectory()?ee(e,t):p.copyFileSync(e,t)}function I(e){if(p.existsSync(e))for(let t of p.readdirSync(e))t!==".git"&&p.rmSync(b.resolve(e,t),{recursive:!0,force:!0})}function F(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function U(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function V(e){if(!e)return;let o=e.split(" ")[0].split("/");return{name:o[0],version:o[1]}}function R(e,t){let{variant:o,framework:g}=e,u=g;return u[t]||!!u?.variants?.find(y=>y.name===o&&y[t])}var $=W(ae(process.argv.slice(2),{string:["_"]})),D=process.cwd(),G=[{name:"vue",display:"Vue",color:ie,variants:[{name:"vue",display:"Web",color:v},{name:"electron-vue",display:"Electron",color:N}]},{name:"react",display:"React",color:oe,variants:[{name:"react",display:"Web",color:v},{name:"electron-react",display:"Electron",color:N}]},{name:"node",display:"Node",color:v,publish:!0,test:!0,variants:[{name:"node",display:"Base",color:v},{name:"node-electron",display:"Electron",color:N}]}],J=G.map(e=>e.variants&&e.variants.map(t=>t.name)||[e.name]).reduce((e,t)=>e.concat(t),[]),le={_gitignore:".gitignore","_lintstagedrc.cjs":".lintstagedrc.cjs"},A="my-app";function B(e){let t=k.exec(`git config --get ${e}`,{silent:!0});if(t.code===0)return t.stdout.trim()}async function me(){let e=j($._[0]),t=$.template||$.t,o=e||A,g=()=>o==="."?l.basename(l.resolve()):o,u={};u=await ce([{type:e?null:"text",name:"projectName",message:d("Project name:"),initial:A,onState:n=>{o=j(n.value)||A}},{type:()=>!a.existsSync(o)||z(o)?null:"toggle",name:"overwrite",message:()=>(o==="."?"Current directory":`Target directory "${o}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"yes",inactive:"no"},{type:(n,{overwrite:r})=>{if(r===!1)throw console.log(L("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>F(g())?null:"text",name:"packageName",message:d("Package name:"),initial:()=>U(g()),validate:n=>F(n)||"Invalid package.json name"},{type:t&&J.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!J.includes(t)?d(`"${t}" isn't a valid template. Please choose from below: `):d("Select a framework:"),initial:0,choices:G.map(n=>{let r=n.color;return{title:r(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(r=>{let s=r.color;return{title:s(r.display||r.name),value:r.name}})},{type:(n,r)=>R(r,"publish")?"toggle":null,name:"needPublish",message:d("Whether to publish to the npm repository?"),initial:!0,active:"yes",inactive:"no"},{type:(n,r)=>R(r,"test")?"toggle":null,name:"needTest",message:d("Whether to add Test?"),initial:!0,active:"yes",inactive:"no"}],{onCancel:()=>{throw console.log(L("\u2716")+" Operation cancelled"),new Error}});let{framework:y,overwrite:K,packageName:q,variant:H,needPublish:T,needTest:Q}=u,c=l.join(D,o.substring(o.indexOf("/")+1));K?I(c):a.existsSync(c)||a.mkdirSync(c,{recursive:!0}),console.log(`
|
|
3
|
+
Scaffolding project in ${c}...`);let S=H||y?.name||t||"",_=n=>l.join(re(import.meta.url),"../..",`template-${n}`),C=_(S),O=S.includes("node");[C,_("config")].forEach(n=>{let r=a.readdirSync(n);for(let s of r){let h=le[s]??s;if(O&&s.includes("stylelint"))continue;let x=l.join(c,h);P(l.join(n,s),x)}});let X=`template-${S}`,i=JSON.parse(a.readFileSync(l.join(C,"package.json"),"utf-8")),m=q||g();i.name=m;let f={name:"UserName",email:"name@github.com"};Z(),O&&Y();let M=V(process.env.npm_config_user_agent),w=M?M.name:"npm";k.which("git")&&k.exec(`cd ${c} && git init`);let E=l.relative(D,c);switch(console.log(`
|
|
6
4
|
Done. Now run:
|
|
7
|
-
`),
|
|
5
|
+
`),c!==D&&console.log(` cd ${E.includes(" ")?`"${E}"`:E}`),w){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${w} install`),console.log(` ${w} run dev`);break}function Y(){["LICENSE","README.md","README.zh_CN.md"].forEach(n=>{let r=l.join(c,n);if(!T&&a.existsSync(r)){a.rmSync(r),n==="README.md"&&a.writeFileSync(r,`# ${m}
|
|
6
|
+
`,{encoding:"utf-8"});return}if(!a.existsSync(r))return;let s=a.readFileSync(r,"utf-8").replace(new RegExp(X,"g"),m).replace(new RegExp("{{user.name}}","g"),f.name).replace(new RegExp("{{user.email}}","g"),f.email);if(n.startsWith("README")){let h=m.replace("@","%40"),x=m.replace("@","%40").replace(new RegExp("/","g"),"%2F");s=s.replace("{{badges}}",[``,``,``].join(" "))}a.writeFileSync(r,s)})}function Z(){if(T){k.which("git")&&(f.name=B("user.name")||ne.userInfo().username,f.email=B("user.email")||"",i.author=Object.assign(i.author,f));let n=m.startsWith("@")?m.split("/")[0].substring(1):se(f.name);i.repository.url=`git+https://github.com/${n}/${m.substring(m.indexOf("/")+1)}.git`}else delete i.author,delete i.publishConfig,delete i.repository,delete i.scripts.prepublishOnly,delete i.devDependencies.np;if(!Q){delete i.scripts.test,["jest.config.js","test"].forEach(r=>{let s=l.join(c,r);a.existsSync(s)&&te(s,{force:!0,recursive:!0})});let n=Object.keys(i.devDependencies||{});Array.isArray(n)&&n.forEach(r=>{r.includes("jest")&&delete i.devDependencies[r]})}a.writeFileSync(l.join(c,"package.json"),JSON.stringify(i,null,2)+`
|
|
7
|
+
`)}}me().catch(e=>{e.message&&console.error(e)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/create-app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "create tomjs web app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tomjs",
|
|
@@ -42,15 +42,6 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=18"
|
|
44
44
|
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"dev": "tsup --watch",
|
|
47
|
-
"build": "tsup --minify",
|
|
48
|
-
"lint": "run-s lint:eslint lint:prettier",
|
|
49
|
-
"lint:eslint": "eslint \"src/**/*.{js,cjs,ts}\" *.{js,cjs,ts} --fix --cache",
|
|
50
|
-
"lint:prettier": "prettier --write \"src/**/*.{js,cjs,ts,json,md}\" *.{js,cjs,ts,json,md}",
|
|
51
|
-
"prepare": "husky install",
|
|
52
|
-
"prepublishOnly": "npm run build && np --any-branch --no-yarn --yolo --no-publish --message \"chore: release v%s\""
|
|
53
|
-
},
|
|
54
45
|
"dependencies": {
|
|
55
46
|
"kolorist": "^1.8.0",
|
|
56
47
|
"lodash-es": "^4.17.21",
|
|
@@ -77,5 +68,12 @@
|
|
|
77
68
|
"prettier": "^3.1.0",
|
|
78
69
|
"tsup": "^8.0.1",
|
|
79
70
|
"typescript": "~5.2.2"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"dev": "tsup --watch",
|
|
74
|
+
"build": "tsup --minify",
|
|
75
|
+
"lint": "run-s lint:eslint lint:prettier",
|
|
76
|
+
"lint:eslint": "eslint \"src/**/*.{js,cjs,ts}\" *.{js,cjs,ts} --fix --cache",
|
|
77
|
+
"lint:prettier": "prettier --write \"src/**/*.{js,cjs,ts,json,md}\" *.{js,cjs,ts,json,md}"
|
|
80
78
|
}
|
|
81
|
-
}
|
|
79
|
+
}
|