@tomjs/create-app 0.11.2 → 0.11.4

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,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 We,lightGreen as D,lightYellow as xe,red as Se,reset as w,yellow as Me}from"kolorist";import{camelCase as we}from"lodash-es";import ze from"minimist";import Le from"prompts";import G from"shelljs";import de from"os";import ye from"path";import{blue as Te,red as $,reset as F}from"kolorist";import Ne from"minimist";import H from"prompts";import p from"fs";import M from"path";function R(e){return[["t","template"],["g","git"]].forEach(([r,l])=>{e[l]=e[l]??e[r]}),e}function ce(e){return p.readdirSync(e).length===0}function z(e){return e?.trim().replace(/\/+$/g,"")}function Ge(e,r){p.mkdirSync(r,{recursive:!0});for(let l of p.readdirSync(e)){let x=M.resolve(e,l),f=M.resolve(r,l);L(x,f)}}function L(e,r){p.statSync(e).isDirectory()?Ge(e,r):p.copyFileSync(e,r)}function ae(e){if(p.existsSync(e))for(let r of p.readdirSync(e))p.rmSync(M.resolve(e,r),{recursive:!0,force:!0})}function Y(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function le(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function pe(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 me(e){return p.existsSync(e)?p.readFileSync(e,"utf8"):""}function A(e){p.existsSync(e)&&p.rmSync(e,{recursive:!0,force:!0})}function ue(e){p.existsSync(e)||p.mkdirSync(e,{recursive:!0})}var _e=R(Ne(process.argv.slice(2),{string:["_"]})),ge={repo:"https://github.com",owner:de.userInfo().username};function K(e){let{repo:r,owner:l}=e;return`${r}${r.endsWith("/")?"":"/"}${l}`}async function fe(e){let r=await H([{type:"text",name:"repo",message:F("Git repository url:"),initial:e?.repo||ge.repo},{type:"text",name:"owner",message:F("Git repository owner:"),initial:e?.owner||ge.owner}],{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}});return{id:e?.id||Date.now().toString(),repo:r.repo,owner:r.owner}}var he=ye.join(de.homedir(),".tomjs","create-app"),ve=ye.join(he,"config.json");function O(){return ue(he),Object.assign({gitRepos:[]},S(ve))}function Ue(e){let r=O();r.createTime?r.updateTime=Date.now():r.createTime=Date.now(),v(ve,Object.assign(r,e))}function B(e){Ue({gitRepos:e})}async function q(){let{gitRepos:e}=O();(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:K(y),value:y.id})).concat([{title:"Add",value:"add"},{title:$("Exit"),value:"exit"}]),x=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:l},{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}}),{repoId:f}=x;if(f==="exit")return;if(f==="add"){let y=await fe();return e.push(y),B(e),r()}let j=e.findIndex(y=>y.id===f),b=await H([{type:"select",name:"action",message:F("Select an action?"),choices:[{title:"Edit",value:"edit"},{title:"Remove",value:"remove"},{title:"Exit",value:"exit"}]},{type:y=>y==="remove"&&"toggle",name:"confirmRemove",message:F("Where confirm to remove?"),initial:!0,active:"Yes",inactive:"No"}],{onCancel:()=>{throw console.log($("\u2716")+" Operation cancelled"),new Error}}),{action:E,confirmRemove:T}=b;if(E==="exit")return q();if(E==="remove")return T&&(e.splice(j,1),B(e)),r();let N=await fe(e[j]);return e[j]=N,B(e),r()}}var Q=R(ze(process.argv.slice(2),{string:["_"]})),X=process.cwd(),Ye=["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:We,options:[{id:"publish",name:"Git Repository"},{id:"ssh",name:"Git init by SSH"}],variants:[{name:"vscode",display:"Base",color:xe},{name:"vscode-vue",display:"Vue",color:D},{name:"vscode-react",display:"React",color:C}]},{name:"node",display:"Node",color:xe,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),[]),Z="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 Be(){let e=z(Q._[0]),r=Q.template||Q.t,l=e||Z,x=()=>l==="."?c.basename(c.resolve()):l,f=be(l),{gitRepos:j}=O(),b=await Le([{type:e?null:"text",name:"projectName",message:w("Project name:"),initial:Z,onState:t=>{l=z(t.value)||Z,f=be(l)}},{type:()=>!s.existsSync(f)||ce(f)?null:"toggle",name:"overwrite",message:()=>(f==="."?"Current directory":`Target directory "${f}"`)+" is not empty. Remove existing files and continue?",initial:!1,active:"Yes",inactive:"No"},{type:(t,{overwrite:n})=>{if(n===!1)throw console.log(Se("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>Y(x())?null:"text",name:"packageName",message:w("Package name:"),initial:()=>le(x()),validate:t=>Y(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=K(t);return{title:n,value:n}})}],{onCancel:()=>{throw console.log(Se("\u2716")+" Operation cancelled"),new Error}}),{framework:E,overwrite:T,packageName:N,variant:y,gitUserUrl:ee}=b,g=b.options||[],a=c.join(X,f);T?ae(a):s.existsSync(a)||s.mkdirSync(a,{recursive:!0}),console.log(`
4
- Scaffolding project in ${a}...`);let _=y||E?.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&&!g.includes("examples")||_==="vscode")&&i.includes("stylelint"))continue;let u=c.join(a,o);L(c.join(t,i),u)}});let m=N||x(),P={name:ke("user.name")||Ve.userInfo().username,email:ke("user.email")||""},V={"pkg.name":m,"git.name":P.name,"git.email":P.email,"git.url":Re(),"git.fullUrl":te()};function Re(){let t=m.startsWith("@")?m.split("/")[0].substring(1):we(P.name);return`${ee||`https://github.com/${t}`}/${m.substring(m.indexOf("/")+1)}`}function te(t=!1){let n=m.startsWith("@")?m.split("/")[0].substring(1):we(P.name),i=ee||`https://github.com/${n}`;return t&&(i=i.replace(/http(s):\/\//g,"git@").replace(/\//,":")),`${i}/${m.substring(m.indexOf("/")+1)}.git`}$e(),I&&(Ae(),Ce(),De());let ne=pe(process.env.npm_config_user_agent),J=ne?ne.name:"npm";G.which("git")&&(G.exec(`cd ${a} && git init`),g.includes("publish")&&G.exec(`cd ${a} && git remote add origin ${te(g.includes("ssh"))}`));let W=c.relative(X,a);switch(console.log(`
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!==X&&console.log(` cd ${W.includes(" ")?`"${W}"`:W}`),J){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${J} install`),console.log(` ${J} run dev`);break}function Ae(){Oe(".lintstagedrc.cjs","jest.config.cjs","tsconfig.json","tsup.config.ts");let t=g.find(i=>["vite"].includes(i)),n=["#pnpm",`pnpm add ${m}${t?" -D":""}`,"","#yarn",`yarn add ${m}${t?" -D":""}`,"","#npm",`npm i ${m}${t?" --save-dev":""}`].join(`
7
- `);["LICENSE","README.md","README.zh_CN.md"].forEach(i=>{let o=c.join(a,i);if(!g.includes("publish")&&s.existsSync(o)){s.rmSync(o),i==="README.md"&&s.writeFileSync(o,`# ${m}
8
- `,{encoding:"utf-8"});return}if(!s.existsSync(o))return;let u=Object.assign({},V,{"pkg.install":n}),d=s.readFileSync(o,"utf-8");Object.keys(u).forEach(h=>{d=d.replace(new RegExp("{{"+h+"}}","g"),u[h])}),s.writeFileSync(o,d,"utf8")})}function k(t,...n){["dependencies","devDependencies"].forEach(i=>{Object.keys(t[i]||{}).forEach(o=>{n.find(u=>o.includes(u))&&delete t[i][o]})})}function ie(...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=m,g.includes("publish")||(delete n.author,delete n.publishConfig,delete n.repository,delete n.scripts.prepublishOnly,delete n.devDependencies.np),I&&(g.includes("electron")||(k(n,"electron"),n.scripts["lint:eslint"]=n.scripts["lint:eslint"].replace(",electron","")),g.includes("vite")||k(n,"vite")),v(t,n);let i=me(t);Object.keys(V).forEach(o=>{i=i.replace(new RegExp("{{"+o+"}}","g"),V[o])}),s.writeFileSync(t,i)}function Fe(t,n){let i=t.lastIndexOf("."),o=t.substring(0,i)+"."+n+t.substring(i),u=c.join(a,t),d=c.join(a,o);s.existsSync(d)&&(g.includes(n)?(A(u),Ie(d,u)):A(d))}function Oe(...t){t.forEach(n=>{Ye.forEach(i=>{Fe(n,i)})})}function Ce(){let t=c.join(a,"package.json"),n=S(t);if(g.includes("test")){if(g.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 ie("jest.config.cjs");return}delete n.scripts.test,n.scripts["lint:eslint"]=n.scripts["lint:eslint"].replace(",test",""),k(n,"jest","vitest"),ie(".lintstagedrc.cjs","jest.config.cjs","test"),v(t,n)}function De(){if(!g.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=g.includes("electron");["vue","react"].forEach(i=>{let o=U(n?`electron-${i}`:i),u=c.join(t,i);if(!s.existsSync(o)){console.log(`${Me(o)} template is not exist`);return}s.cpSync(o,u,{recursive:!0});let d=S(c.join(u,"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(u,"package.json"),d),["_lintstagedrc.cjs"].forEach(h=>{let re=c.join(u,h);s.existsSync(re)&&s.rmSync(re,{recursive:!0})})}),s.writeFileSync(c.join(a,"pnpm-workspace.yaml"),`packages:
9
- - 'examples/*'`,{encoding:"utf-8"})}}q().then(async()=>Be().catch(e=>{e.message&&console.error(e)})).catch(e=>{e.message&&console.error(e)});
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomjs/create-app",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "description": "create tomjs web app",
5
5
  "keywords": [
6
6
  "tomjs",
@@ -58,7 +58,7 @@
58
58
  "@tomjs/tsconfig": "^1.3.0",
59
59
  "@types/lodash-es": "^4.17.12",
60
60
  "@types/minimist": "^1.2.5",
61
- "@types/node": "^18.19.6",
61
+ "@types/node": "^18.19.7",
62
62
  "@types/prompts": "^2.4.9",
63
63
  "@types/shelljs": "^0.8.15",
64
64
  "cross-env": "^7.0.3",
@@ -46,6 +46,7 @@ tsconfig.tsbuildinfo
46
46
  *.tar.*
47
47
  *.tgz
48
48
  *.zip
49
+ *.vsix
49
50
 
50
51
  # IDEA
51
52
  .idea
@@ -32,8 +32,8 @@
32
32
  "@tomjs/stylelint": "^2.2.0",
33
33
  "@tomjs/tsconfig": "^1.3.0",
34
34
  "@tomjs/vite-plugin-electron": "^1.8.2",
35
- "@types/node": "^18.19.6",
36
- "@types/react": "^18.2.47",
35
+ "@types/node": "^18.19.7",
36
+ "@types/react": "^18.2.48",
37
37
  "@types/react-dom": "^18.2.18",
38
38
  "@vitejs/plugin-react-swc": "^3.5.0",
39
39
  "cross-env": "^7.0.3",
@@ -31,7 +31,7 @@
31
31
  "@tomjs/stylelint": "^2.2.0",
32
32
  "@tomjs/tsconfig": "^1.3.0",
33
33
  "@tomjs/vite-plugin-electron": "^1.8.2",
34
- "@types/node": "^18.19.6",
34
+ "@types/node": "^18.19.7",
35
35
  "@vitejs/plugin-vue": "^5.0.3",
36
36
  "cross-env": "^7.0.3",
37
37
  "electron": "^28.1.3",
@@ -6,8 +6,8 @@
6
6
  "node"
7
7
  ],
8
8
  "author": {
9
- "name": "{{git.name}}",
10
- "email": "{{git.email}}"
9
+ "name": "{{user.name}}",
10
+ "email": "{{user.email}}"
11
11
  },
12
12
  "license": "MIT",
13
13
  "main": "./dist/index.js",
@@ -59,7 +59,7 @@
59
59
  "@tomjs/stylelint": "^2.2.0",
60
60
  "@tomjs/tsconfig": "^1.3.0",
61
61
  "@types/jest": "^29.5.11",
62
- "@types/node": "^18.19.6",
62
+ "@types/node": "^18.19.7",
63
63
  "cross-env": "^7.0.3",
64
64
  "electron": "^28.1.3",
65
65
  "eslint": "^8.56.0",
@@ -27,8 +27,8 @@
27
27
  "@tomjs/prettier": "^1.1.1",
28
28
  "@tomjs/stylelint": "^2.2.0",
29
29
  "@tomjs/tsconfig": "^1.3.0",
30
- "@types/node": "^18.19.6",
31
- "@types/react": "^18.2.47",
30
+ "@types/node": "^18.19.7",
31
+ "@types/react": "^18.2.48",
32
32
  "@types/react-dom": "^18.2.18",
33
33
  "@vitejs/plugin-react-swc": "^3.5.0",
34
34
  "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.
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "{{pkg.name}}",
3
+ "displayName": "{{pkg.name}}",
4
+ "description": "",
3
5
  "version": "0.0.0",
4
- "description": "vscode extension template",
6
+ "publisher": "{{git.org}}",
5
7
  "license": "MIT",
6
8
  "engines": {
7
9
  "node": ">=14",
@@ -46,10 +48,8 @@
46
48
  "@tomjs/eslint": "^1.2.2",
47
49
  "@tomjs/prettier": "^1.1.1",
48
50
  "@tomjs/tsconfig": "^1.3.0",
49
- "@types/node": "^18.19.6",
51
+ "@types/node": "^18.19.7",
50
52
  "@types/vscode": "^1.56.0",
51
- "@vitejs/plugin-vue": "^5.0.3",
52
- "cross-env": "^7.0.3",
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.
@@ -1,5 +1,5 @@
1
1
  import { Disposable, Uri, ViewColumn, Webview, WebviewPanel, window } from 'vscode';
2
- // import __getWebviewHtml from '@tomjs/vscode-extension-webview';
2
+ // import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';
3
3
 
4
4
  function uuid() {
5
5
  let text = '';
@@ -119,8 +119,7 @@ export class MainPanel {
119
119
  const nonce = uuid();
120
120
 
121
121
  if (process.env.VITE_DEV_SERVER_URL) {
122
- // @ts-ignore
123
- return __getWebviewHtml({ serverUrl: process.env.VITE_DEV_SERVER_URL });
122
+ return __getWebviewHtml__(process.env.VITE_DEV_SERVER_URL);
124
123
  }
125
124
 
126
125
  // Tip: Install the es6-string-html VS Code extension to enable code highlighting below
@@ -54,10 +54,10 @@
54
54
  "@tomjs/prettier": "^1.1.1",
55
55
  "@tomjs/stylelint": "^2.2.0",
56
56
  "@tomjs/tsconfig": "^1.3.0",
57
- "@tomjs/vite-plugin-vscode": "^1.3.2",
57
+ "@tomjs/vite-plugin-vscode": "^1.4.0",
58
58
  "@tomjs/vscode-extension-webview": "^1.2.0",
59
- "@types/node": "^18.19.6",
60
- "@types/react": "^18.2.47",
59
+ "@types/node": "^18.19.7",
60
+ "@types/react": "^18.2.48",
61
61
  "@types/react-dom": "^18.2.18",
62
62
  "@types/vscode": "^1.56.0",
63
63
  "@types/vscode-webview": "^1.57.4",
@@ -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,5 +1,5 @@
1
1
  import { Disposable, Uri, ViewColumn, Webview, WebviewPanel, window } from 'vscode';
2
- // import __getWebviewHtml from '@tomjs/vscode-extension-webview';
2
+ // import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';
3
3
 
4
4
  function uuid() {
5
5
  let text = '';
@@ -119,8 +119,7 @@ export class MainPanel {
119
119
  const nonce = uuid();
120
120
 
121
121
  if (process.env.VITE_DEV_SERVER_URL) {
122
- // @ts-ignore
123
- return __getWebviewHtml({ serverUrl: process.env.VITE_DEV_SERVER_URL });
122
+ return __getWebviewHtml__(process.env.VITE_DEV_SERVER_URL);
124
123
  }
125
124
 
126
125
  // Tip: Install the es6-string-html VS Code extension to enable code highlighting below
@@ -52,9 +52,9 @@
52
52
  "@tomjs/prettier": "^1.1.1",
53
53
  "@tomjs/stylelint": "^2.2.0",
54
54
  "@tomjs/tsconfig": "^1.3.0",
55
- "@tomjs/vite-plugin-vscode": "^1.3.2",
55
+ "@tomjs/vite-plugin-vscode": "^1.4.0",
56
56
  "@tomjs/vscode-extension-webview": "^1.2.0",
57
- "@types/node": "^18.19.6",
57
+ "@types/node": "^18.19.7",
58
58
  "@types/vscode": "^1.56.0",
59
59
  "@types/vscode-webview": "^1.57.4",
60
60
  "@vitejs/plugin-vue": "^5.0.3",
@@ -26,7 +26,7 @@
26
26
  "@tomjs/prettier": "^1.1.1",
27
27
  "@tomjs/stylelint": "^2.2.0",
28
28
  "@tomjs/tsconfig": "^1.3.0",
29
- "@types/node": "^18.19.6",
29
+ "@types/node": "^18.19.7",
30
30
  "@vitejs/plugin-vue": "^5.0.3",
31
31
  "cross-env": "^7.0.3",
32
32
  "eslint": "^8.56.0",