create-express-esm 1.0.0

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/bin/cli.js ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from 'commander';
4
+ import inquirer from 'inquirer';
5
+ import fs from 'fs-extra';
6
+ import path from 'path';
7
+ import chalk from 'chalk';
8
+ import { execSync } from 'child_process';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ // ESM에서 __dirname 사용하기 위한 설정
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+
15
+ program
16
+ .version('1.0.0')
17
+ .description('Layered Architecture 기반의 Modern Express 프로젝트 생성기');
18
+
19
+ program
20
+ .action(async () => {
21
+ console.log(chalk.blue.bold('\n🚀 Create Express ESM 시작!\n'));
22
+
23
+ // 1. 사용자 질문
24
+ const answers = await inquirer.prompt([
25
+ {
26
+ type: 'input',
27
+ name: 'projectName',
28
+ message: '생성할 프로젝트 이름을 입력하세요:',
29
+ default: 'my-app',
30
+ }
31
+ ]);
32
+
33
+ const { projectName } = answers;
34
+ const targetPath = path.join(process.cwd(), projectName);
35
+ const templatePath = path.join(__dirname, '../template');
36
+
37
+ // 2. 템플릿 복사
38
+ console.log(chalk.cyan(`\n📂 템플릿을 복사하는 중...`));
39
+ try {
40
+ if (fs.existsSync(targetPath)) {
41
+ console.error(chalk.red(`❌ 오류: '${projectName}' 폴더가 이미 존재합니다.`));
42
+ process.exit(1);
43
+ }
44
+
45
+ await fs.copy(templatePath, targetPath);
46
+
47
+ // package.json 이름 수정
48
+ const pkgPath = path.join(targetPath, 'package.json');
49
+ const pkg = await fs.readJson(pkgPath);
50
+ pkg.name = projectName;
51
+ await fs.writeJson(pkgPath, pkg, { spaces: 2 });
52
+
53
+ console.log(chalk.green(`✅ 복사 완료!`));
54
+
55
+ // 3. 자동 설치 (핵심 기능!)
56
+ console.log(chalk.yellow(`\n📦 패키지 자동 설치를 진행합니다... (npm install)`));
57
+
58
+ execSync('npm install', {
59
+ cwd: targetPath,
60
+ stdio: 'inherit' // 설치 로그를 터미널에 보여줌
61
+ });
62
+
63
+ console.log(chalk.green(`\n✨ 모든 설치가 완료되었습니다!`));
64
+ console.log(chalk.white(`\n다음 명령어로 시작하세요:\n`));
65
+ console.log(chalk.cyan(` cd ${projectName}`));
66
+ console.log(chalk.cyan(` npm run dev`));
67
+
68
+ } catch (error) {
69
+ console.error(chalk.red('오류 발생:'), error);
70
+ }
71
+ });
72
+
73
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "create-express-esm",
3
+ "version": "1.0.0",
4
+ "description": "ESM + Layered Arch + Auto Install CLI",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "create-express-esm": "./bin/cli.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "type": "module",
16
+ "dependencies": {
17
+ "chalk": "^5.6.2",
18
+ "commander": "^14.0.2",
19
+ "fs-extra": "^11.3.2",
20
+ "inquirer": "^13.0.1"
21
+ }
22
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "my-express-app",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "start": "node src/server.js",
7
+ "dev": "nodemon src/server.js"
8
+ },
9
+ "dependencies": {
10
+ "express": "^4.18.2",
11
+ "cors": "^2.8.5",
12
+ "dotenv": "^16.3.1",
13
+ "morgan": "^1.10.0"
14
+ },
15
+ "devDependencies": {
16
+ "nodemon": "^3.0.2"
17
+ }
18
+ }
@@ -0,0 +1,17 @@
1
+ import express from 'express';
2
+ import cors from 'cors';
3
+ import morgan from 'morgan';
4
+ import userRoutes from './routes/userRoutes.js';
5
+
6
+ const app = express();
7
+
8
+ app.use(cors());
9
+ app.use(morgan('dev'));
10
+ app.use(express.json());
11
+
12
+ // 라우터 연결 (Layered Arch 시작점)
13
+ app.use('/api/users', userRoutes);
14
+
15
+ app.get('/', (req, res) => res.send('Welcome to Modern Express!'));
16
+
17
+ export default app;
@@ -0,0 +1,10 @@
1
+ import * as userService from '../services/userService.js';
2
+
3
+ export const getUsers = async (req, res) => {
4
+ try {
5
+ const users = await userService.findAllUsers(); // 서비스 호출
6
+ res.json(users);
7
+ } catch (error) {
8
+ res.status(500).json({ message: error.message });
9
+ }
10
+ };
@@ -0,0 +1,8 @@
1
+ import express from 'express';
2
+ import * as userController from '../controllers/userController.js';
3
+
4
+ const router = express.Router();
5
+
6
+ router.get('/', userController.getUsers);
7
+
8
+ export default router;
@@ -0,0 +1,9 @@
1
+ import app from './app.js';
2
+ import dotenv from 'dotenv';
3
+
4
+ dotenv.config();
5
+ const PORT = process.env.PORT || 3000;
6
+
7
+ app.listen(PORT, () => {
8
+ console.log(`🚀 Server running on http://localhost:${PORT}`);
9
+ });
@@ -0,0 +1,8 @@
1
+ // 나중에는 여기서 Model(DB)을 호출합니다.
2
+ export const findAllUsers = async () => {
3
+ // 비즈니스 로직 처리...
4
+ return [
5
+ { id: 1, name: "Developer Lee", role: "Fullstack" },
6
+ { id: 2, name: "Genius AI", role: "Assistant" }
7
+ ];
8
+ };