mvc-beckend-cli 1.3.1 → 1.3.8
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/README +21 -0
- package/dist/actions/actions.js +23 -12
- package/dist/data/data.actions.js +80 -2
- package/dist/index.js +2 -2
- package/package.json +3 -2
package/README
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# 🚀 MVC Backend CLI
|
|
2
|
+
|
|
3
|
+
> Быстрый генератор MVC проектов для Express.js с TypeScript
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mvc-backend-cli)
|
|
6
|
+
[](https://www.npmjs.com/package/mvc-backend-cli)
|
|
7
|
+
[](https://github.com/yourusername/mvc-backend-cli/blob/main/LICENSE)
|
|
8
|
+
|
|
9
|
+
Инструмент для быстрого создания бэкенд-проектов на **Express.js** с использованием **MVC архитектуры** и **TypeScript**. Автоматически генерирует всю структуру проекта, конфигурацию и шаблонный код.
|
|
10
|
+
|
|
11
|
+
## 📦 Установка
|
|
12
|
+
|
|
13
|
+
### Глобальная установка
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g mvc-backend-cli
|
|
16
|
+
|
|
17
|
+
команда
|
|
18
|
+
mvc-cli init ...
|
|
19
|
+
|
|
20
|
+
📁 Полная структура папок
|
|
21
|
+
🗄️ Базовая настройка Express
|
package/dist/actions/actions.js
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
1
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import { DATA_CONTROLLERS, DATA_INDEX, DATA_MODELS, DATA_SERVICES } from '../data/data.actions.js';
|
|
4
5
|
export const init_base_folders = async (name) => {
|
|
6
|
+
logGreetings();
|
|
5
7
|
try {
|
|
6
|
-
await
|
|
7
|
-
await mkdir(
|
|
8
|
-
await mkdir(
|
|
9
|
-
await mkdir(
|
|
10
|
-
|
|
8
|
+
await writeFile('index.js', DATA_INDEX(), 'utf-8');
|
|
9
|
+
await mkdir(`src/${name}`, { recursive: true });
|
|
10
|
+
await mkdir(`src/${name}/controllers`, { recursive: true });
|
|
11
|
+
await mkdir(`src/${name}/models`, { recursive: true });
|
|
12
|
+
await mkdir(`src/${name}/services`, { recursive: true });
|
|
13
|
+
console.log(`${pc.green('✔')} Архитектура папок MVC для проекта "${pc.bold(name)}" успешно создана!`);
|
|
14
|
+
console.log('\n' + pc.yellow('🚀 Что делать дальше:'));
|
|
15
|
+
console.log(` Создайте структуру файлов: ${pc.magenta(`mvc-cli struct ${name} <ваша_структура>`)}\n`);
|
|
11
16
|
}
|
|
12
17
|
catch (error) {
|
|
13
|
-
console.error('Ошибка
|
|
18
|
+
console.error('\n' + pc.red(`❌ Ошибка инициализации MVC: ${error.message}\n`));
|
|
14
19
|
}
|
|
15
20
|
};
|
|
16
21
|
export const create_files_struct = async (structPath = 'app', structName) => {
|
|
22
|
+
logGreetings();
|
|
17
23
|
try {
|
|
18
|
-
const controllerPath = join(structPath, 'controllers', `${structName}.controller.ts`);
|
|
19
|
-
const servicesPath = join(structPath, 'services', `${structName}.service.ts`);
|
|
20
|
-
const modelsPath = join(structPath, 'models', `${structName}.models.ts`);
|
|
24
|
+
const controllerPath = join("src/" + structPath, 'controllers', `${structName}.controller.ts`);
|
|
25
|
+
const servicesPath = join("src/" + structPath, 'services', `${structName}.service.ts`);
|
|
26
|
+
const modelsPath = join("src/" + structPath, 'models', `${structName}.models.ts`);
|
|
21
27
|
await writeFile(controllerPath, DATA_CONTROLLERS(structName), 'utf-8');
|
|
22
28
|
await writeFile(servicesPath, DATA_SERVICES(structName), 'utf-8');
|
|
23
29
|
await writeFile(modelsPath, DATA_MODELS(structName), 'utf-8');
|
|
30
|
+
console.log(`${pc.green('✔')} Структура "${pc.bold(structName)}" для проекта "${pc.bold(structPath)}" успешно создана!`);
|
|
24
31
|
}
|
|
25
32
|
catch (error) {
|
|
26
|
-
console.
|
|
33
|
+
console.error('\n' + pc.red(`❌ Ошибка создания структуры: ${error.message}\n`));
|
|
27
34
|
}
|
|
28
35
|
};
|
|
36
|
+
const logGreetings = () => {
|
|
37
|
+
console.log(pc.cyan('\n⚙️ MVC-BECKEND-CLI Generator v1.3.3'));
|
|
38
|
+
console.log(pc.dim('-----------------------------------'));
|
|
39
|
+
};
|
|
@@ -15,8 +15,86 @@ export const DATA_SERVICES = (serviceName) => {
|
|
|
15
15
|
|
|
16
16
|
const { request, response } = pkg;
|
|
17
17
|
|
|
18
|
-
export const ${serviceName}Service = {
|
|
18
|
+
export const ${parsedWord(serviceName)}Service = {
|
|
19
|
+
|
|
20
|
+
async getAll${parsedWord(serviceName)}s() {
|
|
21
|
+
try {
|
|
22
|
+
|
|
23
|
+
} catch (error) {
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
async get${parsedWord(serviceName)}ById(id: string) {
|
|
29
|
+
try {
|
|
30
|
+
|
|
31
|
+
} catch (error) {
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
async create${parsedWord(serviceName)}(data: any) {
|
|
37
|
+
try {
|
|
38
|
+
|
|
39
|
+
} catch (error) {
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
async update${parsedWord(serviceName)}(id: string, data: any) {
|
|
45
|
+
try {
|
|
46
|
+
|
|
47
|
+
} catch (error) {
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
async delete${parsedWord(serviceName)}(id: string) {
|
|
53
|
+
try {
|
|
54
|
+
|
|
55
|
+
} catch (error) {
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
}`;
|
|
19
61
|
};
|
|
20
62
|
export const DATA_MODELS = (modelName) => {
|
|
21
|
-
return `export const ${modelName}Model = {
|
|
63
|
+
return `export const ${parsedWord(modelName)}Model = {
|
|
64
|
+
|
|
65
|
+
async findAll() {},
|
|
66
|
+
|
|
67
|
+
async findById(id: string) {},
|
|
68
|
+
|
|
69
|
+
async create(data) {},
|
|
70
|
+
|
|
71
|
+
async update(id: string, data) {},
|
|
72
|
+
|
|
73
|
+
async delete(id: string) {},
|
|
74
|
+
}`;
|
|
75
|
+
};
|
|
76
|
+
export const DATA_INDEX = () => {
|
|
77
|
+
return `import express from 'express';
|
|
78
|
+
import routes from './routes/routes.js';
|
|
79
|
+
import cors from 'cors';
|
|
80
|
+
|
|
81
|
+
const app = express();
|
|
82
|
+
|
|
83
|
+
app.use(cors();
|
|
84
|
+
|
|
85
|
+
app.use(express.json({ limit: '10mb' }));
|
|
86
|
+
|
|
87
|
+
app.use('/api', routes);
|
|
88
|
+
|
|
89
|
+
app.get('/health', (req, res) => {
|
|
90
|
+
res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
app.listen(PORT, () => {
|
|
94
|
+
console.log('Сервер запущен, успешно работает на порту' + PORT);
|
|
95
|
+
})
|
|
96
|
+
`;
|
|
97
|
+
};
|
|
98
|
+
const parsedWord = (string) => {
|
|
99
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
22
100
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program } from 'commander';
|
|
3
|
-
import { create_files_struct, init_base_folders } from '
|
|
3
|
+
import { create_files_struct, init_base_folders } from '../actions/actions.js';
|
|
4
4
|
program
|
|
5
5
|
.version('1.0.0')
|
|
6
6
|
.description('CLI для бэкенд проектов MVC');
|
|
@@ -13,6 +13,6 @@ program
|
|
|
13
13
|
.argument('<structPath>', 'Путь до папок структур')
|
|
14
14
|
.argument('<nameSctructure>', 'Название структуры генераторов')
|
|
15
15
|
.action((structPath, nameSctructure) => {
|
|
16
|
-
|
|
16
|
+
create_files_struct(structPath, nameSctructure);
|
|
17
17
|
});
|
|
18
18
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mvc-beckend-cli",
|
|
3
3
|
"description": "CLI для быстрой генерации бэкенд проектов на архитектуре MVC",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.8",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Turbo_MaKsIk12",
|
|
7
7
|
"type": "module",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"scaffold"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"commander": "^15.0.0"
|
|
22
|
+
"commander": "^15.0.0",
|
|
23
|
+
"picocolors": "^1.1.1"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@types/node": "^26.1.1",
|