@tomjs/create-app 0.8.3 → 0.10.0

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 CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import a,{renameSync as Ge}from"fs";import Ne from"os";import r from"path";import{fileURLToPath as Oe}from"url";import{lightBlue as O,lightCyan as Fe,lightGreen as F,lightYellow as fe,red as de,reset as w,yellow as Te}from"kolorist";import{camelCase as De}from"lodash-es";import Ue from"minimist";import _e from"prompts";import E from"shelljs";import pe from"os";import me from"path";import{blue as Pe,red as $,reset as G}from"kolorist";import Ae from"minimist";import H from"prompts";import l from"fs";import M from"path";function A(e){return[["t","template"],["g","git"]].forEach(([n,c])=>{e[c]=e[c]??e[n]}),e}function ie(e){return l.readdirSync(e).length===0}function z(e){return e?.trim().replace(/\/+$/g,"")}function Re(e,n){l.mkdirSync(n,{recursive:!0});for(let c of l.readdirSync(e)){let y=M.resolve(e,c),m=M.resolve(n,c);Y(y,m)}}function Y(e,n){l.statSync(e).isDirectory()?Re(e,n):l.copyFileSync(e,n)}function oe(e){if(l.existsSync(e))for(let n of l.readdirSync(e))l.rmSync(M.resolve(e,n),{recursive:!0,force:!0})}function L(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function re(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function se(e){if(!e)return;let c=e.split(" ")[0].split("/");return{name:c[0],version:c[1]}}function v(e){if(l.existsSync(e))try{return JSON.parse(l.readFileSync(e,"utf8"))}catch(n){console.error(n)}}function x(e,n){l.writeFileSync(e,JSON.stringify(n,null,2)+`
3
- `)}function C(e){l.existsSync(e)&&l.rmSync(e,{recursive:!0,force:!0})}function ce(e){l.existsSync(e)||l.mkdirSync(e,{recursive:!0})}var Ce=A(Ae(process.argv.slice(2),{string:["_"]})),ae={repo:"https://github.com",owner:pe.userInfo().username};function K(e){let{repo:n,owner:c}=e;return`${n}${n.endsWith("/")?"":"/"}${c}`}async function le(e){let n=await H([{type:"text",name:"repo",message:G("Git repository url:"),initial:e?.repo||ae.repo},{type:"text",name:"owner",message:G("Git repository owner:"),initial:e?.owner||ae.owner}],{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}});return{id:e?.id||Date.now().toString(),repo:n.repo,owner:n.owner}}var ue=me.join(pe.homedir(),".tomjs","create-app"),ge=me.join(ue,"config.json");function N(){return ce(ue),Object.assign({gitRepos:[]},v(ge))}function $e(e){let n=N();n.createTime?n.updateTime=Date.now():n.createTime=Date.now(),x(ge,Object.assign(n,e))}function B(e){$e({gitRepos:e})}async function q(){let{gitRepos:e}=N();(e.length===0||Ce.git)&&(e.length===0&&console.log(`You need to set the ${Pe("git remote repository")} for the first time.`),await n());async function n(){let c=e.map(f=>({title:K(f),value:f.id})).concat([{title:"Add",value:"add"},{title:$("Exit"),value:"exit"}]),y=await H({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:c},{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}}),{repoId:m}=y;if(m==="exit")return;if(m==="add"){let f=await le();return e.push(f),B(e),n()}let S=e.findIndex(f=>f.id===m),R=await H([{type:"select",name:"action",message:G("Select an action?"),choices:[{title:"Edit",value:"edit"},{title:"Remove",value:"remove"},{title:"Exit",value:"exit"}]},{type:f=>f==="remove"&&"toggle",name:"confirmRemove",message:G("Where confirm to remove?"),initial:!0,active:"Yes",inactive:"No"}],{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}}),{action:P,confirmRemove:T}=R;if(P==="exit")return q();if(P==="remove")return T&&(e.splice(S,1),B(e)),n();let D=await le(e[S]);return e[S]=D,B(e),n()}}var Q=A(Ue(process.argv.slice(2),{string:["_"]})),X=process.cwd(),xe=[{name:"web",display:"Web App",color:F,variants:[{name:"vue",display:"Vue",color:F},{name:"react",display:"React",color:O}]},{name:"electron",display:"Electron App",color:O,variants:[{name:"electron-vue",display:"Vue",color:F},{name:"electron-react",display:"React",color:O}]},{name:"vscode",display:"VSCode Extension",color:Fe,options:[{id:"publish",name:"Git Repository + NPM Publish"},{id:"ssh",name:"Git init by SSH"}],variants:[{name:"vscode",display:"Base",color:fe},{name:"vscode-vue",display:"Vue",color:F},{name:"vscode-react",display:"React",color:O}]},{name:"node",display:"Node",color:fe,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"}]}],ye=xe.map(e=>e.variants&&e.variants.map(n=>n.name)||[e.name]).reduce((e,n)=>e.concat(n),[]),Z="my-app";function he(e){let n=E.exec(`git config --get ${e}`,{silent:!0});if(n.code===0)return n.stdout.trim()}function ve(e){return e.length>1?e.substring(e.indexOf("/")+1):e}async function Ie(){let e=z(Q._[0]),n=Q.template||Q.t,c=e||Z,y=()=>c==="."?r.basename(r.resolve()):c,m=ve(c),{gitRepos:S}=N(),R=await _e([{type:e?null:"text",name:"projectName",message:w("Project name:"),initial:Z,onState:t=>{c=z(t.value)||Z,m=ve(c)}},{type:()=>!a.existsSync(m)||ie(m)?null:"toggle",name:"overwrite",message:()=>(m==="."?"Current directory":`Target directory "${m}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"Yes",inactive:"No"},{type:(t,{overwrite:i})=>{if(i===!1)throw console.log(de("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>L(y())?null:"text",name:"packageName",message:w("Package name:"),initial:()=>re(y()),validate:t=>L(t)||"Invalid package.json name"},{type:n&&ye.includes(n)?null:"select",name:"framework",message:typeof n=="string"&&!ye.includes(n)?w(`"${n}" isn't a valid template. Please choose from below: `):w("Select a framework:"),initial:0,choices:xe.map(t=>{let i=t.color;return{title:i(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(i=>{let o=i.color;return{title:o(i.display||i.name),value:i.name}})},{type:(t,i)=>{let{framework:o}=i;return o&&Array.isArray(o.options)&&o.options.length?"multiselect":null},name:"options",message:w("Select optional options:"),instructions:!1,choices:(t,i)=>{let{framework:o}=i;return o?.options?.map(p=>({title:p.name,value:p.id}))}},{type:(t,i)=>S.length&&Array.isArray(i.options)&&i.options.includes("publish")?"select":null,name:"gitUserUrl",message:w("Which git repository to publish to?"),choices:S.map(t=>{let i=K(t);return{title:i,value:i}})}],{onCancel:()=>{throw console.log(de("\u2716")+" Operation cancelled"),new Error}}),{framework:P,overwrite:T,packageName:D,variant:f,gitUserUrl:we}=R,u=R.options||[],s=r.join(X,m);T?oe(s):a.existsSync(s)||a.mkdirSync(s,{recursive:!0}),console.log(`
4
- Scaffolding project in ${s}...`);let U=f||P?.name||n||"",_=t=>r.join(Oe(import.meta.url),"../..",`template-${t}`),Se=_(U),I=U.includes("node");[Se,_("config")].forEach(t=>{let i=a.readdirSync(t);for(let o of i){let p=o.startsWith("_")?o.replace("_","."):o;if((I&&!u.includes("examples")||U==="vscode")&&o.includes("stylelint"))continue;let g=r.join(s,p);Y(r.join(t,o),g)}});let h=D||y(),j={name:"UserName",email:"name@github.com"};function ee(t=!1){let i=h.startsWith("@")?h.split("/")[0].substring(1):De(j.name),o=we||`https://github.com/${i}`;return t&&(o=o.replace(/http(s):\/\//g,"git@").replace(/\//,":")),`${o}/${h.substring(h.indexOf("/")+1)}.git`}ke(),I&&(je(),be(),Ee());let te=se(process.env.npm_config_user_agent),J=te?te.name:"npm";E.which("git")&&(E.exec(`cd ${s} && git init`),u.includes("publish")&&E.exec(`cd ${s} && git remote add origin ${ee(u.includes("ssh"))}`));let V=r.relative(X,s);switch(console.log(`
2
+ import a,{renameSync as Ne}from"fs";import Te from"os";import r from"path";import{fileURLToPath as _e}from"url";import{lightBlue as D,lightCyan as Ue,lightGreen as G,lightYellow as ye,red as he,reset as w,yellow as Ie}from"kolorist";import{camelCase as Ve}from"lodash-es";import Je from"minimist";import Me from"prompts";import E from"shelljs";import ge from"os";import ue from"path";import{blue as Ce,red as O,reset as C}from"kolorist";import Fe from"minimist";import B from"prompts";import p from"fs";import M from"path";function A(e){return[["t","template"],["g","git"]].forEach(([i,l])=>{e[l]=e[l]??e[i]}),e}function re(e){return p.readdirSync(e).length===0}function W(e){return e?.trim().replace(/\/+$/g,"")}function Oe(e,i){p.mkdirSync(i,{recursive:!0});for(let l of p.readdirSync(e)){let v=M.resolve(e,l),u=M.resolve(i,l);z(v,u)}}function z(e,i){p.statSync(e).isDirectory()?Oe(e,i):p.copyFileSync(e,i)}function se(e){if(p.existsSync(e))for(let i of p.readdirSync(e))p.rmSync(M.resolve(e,i),{recursive:!0,force:!0})}function L(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function ce(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function ae(e){if(!e)return;let l=e.split(" ")[0].split("/");return{name:l[0],version:l[1]}}function x(e){if(p.existsSync(e))try{return JSON.parse(p.readFileSync(e,"utf8"))}catch(i){console.error(i)}}function h(e,i){p.writeFileSync(e,JSON.stringify(i,null,2)+`
3
+ `)}function $(e){p.existsSync(e)&&p.rmSync(e,{recursive:!0,force:!0})}function le(e){p.existsSync(e)||p.mkdirSync(e,{recursive:!0})}var De=A(Fe(process.argv.slice(2),{string:["_"]})),pe={repo:"https://github.com",owner:ge.userInfo().username};function H(e){let{repo:i,owner:l}=e;return`${i}${i.endsWith("/")?"":"/"}${l}`}async function me(e){let i=await B([{type:"text",name:"repo",message:C("Git repository url:"),initial:e?.repo||pe.repo},{type:"text",name:"owner",message:C("Git repository owner:"),initial:e?.owner||pe.owner}],{onCancel:()=>{throw console.log(O("\u2716")+" Operation cancelled"),new Error}});return{id:e?.id||Date.now().toString(),repo:i.repo,owner:i.owner}}var fe=ue.join(ge.homedir(),".tomjs","create-app"),de=ue.join(fe,"config.json");function F(){return le(fe),Object.assign({gitRepos:[]},x(de))}function Ge(e){let i=F();i.createTime?i.updateTime=Date.now():i.createTime=Date.now(),h(de,Object.assign(i,e))}function Y(e){Ge({gitRepos:e})}async function K(){let{gitRepos:e}=F();(e.length===0||De.git)&&(e.length===0&&console.log(`You need to set the ${Ce("git remote repository")} for the first time.`),await i());async function i(){let l=e.map(f=>({title:H(f),value:f.id})).concat([{title:"Add",value:"add"},{title:O("Exit"),value:"exit"}]),v=await B({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(O("\u2716")+" Operation cancelled"),new Error}}),{repoId:u}=v;if(u==="exit")return;if(u==="add"){let f=await me();return e.push(f),Y(e),i()}let S=e.findIndex(f=>f.id===u),P=await B([{type:"select",name:"action",message:C("Select an action?"),choices:[{title:"Edit",value:"edit"},{title:"Remove",value:"remove"},{title:"Exit",value:"exit"}]},{type:f=>f==="remove"&&"toggle",name:"confirmRemove",message:C("Where confirm to remove?"),initial:!0,active:"Yes",inactive:"No"}],{onCancel:()=>{throw console.log(O("\u2716")+" Operation cancelled"),new Error}}),{action:R,confirmRemove:N}=P;if(R==="exit")return K();if(R==="remove")return N&&(e.splice(S,1),Y(e)),i();let T=await me(e[S]);return e[S]=T,Y(e),i()}}var q=A(Je(process.argv.slice(2),{string:["_"]})),Q=process.cwd(),We=["test","vite","electron","examples"],Se=[{name:"web",display:"Web App",color:G,variants:[{name:"vue",display:"Vue",color:G},{name:"react",display:"React",color:D}]},{name:"electron",display:"Electron App",color:D,variants:[{name:"electron-vue",display:"Vue",color:G},{name:"electron-react",display:"React",color:D}]},{name:"vscode",display:"VSCode Extension",color:Ue,options:[{id:"publish",name:"Git Repository + NPM Publish"},{id:"ssh",name:"Git init by SSH"}],variants:[{name:"vscode",display:"Base",color:ye},{name:"vscode-vue",display:"Vue",color:G},{name:"vscode-react",display:"React",color:D}]},{name:"node",display:"Node",color:ye,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"}]}],ve=Se.map(e=>e.variants&&e.variants.map(i=>i.name)||[e.name]).reduce((e,i)=>e.concat(i),[]),X="my-app";function xe(e){let i=E.exec(`git config --get ${e}`,{silent:!0});if(i.code===0)return i.stdout.trim()}function we(e){return e.length>1?e.substring(e.indexOf("/")+1):e}async function ze(){let e=W(q._[0]),i=q.template||q.t,l=e||X,v=()=>l==="."?r.basename(r.resolve()):l,u=we(l),{gitRepos:S}=F(),P=await Me([{type:e?null:"text",name:"projectName",message:w("Project name:"),initial:X,onState:t=>{l=W(t.value)||X,u=we(l)}},{type:()=>!a.existsSync(u)||re(u)?null:"toggle",name:"overwrite",message:()=>(u==="."?"Current directory":`Target directory "${u}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"Yes",inactive:"No"},{type:(t,{overwrite:o})=>{if(o===!1)throw console.log(he("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>L(v())?null:"text",name:"packageName",message:w("Package name:"),initial:()=>ce(v()),validate:t=>L(t)||"Invalid package.json name"},{type:i&&ve.includes(i)?null:"select",name:"framework",message:typeof i=="string"&&!ve.includes(i)?w(`"${i}" isn't a valid template. Please choose from below: `):w("Select a framework:"),initial:0,choices:Se.map(t=>{let o=t.color;return{title:o(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(o=>{let n=o.color;return{title:n(o.display||o.name),value:o.name}})},{type:(t,o)=>{let{framework:n}=o;return n&&Array.isArray(n.options)&&n.options.length?"multiselect":null},name:"options",message:w("Select optional options:"),instructions:!1,choices:(t,o)=>{let{framework:n}=o;return n?.options?.map(s=>({title:s.name,value:s.id}))}},{type:(t,o)=>S.length&&Array.isArray(o.options)&&o.options.includes("publish")?"select":null,name:"gitUserUrl",message:w("Which git repository to publish to?"),choices:S.map(t=>{let o=H(t);return{title:o,value:o}})}],{onCancel:()=>{throw console.log(he("\u2716")+" Operation cancelled"),new Error}}),{framework:R,overwrite:N,packageName:T,variant:f,gitUserUrl:je}=P,m=P.options||[],c=r.join(Q,u);N?se(c):a.existsSync(c)||a.mkdirSync(c,{recursive:!0}),console.log(`
4
+ Scaffolding project in ${c}...`);let _=f||R?.name||i||"",U=t=>r.join(_e(import.meta.url),"../..",`template-${t}`),ke=U(_),I=_.includes("node");[ke,U("config")].forEach(t=>{let o=a.readdirSync(t);for(let n of o){let s=n.startsWith("_")?n.replace("_","."):n;if((I&&!m.includes("examples")||_==="vscode")&&n.includes("stylelint"))continue;let g=r.join(c,s);z(r.join(t,n),g)}});let d=T||v(),j={name:"UserName",email:"name@github.com"};function Z(t=!1){let o=d.startsWith("@")?d.split("/")[0].substring(1):Ve(j.name),n=je||`https://github.com/${o}`;return t&&(n=n.replace(/http(s):\/\//g,"git@").replace(/\//,":")),`${n}/${d.substring(d.indexOf("/")+1)}.git`}Ee(),I&&(be(),Ae(),$e());let ee=ae(process.env.npm_config_user_agent),V=ee?ee.name:"npm";E.which("git")&&(E.exec(`cd ${c} && git init`),m.includes("publish")&&E.exec(`cd ${c} && git remote add origin ${Z(m.includes("ssh"))}`));let J=r.relative(Q,c);switch(console.log(`
5
5
  Done. Now run:
6
- `),s!==X&&console.log(` cd ${V.includes(" ")?`"${V}"`:V}`),J){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${J} install`),console.log(` ${J} run dev`);break}function je(){["LICENSE","README.md","README.zh_CN.md"].forEach(t=>{let i=r.join(s,t);if(!u.includes("publish")&&a.existsSync(i)){a.rmSync(i),t==="README.md"&&a.writeFileSync(i,`# ${h}
7
- `,{encoding:"utf-8"});return}if(!a.existsSync(i))return;let o=a.readFileSync(i,"utf-8").replace(new RegExp("{{pkg.name}}","g"),h).replace(new RegExp("{{user.name}}","g"),j.name).replace(new RegExp("{{user.email}}","g"),j.email);a.writeFileSync(i,o)})}function k(t,...i){["dependencies","devDependencies"].forEach(o=>{Object.keys(t[o]||{}).forEach(p=>{i.find(g=>p.includes(g))&&delete t[o][p]})})}function ke(){let t=v(r.join(s,"package.json"));t.name=h,u.includes("publish")?(E.which("git")&&(j.name=he("user.name")||Ne.userInfo().username,j.email=he("user.email")||"",t.author=Object.assign({},t.author,j)),t.publishConfig={access:"public",registry:"https://registry.npmjs.org/"},t.repository??={type:"git"},t.repository.url=`git+${ee()}`):(delete t.author,delete t.publishConfig,delete t.repository,delete t.scripts.prepublishOnly,delete t.devDependencies.np),I&&(u.includes("electron")||(k(t,"electron"),t.scripts["lint:eslint"]=t.scripts["lint:eslint"].replace(",electron","")),u.includes("vite")||k(t,"vite")),x(r.join(s,"package.json"),t)}function W(t,i){let o=t.lastIndexOf("."),p=t.substring(0,o)+"."+i+t.substring(o),g=r.join(s,t),d=r.join(s,p);u.includes(i)?(C(g),a.existsSync(d)&&Ge(d,g)):C(d)}function be(){if(W("tsconfig.json","test"),W("jest.config.cjs","electron"),u.includes("test"))return;a.readdirSync(s).filter(o=>o.startsWith("jest.config")||["test"].includes(o)).forEach(o=>{C(r.join(s,o))});let t=r.join(s,"package.json"),i=v(t);delete i.scripts.test,i.scripts["lint:eslint"]=i.scripts["lint:eslint"].replace(",test",""),k(i,"jest"),x(t,i)}function Ee(){if(W(".lintstagedrc.cjs","examples"),!u.includes("examples")){let o=v(r.join(s,"package.json"));o.scripts.lint=o.scripts.lint.replace(" lint:stylelint",""),o.scripts["lint:eslint"]=o.scripts["lint:eslint"].replace(",examples",""),delete o.scripts["lint:stylelint"],k(o,"stylelint"),x(r.join(s,"package.json"),o);return}let t=r.join(s,"examples");a.mkdirSync(t);let i=u.includes("electron");["vue","react"].forEach(o=>{let p=_(i?`electron-${o}`:o),g=r.join(t,o);if(!a.existsSync(p)){console.log(`${Te(p)} template is not exist`);return}a.cpSync(p,g,{recursive:!0});let d=v(r.join(g,"package.json"));Object.keys(d.scripts).forEach(b=>{(b.startsWith("lint")||["prepare"].includes(b))&&delete d.scripts[b]}),k(d,"eslint","prettier","stylelint","commitlint","husky","lint-staged","tsconfig","lint-staged","npm-run-all"),x(r.join(g,"package.json"),d),["_lintstagedrc.cjs"].forEach(b=>{let ne=r.join(g,b);a.existsSync(ne)&&a.rmSync(ne,{recursive:!0})})}),a.writeFileSync(r.join(s,"pnpm-workspace.yaml"),`packages:
8
- - 'examples/*'`,{encoding:"utf-8"})}}q().then(async()=>Ie().catch(e=>{e.message&&console.error(e)})).catch(e=>{e.message&&console.error(e)});
6
+ `),c!==Q&&console.log(` cd ${J.includes(" ")?`"${J}"`:J}`),V){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${V} install`),console.log(` ${V} run dev`);break}function be(){Re(".lintstagedrc.cjs","jest.config.cjs","tsconfig.json","tsup.config.ts");let t=m.find(n=>["vite"].includes(n)),o=["#pnpm",`pnpm add ${d}${t?" -D":""}`,"","#yarn",`yarn add ${d}${t?" -D":""}`,"","#npm",`npm i ${d}${t?" --save-dev":""}`].join(`
7
+ `);["LICENSE","README.md","README.zh_CN.md"].forEach(n=>{let s=r.join(c,n);if(!m.includes("publish")&&a.existsSync(s)){a.rmSync(s),n==="README.md"&&a.writeFileSync(s,`# ${d}
8
+ `,{encoding:"utf-8"});return}if(!a.existsSync(s))return;let g=a.readFileSync(s,"utf-8").replace(new RegExp("{{pkg.name}}","g"),d).replace(new RegExp("{{pkg.install}}","g"),o).replace(new RegExp("{{user.name}}","g"),j.name).replace(new RegExp("{{user.email}}","g"),j.email);a.writeFileSync(s,g)})}function k(t,...o){["dependencies","devDependencies"].forEach(n=>{Object.keys(t[n]||{}).forEach(s=>{o.find(g=>s.includes(g))&&delete t[n][s]})})}function te(...t){!Array.isArray(t)||t.length===0||t.forEach(o=>{let n=r.join(c,o);a.existsSync(n)&&$(n)})}function Ee(){let t=x(r.join(c,"package.json"));t.name=d,m.includes("publish")?(E.which("git")&&(j.name=xe("user.name")||Te.userInfo().username,j.email=xe("user.email")||"",t.author=Object.assign({},t.author,j)),t.publishConfig={access:"public",registry:"https://registry.npmjs.org/"},t.repository??={type:"git"},t.repository.url=`git+${Z()}`):(delete t.author,delete t.publishConfig,delete t.repository,delete t.scripts.prepublishOnly,delete t.devDependencies.np),I&&(m.includes("electron")||(k(t,"electron"),t.scripts["lint:eslint"]=t.scripts["lint:eslint"].replace(",electron","")),m.includes("vite")||k(t,"vite")),h(r.join(c,"package.json"),t)}function Pe(t,o){let n=t.lastIndexOf("."),s=t.substring(0,n)+"."+o+t.substring(n),g=r.join(c,t),y=r.join(c,s);a.existsSync(y)&&(m.includes(o)?($(g),Ne(y,g)):$(y))}function Re(...t){t.forEach(o=>{We.forEach(n=>{Pe(o,n)})})}function Ae(){let t=r.join(c,"package.json"),o=x(t);if(m.includes("test")){if(m.includes("electron")){k(o,"vitest"),h(t,o);let n=r.join(c,"test/simple.test.ts");if(a.existsSync(n)){let s=a.readFileSync(n,{encoding:"utf8"});a.writeFileSync(n,s.replace("import { describe, expect, it } from 'vitest';",""),{encoding:"utf8"})}}else te("jest.config.cjs");return}delete o.scripts.test,o.scripts["lint:eslint"]=o.scripts["lint:eslint"].replace(",test",""),k(o,"jest","vitest"),te(".lintstagedrc.cjs","jest.config.cjs","test"),h(t,o)}function $e(){if(!m.includes("examples")){let n=x(r.join(c,"package.json"));n.scripts.lint=n.scripts.lint.replace(" lint:stylelint",""),n.scripts["lint:eslint"]=n.scripts["lint:eslint"].replace(",examples",""),delete n.scripts["lint:stylelint"],k(n,"stylelint"),h(r.join(c,"package.json"),n);return}let t=r.join(c,"examples");a.mkdirSync(t);let o=m.includes("electron");["vue","react"].forEach(n=>{let s=U(o?`electron-${n}`:n),g=r.join(t,n);if(!a.existsSync(s)){console.log(`${Ie(s)} template is not exist`);return}a.cpSync(s,g,{recursive:!0});let y=x(r.join(g,"package.json"));Object.keys(y.scripts).forEach(b=>{(b.startsWith("lint")||["prepare"].includes(b))&&delete y.scripts[b]}),k(y,"eslint","prettier","stylelint","commitlint","husky","lint-staged","tsconfig","lint-staged","npm-run-all"),h(r.join(g,"package.json"),y),["_lintstagedrc.cjs"].forEach(b=>{let ne=r.join(g,b);a.existsSync(ne)&&a.rmSync(ne,{recursive:!0})})}),a.writeFileSync(r.join(c,"pnpm-workspace.yaml"),`packages:
9
+ - 'examples/*'`,{encoding:"utf-8"})}}K().then(async()=>ze().catch(e=>{e.message&&console.error(e)})).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.8.3",
3
+ "version": "0.10.0",
4
4
  "description": "create tomjs web app",
5
5
  "keywords": [
6
6
  "tomjs",
@@ -58,21 +58,23 @@
58
58
  "@tomjs/tsconfig": "^1.2.1",
59
59
  "@types/lodash-es": "^4.17.12",
60
60
  "@types/minimist": "^1.2.5",
61
- "@types/node": "^18.19.3",
61
+ "@types/node": "^18.19.4",
62
62
  "@types/prompts": "^2.4.9",
63
63
  "@types/shelljs": "^0.8.15",
64
+ "cross-env": "^7.0.3",
64
65
  "eslint": "^8.56.0",
65
66
  "husky": "^8.0.3",
66
67
  "lint-staged": "^15.2.0",
67
68
  "np": "^9.2.0",
68
69
  "npm-run-all": "^4.1.5",
69
70
  "prettier": "^3.1.1",
70
- "stylelint": "^16.0.2",
71
+ "stylelint": "^16.1.0",
71
72
  "tsup": "^8.0.1",
72
73
  "typescript": "~5.3.3"
73
74
  },
74
75
  "scripts": {
75
76
  "dev": "tsup --watch",
77
+ "debug": "cross-env VSCODE_DEBUG=1 tsup --watch",
76
78
  "build": "tsup --minify",
77
79
  "lint": "run-s lint:eslint lint:stylelint lint:prettier",
78
80
  "lint:eslint": "eslint \"{src,template-*}/**/*.{js,cjs,ts}\" *.{js,cjs,ts} --fix --cache",
@@ -31,9 +31,9 @@
31
31
  "@tomjs/prettier": "^1.1.1",
32
32
  "@tomjs/stylelint": "^2.1.1",
33
33
  "@tomjs/tsconfig": "^1.2.1",
34
- "@tomjs/vite-plugin-electron": "^1.8.0",
35
- "@types/node": "^18.19.3",
36
- "@types/react": "^18.2.45",
34
+ "@tomjs/vite-plugin-electron": "^1.8.2",
35
+ "@types/node": "^18.19.4",
36
+ "@types/react": "^18.2.46",
37
37
  "@types/react-dom": "^18.2.18",
38
38
  "@vitejs/plugin-react-swc": "^3.5.0",
39
39
  "cross-env": "^7.0.3",
@@ -45,7 +45,7 @@
45
45
  "npm-run-all": "^4.1.5",
46
46
  "prettier": "^3.1.1",
47
47
  "rimraf": "^5.0.5",
48
- "stylelint": "^16.0.2",
48
+ "stylelint": "^16.1.0",
49
49
  "tsx": "^4.7.0",
50
50
  "typescript": "~5.3.3",
51
51
  "vite": "^5.0.10",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@tomjs/electron-devtools-installer": "^2.0.6",
24
- "vue": "^3.3.13"
24
+ "vue": "^3.4.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@commitlint/cli": "^18.4.3",
@@ -30,9 +30,9 @@
30
30
  "@tomjs/prettier": "^1.1.1",
31
31
  "@tomjs/stylelint": "^2.1.1",
32
32
  "@tomjs/tsconfig": "^1.2.1",
33
- "@tomjs/vite-plugin-electron": "^1.8.0",
34
- "@types/node": "^18.19.3",
35
- "@vitejs/plugin-vue": "^4.5.2",
33
+ "@tomjs/vite-plugin-electron": "^1.8.2",
34
+ "@types/node": "^18.19.4",
35
+ "@vitejs/plugin-vue": "^5.0.2",
36
36
  "cross-env": "^7.0.3",
37
37
  "electron": "^28.1.0",
38
38
  "electron-builder": "^24.9.1",
@@ -42,11 +42,11 @@
42
42
  "npm-run-all": "^4.1.5",
43
43
  "prettier": "^3.1.1",
44
44
  "rimraf": "^5.0.5",
45
- "stylelint": "^16.0.2",
45
+ "stylelint": "^16.1.0",
46
46
  "tsx": "^4.7.0",
47
47
  "typescript": "~5.3.3",
48
48
  "vite": "^5.0.10",
49
49
  "vite-plugin-electron-renderer": "^0.14.5",
50
- "vue-tsc": "^1.8.26"
50
+ "vue-tsc": "^1.8.27"
51
51
  }
52
52
  }
@@ -9,12 +9,5 @@
9
9
  ## Install
10
10
 
11
11
  ```bash
12
- # pnpm
13
- pnpm add {{pkg.name}} -D
14
-
15
- # yarn
16
- yarn add {{pkg.name}} -D
17
-
18
- # npm
19
- npm i {{pkg.name}} --save-dev
12
+ {{pkg.install}}
20
13
  ```
@@ -9,12 +9,5 @@
9
9
  ## 安装
10
10
 
11
11
  ```bash
12
- # pnpm
13
- pnpm add {{pkg.name}} -D
14
-
15
- # yarn
16
- yarn add {{pkg.name}} -D
17
-
18
- # npm
19
- npm i {{pkg.name}} --save-dev
12
+ {{pkg.install}}
20
13
  ```
@@ -59,7 +59,7 @@
59
59
  "@tomjs/stylelint": "^2.1.1",
60
60
  "@tomjs/tsconfig": "^1.2.1",
61
61
  "@types/jest": "^29.5.11",
62
- "@types/node": "^18.19.3",
62
+ "@types/node": "^18.19.4",
63
63
  "cross-env": "^7.0.3",
64
64
  "electron": "^28.1.0",
65
65
  "eslint": "^8.56.0",
@@ -70,11 +70,12 @@
70
70
  "npm-run-all": "^4.1.5",
71
71
  "prettier": "^3.1.1",
72
72
  "rimraf": "^5.0.5",
73
- "stylelint": "^16.0.2",
73
+ "stylelint": "^16.1.0",
74
74
  "ts-jest": "^29.1.1",
75
75
  "tsup": "^8.0.1",
76
76
  "tsx": "^4.7.0",
77
77
  "typescript": "~5.3.3",
78
- "vite": "^5.0.10"
78
+ "vite": "^5.0.10",
79
+ "vitest": "^1.1.1"
79
80
  }
80
81
  }
@@ -1,5 +1,7 @@
1
- describe('simple', () => {
2
- it('should work', () => {
3
- expect(1).toBe(1);
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ describe('some test', () => {
4
+ it('1 + 1 = 2', () => {
5
+ expect(1 + 1).toBe(2);
4
6
  });
5
7
  });
@@ -1,10 +1,14 @@
1
1
  import { defineConfig } from 'tsup';
2
2
 
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- format: ['esm', 'cjs'],
6
- target: ['es2021', 'node16'],
7
- clean: true,
8
- dts: true,
9
- splitting: true,
3
+ export default defineConfig(options => {
4
+ return {
5
+ entry: ['src/index.ts'],
6
+ format: ['esm', 'cjs'],
7
+ target: ['es2021', 'node16'],
8
+ shims: true,
9
+ clean: true,
10
+ sourcemap: !!options.watch,
11
+ dts: true,
12
+ splitting: true,
13
+ };
10
14
  });
@@ -0,0 +1,15 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig(options => {
4
+ return {
5
+ entry: ['src/index.ts'],
6
+ format: ['esm', 'cjs'],
7
+ target: ['es2021', 'node16'],
8
+ external: ['vite'],
9
+ shims: true,
10
+ clean: true,
11
+ sourcemap: !!options.watch,
12
+ dts: true,
13
+ splitting: true,
14
+ };
15
+ });
@@ -27,8 +27,8 @@
27
27
  "@tomjs/prettier": "^1.1.1",
28
28
  "@tomjs/stylelint": "^2.1.1",
29
29
  "@tomjs/tsconfig": "^1.2.1",
30
- "@types/node": "^18.19.3",
31
- "@types/react": "^18.2.45",
30
+ "@types/node": "^18.19.4",
31
+ "@types/react": "^18.2.46",
32
32
  "@types/react-dom": "^18.2.18",
33
33
  "@vitejs/plugin-react-swc": "^3.5.0",
34
34
  "cross-env": "^7.0.3",
@@ -37,7 +37,7 @@
37
37
  "lint-staged": "^15.2.0",
38
38
  "npm-run-all": "^4.1.5",
39
39
  "prettier": "^3.1.1",
40
- "stylelint": "^16.0.2",
40
+ "stylelint": "^16.1.0",
41
41
  "typescript": "~5.3.3",
42
42
  "vite": "^5.0.10"
43
43
  }
@@ -45,9 +45,9 @@
45
45
  "@tomjs/eslint": "^1.2.1",
46
46
  "@tomjs/prettier": "^1.1.1",
47
47
  "@tomjs/tsconfig": "^1.2.1",
48
- "@types/node": "^18.19.3",
48
+ "@types/node": "^18.19.4",
49
49
  "@types/vscode": "^1.85.0",
50
- "@vitejs/plugin-vue": "^4.5.2",
50
+ "@vitejs/plugin-vue": "^5.0.2",
51
51
  "cross-env": "^7.0.3",
52
52
  "eslint": "^8.56.0",
53
53
  "husky": "^8.0.3",
@@ -48,10 +48,10 @@
48
48
  "@tomjs/prettier": "^1.1.1",
49
49
  "@tomjs/stylelint": "^2.1.1",
50
50
  "@tomjs/tsconfig": "^1.2.1",
51
- "@tomjs/vite-plugin-vscode": "^1.1.0",
52
- "@tomjs/vscode-extension-webview": "^1.1.1",
53
- "@types/node": "^18.19.3",
54
- "@types/react": "^18.2.45",
51
+ "@tomjs/vite-plugin-vscode": "^1.2.0",
52
+ "@tomjs/vscode-extension-webview": "^1.2.0",
53
+ "@types/node": "^18.19.4",
54
+ "@types/react": "^18.2.46",
55
55
  "@types/react-dom": "^18.2.18",
56
56
  "@types/vscode": "^1.85.0",
57
57
  "@types/vscode-webview": "^1.57.4",
@@ -63,7 +63,7 @@
63
63
  "npm-run-all": "^4.1.5",
64
64
  "prettier": "^3.1.1",
65
65
  "rimraf": "^5.0.5",
66
- "stylelint": "^16.0.2",
66
+ "stylelint": "^16.1.0",
67
67
  "tsx": "^4.7.0",
68
68
  "typescript": "~5.3.3",
69
69
  "vite": "^5.0.10"
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@vscode/webview-ui-toolkit": "^1.4.0",
41
- "vue": "^3.3.13"
41
+ "vue": "^3.4.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@commitlint/cli": "^18.4.3",
@@ -47,12 +47,12 @@
47
47
  "@tomjs/prettier": "^1.1.1",
48
48
  "@tomjs/stylelint": "^2.1.1",
49
49
  "@tomjs/tsconfig": "^1.2.1",
50
- "@tomjs/vite-plugin-vscode": "^1.1.0",
51
- "@tomjs/vscode-extension-webview": "^1.1.1",
52
- "@types/node": "^18.19.3",
50
+ "@tomjs/vite-plugin-vscode": "^1.2.0",
51
+ "@tomjs/vscode-extension-webview": "^1.2.0",
52
+ "@types/node": "^18.19.4",
53
53
  "@types/vscode": "^1.85.0",
54
54
  "@types/vscode-webview": "^1.57.4",
55
- "@vitejs/plugin-vue": "^4.5.2",
55
+ "@vitejs/plugin-vue": "^5.0.2",
56
56
  "cross-env": "^7.0.3",
57
57
  "eslint": "^8.56.0",
58
58
  "husky": "^8.0.3",
@@ -60,10 +60,10 @@
60
60
  "npm-run-all": "^4.1.5",
61
61
  "prettier": "^3.1.1",
62
62
  "rimraf": "^5.0.5",
63
- "stylelint": "^16.0.2",
63
+ "stylelint": "^16.1.0",
64
64
  "tsx": "^4.7.0",
65
65
  "typescript": "~5.3.3",
66
66
  "vite": "^5.0.10",
67
- "vue-tsc": "^1.8.26"
67
+ "vue-tsc": "^1.8.27"
68
68
  }
69
69
  }
@@ -17,7 +17,7 @@
17
17
  "prepare": "husky install"
18
18
  },
19
19
  "dependencies": {
20
- "vue": "^3.3.13"
20
+ "vue": "^3.4.3"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@commitlint/cli": "^18.4.3",
@@ -26,17 +26,17 @@
26
26
  "@tomjs/prettier": "^1.1.1",
27
27
  "@tomjs/stylelint": "^2.1.1",
28
28
  "@tomjs/tsconfig": "^1.2.1",
29
- "@types/node": "^18.19.3",
30
- "@vitejs/plugin-vue": "^4.5.2",
29
+ "@types/node": "^18.19.4",
30
+ "@vitejs/plugin-vue": "^5.0.2",
31
31
  "cross-env": "^7.0.3",
32
32
  "eslint": "^8.56.0",
33
33
  "husky": "^8.0.3",
34
34
  "lint-staged": "^15.2.0",
35
35
  "npm-run-all": "^4.1.5",
36
36
  "prettier": "^3.1.1",
37
- "stylelint": "^16.0.2",
37
+ "stylelint": "^16.1.0",
38
38
  "typescript": "~5.3.3",
39
39
  "vite": "^5.0.10",
40
- "vue-tsc": "^1.8.26"
40
+ "vue-tsc": "^1.8.27"
41
41
  }
42
42
  }