create-golden 1.4.2 → 1.4.4

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.
Files changed (2) hide show
  1. package/index.js +39 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -139,6 +139,42 @@ function saveToken(token) {
139
139
  }
140
140
  }
141
141
 
142
+ function updateGitignore(projectRoot) {
143
+ const gitignorePath = path.join(projectRoot, '.gitignore');
144
+ const ignoreRules = ['.cursorrules', '代码规范.md'];
145
+
146
+ try {
147
+ let gitignoreContent = '';
148
+ if (fs.existsSync(gitignorePath)) {
149
+ gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
150
+ }
151
+
152
+ const lines = gitignoreContent.split('\n');
153
+ let hasChanges = false;
154
+
155
+ // 检查并添加每个忽略规则
156
+ for (const ignoreRule of ignoreRules) {
157
+ const hasRule = lines.some(line => line.trim() === ignoreRule);
158
+
159
+ if (!hasRule) {
160
+ // 如果文件不为空且最后一行不是空行,添加换行
161
+ if (gitignoreContent && !gitignoreContent.endsWith('\n')) {
162
+ gitignoreContent += '\n';
163
+ }
164
+ gitignoreContent += ignoreRule + '\n';
165
+ hasChanges = true;
166
+ }
167
+ }
168
+
169
+ if (hasChanges) {
170
+ fs.writeFileSync(gitignorePath, gitignoreContent, 'utf8');
171
+ }
172
+ } catch (err) {
173
+ // 忽略错误,不影响主流程
174
+ console.warn('Warning: Could not update .gitignore:', err.message);
175
+ }
176
+ }
177
+
142
178
  function promptToken() {
143
179
  return new Promise((resolve) => {
144
180
  const rl = readline.createInterface({
@@ -240,6 +276,9 @@ async function handleInit(projectName) {
240
276
 
241
277
  // 验证是否找到了有效的项目目录
242
278
  if (fs.existsSync(path.join(projectRootPath, 'package.json'))) {
279
+ // 更新 .gitignore,添加 .cursorrules 忽略规则
280
+ updateGitignore(projectRootPath);
281
+
243
282
  if (projectName) {
244
283
  console.log(`Successfully created ${projectName}!`);
245
284
  console.log(`\nNext steps:`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-golden",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Create a new golden-template project from the latest GitHub repository (requires GITHUB_TOKEN)",
5
5
  "main": "index.js",
6
6
  "bin": {