Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6806c0

Browse files
feat: add permissions
1 parent 59366fc commit f6806c0

File tree

11 files changed

+156
-62
lines changed

11 files changed

+156
-62
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Command, Option } from 'commander';
2+
import { UploadEasUpdatesSourcemaps, UploadEasUpdatesSourcemapsOptions } from '../upload';
3+
4+
export const uploadEasUpdatesSourcemapsCommand = new Command();
5+
6+
uploadEasUpdatesSourcemapsCommand
7+
.name('upload-eas-updates-sourcemaps')
8+
.addOption(new Option('-f, --file <path>', 'The path of eas update folder').makeOptionMandatory())
9+
.addOption(
10+
new Option('-t, --token <value>', 'Your App Token')
11+
.env('INSTABUG_APP_TOKEN')
12+
.makeOptionMandatory(),
13+
)
14+
.addOption(
15+
new Option('-n, --name <value>', 'The app version name')
16+
.env('INSTABUG_APP_VERSION_NAME')
17+
.makeOptionMandatory(),
18+
)
19+
.addOption(
20+
new Option('-c, --code <value>', 'The app version code')
21+
.env('INSTABUG_APP_VERSION_CODE')
22+
.makeOptionMandatory(),
23+
)
24+
.addOption(
25+
new Option('--androidUpdateId <value>', "The CodePush label if it's a CodePush release"),
26+
)
27+
28+
.addOption(new Option('--iosUpdateId <value>', "The CodePush label if it's a CodePush release"))
29+
.action(function (this: Command) {
30+
const options = this.opts<UploadEasUpdatesSourcemapsOptions>();
31+
UploadEasUpdatesSourcemaps(options);
32+
})
33+
.showHelpAfterError();

cli/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Command } from 'commander';
33

44
import { uploadSourcemapsCommand } from './commands/UploadSourcemaps';
55
import { UploadSoFilesCommand } from './commands/UploadSoFiles';
6+
import { uploadEasUpdatesSourcemapsCommand } from './commands/UploadEasUpdatesSourcemaps';
67

78
const program = new Command();
89

@@ -12,6 +13,7 @@ program
1213
.description('A CLI for uploading source maps to Instabug dashboard.')
1314
.usage('[command]')
1415
.addCommand(uploadSourcemapsCommand)
15-
.addCommand(UploadSoFilesCommand);
16+
.addCommand(UploadSoFilesCommand)
17+
.addCommand(uploadEasUpdatesSourcemapsCommand);
1618

1719
program.parse(process.argv);

cli/upload/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './uploadSourcemaps';
22
export * from './uploadSoFiles';
3+
export * from './uploadEasUpdatesSourcemaps';
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import fs from 'fs';
2+
import { uploadSourcemaps } from './uploadSourcemaps';
3+
import * as path from 'path';
4+
5+
export interface UploadEasUpdatesSourcemapsOptions {
6+
file: string;
7+
token: string;
8+
name: string;
9+
code: string;
10+
androidUpdateId?: string;
11+
iosUpdateId?: string;
12+
/**
13+
* Disables logging to the console and prevents process exit on error.
14+
*
15+
* @default false
16+
* */
17+
silent?: boolean;
18+
}
19+
20+
function getMapFile(folderPath: string): string | null {
21+
try {
22+
const files = fs.readdirSync(folderPath);
23+
const mapFile = files.find((file) => file.endsWith('.map'));
24+
if (!mapFile) {
25+
return null;
26+
}
27+
return path.join(folderPath, mapFile);
28+
} catch (err) {
29+
console.error('Failed to read folder:', err);
30+
return null;
31+
}
32+
}
33+
34+
/**
35+
* Uploads JavaScript sourcemaps to Instabug.
36+
*
37+
* @param opts Options for the sourcemaps upload process.
38+
* @returns A promise that resolves to a boolean indicating whether the upload was successful.
39+
*/
40+
export const UploadEasUpdatesSourcemaps = async (
41+
opts: UploadEasUpdatesSourcemapsOptions,
42+
): Promise<boolean> => {
43+
const jsFolderPath = path.join(opts.file, '_expo', 'static', 'js');
44+
45+
const androidFile = getMapFile(path.join(jsFolderPath, 'android'));
46+
const iosFile = getMapFile(path.join(jsFolderPath, 'ios'));
47+
if (androidFile && fs.existsSync(androidFile)) {
48+
await uploadSourcemaps({
49+
platform: 'android',
50+
name: opts.name,
51+
code: opts.code,
52+
token: opts.token,
53+
label: opts.androidUpdateId,
54+
file: androidFile,
55+
silent: opts.silent,
56+
});
57+
}
58+
59+
if (iosFile && fs.existsSync(iosFile)) {
60+
await uploadSourcemaps({
61+
platform: 'ios',
62+
name: opts.name,
63+
code: opts.code,
64+
token: opts.token,
65+
label: opts.iosUpdateId,
66+
file: iosFile,
67+
silent: opts.silent,
68+
});
69+
}
70+
return true;
71+
};

hooks/src/index.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

hooks/tsconfig.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

plugin/src/withInstabug.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ import { withInstabugIOS } from './withInstabugIOS';
55

66
export interface PluginProps {
77
name?: string;
8-
enable?: boolean;
8+
forceUploadSourceMaps?: boolean;
9+
enableMediaUploadBugReporting?: boolean;
910
}
1011

1112
const withInstabugPlugin: ConfigPlugin<PluginProps> = (config, props) => {
1213
let cfg = config;
13-
if (props.enable === null) {
14-
props.enable = false;
14+
if (props.forceUploadSourceMaps === null) {
15+
props.forceUploadSourceMaps = false;
1516
}
16-
if (props.enable === true) {
17+
18+
if (props.enableMediaUpload === null) {
19+
props.enableMediaUpload = true;
20+
}
21+
if (props.forceUploadSourceMaps === true) {
1722
try {
1823
cfg = withInstabugAndroid(cfg, {
1924
...props,

plugin/src/withInstabugIOS.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ConfigPlugin, XcodeProject } from 'expo/config-plugins';
2-
import { withXcodeProject } from 'expo/config-plugins';
2+
import { withXcodeProject, withInfoPlist } from 'expo/config-plugins';
33
import type { PluginProps } from './withInstabug';
44
import * as path from 'path';
55
import * as fs from 'fs';
@@ -9,7 +9,7 @@ const PHASE_COMMENT = 'Bundle React Native code and images';
99
const INSTABUG_BUILD_PHASE = '[instabug-reactnative] Upload Sourcemap';
1010

1111
export const withInstabugIOS: ConfigPlugin<PluginProps> = (config, props) => {
12-
return withXcodeProject(config, (configXcode) => {
12+
let cfg = withXcodeProject(config, (configXcode) => {
1313
const xcodeProject: XcodeProject = configXcode.modResults;
1414
const buildPhases = xcodeProject.hash.project.objects[BUILD_PHASE];
1515

@@ -34,7 +34,7 @@ export const withInstabugIOS: ConfigPlugin<PluginProps> = (config, props) => {
3434
// Add Instabug build phase if not present
3535
const instabugPhase = findPhaseByName(INSTABUG_BUILD_PHASE);
3636

37-
if (instabugPhase == null && props.enable) {
37+
if (instabugPhase == null && props.forceUploadSourceMaps) {
3838
const packagePath = require.resolve(`${props.name}/package.json`);
3939
const packageDir = path.dirname(packagePath);
4040
const sourcemapsPath = path.join(packageDir, 'ios/sourcemaps.sh');
@@ -57,6 +57,25 @@ export const withInstabugIOS: ConfigPlugin<PluginProps> = (config, props) => {
5757

5858
return configXcode;
5959
});
60+
if (props.enableMediaUploadBugReporting) {
61+
const instabugConfig = config?.extra?.instabug || {}; // Read custom configuration from extra.instabug
62+
63+
const microphonePermission =
64+
instabugConfig.microphonePermission || 'This app needs access to your microphone.';
65+
const photoLibraryPermission =
66+
instabugConfig.photoLibraryPermission || 'This app needs access to your photos.';
67+
68+
// Modify Info.plist for iOS
69+
cfg = withInfoPlist(config, (configXcode) => {
70+
configXcode.ios.infoPlist = {
71+
...configXcode.ios.infoPlist,
72+
NSMicrophoneUsageDescription: microphonePermission,
73+
NSPhotoLibraryUsageDescription: photoLibraryPermission,
74+
};
75+
return config;
76+
});
77+
}
78+
return cfg;
6079
};
6180

6281
function addSourceMapExport(script: string): string {

post-publish.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

rollup.config.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@ export default [
3131
},
3232
plugins: [...commonPlugins, typescript({ tsconfig: './plugin/tsconfig.json' })],
3333
},
34-
{
35-
input: ['hooks/src/index.ts'],
36-
output: {
37-
dir: 'hooks/build',
38-
format: 'cjs',
39-
},
40-
plugins: [...commonPlugins, typescript({ tsconfig: './hooks/tsconfig.json' })],
41-
},
4234
{
4335
input: ['cli/upload/index.ts'],
4436
output: {
4537
dir: 'upload',
4638
format: 'cjs',
4739
},
48-
plugins: [...commonPlugins, typescript({ tsconfig: './tsconfig.upload.json' })],
40+
plugins: [
41+
...commonPlugins,
42+
babel({
43+
babelHelpers: 'bundled',
44+
exclude: 'node_modules/**', // <--- important
45+
}),
46+
typescript({ tsconfig: './tsconfig.upload.json' }),
47+
],
4948
},
5049
];

yarn.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"@babel/traverse" "^7.27.1"
214214
"@babel/types" "^7.27.1"
215215

216-
"@babel/helper-module-imports@^7.25.9", "@babel/helper-module-imports@^7.27.1":
216+
"@babel/helper-module-imports@^7.18.6", "@babel/helper-module-imports@^7.25.9", "@babel/helper-module-imports@^7.27.1":
217217
version "7.27.1"
218218
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.27.1.tgz#7ef769a323e2655e126673bb6d2d6913bbead204"
219219
integrity sha512-0gSFWUPNXNopqtIPQvlD5WgXYI5GY2kP2cCvoT8kczjbfcfuIljTbcWrulD1CIPIX2gt1wghbDy08yE1p+/r3w==
@@ -2745,6 +2745,14 @@
27452745
dependencies:
27462746
nanoid "^3.1.23"
27472747

2748+
"@rollup/plugin-babel@^6.0.4":
2749+
version "6.0.4"
2750+
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-6.0.4.tgz#bd698e351fa9aa9619fcae780aea2a603d98e4c4"
2751+
integrity sha512-YF7Y52kFdFT/xVSuVdjkV5ZdX/3YtmX0QulG+x0taQOtJdHYzVU61aSSkAgVJ7NOv6qPkIYiJSgSWWN/DM5sGw==
2752+
dependencies:
2753+
"@babel/helper-module-imports" "^7.18.6"
2754+
"@rollup/pluginutils" "^5.0.1"
2755+
27482756
"@rollup/plugin-commonjs@^25.0.3":
27492757
version "25.0.8"
27502758
resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.8.tgz#c77e608ab112a666b7f2a6bea625c73224f7dd34"

0 commit comments

Comments
 (0)