create-web-kit 25.728.1502 → 25.728.1636
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/config/frameworks.js +1 -1
- package/dist/generators/nextjs-csr.js +83 -16
- package/dist/templates/nextjs-csr/.env.development +2 -0
- package/dist/templates/nextjs-csr/.env.production +2 -0
- package/dist/templates/nextjs-csr/.env.test +2 -0
- package/dist/templates/nextjs-csr/.husky/_/husky.sh +36 -0
- package/dist/templates/nextjs-csr/.husky/pre-commit +4 -0
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ export const FRAMEWORKS = [
|
|
|
27
27
|
workingDir: "target",
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
command: "pnpm add -D prettier @types/node",
|
|
30
|
+
command: "pnpm add -D prettier @types/node husky lint-staged prettier-plugin-tailwindcss @trivago/prettier-plugin-sort-imports eslint-config-prettier",
|
|
31
31
|
description: "Installing development dependencies",
|
|
32
32
|
workingDir: "target",
|
|
33
33
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
3
4
|
import { copyTemplateFiles } from "../utils/template.js";
|
|
4
5
|
const TEMPLATE_NAME = "nextjs-csr";
|
|
5
6
|
const TEMPLATE_FILES = [
|
|
@@ -7,6 +8,11 @@ const TEMPLATE_FILES = [
|
|
|
7
8
|
{ source: "prettier.config.json", destination: ".prettierrc", isJson: true },
|
|
8
9
|
{ source: "eslint.config.mjs", destination: "eslint.config.mjs" },
|
|
9
10
|
{ source: "next.config.ts", destination: "next.config.ts" },
|
|
11
|
+
{ source: ".env.test", destination: ".env.test" },
|
|
12
|
+
{ source: ".env.development", destination: ".env.development" },
|
|
13
|
+
{ source: ".env.production", destination: ".env.production" },
|
|
14
|
+
{ source: ".husky/pre-commit", destination: ".husky/pre-commit" },
|
|
15
|
+
{ source: ".husky/_/husky.sh", destination: ".husky/_/husky.sh" },
|
|
10
16
|
// DevContainer
|
|
11
17
|
{
|
|
12
18
|
source: ".devcontainer/devcontainer.json",
|
|
@@ -41,8 +47,83 @@ const TEMPLATE_FILES = [
|
|
|
41
47
|
export function createNextjsCSRFiles(root) {
|
|
42
48
|
// Copy all template files
|
|
43
49
|
copyTemplateFiles(TEMPLATE_NAME, TEMPLATE_FILES, root);
|
|
44
|
-
//
|
|
50
|
+
// Configure package.json with husky and lint-staged
|
|
51
|
+
copyConfigHuskyPackage(root);
|
|
52
|
+
// Copy IE compatibility page
|
|
45
53
|
copyIECompatibilityPage(root);
|
|
54
|
+
// Initialize husky after all files are copied
|
|
55
|
+
initializeHusky(root);
|
|
56
|
+
}
|
|
57
|
+
function copyConfigHuskyPackage(root) {
|
|
58
|
+
const pkgPath = path.join(root, "package.json");
|
|
59
|
+
try {
|
|
60
|
+
const pkgContent = fs.readFileSync(pkgPath, "utf-8");
|
|
61
|
+
const pkg = JSON.parse(pkgContent);
|
|
62
|
+
// 添加 prepare 脚本
|
|
63
|
+
if (!pkg.scripts) {
|
|
64
|
+
pkg.scripts = {};
|
|
65
|
+
}
|
|
66
|
+
pkg.scripts.prepare = "husky";
|
|
67
|
+
// 添加 lint-staged 配置
|
|
68
|
+
pkg["lint-staged"] = {
|
|
69
|
+
"**/*.{js,jsx,ts,tsx,json,css,scss,md}": ["prettier --write"],
|
|
70
|
+
"**/*.{js,jsx,ts,tsx}": ["eslint --fix"],
|
|
71
|
+
};
|
|
72
|
+
// 写回文件
|
|
73
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
74
|
+
console.log("✅ Updated package.json with husky and lint-staged configuration");
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error("❌ Failed to update package.json:", error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function initializeHusky(root) {
|
|
81
|
+
try {
|
|
82
|
+
console.log("🔧 Initializing Git repository...");
|
|
83
|
+
try {
|
|
84
|
+
execSync("git init", {
|
|
85
|
+
cwd: root,
|
|
86
|
+
stdio: "inherit",
|
|
87
|
+
});
|
|
88
|
+
console.log("✅ Git repository initialized");
|
|
89
|
+
}
|
|
90
|
+
catch (gitError) {
|
|
91
|
+
console.warn("⚠️ Git init failed or already initialized:", gitError);
|
|
92
|
+
}
|
|
93
|
+
execSync("npx husky install", {
|
|
94
|
+
cwd: root,
|
|
95
|
+
stdio: "inherit",
|
|
96
|
+
});
|
|
97
|
+
// 确保 .husky 目录存在
|
|
98
|
+
const huskyDir = path.join(root, ".husky");
|
|
99
|
+
if (!fs.existsSync(huskyDir)) {
|
|
100
|
+
fs.mkdirSync(huskyDir, { recursive: true });
|
|
101
|
+
}
|
|
102
|
+
// 确保 .husky/_/ 目录存在
|
|
103
|
+
const huskyUnderscoreDir = path.join(huskyDir, "_");
|
|
104
|
+
if (!fs.existsSync(huskyUnderscoreDir)) {
|
|
105
|
+
fs.mkdirSync(huskyUnderscoreDir, { recursive: true });
|
|
106
|
+
}
|
|
107
|
+
// 创建 pre-commit 钩子文件
|
|
108
|
+
const preCommitPath = path.join(huskyDir, "pre-commit");
|
|
109
|
+
const preCommitContent = `#!/usr/bin/env sh
|
|
110
|
+
. "$(dirname -- "$0")/_/husky.sh"
|
|
111
|
+
|
|
112
|
+
npx lint-staged
|
|
113
|
+
`;
|
|
114
|
+
fs.writeFileSync(preCommitPath, preCommitContent);
|
|
115
|
+
// 设置执行权限
|
|
116
|
+
try {
|
|
117
|
+
fs.chmodSync(preCommitPath, 0o755);
|
|
118
|
+
}
|
|
119
|
+
catch (chmodError) {
|
|
120
|
+
console.warn("⚠️ Could not set execute permission for pre-commit hook");
|
|
121
|
+
}
|
|
122
|
+
console.log("✅ Husky pre-commit hook created successfully");
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.error("❌ Failed to initialize husky:", error);
|
|
126
|
+
}
|
|
46
127
|
}
|
|
47
128
|
function copyIECompatibilityPage(root) {
|
|
48
129
|
const ieHtmlPath = path.join(path.dirname(new URL(import.meta.url).pathname), "../assets/html/ie.html");
|
|
@@ -51,21 +132,7 @@ function copyIECompatibilityPage(root) {
|
|
|
51
132
|
ieHtmlContent = fs.readFileSync(ieHtmlPath, "utf-8");
|
|
52
133
|
}
|
|
53
134
|
catch (error) {
|
|
54
|
-
|
|
55
|
-
ieHtmlContent = `<!DOCTYPE html>
|
|
56
|
-
<html lang="zh-CN">
|
|
57
|
-
<head>
|
|
58
|
-
<meta charset="UTF-8">
|
|
59
|
-
<meta httpEquiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
60
|
-
<meta name="renderer" content="webkit" />
|
|
61
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
|
|
62
|
-
<title>浏览器兼容性提示</title>
|
|
63
|
-
</head>
|
|
64
|
-
<body>
|
|
65
|
-
<h1>请升级您的浏览器</h1>
|
|
66
|
-
<p>您正在使用过时的浏览器版本,请升级到现代浏览器以获得更好的体验。</p>
|
|
67
|
-
</body>
|
|
68
|
-
</html>`;
|
|
135
|
+
console.error(error);
|
|
69
136
|
}
|
|
70
137
|
// Ensure public directory exists
|
|
71
138
|
const publicDir = path.join(root, "public");
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
if [ -z "$husky_skip_init" ]; then
|
|
3
|
+
debug () {
|
|
4
|
+
if [ "$HUSKY_DEBUG" = "1" ]; then
|
|
5
|
+
echo "husky (debug) - $1"
|
|
6
|
+
fi
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
readonly hook_name="$(basename -- "$0")"
|
|
10
|
+
debug "starting $hook_name..."
|
|
11
|
+
|
|
12
|
+
if [ "$HUSKY" = "0" ]; then
|
|
13
|
+
debug "HUSKY env variable is set to 0, skipping hook"
|
|
14
|
+
exit 0
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
if [ -f ~/.huskyrc ]; then
|
|
18
|
+
debug "sourcing ~/.huskyrc"
|
|
19
|
+
. ~/.huskyrc
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
readonly husky_skip_init=1
|
|
23
|
+
export husky_skip_init
|
|
24
|
+
sh -e "$0" "$@"
|
|
25
|
+
exitcode="$?"
|
|
26
|
+
|
|
27
|
+
if [ $exitcode != 0 ]; then
|
|
28
|
+
echo "husky - $hook_name hook exited with code $exitcode (error)"
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
if [ $exitcode = 127 ]; then
|
|
32
|
+
echo "husky - command not found in PATH=$PATH"
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
exit $exitcode
|
|
36
|
+
fi
|
package/package.json
CHANGED