1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-10-30 22:33:11 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

add gitignore check

This commit is contained in:
sunnylqm
2025-04-01 23:13:20 +08:00
parent b725d2b08e
commit fbdacfffd2
4 changed files with 48 additions and 11 deletions

View File

@@ -0,0 +1,33 @@
import fs from 'node:fs';
import path from 'node:path';
import { credentialFile, tempDir } from './constants';
export function addGitIgnore() {
const shouldIgnore = [credentialFile, tempDir];
const gitignorePath = path.join(process.cwd(), '.gitignore');
if (!fs.existsSync(gitignorePath)) {
return;
}
const gitignoreContent = fs.readFileSync(gitignorePath, 'utf-8');
const gitignoreLines = gitignoreContent.split('\n');
for (const line of gitignoreLines) {
const index = shouldIgnore.indexOf(line);
if (index !== -1) {
shouldIgnore.splice(index, 1);
}
}
if (shouldIgnore.length > 0) {
for (const line of shouldIgnore) {
gitignoreLines.push(line);
console.log(`Added ${line} to .gitignore`);
}
fs.writeFileSync(gitignorePath, gitignoreLines.join('\n'));
}
}