@seip/blue-bird 0.1.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/.env_example +12 -0
- package/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +81 -0
- package/backend/index.js +13 -0
- package/backend/routes/app.js +41 -0
- package/core/app.js +150 -0
- package/core/auth.js +59 -0
- package/core/cli/init.js +116 -0
- package/core/cli/react.js +394 -0
- package/core/config.js +42 -0
- package/core/logger.js +80 -0
- package/core/middleware.js +27 -0
- package/core/router.js +96 -0
- package/core/template.js +223 -0
- package/core/upload.js +70 -0
- package/core/validate.js +275 -0
- package/package.json +39 -0
package/.env_example
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
DEBUG=true
|
|
2
|
+
DESCRIPTION_META="Example description meta"
|
|
3
|
+
KEYWORDS_META="Example keywords meta"
|
|
4
|
+
TITLE_META="Blue Bird"
|
|
5
|
+
AUTHOR_META="Blue Bird"
|
|
6
|
+
DESCRIPTION="Description project"
|
|
7
|
+
TITLE="Blue Bird"
|
|
8
|
+
VERSION="1.0.0"
|
|
9
|
+
LANGMETA="en"
|
|
10
|
+
HOST="http://localhost"
|
|
11
|
+
PORT=3001
|
|
12
|
+
STATIC_PATH="frontend/public"
|
package/.gitattributes
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andres Paiva
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://seip25.github.io/Blue-bird/blue-bird.png" alt="Blue Bird Logo" width="120" />
|
|
3
|
+
<h1>Blue Bird Framework</h1>
|
|
4
|
+
<p><strong>The Future of Express & React Development</strong></p>
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@seip/blue-bird)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<hr />
|
|
11
|
+
|
|
12
|
+
## 🌟 Introduction / Introducción
|
|
13
|
+
|
|
14
|
+
**Blue Bird** is a powerful, opinionated structure based on **Express** and **React**. It's designed to help developers build fast, scalable applications with hydrated components (Islands or Full views) and everything pre-configured.
|
|
15
|
+
|
|
16
|
+
**Blue Bird** es una estructura potente basada en **Express** y **React**. Está diseñada para ayudar a los desarrolladores a construir aplicaciones rápidas y escalables con componentes hidratados (Islas o vistas completas) y todo pre-configurado.
|
|
17
|
+
|
|
18
|
+
<hr />
|
|
19
|
+
|
|
20
|
+
## 🚀 Key Features / Características Clave
|
|
21
|
+
|
|
22
|
+
- ⚡ **All-In-One**: Express, React, Vite, JWT Auth, and Validations ready to go.
|
|
23
|
+
- 💎 **Flexible**: Extensible via standard Express `.use()` middleware.
|
|
24
|
+
- 🏝️ **Island Architecture**: Hydrate only what you need with React.
|
|
25
|
+
- 🔐 **Secure**: Integrated JWT authentication and multi-language validation.
|
|
26
|
+
- 📁 **Uploads**: Easy file handling with Multer-based helpers.
|
|
27
|
+
|
|
28
|
+
<hr />
|
|
29
|
+
|
|
30
|
+
## 🛠️ Quick Start / Inicio Rápido
|
|
31
|
+
|
|
32
|
+
### 1. Installation / Instalación
|
|
33
|
+
```bash
|
|
34
|
+
npm install @seip/blue-bird
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. Initialize / Inicializar
|
|
38
|
+
```bash
|
|
39
|
+
npx blue-bird
|
|
40
|
+
```
|
|
41
|
+
*This copies the base structure: `backend`, `frontend`, and `.env`.*
|
|
42
|
+
*Esto copia la estructura base: `backend`, `frontend` y `.env`.*
|
|
43
|
+
|
|
44
|
+
### 3. Setup React
|
|
45
|
+
```bash
|
|
46
|
+
npm run react
|
|
47
|
+
```
|
|
48
|
+
*Configures React, React Router, and Vite automatically.*
|
|
49
|
+
*Configura React, React Router y Vite automáticamente.*
|
|
50
|
+
|
|
51
|
+
### 4. Development / Desarrollo
|
|
52
|
+
```bash
|
|
53
|
+
# Start Backend (Express)
|
|
54
|
+
npm run dev
|
|
55
|
+
|
|
56
|
+
# Start Frontend (Vite)
|
|
57
|
+
npm run vite:dev
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
<hr />
|
|
61
|
+
|
|
62
|
+
## 📖 Documentation / Documentación
|
|
63
|
+
|
|
64
|
+
Check out our full documentation for detailed API reference and examples:
|
|
65
|
+
|
|
66
|
+
- 🇺🇸 [English Documentation](https://seip25.github.io/Blue-bird/en.html)
|
|
67
|
+
- 🇪🇸 [Documentación en Español](https://seip25.github.io/Blue-bird/index.html)
|
|
68
|
+
|
|
69
|
+
<hr />
|
|
70
|
+
|
|
71
|
+
## 📄 License / Licencia
|
|
72
|
+
|
|
73
|
+
Distributed under the **MIT License**. See `LICENSE` for more information.
|
|
74
|
+
|
|
75
|
+
Distribuido bajo la **Licencia MIT**. Mira `LICENSE` para más información.
|
|
76
|
+
|
|
77
|
+
<hr />
|
|
78
|
+
|
|
79
|
+
<div align="center">
|
|
80
|
+
<p>Made with ❤️ by <strong>Seip25</strong></p>
|
|
81
|
+
</div>
|
package/backend/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Router from "@seip/blue-bird/core/router.js"
|
|
2
|
+
import Validator from "@seip/blue-bird/core/validate.js"
|
|
3
|
+
import Template from "@seip/blue-bird/core/template.js"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const routerUsers = new Router("/")
|
|
7
|
+
|
|
8
|
+
routerUsers.get("/users", (req, res) => {
|
|
9
|
+
const users = [
|
|
10
|
+
{
|
|
11
|
+
name: "John Doe",
|
|
12
|
+
email: "john.doe@example.com",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "Jane Doe2",
|
|
16
|
+
email: "jane.doe2@example.com",
|
|
17
|
+
},
|
|
18
|
+
]
|
|
19
|
+
res.json(users)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const loginSchema = {
|
|
23
|
+
email: { required: true, email: true },
|
|
24
|
+
password: { required: true, min: 6 }
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const loginValidator = new Validator(loginSchema, 'es');
|
|
28
|
+
|
|
29
|
+
routerUsers.post('/login', loginValidator.middleware(), (req, res) => {
|
|
30
|
+
res.json({ message: 'Login successful' });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
routerUsers.get("*", (req, res) => {
|
|
35
|
+
const response = Template.renderReact(res, "App", { title: "Example title" });
|
|
36
|
+
return response;
|
|
37
|
+
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export default routerUsers
|
package/core/app.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import express from "express"
|
|
2
|
+
import cors from "cors"
|
|
3
|
+
import path from "path"
|
|
4
|
+
import chalk from "chalk"
|
|
5
|
+
import cookieParser from "cookie-parser"
|
|
6
|
+
import Config from "./config.js"
|
|
7
|
+
import Logger from "./logger.js"
|
|
8
|
+
|
|
9
|
+
const __dirname = Config.dirname()
|
|
10
|
+
const props = Config.props()
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Main Application class to manage Express server, routes, and middlewares.
|
|
14
|
+
*/
|
|
15
|
+
class App {
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the App instance with the provided options.
|
|
18
|
+
* @param {Object} [options] - Configuration options for the application.
|
|
19
|
+
* @param {Array<{path: string, router: import('express').Router}>} [options.routes=[]] - Array of route objects containing path and router components.
|
|
20
|
+
* @param {Object} [options.cors={}] - CORS configuration options.
|
|
21
|
+
* @param {Array<Function>} [options.middlewares=[]] - Array of middleware functions to be applied.
|
|
22
|
+
* @param {number|string} [options.port=3000] - Server port.
|
|
23
|
+
* @param {string} [options.host="http://localhost"] - Server host URL.
|
|
24
|
+
* @param {boolean} [options.logger=true] - Whether to enable the request logger.
|
|
25
|
+
* @param {boolean} [options.notFound=true] - Whether to enable the default 404 handler.
|
|
26
|
+
* @param {boolean} [options.json=true] - Whether to enable JSON body parsing.
|
|
27
|
+
* @param {boolean} [options.urlencoded=true] - Whether to enable URL-encoded body parsing.
|
|
28
|
+
* @param {Object} [options.static={path: null, options: {}}] - Static file configuration.
|
|
29
|
+
* @param {boolean} [options.cookieParser=true] - Whether to enable cookie parsing.
|
|
30
|
+
*/
|
|
31
|
+
constructor(options = {
|
|
32
|
+
routes: [],
|
|
33
|
+
cors: {},
|
|
34
|
+
middlewares: [],
|
|
35
|
+
port: null,
|
|
36
|
+
host: null,
|
|
37
|
+
logger: true,
|
|
38
|
+
notFound: true,
|
|
39
|
+
json: true,
|
|
40
|
+
urlencoded: true,
|
|
41
|
+
static: {
|
|
42
|
+
path: null,
|
|
43
|
+
options: {}
|
|
44
|
+
},
|
|
45
|
+
cookieParser: true,
|
|
46
|
+
|
|
47
|
+
}) {
|
|
48
|
+
this.app = express()
|
|
49
|
+
this.routes = options.routes || []
|
|
50
|
+
this.cors = options.cors || {}
|
|
51
|
+
this.middlewares = options.middlewares || []
|
|
52
|
+
this.port = options.port || props.port
|
|
53
|
+
this.host = options.host || props.host
|
|
54
|
+
this.logger = options.logger || true
|
|
55
|
+
this.notFound = options.notFound || true
|
|
56
|
+
this.json = options.json || true
|
|
57
|
+
this.urlencoded = options.urlencoded || true
|
|
58
|
+
this.static = options.static || props.static
|
|
59
|
+
this.cookieParser = options.cookieParser || true
|
|
60
|
+
this.dispatch()
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Registers a custom middleware or module in the Express application.
|
|
66
|
+
* @param {Function|import('express').Router} record - The middleware function or Express router to register.
|
|
67
|
+
*/
|
|
68
|
+
use(record) {
|
|
69
|
+
this.app.use(record)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Bootstraps the application by configuring global middlewares and routes.
|
|
74
|
+
* Sets up JSON parsing, URL encoding, CORS, and custom middlewares.
|
|
75
|
+
*/
|
|
76
|
+
dispatch() {
|
|
77
|
+
if (this.json) this.app.use(express.json())
|
|
78
|
+
if (this.urlencoded) this.app.use(express.urlencoded({ extended: true }))
|
|
79
|
+
if (this.cookieParser) this.app.use(cookieParser())
|
|
80
|
+
if (this.static.path) this.app.use(express.static(path.join(__dirname, this.static.path), this.static.options))
|
|
81
|
+
this.app.use(cors(this.cors))
|
|
82
|
+
this.middlewares.map(middleware => {
|
|
83
|
+
this.app.use(middleware)
|
|
84
|
+
})
|
|
85
|
+
if (this.logger) this.middlewareLogger()
|
|
86
|
+
this.app.use((req, res, next) => {
|
|
87
|
+
res.setHeader('X-Powered-By', 'Blue Bird');
|
|
88
|
+
next();
|
|
89
|
+
});
|
|
90
|
+
this.dispatchRoutes()
|
|
91
|
+
|
|
92
|
+
if (this.notFound) this.notFoundDefault()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Middleware that logs incoming HTTP requests to the console and to a log file.
|
|
98
|
+
*/
|
|
99
|
+
middlewareLogger() {
|
|
100
|
+
this.app.use((req, res, next) => {
|
|
101
|
+
const method = req.method
|
|
102
|
+
const url = req.url
|
|
103
|
+
const params = Object.keys(req.params).length > 0 ? ` ${JSON.stringify(req.params)}` : ""
|
|
104
|
+
const ip = req.ip
|
|
105
|
+
const now = new Date().toISOString()
|
|
106
|
+
const time = `${now.split("T")[0]} ${now.split("T")[1].split(".")[0]}`
|
|
107
|
+
let message = ` ${time} -${ip} -[${method}] ${url} ${params}`
|
|
108
|
+
const logger = new Logger()
|
|
109
|
+
logger.info(message)
|
|
110
|
+
if (props.debug) {
|
|
111
|
+
message = `${chalk.bold.green(time)} - ${chalk.bold.cyan(ip)} -[${chalk.bold.red(method)}] ${chalk.bold.blue(url)} ${chalk.bold.yellow(params)}`
|
|
112
|
+
console.log(message)
|
|
113
|
+
}
|
|
114
|
+
next()
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Iterates through the stored routes and attaches them to the Express application instance.
|
|
120
|
+
*/
|
|
121
|
+
dispatchRoutes() {
|
|
122
|
+
this.routes.map(route => {
|
|
123
|
+
this.app.use(route.path, route.router)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Default 404 handler for unmatched routes.
|
|
128
|
+
* Returns a JSON response with a "Not Found" message.
|
|
129
|
+
*/
|
|
130
|
+
notFoundDefault() {
|
|
131
|
+
this.app.use((req, res) => {
|
|
132
|
+
return res.status(404).json({ message: "Not Found" })
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Starts the HTTP server and begins listening for incoming connections.
|
|
137
|
+
*/
|
|
138
|
+
run() {
|
|
139
|
+
this.app.listen(this.port, () => {
|
|
140
|
+
console.log(
|
|
141
|
+
chalk.bold.blue('Blue Bird Server Online\n') +
|
|
142
|
+
chalk.bold.cyan('Host: ') + chalk.green(`${this.host}:${this.port}`) + '\n' +
|
|
143
|
+
chalk.gray('────────────────────────────────')
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default App
|
|
150
|
+
|
package/core/auth.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Auth class to handle JWT generation, verification and protection.
|
|
5
|
+
*/
|
|
6
|
+
class Auth {
|
|
7
|
+
/**
|
|
8
|
+
* Generates a JWT token.
|
|
9
|
+
* @param {Object} payload - The data to store in the token.
|
|
10
|
+
* @param {string} [secret=process.env.JWT_SECRET] - The secret key.
|
|
11
|
+
* @param {string|number} [expiresIn='24h'] - Expiration time.
|
|
12
|
+
* @returns {string} The generated token.
|
|
13
|
+
*/
|
|
14
|
+
static generateToken(payload, secret = process.env.JWT_SECRET || 'blue-bird-secret', expiresIn = '24h') {
|
|
15
|
+
return jwt.sign(payload, secret, { expiresIn });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Verifies a JWT token.
|
|
20
|
+
* @param {string} token - The token to verify.
|
|
21
|
+
* @param {string} [secret=process.env.JWT_SECRET] - The secret key.
|
|
22
|
+
* @returns {Object|null} The decoded payload or null if invalid.
|
|
23
|
+
*/
|
|
24
|
+
static verifyToken(token, secret = process.env.JWT_SECRET || 'blue-bird-secret') {
|
|
25
|
+
try {
|
|
26
|
+
return jwt.verify(token, secret);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Middleware to protect routes. Checks for token in Cookies or Authorization header.
|
|
34
|
+
* @param {Object} options - Options for protection.
|
|
35
|
+
* @param {string} [options.redirect] - URL to redirect if not authenticated (for web routes).
|
|
36
|
+
* @returns {Function} Express middleware.
|
|
37
|
+
*/
|
|
38
|
+
static protect(options = { redirect: null }) {
|
|
39
|
+
return (req, res, next) => {
|
|
40
|
+
const token = req.cookies?.token || req.headers.authorization?.split(" ")[1];
|
|
41
|
+
|
|
42
|
+
if (!token) {
|
|
43
|
+
if (options.redirect) return res.redirect(options.redirect);
|
|
44
|
+
return res.status(401).json({ message: "Unauthorized: No token provided" });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const decoded = this.verifyToken(token);
|
|
48
|
+
if (!decoded) {
|
|
49
|
+
if (options.redirect) return res.redirect(options.redirect);
|
|
50
|
+
return res.status(401).json({ message: "Unauthorized: Invalid token" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
req.user = decoded;
|
|
54
|
+
next();
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default Auth;
|
package/core/cli/init.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
class ProjectInit {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.appDir = process.cwd();
|
|
10
|
+
this.sourceDir = path.resolve(import.meta.dirname, "../../");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async run() {
|
|
14
|
+
console.log(chalk.cyan("Starting Blue Bird project initialization..."));
|
|
15
|
+
|
|
16
|
+
const itemsToCopy = [
|
|
17
|
+
"backend",
|
|
18
|
+
"frontend",
|
|
19
|
+
".env_example"
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
itemsToCopy.forEach(item => {
|
|
24
|
+
const src = path.join(this.sourceDir, item);
|
|
25
|
+
const dest = path.join(this.appDir, item);
|
|
26
|
+
|
|
27
|
+
if (fs.existsSync(src)) {
|
|
28
|
+
if (!fs.existsSync(dest)) {
|
|
29
|
+
this.copyRecursive(src, dest);
|
|
30
|
+
console.log(chalk.green(`✓ Copied ${item} to root.`));
|
|
31
|
+
} else {
|
|
32
|
+
console.log(chalk.yellow(`! ${item} already exists, skipping.`));
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
console.warn(chalk.red(`✗ Source ${item} not found in ${this.sourceDir}`));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const envPath = path.join(this.appDir, ".env");
|
|
40
|
+
const envExamplePath = path.join(this.appDir, ".env_example");
|
|
41
|
+
if (fs.existsSync(envExamplePath) && !fs.existsSync(envPath)) {
|
|
42
|
+
fs.copyFileSync(envExamplePath, envPath);
|
|
43
|
+
console.log(chalk.green("✓ Created .env from .env_example."));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.updatePackageJson();
|
|
47
|
+
|
|
48
|
+
console.log(chalk.blue("\nBlue Bird initialization completed!"));
|
|
49
|
+
console.log(chalk.white("Next steps:"));
|
|
50
|
+
console.log(chalk.bold(" npm install"));
|
|
51
|
+
console.log(chalk.bold(" npm run react"));
|
|
52
|
+
console.log(chalk.bold(" npm run dev"));
|
|
53
|
+
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(chalk.red("Error during initialization:"), error.message);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
updatePackageJson() {
|
|
60
|
+
const pkgPath = path.join(this.appDir, "package.json");
|
|
61
|
+
if (fs.existsSync(pkgPath)) {
|
|
62
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
63
|
+
pkg.scripts = pkg.scripts || {};
|
|
64
|
+
|
|
65
|
+
const scriptsToAdd = {
|
|
66
|
+
"dev": "node --watch --env-file=.env backend/index.js",
|
|
67
|
+
"start": "node --env-file=.env backend/index.js",
|
|
68
|
+
"react": "blue-bird react",
|
|
69
|
+
"init": "blue-bird"
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
let updated = false;
|
|
73
|
+
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
74
|
+
if (!pkg.scripts[key]) {
|
|
75
|
+
pkg.scripts[key] = value;
|
|
76
|
+
updated = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (updated) {
|
|
81
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
82
|
+
console.log(chalk.green("✓ Updated package.json scripts."));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
copyRecursive(src, dest) {
|
|
88
|
+
const stats = fs.statSync(src);
|
|
89
|
+
const isDirectory = stats.isDirectory();
|
|
90
|
+
|
|
91
|
+
if (isDirectory) {
|
|
92
|
+
if (!fs.existsSync(dest)) {
|
|
93
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
94
|
+
}
|
|
95
|
+
fs.readdirSync(src).forEach(childItemName => {
|
|
96
|
+
this.copyRecursive(path.join(src, childItemName), path.join(dest, childItemName));
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
fs.copyFileSync(src, dest);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const initializer = new ProjectInit();
|
|
105
|
+
|
|
106
|
+
const args = process.argv.slice(2);
|
|
107
|
+
const command = args[0];
|
|
108
|
+
|
|
109
|
+
if (command === "react") {
|
|
110
|
+
// Dynamically import ReactScaffold to avoid circular dependencies if any,
|
|
111
|
+
// or just run it if it's separate.
|
|
112
|
+
import("./react.js");
|
|
113
|
+
} else {
|
|
114
|
+
initializer.run();
|
|
115
|
+
}
|
|
116
|
+
|