@tomjs/create-app 0.0.23 → 0.1.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Tom Gao
3
+ Copyright (c) 2023-PRESENT Tom Gao<tom@tomgao.cc>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import s from"fs";import i from"path";import{fileURLToPath as Q}from"url";import{blue as d,cyan as X,green as Y,red as z,reset as g,yellow as j}from"kolorist";import Z from"minimist";import ee from"prompts";import M from"shelljs";import l from"fs";import w from"path";function C(e){return[["t","template"]].forEach(([t,r])=>{e[r]=e[r]??e[t]}),e}function D(e){let t=l.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function S(e){return e?.trim().replace(/\/+$/g,"")}function B(e,t){l.mkdirSync(t,{recursive:!0});for(let r of l.readdirSync(e)){let m=w.resolve(e,r),f=w.resolve(t,r);h(m,f)}}function h(e,t){l.statSync(e).isDirectory()?B(e,t):l.copyFileSync(e,t)}function R(e){if(l.existsSync(e))for(let t of l.readdirSync(e))t!==".git"&&l.rmSync(w.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 T(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function V(e){if(!e)return;let r=e.split(" ")[0].split("/");return{name:r[0],version:r[1]}}var N=C(Z(process.argv.slice(2),{string:["_"]})),x=process.cwd(),L=[{name:"vue",display:"Vue",color:Y,variants:[{name:"vue",display:"Web",color:d},{name:"electron-vue",display:"Electron",color:j}]},{name:"react",display:"React",color:X,variants:[{name:"react",display:"Web",color:d},{name:"electron-react",display:"Electron",color:j}]},{name:"node",display:"Node",color:d,variants:[{name:"node",display:"base",color:d},{name:"node-github",display:"Github + NPM",color:j}]}],O=L.map(e=>e.variants&&e.variants.map(t=>t.name)||[e.name]).reduce((e,t)=>e.concat(t),[]),te={_gitignore:".gitignore","_lintstagedrc.cjs":".lintstagedrc.cjs"},b="my-app";async function ne(){let e=S(N._[0]),t=N.template||N.t,r=e||b,m=()=>r==="."?i.basename(i.resolve()):r,f={name:"",email:""},E={};E=await ee([{type:e?null:"text",name:"projectName",message:g("Project name:"),initial:b,onState:n=>{r=S(n.value)||b}},{type:()=>!s.existsSync(r)||D(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(z("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>F(m())?null:"text",name:"packageName",message:g("Package name:"),initial:()=>T(m()),validate:n=>F(n)||"Invalid package.json name"},{type:t&&O.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!O.includes(t)?g(`"${t}" isn't a valid template. Please choose from below: `):g("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:g("Select a variant:"),choices:n=>n?.variants?.map(o=>{let c=o.color;return{title:c(o.display||o.name),value:o.name}})}],{onCancel:()=>{throw console.log(z("\u2716")+" Operation cancelled"),new Error}});let{framework:U,overwrite:W,packageName:G,variant:I}=E,a=i.join(x,r);W?R(a):s.existsSync(a)||s.mkdirSync(a,{recursive:!0}),console.log(`
3
- Scaffolding project in ${a}...`);let u=I||U?.name||t||"",P=n=>i.join(Q(import.meta.url),"../..",`template-${n}`),_=P(u),J=u.includes("node");[_,P("config")].forEach(n=>{let o=s.readdirSync(n);for(let c of o){let K=te[c]??c;if(J&&c.includes("stylelint"))continue;let q=i.join(a,K);h(i.join(n,c),q)}});let $=u.includes("github"),H=`template-${u}`,p=JSON.parse(s.readFileSync(i.join(_,"package.json"),"utf-8")),y=G||m();p.name=y,$&&(p.name=`@tomjs/${y}`,p.author=Object.assign(p.author,f)),s.writeFileSync(i.join(a,"package.json"),JSON.stringify(p,null,2)+`
4
- `),$&&["package.json","README.md","README.zh_CN.md"].forEach(n=>{let o=i.join(a,n);if(s.existsSync(o)){let c=s.readFileSync(o,"utf-8");s.writeFileSync(o,c.replace(new RegExp(H,"g"),y))}});let A=V(process.env.npm_config_user_agent),v=A?A.name:"npm";M.which("git")&&M.exec(`cd ${a} && git init`);let k=i.relative(x,a);switch(console.log(`
2
+ import s from"fs";import X from"os";import a from"path";import{fileURLToPath as Y}from"url";import{blue as v,cyan as Z,green as ee,red as z,reset as f,yellow as b}from"kolorist";import te from"minimist";import ne from"prompts";import k from"shelljs";import l from"fs";import S from"path";function A(e){return[["t","template"]].forEach(([t,r])=>{e[r]=e[r]??e[t]}),e}function D(e){let t=l.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function x(e){return e?.trim().replace(/\/+$/g,"")}function Q(e,t){l.mkdirSync(t,{recursive:!0});for(let r of l.readdirSync(e)){let p=S.resolve(e,r),d=S.resolve(t,r);F(p,d)}}function F(e,t){l.statSync(e).isDirectory()?Q(e,t):l.copyFileSync(e,t)}function T(e){if(l.existsSync(e))for(let t of l.readdirSync(e))t!==".git"&&l.rmSync(S.resolve(e,t),{recursive:!0,force:!0})}function N(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function O(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function V(e){if(!e)return;let r=e.split(" ")[0].split("/");return{name:r[0],version:r[1]}}var E=A(te(process.argv.slice(2),{string:["_"]})),j=process.cwd(),G=[{name:"vue",display:"Vue",color:ee,variants:[{name:"vue",display:"Web",color:v},{name:"electron-vue",display:"Electron",color:b}]},{name:"react",display:"React",color:Z,variants:[{name:"react",display:"Web",color:v},{name:"electron-react",display:"Electron",color:b}]},{name:"node",display:"Node",color:v,variants:[{name:"node",display:"base",color:v},{name:"node-github",display:"Github + NPM",color:b}]}],M=G.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"},P="my-app";function I(e){let t=k.exec(`git config --get ${e}`,{silent:!0});if(t.code===0)return t.stdout.trim()}async function oe(){let e=x(E._[0]),t=E.template||E.t,r=e||P,p=()=>r==="."?a.basename(a.resolve()):r,d={};d=await ne([{type:e?null:"text",name:"projectName",message:f("Project name:"),initial:P,onState:n=>{r=x(n.value)||P}},{type:()=>!s.existsSync(r)||D(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(z("\u2716")+" Operation cancelled"),new Error;return null},name:"overwriteChecker"},{type:()=>N(p())?null:"text",name:"packageName",message:f("Package name:"),initial:()=>O(p()),validate:n=>N(n)||"Invalid package.json name"},{type:t&&M.includes(t)?null:"select",name:"framework",message:typeof t=="string"&&!M.includes(t)?f(`"${t}" isn't a valid template. Please choose from below: `):f("Select a framework:"),initial:0,choices:G.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:f("Select a variant:"),choices:n=>n?.variants?.map(o=>{let c=o.color;return{title:c(o.display||o.name),value:o.name}})}],{onCancel:()=>{throw console.log(z("\u2716")+" Operation cancelled"),new Error}});let{framework:L,overwrite:U,packageName:W,variant:J}=d,i=a.join(j,r.substring(r.indexOf("/")+1));U?T(i):s.existsSync(i)||s.mkdirSync(i,{recursive:!0}),console.log(`
3
+ Scaffolding project in ${i}...`);let y=J||L?.name||t||"",$=n=>a.join(Y(import.meta.url),"../..",`template-${n}`),C=$(y),H=y.includes("node");[C,$("config")].forEach(n=>{let o=s.readdirSync(n);for(let c of o){let q=re[c]??c;if(H&&c.includes("stylelint"))continue;let B=a.join(i,q);F(a.join(n,c),B)}});let R=y.includes("github"),K=`template-${y}`,u=JSON.parse(s.readFileSync(a.join(C,"package.json"),"utf-8")),m=W||p();u.name=m;let g={name:"Tom Gao",email:"tom@tomgao.cc"};if(R){k.which("git")&&(g.name=I("user.name")||X.userInfo().username,g.email=I("user.email")||"",u.author=Object.assign(u.author,g));let n=m.startsWith("@")?m.split("/")[0].substring(1):g.name;u.repository.url=`https://github.com/${n}/${m.substring(m.indexOf("/")+1)}.git`}s.writeFileSync(a.join(i,"package.json"),JSON.stringify(u,null,2)+`
4
+ `),R&&["LICENSE","README.md","README.zh_CN.md"].forEach(n=>{let o=a.join(i,n);if(s.existsSync(o)){let c=s.readFileSync(o,"utf-8");s.writeFileSync(o,c.replace(new RegExp(K,"g"),m).replace(new RegExp("{{user.name}}","g"),g.name).replace(new RegExp("{{user.email}}","g"),g.email))}});let _=V(process.env.npm_config_user_agent),w=_?_.name:"npm";k.which("git")&&k.exec(`cd ${i} && git init`);let h=a.relative(j,i);switch(console.log(`
5
5
  Done. Now run:
6
- `),a!==x&&console.log(` cd ${k.includes(" ")?`"${k}"`:k}`),v){case"yarn":console.log(" yarn"),console.log(" yarn dev");break;default:console.log(` ${v} install`),console.log(` ${v} run dev`);break}}ne().catch(e=>{e.message&&console.error(e)});
6
+ `),i!==j&&console.log(` cd ${h.includes(" ")?`"${h}"`:h}`),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,15 +1,22 @@
1
1
  {
2
2
  "name": "@tomjs/create-app",
3
- "version": "0.0.23",
3
+ "version": "0.1.0",
4
4
  "description": "create tomjs web app",
5
5
  "keywords": [
6
6
  "tomjs",
7
7
  "front-end",
8
+ "frontend",
9
+ "back-end",
10
+ "backend",
8
11
  "create",
12
+ "create-app",
9
13
  "app",
14
+ "template",
10
15
  "vite",
11
16
  "vue",
12
- "react"
17
+ "react",
18
+ "electron",
19
+ "node"
13
20
  ],
14
21
  "author": {
15
22
  "name": "Tom Gao",
@@ -3,7 +3,9 @@
3
3
  "version": "0.0.0",
4
4
  "description": "basic node.js template",
5
5
  "keywords": [
6
- "tomjs"
6
+ "tomjs",
7
+ "node",
8
+ "backend"
7
9
  ],
8
10
  "engines": {
9
11
  "node": ">=16"
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Tom Gao <tom@tomgao.cc>
3
+ Copyright (c) {{user.name}}<{{user.email}}>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
- # @tomjs/template-node-github
1
+ # template-node-github
2
2
 
3
- ![npm](https://img.shields.io/npm/v/%40tomjs/template-node-github) ![NPM](https://img.shields.io/npm/l/%40tomjs%2Ftemplate-node-github) ![npm package minimized gzipped size (scoped version select exports)](https://img.shields.io/bundlejs/size/%40tomjs/template-node-github)
3
+ ![npm](https://img.shields.io/npm/v/template-node-github) ![NPM](https://img.shields.io/npm/l/template-node-github) ![npm package minimized gzipped size (scoped version select exports)](https://img.shields.io/bundlejs/size/template-node-github)
4
4
 
5
5
  Basic node template
6
6
 
@@ -11,17 +11,17 @@ Basic node template
11
11
  With `pnpm`
12
12
 
13
13
  ```bash
14
- pnpm add @tomjs/template-node-github
14
+ pnpm add template-node-github
15
15
  ```
16
16
 
17
17
  With `yarn`
18
18
 
19
19
  ```bash
20
- yarn add @tomjs/template-node-github
20
+ yarn add template-node-github
21
21
  ```
22
22
 
23
23
  With `npm`
24
24
 
25
25
  ```bash
26
- npm i @tomjs/template-node-github
26
+ npm i template-node-github
27
27
  ```
@@ -1,6 +1,6 @@
1
- # @tomjs/template-node-github
1
+ # template-node-github
2
2
 
3
- ![npm](https://img.shields.io/npm/v/%40tomjs/template-node-github) ![NPM](https://img.shields.io/npm/l/%40tomjs%2Ftemplate-node-github) ![npm package minimized gzipped size (scoped version select exports)](https://img.shields.io/bundlejs/size/%40tomjs/template-node-github)
3
+ ![npm](https://img.shields.io/npm/v/template-node-github) ![NPM](https://img.shields.io/npm/l/template-node-github) ![npm package minimized gzipped size (scoped version select exports)](https://img.shields.io/bundlejs/size/template-node-github)
4
4
 
5
5
  基础 node 模板
6
6
 
@@ -11,17 +11,17 @@
11
11
  使用 `pnpm`
12
12
 
13
13
  ```bash
14
- pnpm add @tomjs/template-node-github
14
+ pnpm add template-node-github
15
15
  ```
16
16
 
17
17
  使用 `yarn`
18
18
 
19
19
  ```bash
20
- yarn add @tomjs/template-node-github
20
+ yarn add template-node-github
21
21
  ```
22
22
 
23
23
  使用 `npm`
24
24
 
25
25
  ```bash
26
- npm i @tomjs/template-node-github
26
+ npm i template-node-github
27
27
  ```
@@ -1,13 +1,16 @@
1
1
  {
2
- "name": "@tomjs/template-node-github",
2
+ "name": "template-node-github",
3
3
  "version": "0.0.0",
4
4
  "description": "basic node.js template",
5
5
  "keywords": [
6
- "tomjs"
6
+ "tomjs",
7
+ "node",
8
+ "back-end",
9
+ "backend"
7
10
  ],
8
11
  "author": {
9
- "name": "Tom Gao",
10
- "email": "tom@tomgao.cc"
12
+ "name": "name",
13
+ "email": "name@github.com"
11
14
  },
12
15
  "license": "MIT",
13
16
  "engines": {
@@ -22,7 +25,7 @@
22
25
  },
23
26
  "repository": {
24
27
  "type": "git",
25
- "url": "git+https://github.com/tomgao365/template-node-github.git"
28
+ "url": "git+https://github.com/xxx/template-node-github.git"
26
29
  },
27
30
  "main": "./dist/index.js",
28
31
  "module": "./dist/index.mjs",