create-soybean 0.6.6 → 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 CHANGED
@@ -1,182 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
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.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",
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "template-react",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "scripts": {}
5
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "template-react-native",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "scripts": {}
5
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "template-solid",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "scripts": {}
5
5
  }
@@ -6,6 +6,9 @@ export default defineBuildConfig({
6
6
  declaration: true,
7
7
  rollup: {
8
8
  emitCJS: true,
9
- inlineDependencies: true
9
+ inlineDependencies: true,
10
+ esbuild: {
11
+ minify: true
12
+ }
10
13
  }
11
14
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-lib-starter",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.mjs",
@@ -29,15 +29,16 @@
29
29
  "cli-progress": "3.12.0",
30
30
  "consola": "3.2.3",
31
31
  "dayjs": "1.11.9",
32
- "execa": "7.2.0",
32
+ "execa": "8.0.1",
33
33
  "kolorist": "1.8.0",
34
34
  "ofetch": "1.1.1"
35
35
  },
36
36
  "devDependencies": {
37
+ "@soybeanjs/cli": "0.6.7",
37
38
  "@types/cli-progress": "3.11.0",
38
- "@types/node": "20.4.6",
39
- "eslint": "8.46.0",
40
- "eslint-config-soybeanjs": "0.5.4",
39
+ "@types/node": "20.5.1",
40
+ "eslint": "8.47.0",
41
+ "eslint-config-soybeanjs": "0.5.5",
41
42
  "tsx": "3.12.7",
42
43
  "typescript": "5.1.6",
43
44
  "unbuild": "1.2.1"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "template-vue",
3
- "version": "0.6.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.5",
20
- "@types/node": "20.4.6",
21
- "@vitejs/plugin-vue": "4.2.3",
22
- "@vitejs/plugin-vue-jsx": "3.0.1",
23
- "eslint": "8.46.0",
24
- "eslint-config-soybeanjs": "0.5.4",
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.8",
27
+ "vite": "4.4.9",
28
28
  "vue-tsc": "1.8.8"
29
29
  }
30
30
  }