create-golden 1.4.2 → 1.4.3

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 +31 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -139,6 +139,34 @@ function saveToken(token) {
139
139
  }
140
140
  }
141
141
 
142
+ function updateGitignore(projectRoot) {
143
+ const gitignorePath = path.join(projectRoot, '.gitignore');
144
+ const ignoreRule = '.cursorrules';
145
+
146
+ try {
147
+ let gitignoreContent = '';
148
+ if (fs.existsSync(gitignorePath)) {
149
+ gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
150
+ }
151
+
152
+ // 检查是否已经包含 .cursorrules
153
+ const lines = gitignoreContent.split('\n');
154
+ const hasCursorrules = lines.some(line => line.trim() === ignoreRule);
155
+
156
+ if (!hasCursorrules) {
157
+ // 如果文件不为空且最后一行不是空行,添加换行
158
+ if (gitignoreContent && !gitignoreContent.endsWith('\n')) {
159
+ gitignoreContent += '\n';
160
+ }
161
+ gitignoreContent += ignoreRule + '\n';
162
+ fs.writeFileSync(gitignorePath, gitignoreContent, 'utf8');
163
+ }
164
+ } catch (err) {
165
+ // 忽略错误,不影响主流程
166
+ console.warn('Warning: Could not update .gitignore:', err.message);
167
+ }
168
+ }
169
+
142
170
  function promptToken() {
143
171
  return new Promise((resolve) => {
144
172
  const rl = readline.createInterface({
@@ -240,6 +268,9 @@ async function handleInit(projectName) {
240
268
 
241
269
  // 验证是否找到了有效的项目目录
242
270
  if (fs.existsSync(path.join(projectRootPath, 'package.json'))) {
271
+ // 更新 .gitignore,添加 .cursorrules 忽略规则
272
+ updateGitignore(projectRootPath);
273
+
243
274
  if (projectName) {
244
275
  console.log(`Successfully created ${projectName}!`);
245
276
  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.3",
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": {