create-soybean 0.6.5 → 0.6.7
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 +4 -180
- package/package.json +5 -5
- package/template-react/_gitignore +1 -0
- package/template-react/package.json +1 -1
- package/template-react-native/_gitignore +1 -0
- package/template-react-native/package.json +1 -1
- package/template-solid/_gitignore +1 -0
- package/template-solid/package.json +1 -1
- package/template-ts-lib/.vscode/extensions.json +1 -5
- package/template-ts-lib/.vscode/launch.json +1 -1
- package/template-ts-lib/.vscode/settings.json +1 -2
- package/template-ts-lib/_gitignore +1 -0
- package/template-ts-lib/build.config.ts +4 -1
- package/template-ts-lib/package.json +23 -5
- package/template-vue/.vscode/settings.json +1 -2
- package/template-vue/_gitignore +1 -0
- package/template-vue/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -1,182 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fs from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { green, blue, cyan, lightBlue, reset, red } from 'kolorist';
|
|
6
|
-
import minimist from 'minimist';
|
|
7
|
-
import prompts from 'prompts';
|
|
8
|
-
import { consola } from 'consola';
|
|
9
|
-
|
|
10
|
-
function formatTargetDir(targetDir) {
|
|
11
|
-
return targetDir?.trim()?.replace(/\/+$/g, "");
|
|
12
|
-
}
|
|
13
|
-
function isPathEmpty($path) {
|
|
14
|
-
const files = fs.readdirSync($path);
|
|
15
|
-
return files.length === 0 || files.length === 1 && files[0] === ".git";
|
|
16
|
-
}
|
|
17
|
-
function isValidPackageName(projectName) {
|
|
18
|
-
return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(projectName);
|
|
19
|
-
}
|
|
20
|
-
function toValidPackageName(projectName) {
|
|
21
|
-
return projectName.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z\d\-~]+/g, "-");
|
|
22
|
-
}
|
|
23
|
-
function emptyDir(dir) {
|
|
24
|
-
const isExist = fs.existsSync(dir);
|
|
25
|
-
if (!isExist) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const files = fs.readdirSync(dir);
|
|
29
|
-
for (const file of files) {
|
|
30
|
-
if (file !== ".git") {
|
|
31
|
-
const filePath = path.resolve(dir, file);
|
|
32
|
-
fs.rmSync(filePath, { recursive: true, force: true });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function copyDir(srcDir, destDir) {
|
|
37
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
38
|
-
const files = fs.readdirSync(srcDir);
|
|
39
|
-
for (const file of files) {
|
|
40
|
-
const srcFile = path.resolve(srcDir, file);
|
|
41
|
-
const destFile = path.resolve(destDir, file);
|
|
42
|
-
copy(srcFile, destFile);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function copy(src, dest) {
|
|
46
|
-
const stat = fs.statSync(src);
|
|
47
|
-
if (stat.isDirectory()) {
|
|
48
|
-
copyDir(src, dest);
|
|
49
|
-
} else {
|
|
50
|
-
fs.copyFileSync(src, dest);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const templates = [
|
|
55
|
-
{
|
|
56
|
-
type: "vue",
|
|
57
|
-
name: "Vue 3",
|
|
58
|
-
color: green
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
type: "ts-lib",
|
|
62
|
-
name: "TypeScript library",
|
|
63
|
-
color: blue
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
type: "react",
|
|
67
|
-
name: "React",
|
|
68
|
-
color: cyan
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
type: "react-native",
|
|
72
|
-
name: "React Native",
|
|
73
|
-
color: cyan
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
type: "solid",
|
|
77
|
-
name: "Solid",
|
|
78
|
-
color: lightBlue
|
|
79
|
-
}
|
|
80
|
-
];
|
|
81
|
-
const TEMPLATES = templates.map((t) => t.type);
|
|
82
|
-
const renameFiles = {
|
|
83
|
-
_gitignore: ".gitignore",
|
|
84
|
-
_eslintrc: ".eslintrc",
|
|
85
|
-
_npmrc: ".npmrc"
|
|
86
|
-
};
|
|
87
|
-
const defaultTargetDir = "create-soybean-project";
|
|
88
|
-
async function setupCli() {
|
|
89
|
-
const cwd = process.cwd();
|
|
90
|
-
const argv = minimist(process.argv.slice(2), { string: ["_"] });
|
|
91
|
-
const argTargetDir = formatTargetDir(argv._[0]);
|
|
92
|
-
const argTemplate = argv.template || argv.t;
|
|
93
|
-
let targetDir = argTargetDir || defaultTargetDir;
|
|
94
|
-
function getProjectName() {
|
|
95
|
-
return targetDir === "." ? path.basename(path.resolve()) : targetDir;
|
|
96
|
-
}
|
|
97
|
-
let result = null;
|
|
98
|
-
try {
|
|
99
|
-
result = await prompts([
|
|
100
|
-
{
|
|
101
|
-
type: argTargetDir ? null : "text",
|
|
102
|
-
name: "projectName",
|
|
103
|
-
message: reset("Project name:"),
|
|
104
|
-
initial: defaultTargetDir,
|
|
105
|
-
onState: (state) => {
|
|
106
|
-
targetDir = formatTargetDir(state.value) || defaultTargetDir;
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
type: () => !fs.existsSync(targetDir) || isPathEmpty(targetDir) ? null : "confirm",
|
|
111
|
-
name: "overwrite",
|
|
112
|
-
message: () => `${targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`} is not empty. Remove existing files and continue?`
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
type: (_, { overwrite: overwrite2 }) => {
|
|
116
|
-
if (overwrite2 === false) {
|
|
117
|
-
throw new Error(`${red("\u2716")} Operation cancelled`);
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
},
|
|
121
|
-
name: "overwriteChecker"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
type: () => isValidPackageName(getProjectName()) ? null : "text",
|
|
125
|
-
name: "packageName",
|
|
126
|
-
message: reset("Package name:"),
|
|
127
|
-
initial: () => toValidPackageName(getProjectName()),
|
|
128
|
-
validate: (dir) => isValidPackageName(dir) || "Invalid package.json name"
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
type: argTemplate && TEMPLATES.includes(argTemplate) ? null : "select",
|
|
132
|
-
name: "template",
|
|
133
|
-
message: typeof argTemplate === "string" && !TEMPLATES.includes(argTemplate) ? reset(`"${argTemplate}" isn't a valid template. Please choose from below: `) : reset("Select a template:"),
|
|
134
|
-
initial: 0,
|
|
135
|
-
choices: templates.map(({ type, name, color }) => ({
|
|
136
|
-
title: color(name),
|
|
137
|
-
value: type
|
|
138
|
-
}))
|
|
139
|
-
}
|
|
140
|
-
]);
|
|
141
|
-
} catch (error) {
|
|
142
|
-
consola.error(error);
|
|
143
|
-
}
|
|
144
|
-
if (!result) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
const { template, overwrite, packageName } = result;
|
|
148
|
-
const root = path.join(cwd, targetDir);
|
|
149
|
-
if (overwrite) {
|
|
150
|
-
emptyDir(root);
|
|
151
|
-
} else if (!fs.existsSync(root)) {
|
|
152
|
-
fs.mkdirSync(root, { recursive: true });
|
|
153
|
-
}
|
|
154
|
-
const $template = template || argTemplate;
|
|
155
|
-
consola.info(`
|
|
156
|
-
Scaffolding project in ${root}...`);
|
|
157
|
-
const templateDir = path.resolve(fileURLToPath(import.meta.url), "../..", `template-${$template}`);
|
|
158
|
-
const write = (file, content) => {
|
|
159
|
-
const targetPath = path.join(root, renameFiles[file] ?? file);
|
|
160
|
-
if (content) {
|
|
161
|
-
fs.writeFileSync(targetPath, content);
|
|
162
|
-
} else {
|
|
163
|
-
copy(path.join(templateDir, file), targetPath);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
const files = fs.readdirSync(templateDir);
|
|
167
|
-
for (const file of files.filter((f) => f !== "package.json")) {
|
|
168
|
-
write(file);
|
|
169
|
-
}
|
|
170
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(templateDir, `package.json`), "utf-8"));
|
|
171
|
-
pkg.name = packageName || getProjectName();
|
|
172
|
-
write("package.json", `${JSON.stringify(pkg, null, 2)}
|
|
173
|
-
`);
|
|
174
|
-
const cdProjectName = path.relative(cwd, root);
|
|
175
|
-
consola.info(`
|
|
2
|
+
import r from"node:fs";import i from"node:path";import{fileURLToPath as T}from"node:url";import{green as C,blue as O,cyan as j,lightBlue as R,reset as u,red as E}from"kolorist";import F from"minimist";import V from"prompts";import{consola as y}from"consola";function k(e){return e?.trim()?.replace(/\/+$/g,"")}function I(e){const t=r.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function $(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function J(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function L(e){if(!r.existsSync(e))return;const t=r.readdirSync(e);for(const l of t)if(l!==".git"){const o=i.resolve(e,l);r.rmSync(o,{recursive:!0,force:!0})}}function B(e,t){r.mkdirSync(t,{recursive:!0});const l=r.readdirSync(e);for(const o of l){const a=i.resolve(e,o),m=i.resolve(t,o);h(a,m)}}function h(e,t){r.statSync(e).isDirectory()?B(e,t):r.copyFileSync(e,t)}const N=[{type:"vue",name:"Vue 3",color:C},{type:"ts-lib",name:"TypeScript library",color:O},{type:"react",name:"React",color:j},{type:"react-native",name:"React Native",color:j},{type:"solid",name:"Solid",color:R}],b=N.map(e=>e.type),M={_gitignore:".gitignore",_eslintrc:".eslintrc",_npmrc:".npmrc"},v="create-soybean-project";async function U(){const e=process.cwd(),t=F(process.argv.slice(2),{string:["_"]}),l=k(t._[0]),o=t.template||t.t;let a=l||v;function m(){return a==="."?i.basename(i.resolve()):a}let f=null;try{f=await V([{type:l?null:"text",name:"projectName",message:u("Project name:"),initial:v,onState:n=>{a=k(n.value)||v}},{type:()=>!r.existsSync(a)||I(a)?null:"confirm",name:"overwrite",message:()=>`${a==="."?"Current directory":`Target directory "${a}"`} is not empty. Remove existing files and continue?`},{type:(n,{overwrite:c})=>{if(c===!1)throw new Error(`${E("\u2716")} Operation cancelled`);return null},name:"overwriteChecker"},{type:()=>$(m())?null:"text",name:"packageName",message:u("Package name:"),initial:()=>J(m()),validate:n=>$(n)||"Invalid package.json name"},{type:o&&b.includes(o)?null:"select",name:"template",message:typeof o=="string"&&!b.includes(o)?u(`"${o}" isn't a valid template. Please choose from below: `):u("Select a template:"),initial:0,choices:N.map(({type:n,name:c,color:p})=>({title:p(c),value:n}))}])}catch(n){y.error(n)}if(!f)return;const{template:P,overwrite:_,packageName:x}=f,s=i.join(e,a);_?L(s):r.existsSync(s)||r.mkdirSync(s,{recursive:!0});const z=P||o;y.info(`
|
|
3
|
+
Scaffolding project in ${s}...`);const d=i.resolve(T(import.meta.url),"../..",`template-${z}`),S=(n,c)=>{const p=i.join(s,M[n]??n);c?r.writeFileSync(p,c):h(i.join(d,n),p)},D=r.readdirSync(d);for(const n of D.filter(c=>c!=="package.json"))S(n);const w=JSON.parse(r.readFileSync(i.join(d,"package.json"),"utf-8"));w.name=x||m(),S("package.json",`${JSON.stringify(w,null,2)}
|
|
4
|
+
`);const g=i.relative(e,s);y.info(`
|
|
176
5
|
Done. Now run:
|
|
177
|
-
`);
|
|
178
|
-
if (root !== cwd) {
|
|
179
|
-
consola.info(` cd ${cdProjectName.includes(" ") ? `"${cdProjectName}"` : cdProjectName}`);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
setupCli();
|
|
6
|
+
`),s!==e&&y.info(` cd ${g.includes(" ")?`"${g}"`:g}`)}U();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-soybean",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "SoybeanJS's command line to create different project templates",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Soybean",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"template-*"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"consola": "
|
|
23
|
+
"consola": "3.2.3",
|
|
24
24
|
"kolorist": "1.8.0",
|
|
25
25
|
"minimist": "1.2.8",
|
|
26
|
-
"prompts": "
|
|
26
|
+
"prompts": "2.4.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/minimist": "
|
|
30
|
-
"@types/prompts": "
|
|
29
|
+
"@types/minimist": "1.2.2",
|
|
30
|
+
"@types/prompts": "2.4.4",
|
|
31
31
|
"typescript": "5.1.6",
|
|
32
32
|
"unbuild": "1.2.1"
|
|
33
33
|
},
|
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
"formulahendry.auto-close-tag",
|
|
9
9
|
"formulahendry.auto-rename-tag",
|
|
10
10
|
"kisstkondoros.vscode-gutter-preview",
|
|
11
|
-
"
|
|
12
|
-
"mhutchie.git-graph",
|
|
13
|
-
"sdras.vue-vscode-snippets",
|
|
14
|
-
"vue.volar",
|
|
15
|
-
"vue.vscode-typescript-vue-plugin"
|
|
11
|
+
"mhutchie.git-graph"
|
|
16
12
|
]
|
|
17
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-lib-starter",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./dist/index.mjs",
|
|
@@ -16,12 +16,30 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "pnpm typecheck && unbuild",
|
|
19
|
-
"typecheck": "tsc --noEmit"
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"lint": "eslint . --fix",
|
|
21
|
+
"format": "soy prettier-write",
|
|
22
|
+
"commit": "soy git-commit",
|
|
23
|
+
"cleanup": "soy cleanup",
|
|
24
|
+
"ncu": "soy ncu",
|
|
25
|
+
"publish-pkg": "pnpm publish --access public",
|
|
26
|
+
"release": "soy release && pnpm build && pnpm publish-pkg"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"cli-progress": "3.12.0",
|
|
30
|
+
"consola": "3.2.3",
|
|
31
|
+
"dayjs": "1.11.9",
|
|
32
|
+
"execa": "8.0.1",
|
|
33
|
+
"kolorist": "1.8.0",
|
|
34
|
+
"ofetch": "1.1.1"
|
|
20
35
|
},
|
|
21
36
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
37
|
+
"@soybeanjs/cli": "0.6.7",
|
|
38
|
+
"@types/cli-progress": "3.11.0",
|
|
39
|
+
"@types/node": "20.5.1",
|
|
40
|
+
"eslint": "8.47.0",
|
|
41
|
+
"eslint-config-soybeanjs": "0.5.5",
|
|
42
|
+
"tsx": "3.12.7",
|
|
25
43
|
"typescript": "5.1.6",
|
|
26
44
|
"unbuild": "1.2.1"
|
|
27
45
|
}
|
package/template-vue/_gitignore
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "template-vue",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"vue-router": "4.2.4"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@soybeanjs/cli": "0.6.
|
|
20
|
-
"@types/node": "20.
|
|
21
|
-
"@vitejs/plugin-vue": "4.2
|
|
22
|
-
"@vitejs/plugin-vue-jsx": "3.0.
|
|
23
|
-
"eslint": "8.
|
|
24
|
-
"eslint-config-soybeanjs": "0.5.
|
|
19
|
+
"@soybeanjs/cli": "0.6.7",
|
|
20
|
+
"@types/node": "20.5.1",
|
|
21
|
+
"@vitejs/plugin-vue": "4.3.2",
|
|
22
|
+
"@vitejs/plugin-vue-jsx": "3.0.2",
|
|
23
|
+
"eslint": "8.47.0",
|
|
24
|
+
"eslint-config-soybeanjs": "0.5.5",
|
|
25
25
|
"npm-run-all": "4.1.5",
|
|
26
26
|
"typescript": "5.1.6",
|
|
27
|
-
"vite": "4.4.
|
|
27
|
+
"vite": "4.4.9",
|
|
28
28
|
"vue-tsc": "1.8.8"
|
|
29
29
|
}
|
|
30
30
|
}
|