mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 09:41:38 +08:00
add gitignore check
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
|
@@ -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();
|
||||
|
33
src/utils/add-gitignore.ts
Normal file
33
src/utils/add-gitignore.ts
Normal 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'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user