From fbdacfffd2b1d1f212627bd2957c00c856b8c449 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Tue, 1 Apr 2025 23:13:20 +0800 Subject: [PATCH] add gitignore check --- cli.json | 22 +++++++++++----------- src/bundle.ts | 2 ++ src/index.ts | 2 ++ src/utils/add-gitignore.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 src/utils/add-gitignore.ts diff --git a/cli.json b/cli.json index ba1a8cd..a71933c 100644 --- a/cli.json +++ b/cli.json @@ -136,11 +136,11 @@ "hasValue": true }, "intermediaDir": { - "default": ".pushy/intermedia/${platform}", + "default": "${tempDir}/intermedia/${platform}", "hasValue": true }, "output": { - "default": ".pushy/output/${platform}.${time}.ppk", + "default": "${tempDir}/output/${platform}.${time}.ppk", "hasValue": true }, "sourcemap": { @@ -167,7 +167,7 @@ "description": "Create diff patch", "options": { "output": { - "default": ".pushy/output/diff", + "default": "${tempDir}/output/diff", "hasValue": true } } @@ -176,7 +176,7 @@ "description": "Create diff patch from a Android package(.apk)", "options": { "output": { - "default": ".pushy/output/diff-${time}.apk-patch", + "default": "${tempDir}/output/diff-${time}.apk-patch", "hasValue": true } } @@ -185,7 +185,7 @@ "description": "Create diff patch from a iOS package(.ipa)", "options": { "output": { - "default": ".pushy/output/diff-${time}.ipa-patch", + "default": "${tempDir}/output/diff-${time}.ipa-patch", "hasValue": true } } @@ -194,7 +194,7 @@ "description": "Create hdiff patch", "options": { "output": { - "default": ".pushy/output/hdiff", + "default": "${tempDir}/output/hdiff", "hasValue": true } } @@ -203,7 +203,7 @@ "description": "Create hdiff patch from a Android package(.apk)", "options": { "output": { - "default": ".pushy/output/hdiff-${time}.apk-patch", + "default": "${tempDir}/output/hdiff-${time}.apk-patch", "hasValue": true } } @@ -212,7 +212,7 @@ "description": "Create hdiff patch from a Prepare package(.ppk)", "options": { "output": { - "default": ".pushy/output/hdiff-${time}.ppk-patch", + "default": "${tempDir}/output/hdiff-${time}.ppk-patch", "hasValue": true } } @@ -221,7 +221,7 @@ "description": "Create hdiff patch from a Harmony package(.app)", "options": { "output": { - "default": ".pushy/output/hdiff-${time}.app-patch", + "default": "${tempDir}/output/hdiff-${time}.app-patch", "hasValue": true } } @@ -230,7 +230,7 @@ "description": "Create hdiff patch from a iOS package(.ipa)", "options": { "output": { - "default": ".pushy/output/hdiff-${time}.ipa-patch", + "default": "${tempDir}/output/hdiff-${time}.ipa-patch", "hasValue": true } } @@ -241,4 +241,4 @@ "default": false } } -} \ No newline at end of file +} diff --git a/src/bundle.ts b/src/bundle.ts index ed63805..cf61a0c 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -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, }); diff --git a/src/index.ts b/src/index.ts index fc6b985..bf4eaae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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(); diff --git a/src/utils/add-gitignore.ts b/src/utils/add-gitignore.ts new file mode 100644 index 0000000..7ca522d --- /dev/null +++ b/src/utils/add-gitignore.ts @@ -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')); + } +}