1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-09-16 09:41:38 +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

@@ -12,6 +12,7 @@ import os from 'node:os';
const properties = require('properties');
import { depVersions } from './utils/dep-versions';
import { t } from './utils/i18n';
import { tempDir } from './utils/constants';
let bsdiff;
let hdiff;
@@ -908,6 +909,7 @@ export const commands = {
disableHermes,
} = translateOptions({
...options,
tempDir,
platform,
});

View File

@@ -5,6 +5,7 @@ import updateNotifier from 'update-notifier';
import { printVersionCommand } from './utils';
import pkg from '../package.json';
import { t } from './utils/i18n';
import { addGitIgnore } from './utils/add-gitignore';
updateNotifier({ pkg }).notify({
isGlobal: true,
@@ -32,6 +33,7 @@ const commands = {
};
async function run() {
addGitIgnore();
await printVersionCommand();
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
process.exit();

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'));
}
}