create-ts-vite-project 0.1.0 → 0.2.1
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.js +2 -0
- package/package.json +53 -11
- package/template/package.json +3 -2
- package/index.js +0 -239
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var _=Object.create;var E=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var K=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!G.call(r,i)&&i!==t&&E(r,i,{get:()=>e[i],enumerable:!(o=H(e,i))||o.enumerable});return r};var u=(r,e,t)=>(t=r!=null?_(B(r)):{},K(e||!r||!r.__esModule?E(t,"default",{value:r,enumerable:!0}):t,r));var j=u(require("path"));var V=u(require("readline")),d=V.default.createInterface({input:process.stdin,output:process.stdout});function a(r){for(let e of r)console.log(e)}function n(r){return new Promise(e=>{d.question(r,e)})}var l=require("fs"),C=u(require("path"));function M(r,e){let t=C.default.join(r,"package.json");if((0,l.existsSync)(t)){let o=JSON.parse((0,l.readFileSync)(t,"utf8"));o.name=e.name,e.version&&(o.version=e.version),e.productName&&(o.productName=e.productName),e.description&&(o.description=e.description),e.repository&&(o.repository=e.repository),e.author&&(o.author=e.author),(0,l.writeFileSync)(t,JSON.stringify(o,null,2))}}var L=u(require("path"));var D=require("fs"),w=u(require("path"));function k(r,e,t){(0,D.copyFileSync)(w.default.join(e,r),w.default.join(t,r))}var p=require("fs"),x=u(require("path"));function S(r,e){let t=(0,p.readdirSync)(r);for(let o of t){let i=x.default.join(r,o),c=x.default.join(e,o);(0,p.statSync)(i).isDirectory()?((0,p.mkdirSync)(c,{recursive:!0}),S(i,c)):(0,p.copyFileSync)(i,c)}}async function q(r,e){S(L.default.join(r,"template"),e),k(".gitignore",r,e),k("LICENSE",r,e),k("README.md",r,e)}var b=require("child_process");var J=require("child_process");function T(){try{return(0,J.execSync)("yarn --version",{stdio:"ignore"}),"yarn"}catch(r){console.error("\u274C Detect package manager error",r)}return"npm"}async function F(r){try{process.chdir(r);let e=T(),t=e,o=(await n(`Package manager (npm/yarn, default: ${e}): `)).trim().toLowerCase()||"";t=["npm","yarn"].includes(o)?o:e,a([`\u{1F4E6} Using package manager: ${t}`]),a(["\u{1F4E6} Installing dependencies..."]),(0,b.execSync)(`${t} install`,{stdio:"inherit"}),a(["","\u2705 Dependencies installed"])}catch(e){console.error("\u274C Error executing next steps",e)}}var P=require("fs");var f=require("fs");function O(r){try{return(0,f.existsSync)(r)?(0,f.statSync)(r).isDirectory()?(0,f.readdirSync)(r).length===0:(console.error(`\u274C Path is not a directory: ${r}`),!1):!0}catch(e){return console.error("\u274C Error checking directory",e),!1}}async function R(r){if(!O(r)){if((await n(`Directory "${r}" already exists. Overwrite? (y/N): `)).trim().toLowerCase()!=="y"){a(["\u274C Operation cancelled"]);return}(0,P.rmSync)(r,{recursive:!0,force:!0})}try{(0,P.mkdirSync)(r,{recursive:!0})}catch(e){console.error("\u274C Error executing next steps",e);return}}var A={name:"ts-vite-project",version:"0.1.0",productName:"TS Vite Project",description:"TypeScript Vite application",license:"MIT",author:"",repository:"",homepage:""};async function U(r){let{name:e,version:t,productName:o,description:i,license:c,author:s,repository:v,bugs:g,homepage:$}=A;if(r.length?(o=r.map(m=>`${m.slice(0,1).toUpperCase()}${m.slice(1)}`).join(" "),e=r.map(m=>m.toLowerCase()).join("-")):(o=(await n(`Product name (${o}): `)).trim()||o,e=o.split(" ").map(m=>m.toLowerCase()).join("-"),e=(await n(`Project name (${e}): `)).trim()||e),(await n("Config extended project params? (y/N): ")).trim().toLowerCase()==="y"){let h=((await n(`Version (${t}): `)).trim()||t).split(".");for(let N=h.length;N<3;N++)h.push("0");t=h.join("."),i=(await n(`Description (${i}): `)).trim()||i,c=(await n(`License (${c}): `)).trim()||c,s={},s.name=(await n("Author: ")||"").trim(),s.email=(await n("Email: ")||"").trim(),v={};let I=`https://github.com/${s.name}/${e}.git`,y=(await n(`Repository url (${I}): `)).trim()||I;y&&(v.url=`git+${y}`,g={},s.email&&(g.email=s.email),g.url=`${y}/issues`,$=`${y}#readme`)}return{name:e,version:t,productName:o,description:i,license:c,author:s,repository:v,bugs:g,homepage:$}}async function Q(){a(["\u{1F680} Creating TypeScript + Vite Project","(will be installed in project name folder)",""]);let r=process.argv.slice(2),e=await U(r),t=j.default.resolve(e.name),o=j.default.resolve(__dirname,"..");await R(t);try{await q(o,t),M(t,e),a(["","\u2705 Project created successfully!"]),(await n(`
|
|
2
|
+
Install dependencies? (y/N): `)).trim().toLowerCase()==="y"&&await F(t),a(["","Next steps:",`\u{1F4C1} cd ${e.name}`,"\u{1F4E6} npm install","\u2B50 npm run dev","","Happy coding! \u{1F44B}",""])}catch(i){console.error("\u274C Error creating project:",i)}finally{d.close()}}Q().catch(console.error);
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-ts-vite-project",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"productName": "TS Vite Project Template Creator",
|
|
5
|
-
"description": "Template for projects based typescript, vite, vitest, eslint, prettier, electron",
|
|
5
|
+
"description": "Template for projects based typescript, vite, vitest, eslint, prettier, electron, tauri",
|
|
6
|
+
"license": "MIT",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"typescript",
|
|
8
9
|
"electron",
|
|
10
|
+
"tauri",
|
|
9
11
|
"vite",
|
|
10
12
|
"desktop",
|
|
11
13
|
"windows",
|
|
12
14
|
"win32",
|
|
13
15
|
"mac",
|
|
14
16
|
"web",
|
|
17
|
+
"android",
|
|
18
|
+
"ios",
|
|
15
19
|
"create",
|
|
16
20
|
"template",
|
|
17
21
|
"easy",
|
|
@@ -22,18 +26,56 @@
|
|
|
22
26
|
"prettier",
|
|
23
27
|
"vitest"
|
|
24
28
|
],
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "Maxim Nikonov",
|
|
31
|
+
"email": "fwmakc@mail.ru",
|
|
32
|
+
"url": "https://github.com/fwmakc"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/fwmakc/ts-vite-project.git"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/fwmakc/ts-vite-project#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"email": "fwmakc@mail.ru",
|
|
41
|
+
"url": "https://github.com/fwmakc/ts-vite-project/issues"
|
|
31
42
|
},
|
|
32
43
|
"files": [
|
|
44
|
+
"dist",
|
|
33
45
|
"template",
|
|
34
46
|
".gitignore",
|
|
35
47
|
"LICENSE",
|
|
36
|
-
"README.md"
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
"README.md"
|
|
49
|
+
],
|
|
50
|
+
"bin": {
|
|
51
|
+
"create-ts-vite-project": "./dist/index.js"
|
|
52
|
+
},
|
|
53
|
+
"main": "dist/index.js",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "npm run lint && npm run compile",
|
|
56
|
+
"compile": "esbuild src/index.ts --bundle --platform=node --target=node18 --outfile=dist/index.js --minify",
|
|
57
|
+
"dev": "ts-node src/index.ts",
|
|
58
|
+
"start": "node dist/index.js",
|
|
59
|
+
"lint": "eslint . --fix"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@eslint/js": "^9.39.1",
|
|
63
|
+
"@types/jest": "^30.0.0",
|
|
64
|
+
"@types/node": "^24.10.1",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
66
|
+
"@typescript-eslint/parser": "^8.47.0",
|
|
67
|
+
"esbuild": "^0.27.0",
|
|
68
|
+
"eslint": "^9.39.1",
|
|
69
|
+
"eslint-config-prettier": "^10.1.8",
|
|
70
|
+
"eslint-plugin-import": "^2.32.0",
|
|
71
|
+
"eslint-plugin-node": "^11.1.0",
|
|
72
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
73
|
+
"globals": "^16.5.0",
|
|
74
|
+
"jest": "^30.2.0",
|
|
75
|
+
"prettier": "^3.6.2",
|
|
76
|
+
"ts-jest": "^29.4.5",
|
|
77
|
+
"ts-node": "^10.9.2",
|
|
78
|
+
"typescript": "^5.9.3"
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {}
|
|
39
81
|
}
|
package/template/package.json
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
"version": "0.1.0",
|
|
4
4
|
"productName": "TS Vite Project",
|
|
5
5
|
"description": "TypeScript Vite application",
|
|
6
|
+
"license": "MIT",
|
|
6
7
|
"keywords": [],
|
|
7
|
-
"repository": "",
|
|
8
8
|
"author": "",
|
|
9
|
-
"
|
|
9
|
+
"repository": "",
|
|
10
|
+
"homepage": "",
|
|
10
11
|
"main": "electron/main.ts",
|
|
11
12
|
"scripts": {
|
|
12
13
|
"build": "npm run lint && npm run test && npm run compile",
|
package/index.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const readline = require('readline');
|
|
6
|
-
const { execSync } = require('child_process');
|
|
7
|
-
|
|
8
|
-
// Задаем значения по-умолчанию
|
|
9
|
-
const defaults = {
|
|
10
|
-
projectName: 'ts-vite-project',
|
|
11
|
-
version: '0.1.0',
|
|
12
|
-
productName: 'TS Vite Project',
|
|
13
|
-
description: 'TypeScript Vite application',
|
|
14
|
-
repository: '',
|
|
15
|
-
author: '',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const rl = readline.createInterface({
|
|
19
|
-
input: process.stdin,
|
|
20
|
-
output: process.stdout
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
function copyFile(filename, src, dest) {
|
|
24
|
-
fs.copyFileSync(path.join(src, filename), path.join(dest, filename));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function copyRecursive(src, dest) {
|
|
28
|
-
const entries = fs.readdirSync(src);
|
|
29
|
-
|
|
30
|
-
for (const entry of entries) {
|
|
31
|
-
const srcPath = path.join(src, entry);
|
|
32
|
-
const destPath = path.join(dest, entry);
|
|
33
|
-
|
|
34
|
-
const stat = fs.statSync(srcPath);
|
|
35
|
-
|
|
36
|
-
if (stat.isDirectory()) {
|
|
37
|
-
fs.mkdirSync(destPath, { recursive: true });
|
|
38
|
-
copyRecursive(srcPath, destPath);
|
|
39
|
-
} else {
|
|
40
|
-
fs.copyFileSync(srcPath, destPath);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function detectPackageManager() {
|
|
46
|
-
try {
|
|
47
|
-
// Проверяем, установлен ли yarn
|
|
48
|
-
execSync('yarn --version', { stdio: 'ignore' });
|
|
49
|
-
return 'yarn';
|
|
50
|
-
} catch (error) {
|
|
51
|
-
// Если yarn не установлен, используем npm
|
|
52
|
-
return 'npm';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function executeNextSteps(targetDir, silent = false) {
|
|
57
|
-
console.log('\n🔧 Executing next steps...\n');
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// 1. Переходим в директорию проекта
|
|
61
|
-
process.chdir(targetDir);
|
|
62
|
-
console.log('📁 Changed to project directory');
|
|
63
|
-
|
|
64
|
-
// 2. Автоматическое определение или выбор менеджера пакетов
|
|
65
|
-
const detectedManager = detectPackageManager();
|
|
66
|
-
let selectedPackageManager = detectedManager;
|
|
67
|
-
if (!silent) {
|
|
68
|
-
const packageManagerAnswer = await question(`Package manager (npm/yarn, default: ${detectedManager}): `) || detectedManager;
|
|
69
|
-
const validPackageManagers = ['npm', 'yarn'];
|
|
70
|
-
selectedPackageManager = validPackageManagers.includes(packageManagerAnswer.toLowerCase())
|
|
71
|
-
? packageManagerAnswer.toLowerCase()
|
|
72
|
-
: detectedManager;
|
|
73
|
-
}
|
|
74
|
-
console.log(`📦 Using package manager: ${selectedPackageManager}`);
|
|
75
|
-
|
|
76
|
-
// 3. Устанавливаем зависимости
|
|
77
|
-
console.log('📦 Installing dependencies...');
|
|
78
|
-
execSync(`${selectedPackageManager} install`, { stdio: 'inherit' });
|
|
79
|
-
console.log('✅ Dependencies installed');
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error('❌ Error executing next steps:', error.message);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function isDirectoryEmpty(dirPath) {
|
|
86
|
-
try {
|
|
87
|
-
if (!fs.existsSync(dirPath)) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const stats = fs.statSync(dirPath);
|
|
92
|
-
if (!stats.isDirectory()) {
|
|
93
|
-
console.error(`❌ Path is not a directory: ${dirPath}`);
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const files = fs.readdirSync(dirPath);
|
|
98
|
-
return files.length === 0;
|
|
99
|
-
} catch (error) {
|
|
100
|
-
console.error(`❌ Error checking directory: ${error.message}`);
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function question(prompt) {
|
|
106
|
-
return new Promise((resolve) => {
|
|
107
|
-
rl.question(prompt, resolve);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function updatePackageJson(targetDir, fields) {
|
|
112
|
-
const packageJsonPath = path.join(targetDir, 'package.json');
|
|
113
|
-
|
|
114
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
115
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
116
|
-
|
|
117
|
-
// Обновляем только указанные поля
|
|
118
|
-
packageJson.name = fields.name;
|
|
119
|
-
|
|
120
|
-
if (fields.version) packageJson.version = fields.version;
|
|
121
|
-
if (fields.productName) packageJson.productName = fields.productName;
|
|
122
|
-
if (fields.description) packageJson.description = fields.description;
|
|
123
|
-
if (fields.repository) packageJson.repository = fields.repository;
|
|
124
|
-
if (fields.author) packageJson.author = fields.author;
|
|
125
|
-
|
|
126
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async function main() {
|
|
131
|
-
console.log('🚀 Creating TypeScript + Vite Project');
|
|
132
|
-
console.log('(will be installed in project name folder)\n');
|
|
133
|
-
|
|
134
|
-
// Парсим аргументы командной строки
|
|
135
|
-
const args = process.argv.slice(2);
|
|
136
|
-
const projectNameFromArgs = String(args?.[0] || '').trim();
|
|
137
|
-
|
|
138
|
-
if (projectNameFromArgs) {
|
|
139
|
-
defaults.projectName = projectNameFromArgs;
|
|
140
|
-
} else {
|
|
141
|
-
defaults.projectName = await question(`Project name (${defaults.projectName}): `) || defaults.projectName;
|
|
142
|
-
|
|
143
|
-
const version = await question(`Version (${defaults.version}): `) || defaults.version;
|
|
144
|
-
const versionParts = version.split('.');
|
|
145
|
-
|
|
146
|
-
for (let i = versionParts.length; i < 3; i++) {
|
|
147
|
-
versionParts.push(0);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
defaults.version = versionParts.join('.');
|
|
151
|
-
|
|
152
|
-
defaults.productName = await question(`Product name (${defaults.productName}): `) || defaults.productName;
|
|
153
|
-
defaults.description = await question('Description: ') || defaults.description;
|
|
154
|
-
defaults.repository = await question('Repository url: ') || defaults.repository;
|
|
155
|
-
|
|
156
|
-
let author = await question('Author: ') || '';
|
|
157
|
-
author = author.trim();
|
|
158
|
-
|
|
159
|
-
if (author) {
|
|
160
|
-
let email = await question('Email: ') || '';
|
|
161
|
-
email = email.trim();
|
|
162
|
-
|
|
163
|
-
const authors = [];
|
|
164
|
-
if (author) {
|
|
165
|
-
authors.push(author);
|
|
166
|
-
}
|
|
167
|
-
if (email && email !== author) {
|
|
168
|
-
authors.push(`<${email}>`);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
defaults.author = authors.join(' ');
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const targetDir = path.resolve(defaults.projectName);
|
|
176
|
-
|
|
177
|
-
// Проверяем, существует ли директория
|
|
178
|
-
if (!isDirectoryEmpty(targetDir)) {
|
|
179
|
-
const overwrite = await question(`Directory "${targetDir}" already exists. Overwrite? (y/N): `);
|
|
180
|
-
if (overwrite.toLowerCase() !== 'y') {
|
|
181
|
-
console.log('❌ Operation cancelled');
|
|
182
|
-
rl.close();
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
// Удаляем существующую директорию
|
|
186
|
-
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
// Создаем директорию
|
|
191
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
192
|
-
|
|
193
|
-
// Копируем файлы из template
|
|
194
|
-
copyRecursive(path.join(__dirname, 'template'), targetDir);
|
|
195
|
-
|
|
196
|
-
// Копируем остальные файлы
|
|
197
|
-
copyFile('.gitignore', __dirname, targetDir);
|
|
198
|
-
copyFile('LICENSE', __dirname, targetDir);
|
|
199
|
-
copyFile('README.md', __dirname, targetDir);
|
|
200
|
-
|
|
201
|
-
// Обновляем package.json
|
|
202
|
-
updatePackageJson(targetDir, {
|
|
203
|
-
name: defaults.projectName.trim(),
|
|
204
|
-
version: defaults.version.trim(),
|
|
205
|
-
productName: defaults.productName.trim(),
|
|
206
|
-
description: defaults.description.trim(),
|
|
207
|
-
repository: defaults.repository.trim(),
|
|
208
|
-
author: defaults.author.trim()
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
console.log('\n✅ Project created successfully!');
|
|
212
|
-
|
|
213
|
-
// Переходим к Next steps
|
|
214
|
-
console.log('\nNext steps:');
|
|
215
|
-
console.log(`📁 cd ${defaults.projectName}`);
|
|
216
|
-
console.log('📦 npm install');
|
|
217
|
-
console.log('⭐ npm run dev');
|
|
218
|
-
|
|
219
|
-
if (projectNameFromArgs) {
|
|
220
|
-
await executeNextSteps(targetDir, true);
|
|
221
|
-
} else {
|
|
222
|
-
// Запрашиваем выполнение Next steps
|
|
223
|
-
const executeSteps = await question('\nInstall dependencies automatically? (y/N): ');
|
|
224
|
-
|
|
225
|
-
if (executeSteps.toLowerCase() === 'y') {
|
|
226
|
-
await executeNextSteps(targetDir);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
console.log('\nHappy coding! 👋');
|
|
231
|
-
} catch (error) {
|
|
232
|
-
console.error('❌ Error creating project:', error);
|
|
233
|
-
} finally {
|
|
234
|
-
rl.close();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Запускаем основную функцию
|
|
239
|
-
main().catch(console.error);
|