@tomjs/create-app 0.0.23 → 0.0.24
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,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import s from"fs";import
|
|
3
|
-
Scaffolding project in ${
|
|
4
|
-
`)
|
|
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
|
-
`),
|
|
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,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2023
|
|
3
|
+
Copyright (c) 2023 {{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
|
-
#
|
|
1
|
+
# template-node-github
|
|
2
2
|
|
|
3
|
-
  
|
|
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
|
|
14
|
+
pnpm add template-node-github
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
With `yarn`
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
yarn add
|
|
20
|
+
yarn add template-node-github
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
With `npm`
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
npm i
|
|
26
|
+
npm i template-node-github
|
|
27
27
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# template-node-github
|
|
2
2
|
|
|
3
|
-
  
|
|
4
4
|
|
|
5
5
|
基础 node 模板
|
|
6
6
|
|
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
使用 `pnpm`
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
pnpm add
|
|
14
|
+
pnpm add template-node-github
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
使用 `yarn`
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
yarn add
|
|
20
|
+
yarn add template-node-github
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
使用 `npm`
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
npm i
|
|
26
|
+
npm i template-node-github
|
|
27
27
|
```
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "template-node-github",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"description": "basic node.js template",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tomjs"
|
|
7
7
|
],
|
|
8
8
|
"author": {
|
|
9
|
-
"name": "
|
|
10
|
-
"email": "
|
|
9
|
+
"name": "name",
|
|
10
|
+
"email": "name@github.com"
|
|
11
11
|
},
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"engines": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/
|
|
25
|
+
"url": "git+https://github.com/xxx/template-node-github.git"
|
|
26
26
|
},
|
|
27
27
|
"main": "./dist/index.js",
|
|
28
28
|
"module": "./dist/index.mjs",
|