Skip to content

Commit dbacbc1

Browse files
committed
add bundleAfterAndroidStudioBuild to support sentry
1 parent 51affc8 commit dbacbc1

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

cli.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@
161161
}
162162
}
163163
},
164+
"bundleAfterAndroidStudioBuild": {
165+
"description": "bundle after AS build.",
166+
"options": {
167+
"intermediaDir": {
168+
"default": ".pushy/intermedia/${platform}",
169+
"hasValue": true
170+
},
171+
"output": {
172+
"default": ".pushy/output/${platform}.${time}.ppk",
173+
"hasValue": true
174+
}
175+
}
176+
},
164177
"release": {
165178
"description": "Push builded file to server."
166179
},

src/bundle.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'node:path';
2-
import { getRNVersion, translateOptions, checkXcodeScript } from './utils';
2+
import { getRNVersion, translateOptions, checkXcodeScript, checkAndroidStudioScript } from './utils';
33
import * as fs from 'fs-extra';
44
import { ZipFile } from 'yazl';
55
import { open as openZipFile } from 'yauzl';
@@ -722,12 +722,20 @@ export const commands = {
722722

723723
if (platform === 'ios') {
724724
hasSentryScript = checkXcodeScript();
725-
} else {
726-
hasSentryScript = false;
725+
} else if (platform === 'android') {
726+
hasSentryScript = checkAndroidStudioScript();
727727
}
728728

729729
if (hasSentryScript && platform === 'ios') {
730-
throw new Error('请先执行xcodebuild命令,然后再执行pushy bundleAfterXcodeBuild');
730+
throw new Error(
731+
'请先执行xcode build命令,然后再执行pushy bundleAfterXcodeBuild',
732+
);
733+
}
734+
735+
if (hasSentryScript && platform === 'android') {
736+
throw new Error(
737+
'请先执行android build命令,然后再执行pushy bundleAfterAndroidStudioBuild',
738+
);
731739
}
732740

733741
const { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
@@ -790,6 +798,26 @@ export const commands = {
790798
}
791799
},
792800

801+
bundleAfterAndroidStudioBuild: async function ({ options }) {
802+
const { intermediaDir, output } = translateOptions({
803+
...options,
804+
platform: 'android',
805+
});
806+
807+
const realOutput = output.replace(/\$\{time\}/g, `${Date.now()}`);
808+
await pack(path.resolve(intermediaDir), realOutput);
809+
810+
const v = await question('是否现在上传此热更包?(Y/N)');
811+
if (v.toLowerCase() === 'y') {
812+
await this.publish({
813+
args: [realOutput],
814+
options: {
815+
platform: 'android',
816+
},
817+
});
818+
}
819+
},
820+
793821
async diff({ args, options }) {
794822
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
795823

src/utils/checkSentry.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ export function checkXcodeScript() {
2020
return false;
2121
}
2222
}
23+
24+
25+
export function checkAndroidStudioScript() {
26+
try {
27+
const androidAppPath = path.join(process.cwd(), 'android', 'app');
28+
const buildGradlePath = path.join(androidAppPath, 'build.gradle');
29+
30+
const content = fs.readFileSync(buildGradlePath, 'utf8');
31+
const hasSentryGradle = content.includes('@sentry/react-native/package.json');
32+
33+
console.log(`是否包含 sentry.gradle: ${hasSentryGradle}`);
34+
return hasSentryGradle;
35+
} catch (error) {
36+
console.error('读取文件失败:', error);
37+
return false;
38+
}
39+
}

src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import AppInfoParser from './app-info-parser';
66
import semverSatisfies from 'semver/functions/satisfies';
77
import chalk from 'chalk';
88
import latestVersion from '@badisi/latest-version';
9-
import { checkXcodeScript } from './checkSentry';
9+
import { checkXcodeScript, checkAndroidStudioScript } from './checkSentry';
1010

1111
import { read } from 'read';
1212

@@ -227,4 +227,4 @@ export async function printVersionCommand() {
227227

228228
export const pricingPageUrl = 'https://pushy.reactnative.cn/pricing.html';
229229

230-
export { checkXcodeScript };
230+
export { checkXcodeScript, checkAndroidStudioScript };

0 commit comments

Comments
 (0)