@tomjs/create-app 0.11.1 → 0.11.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 +7 -7
- package/package.json +1 -1
- package/template-config/_gitignore +1 -0
- package/template-node/package.json +2 -2
- package/template-vscode/LICENSE +21 -0
- package/template-vscode/package.json +4 -5
- package/template-vscode-react/LICENSE +21 -0
- package/template-vscode-react/package.json +1 -1
- package/template-vscode-vue/LICENSE +21 -0
- package/template-vscode-vue/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import s,{renameSync as Ie}from"fs";import Ve from"os";import c from"path";import{fileURLToPath as Je}from"url";import{lightBlue as C,lightCyan as
|
|
3
|
-
`)}function
|
|
4
|
-
Scaffolding project in ${a}...`);let _=y||
|
|
2
|
+
import s,{renameSync as Ie}from"fs";import Ve from"os";import c from"path";import{fileURLToPath as Je}from"url";import{lightBlue as C,lightCyan as Me,lightGreen as D,lightYellow as Se,red as we,reset as w,yellow as We}from"kolorist";import{camelCase as ze}from"lodash-es";import Le from"minimist";import Ye from"prompts";import G from"shelljs";import ye from"os";import he from"path";import{blue as Te,red as $,reset as O}from"kolorist";import Ne from"minimist";import q from"prompts";import p from"fs";import L from"path";function R(e){return[["t","template"],["g","git"]].forEach(([r,l])=>{e[l]=e[l]??e[r]}),e}function ae(e){return p.readdirSync(e).length===0}function Y(e){return e?.trim().replace(/\/+$/g,"")}function Ge(e,r){p.mkdirSync(r,{recursive:!0});for(let l of p.readdirSync(e)){let x=L.resolve(e,l),g=L.resolve(r,l);B(x,g)}}function B(e,r){p.statSync(e).isDirectory()?Ge(e,r):p.copyFileSync(e,r)}function le(e){if(p.existsSync(e))for(let r of p.readdirSync(e))p.rmSync(L.resolve(e,r),{recursive:!0,force:!0})}function H(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function pe(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function me(e){if(!e)return;let l=e.split(" ")[0].split("/");return{name:l[0],version:l[1]}}function S(e){if(p.existsSync(e))try{return JSON.parse(p.readFileSync(e,"utf8"))}catch(r){console.error(r)}}function v(e,r){p.writeFileSync(e,JSON.stringify(r,null,2)+`
|
|
3
|
+
`)}function ue(e){return p.existsSync(e)?p.readFileSync(e,"utf8"):""}function A(e){p.existsSync(e)&&p.rmSync(e,{recursive:!0,force:!0})}function ge(e){p.existsSync(e)||p.mkdirSync(e,{recursive:!0})}var _e=R(Ne(process.argv.slice(2),{string:["_"]})),fe={repo:"https://github.com",owner:ye.userInfo().username};function Q(e){let{repo:r,owner:l}=e;return`${r}${r.endsWith("/")?"":"/"}${l}`}async function de(e){let r=await q([{type:"text",name:"repo",message:O("Git repository url:"),initial:e?.repo||fe.repo},{type:"text",name:"owner",message:O("Git repository owner:"),initial:e?.owner||fe.owner}],{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}});return{id:e?.id||Date.now().toString(),repo:r.repo,owner:r.owner}}var ve=he.join(ye.homedir(),".tomjs","create-app"),xe=he.join(ve,"config.json");function F(){return ge(ve),Object.assign({gitRepos:[]},S(xe))}function Ue(e){let r=F();r.createTime?r.updateTime=Date.now():r.createTime=Date.now(),v(xe,Object.assign(r,e))}function K(e){Ue({gitRepos:e})}async function X(){let{gitRepos:e}=F();(e.length===0||_e.git)&&(e.length===0&&console.log(`You need to set the ${Te("git remote repository")} for the first time.`),await r());async function r(){let l=e.map(y=>({title:Q(y),value:y.id})).concat([{title:"Add",value:"add"},{title:$("Exit"),value:"exit"}]),x=await q({type:"select",name:"repoId",message:e.length===0?"You choose to add or exit:":"You can choose the repository to be operated, or choose to add or exit:",choices:l},{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}}),{repoId:g}=x;if(g==="exit")return;if(g==="add"){let y=await de();return e.push(y),K(e),r()}let j=e.findIndex(y=>y.id===g),E=await q([{type:"select",name:"action",message:O("Select an action?"),choices:[{title:"Edit",value:"edit"},{title:"Remove",value:"remove"},{title:"Exit",value:"exit"}]},{type:y=>y==="remove"&&"toggle",name:"confirmRemove",message:O("Where confirm to remove?"),initial:!0,active:"Yes",inactive:"No"}],{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}}),{action:P,confirmRemove:T}=E;if(P==="exit")return X();if(P==="remove")return T&&(e.splice(j,1),K(e)),r();let N=await de(e[j]);return e[j]=N,K(e),r()}}var Z=R(Le(process.argv.slice(2),{string:["_"]})),ee=process.cwd(),Be=["test","vite","electron","examples"],Ee=[{name:"web",display:"Web App",color:D,variants:[{name:"vue",display:"Vue",color:D},{name:"react",display:"React",color:C}]},{name:"electron",display:"Electron App",color:C,variants:[{name:"electron-vue",display:"Vue",color:D},{name:"electron-react",display:"React",color:C}]},{name:"vscode",display:"VSCode Extension",color:Me,options:[{id:"publish",name:"Git Repository"},{id:"ssh",name:"Git init by SSH"}],variants:[{name:"vscode",display:"Base",color:Se},{name:"vscode-vue",display:"Vue",color:D},{name:"vscode-react",display:"React",color:C}]},{name:"node",display:"Node",color:Se,options:[{id:"test",name:"Test"},{id:"publish",name:"Git Repository + NPM Publish"},{id:"ssh",name:"Git init by SSH"},{id:"vite",name:"Vite Plugin"},{id:"electron",name:"Electron"},{id:"examples",name:"Examples"}]}],je=Ee.map(e=>e.variants&&e.variants.map(r=>r.name)||[e.name]).reduce((e,r)=>e.concat(r),[]),te="my-app";function ke(e){let r=G.exec(`git config --get ${e}`,{silent:!0});if(r.code===0)return r.stdout.trim()}function be(e){return e.length>1?e.substring(e.indexOf("/")+1):e}async function He(){let e=Y(Z._[0]),r=Z.template||Z.t,l=e||te,x=()=>l==="."?c.basename(c.resolve()):l,g=be(l),{gitRepos:j}=F(),E=await Ye([{type:e?null:"text",name:"projectName",message:w("Project name:"),initial:te,onState:t=>{l=Y(t.value)||te,g=be(l)}},{type:()=>!s.existsSync(g)||ae(g)?null:"toggle",name:"overwrite",message:()=>(g==="."?"Current directory":`Target directory "${g}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"Yes",inactive:"No"},{type:(t,{overwrite:n})=>{if(n===!1)throw console.log(we("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>H(x())?null:"text",name:"packageName",message:w("Package name:"),initial:()=>pe(x()),validate:t=>H(t)||"Invalid package.json name"},{type:r&&je.includes(r)?null:"select",name:"framework",message:typeof r=="string"&&!je.includes(r)?w(`"${r}" isn't a valid template. Please choose from below: `):w("Select a framework:"),initial:0,choices:Ee.map(t=>{let n=t.color;return{title:n(t.display||t.name),value:t}})},{type:t=>t&&t.variants?"select":null,name:"variant",message:w("Select a variant:"),choices:t=>t?.variants?.map(n=>{let i=n.color;return{title:i(n.display||n.name),value:n.name}})},{type:(t,n)=>{let{framework:i}=n;return i&&Array.isArray(i.options)&&i.options.length?"multiselect":null},name:"options",message:w("Select optional options:"),instructions:!1,choices:(t,n)=>{let{framework:i}=n;return i?.options?.map(o=>({title:o.name,value:o.id}))}},{type:(t,n)=>j.length&&Array.isArray(n.options)&&n.options.includes("publish")?"select":null,name:"gitUserUrl",message:w("Which git repository to publish to?"),choices:j.map(t=>{let n=Q(t);return{title:n,value:n}})}],{onCancel:()=>{throw console.log(we("\u2716")+" Operation cancelled"),new Error}}),{framework:P,overwrite:T,packageName:N,variant:y,gitUserUrl:b}=E,u=E.options||[],a=c.join(ee,g);T?le(a):s.existsSync(a)||s.mkdirSync(a,{recursive:!0}),console.log(`
|
|
4
|
+
Scaffolding project in ${a}...`);let _=y||P?.name||r||"",U=t=>c.join(Je(import.meta.url),"../..",`template-${t}`),Pe=U(_),I=_.includes("node");[Pe,U("config")].forEach(t=>{let n=s.readdirSync(t);for(let i of n){let o=i.startsWith("_")?i.replace("_","."):i;if((I&&!u.includes("examples")||_==="vscode")&&i.includes("stylelint"))continue;let m=c.join(a,o);B(c.join(t,i),m)}});let f=N||x(),V={name:ke("user.name")||Ve.userInfo().username,email:ke("user.email")||""},J={"pkg.name":f,"user.name":V.name,"user.email":V.email,"git.org":M(),"git.url":Re(),"git.fullUrl":ne()};function Re(){return`${b||`https://github.com/${M()}`}/${f.substring(f.indexOf("/")+1)}`}function M(){return b?b.substring(b.lastIndexOf("/")+1):f.startsWith("@")?f.split("/")[0].substring(1):ze(V.name)}function ne(t=!1){let n=b||`https://github.com/${M()}`;return t&&(n=n.replace(/http(s):\/\//g,"git@").replace(/\//,":")),`${n}/${f.substring(f.indexOf("/")+1)}.git`}$e(),I&&(Ae(),Ce(),De());let ie=me(process.env.npm_config_user_agent),W=ie?ie.name:"npm";G.which("git")&&(G.exec(`cd ${a} && git init`),u.includes("publish")&&G.exec(`cd ${a} && git remote add origin ${ne(u.includes("ssh"))}`));let z=c.relative(ee,a);switch(console.log(`
|
|
5
5
|
Done. Now run:
|
|
6
|
-
`),a!==
|
|
7
|
-
`);["LICENSE","README.md","README.zh_CN.md"].forEach(i=>{let o=c.join(a,i);if(!
|
|
8
|
-
`,{encoding:"utf-8"});return}if(!s.existsSync(o))return;let
|
|
9
|
-
- 'examples/*'`,{encoding:"utf-8"})}}
|
|
6
|
+
`),a!==ee&&console.log(` cd ${z.includes(" ")?`"${z}"`:z}`),W){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${W} install`),console.log(` ${W} run dev`);break}function Ae(){Fe(".lintstagedrc.cjs","jest.config.cjs","tsconfig.json","tsup.config.ts");let t=u.find(i=>["vite"].includes(i)),n=["#pnpm",`pnpm add ${f}${t?" -D":""}`,"","#yarn",`yarn add ${f}${t?" -D":""}`,"","#npm",`npm i ${f}${t?" --save-dev":""}`].join(`
|
|
7
|
+
`);["LICENSE","README.md","README.zh_CN.md"].forEach(i=>{let o=c.join(a,i);if(!u.includes("publish")&&s.existsSync(o)){s.rmSync(o),i==="README.md"&&s.writeFileSync(o,`# ${f}
|
|
8
|
+
`,{encoding:"utf-8"});return}if(!s.existsSync(o))return;let m=Object.assign({},J,{"pkg.install":n}),d=s.readFileSync(o,"utf-8");Object.keys(m).forEach(h=>{d=d.replace(new RegExp("{{"+h+"}}","g"),m[h])}),s.writeFileSync(o,d,"utf8")})}function k(t,...n){["dependencies","devDependencies"].forEach(i=>{Object.keys(t[i]||{}).forEach(o=>{n.find(m=>o.includes(m))&&delete t[i][o]})})}function re(...t){!Array.isArray(t)||t.length===0||t.forEach(n=>{let i=c.join(a,n);s.existsSync(i)&&A(i)})}function $e(){let t=c.join(a,"package.json"),n=S(t);n.name=f,u.includes("publish")||(delete n.author,delete n.publishConfig,delete n.repository,delete n.scripts.prepublishOnly,delete n.devDependencies.np),I&&(u.includes("electron")||(k(n,"electron"),n.scripts["lint:eslint"]=n.scripts["lint:eslint"].replace(",electron","")),u.includes("vite")||k(n,"vite")),v(t,n);let i=ue(t);Object.keys(J).forEach(o=>{i=i.replace(new RegExp("{{"+o+"}}","g"),J[o])}),s.writeFileSync(t,i)}function Oe(t,n){let i=t.lastIndexOf("."),o=t.substring(0,i)+"."+n+t.substring(i),m=c.join(a,t),d=c.join(a,o);s.existsSync(d)&&(u.includes(n)?(A(m),Ie(d,m)):A(d))}function Fe(...t){t.forEach(n=>{Be.forEach(i=>{Oe(n,i)})})}function Ce(){let t=c.join(a,"package.json"),n=S(t);if(u.includes("test")){if(u.includes("electron")){k(n,"vitest"),v(t,n);let i=c.join(a,"test/simple.test.ts");if(s.existsSync(i)){let o=s.readFileSync(i,{encoding:"utf8"});s.writeFileSync(i,o.replace("import { describe, expect, it } from 'vitest';",""),{encoding:"utf8"})}}else re("jest.config.cjs");return}delete n.scripts.test,n.scripts["lint:eslint"]=n.scripts["lint:eslint"].replace(",test",""),k(n,"jest","vitest"),re(".lintstagedrc.cjs","jest.config.cjs","test"),v(t,n)}function De(){if(!u.includes("examples")){let i=S(c.join(a,"package.json"));i.scripts.lint=i.scripts.lint.replace(" lint:stylelint",""),i.scripts["lint:eslint"]=i.scripts["lint:eslint"].replace(",examples",""),delete i.scripts["lint:stylelint"],k(i,"stylelint"),v(c.join(a,"package.json"),i);return}let t=c.join(a,"examples");s.mkdirSync(t);let n=u.includes("electron");["vue","react"].forEach(i=>{let o=U(n?`electron-${i}`:i),m=c.join(t,i);if(!s.existsSync(o)){console.log(`${We(o)} template is not exist`);return}s.cpSync(o,m,{recursive:!0});let d=S(c.join(m,"package.json"));Object.keys(d.scripts).forEach(h=>{(h.startsWith("lint")||["prepare"].includes(h))&&delete d.scripts[h]}),k(d,"eslint","prettier","stylelint","commitlint","husky","lint-staged","tsconfig","lint-staged","npm-run-all"),v(c.join(m,"package.json"),d),["_lintstagedrc.cjs"].forEach(h=>{let oe=c.join(m,h);s.existsSync(oe)&&s.rmSync(oe,{recursive:!0})})}),s.writeFileSync(c.join(a,"pnpm-workspace.yaml"),`packages:
|
|
9
|
+
- 'examples/*'`,{encoding:"utf-8"})}}X().then(async()=>He().catch(e=>{e.message&&console.error(e)})).catch(e=>{e.message&&console.error(e)});
|
package/package.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT {{user.name}}<{{user.email}}>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "{{pkg.name}}",
|
|
3
|
+
"displayName": "{{pkg.name}}",
|
|
4
|
+
"description": "",
|
|
3
5
|
"version": "0.0.0",
|
|
4
|
-
"
|
|
6
|
+
"publisher": "{{git.org}}",
|
|
5
7
|
"license": "MIT",
|
|
6
8
|
"engines": {
|
|
7
9
|
"node": ">=14",
|
|
@@ -47,9 +49,7 @@
|
|
|
47
49
|
"@tomjs/prettier": "^1.1.1",
|
|
48
50
|
"@tomjs/tsconfig": "^1.3.0",
|
|
49
51
|
"@types/node": "^18.19.6",
|
|
50
|
-
"@types/vscode": "^1.
|
|
51
|
-
"@vitejs/plugin-vue": "^5.0.3",
|
|
52
|
-
"cross-env": "^7.0.3",
|
|
52
|
+
"@types/vscode": "^1.56.0",
|
|
53
53
|
"eslint": "^8.56.0",
|
|
54
54
|
"husky": "^8.0.3",
|
|
55
55
|
"lint-staged": "^15.2.0",
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"prettier": "^3.2.2",
|
|
58
58
|
"rimraf": "^5.0.5",
|
|
59
59
|
"tsup": "^8.0.1",
|
|
60
|
-
"tsx": "^4.7.0",
|
|
61
60
|
"typescript": "~5.3.3"
|
|
62
61
|
}
|
|
63
62
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT {{user.name}}<{{user.email}}>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@types/node": "^18.19.6",
|
|
60
60
|
"@types/react": "^18.2.47",
|
|
61
61
|
"@types/react-dom": "^18.2.18",
|
|
62
|
-
"@types/vscode": "^1.
|
|
62
|
+
"@types/vscode": "^1.56.0",
|
|
63
63
|
"@types/vscode-webview": "^1.57.4",
|
|
64
64
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
65
65
|
"cross-env": "^7.0.3",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT {{user.name}}<{{user.email}}>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@tomjs/vite-plugin-vscode": "^1.3.2",
|
|
56
56
|
"@tomjs/vscode-extension-webview": "^1.2.0",
|
|
57
57
|
"@types/node": "^18.19.6",
|
|
58
|
-
"@types/vscode": "^1.
|
|
58
|
+
"@types/vscode": "^1.56.0",
|
|
59
59
|
"@types/vscode-webview": "^1.57.4",
|
|
60
60
|
"@vitejs/plugin-vue": "^5.0.3",
|
|
61
61
|
"cross-env": "^7.0.3",
|