@seip/blue-bird 0.2.0 → 0.2.2
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 +11 -11
- package/LICENSE +21 -21
- package/README.md +80 -80
- package/backend/index.js +12 -12
- package/backend/routes/app.js +52 -40
- package/core/app.js +182 -182
- package/core/auth.js +69 -69
- package/core/cli/component.js +42 -42
- package/core/cli/init.js +117 -116
- package/core/cli/react.js +408 -393
- package/core/cli/route.js +42 -42
- package/core/config.js +41 -41
- package/core/logger.js +80 -80
- package/core/middleware.js +27 -27
- package/core/router.js +134 -134
- package/core/template.js +283 -220
- package/core/upload.js +76 -76
- package/core/validate.js +291 -291
- package/frontend/index.html +20 -0
- package/package.json +40 -43
package/core/cli/init.js
CHANGED
|
@@ -1,116 +1,117 @@
|
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
"route":"blue-bird route"
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
let updated = false;
|
|
74
|
+
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
75
|
+
if (!pkg.scripts[key]) {
|
|
76
|
+
pkg.scripts[key] = value;
|
|
77
|
+
updated = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (updated) {
|
|
82
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
83
|
+
console.log(chalk.green("✓ Updated package.json scripts."));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
copyRecursive(src, dest) {
|
|
89
|
+
const stats = fs.statSync(src);
|
|
90
|
+
const isDirectory = stats.isDirectory();
|
|
91
|
+
|
|
92
|
+
if (isDirectory) {
|
|
93
|
+
if (!fs.existsSync(dest)) {
|
|
94
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
95
|
+
}
|
|
96
|
+
fs.readdirSync(src).forEach(childItemName => {
|
|
97
|
+
this.copyRecursive(path.join(src, childItemName), path.join(dest, childItemName));
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
fs.copyFileSync(src, dest);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const initializer = new ProjectInit();
|
|
106
|
+
|
|
107
|
+
const args = process.argv.slice(2);
|
|
108
|
+
const command = args[0];
|
|
109
|
+
|
|
110
|
+
if (command === "react") {
|
|
111
|
+
// Dynamically import ReactScaffold to avoid circular dependencies if any,
|
|
112
|
+
// or just run it if it's separate.
|
|
113
|
+
import("./react.js");
|
|
114
|
+
} else {
|
|
115
|
+
initializer.run();
|
|
116
|
+
}
|
|
117
|
+
|