@sentry/wizard 3.9.2 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -6
- package/dist/lib/Constants.d.ts +2 -0
- package/dist/lib/Constants.js +10 -0
- package/dist/lib/Constants.js.map +1 -1
- package/dist/lib/Steps/ChooseIntegration.js +15 -4
- package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
- package/dist/lib/Steps/Integrations/Android.d.ts +9 -0
- package/dist/lib/Steps/Integrations/Android.js +86 -0
- package/dist/lib/Steps/Integrations/Android.js.map +1 -0
- package/dist/lib/Steps/Integrations/Cordova.js +5 -1
- package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
- package/dist/lib/Steps/Integrations/ReactNative.js +3 -3
- package/dist/lib/Steps/Integrations/ReactNative.js.map +1 -1
- package/dist/lib/Steps/Integrations/Remix.d.ts +12 -0
- package/dist/lib/Steps/Integrations/Remix.js +98 -0
- package/dist/lib/Steps/Integrations/Remix.js.map +1 -0
- package/dist/lib/Steps/PromptForParameters.js +36 -3
- package/dist/lib/Steps/PromptForParameters.js.map +1 -1
- package/dist/lib/Steps/SentryProjectSelector.js +1 -1
- package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
- package/dist/package.json +4 -3
- package/dist/src/android/android-wizard.d.ts +2 -0
- package/dist/src/android/android-wizard.js +217 -0
- package/dist/src/android/android-wizard.js.map +1 -0
- package/dist/src/android/code-tools.d.ts +39 -0
- package/dist/src/android/code-tools.js +161 -0
- package/dist/src/android/code-tools.js.map +1 -0
- package/dist/src/android/gradle.d.ts +62 -0
- package/dist/src/android/gradle.js +281 -0
- package/dist/src/android/gradle.js.map +1 -0
- package/dist/src/android/manifest.d.ts +57 -0
- package/dist/src/android/manifest.js +183 -0
- package/dist/src/android/manifest.js.map +1 -0
- package/dist/src/android/templates.d.ts +11 -0
- package/dist/src/android/templates.js +34 -0
- package/dist/src/android/templates.js.map +1 -0
- package/dist/src/apple/apple-wizard.js +123 -64
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/apple/cocoapod.js +4 -3
- package/dist/src/apple/cocoapod.js.map +1 -1
- package/dist/src/apple/code-tools.d.ts +1 -1
- package/dist/src/apple/code-tools.js +43 -19
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/fastlane.d.ts +1 -1
- package/dist/src/apple/fastlane.js +12 -6
- package/dist/src/apple/fastlane.js.map +1 -1
- package/dist/src/apple/templates.d.ts +2 -2
- package/dist/src/apple/templates.js +4 -4
- package/dist/src/apple/templates.js.map +1 -1
- package/dist/src/apple/xcode-manager.d.ts +19 -3
- package/dist/src/apple/xcode-manager.js +126 -24
- package/dist/src/apple/xcode-manager.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +49 -11
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +2 -0
- package/dist/src/nextjs/templates.js +6 -2
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/remix/codemods/handle-error.d.ts +2 -0
- package/dist/src/remix/codemods/handle-error.js +70 -0
- package/dist/src/remix/codemods/handle-error.js.map +1 -0
- package/dist/src/remix/codemods/root-v1.d.ts +1 -0
- package/dist/src/remix/codemods/root-v1.js +133 -0
- package/dist/src/remix/codemods/root-v1.js.map +1 -0
- package/dist/src/remix/codemods/root-v2.d.ts +1 -0
- package/dist/src/remix/codemods/root-v2.js +134 -0
- package/dist/src/remix/codemods/root-v2.js.map +1 -0
- package/dist/src/remix/remix-wizard.d.ts +2 -0
- package/dist/src/remix/remix-wizard.js +196 -0
- package/dist/src/remix/remix-wizard.js.map +1 -0
- package/dist/src/remix/sdk-setup.d.ts +18 -0
- package/dist/src/remix/sdk-setup.js +293 -0
- package/dist/src/remix/sdk-setup.js.map +1 -0
- package/dist/src/remix/templates.d.ts +2 -0
- package/dist/src/remix/templates.js +6 -0
- package/dist/src/remix/templates.js.map +1 -0
- package/dist/src/remix/utils.d.ts +6 -0
- package/dist/src/remix/utils.js +55 -0
- package/dist/src/remix/utils.js.map +1 -0
- package/dist/src/sourcemaps/sourcemaps-wizard.js +49 -25
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sourcemaps/tools/nextjs.js +1 -1
- package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
- package/dist/src/sourcemaps/tools/remix.d.ts +3 -0
- package/dist/src/sourcemaps/tools/remix.js +125 -0
- package/dist/src/sourcemaps/tools/remix.js.map +1 -0
- package/dist/src/sourcemaps/tools/sentry-cli.js +19 -16
- package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.d.ts +2 -1
- package/dist/src/sourcemaps/tools/vite.js +99 -12
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sourcemaps/utils/detect-tool.d.ts +1 -1
- package/dist/src/sourcemaps/utils/detect-tool.js +1 -0
- package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +3 -3
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +34 -44
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/telemetry.js +1 -0
- package/dist/src/telemetry.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +2 -2
- package/dist/src/utils/ast-utils.js +7 -7
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +23 -28
- package/dist/src/utils/clack-utils.js +287 -244
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/package-manager.d.ts +10 -0
- package/dist/{lib/Helper/PackageManager.js → src/utils/package-manager.js} +42 -74
- package/dist/src/utils/package-manager.js.map +1 -0
- package/dist/src/utils/release-registry.d.ts +1 -0
- package/dist/src/utils/release-registry.js +68 -0
- package/dist/src/utils/release-registry.js.map +1 -0
- package/dist/src/utils/sentrycli-utils.d.ts +4 -0
- package/dist/src/utils/sentrycli-utils.js +41 -0
- package/dist/src/utils/sentrycli-utils.js.map +1 -0
- package/dist/test/sourcemaps/tools/vite.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/vite.test.js +132 -0
- package/dist/test/sourcemaps/tools/vite.test.js.map +1 -0
- package/lib/Constants.ts +10 -0
- package/lib/Steps/ChooseIntegration.ts +14 -3
- package/lib/Steps/Integrations/Android.ts +23 -0
- package/lib/Steps/Integrations/Cordova.ts +5 -1
- package/lib/Steps/Integrations/ReactNative.ts +9 -3
- package/lib/Steps/Integrations/Remix.ts +32 -0
- package/lib/Steps/PromptForParameters.ts +48 -3
- package/lib/Steps/SentryProjectSelector.ts +3 -1
- package/package.json +4 -3
- package/src/android/android-wizard.ts +196 -0
- package/src/android/code-tools.ts +156 -0
- package/src/android/gradle.ts +245 -0
- package/src/android/manifest.ts +180 -0
- package/src/android/templates.ts +88 -0
- package/src/apple/apple-wizard.ts +113 -35
- package/src/apple/cocoapod.ts +6 -3
- package/src/apple/code-tools.ts +46 -18
- package/src/apple/fastlane.ts +6 -12
- package/src/apple/templates.ts +2 -8
- package/src/apple/xcode-manager.ts +167 -25
- package/src/nextjs/nextjs-wizard.ts +72 -8
- package/src/nextjs/templates.ts +16 -2
- package/src/remix/codemods/handle-error.ts +67 -0
- package/src/remix/codemods/root-v1.ts +91 -0
- package/src/remix/codemods/root-v2.ts +84 -0
- package/src/remix/remix-wizard.ts +132 -0
- package/src/remix/sdk-setup.ts +300 -0
- package/src/remix/templates.ts +15 -0
- package/src/remix/utils.ts +41 -0
- package/src/sourcemaps/sourcemaps-wizard.ts +28 -5
- package/src/sourcemaps/tools/nextjs.ts +2 -2
- package/src/sourcemaps/tools/remix.ts +90 -0
- package/src/sourcemaps/tools/sentry-cli.ts +8 -7
- package/src/sourcemaps/tools/vite.ts +136 -6
- package/src/sourcemaps/utils/detect-tool.ts +4 -1
- package/src/sveltekit/sdk-setup.ts +4 -4
- package/src/sveltekit/sveltekit-wizard.ts +5 -14
- package/src/telemetry.ts +2 -0
- package/src/utils/ast-utils.ts +7 -5
- package/src/utils/clack-utils.ts +366 -258
- package/src/utils/package-manager.ts +61 -0
- package/src/utils/release-registry.ts +19 -0
- package/src/utils/sentrycli-utils.ts +22 -0
- package/test/sourcemaps/tools/vite.test.ts +149 -0
- package/dist/lib/Helper/PackageManager.d.ts +0 -22
- package/dist/lib/Helper/PackageManager.js.map +0 -1
- package/dist/src/utils/vendor/clack-custom-select.d.ts +0 -21
- package/dist/src/utils/vendor/clack-custom-select.js +0 -137
- package/dist/src/utils/vendor/clack-custom-select.js.map +0 -1
- package/lib/Helper/PackageManager.ts +0 -59
- package/src/utils/vendor/clack-custom-select.ts +0 -160
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.runAndroidWizard = void 0;
|
|
66
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
67
|
+
var fs = __importStar(require("fs"));
|
|
68
|
+
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
69
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
70
|
+
var path = __importStar(require("path"));
|
|
71
|
+
var gradle = __importStar(require("./gradle"));
|
|
72
|
+
var manifest = __importStar(require("./manifest"));
|
|
73
|
+
var codetools = __importStar(require("./code-tools"));
|
|
74
|
+
var clack_utils_1 = require("../utils/clack-utils");
|
|
75
|
+
var telemetry_1 = require("../telemetry");
|
|
76
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
77
|
+
var proguardMappingCliSetupConfig = {
|
|
78
|
+
filename: clack_utils_1.SENTRY_PROPERTIES_FILE,
|
|
79
|
+
name: 'proguard mappings',
|
|
80
|
+
likelyAlreadyHasAuthToken: function (contents) {
|
|
81
|
+
return !!contents.match(/auth\.token=./g);
|
|
82
|
+
},
|
|
83
|
+
tokenContent: function (authToken) {
|
|
84
|
+
return "auth.token=".concat(authToken);
|
|
85
|
+
},
|
|
86
|
+
likelyAlreadyHasOrgAndProject: function (contents) {
|
|
87
|
+
return !!(contents.match(/defaults\.org=./g) &&
|
|
88
|
+
contents.match(/defaults\.project=./g));
|
|
89
|
+
},
|
|
90
|
+
orgAndProjContent: function (org, project) {
|
|
91
|
+
return "defaults.org=".concat(org, "\ndefaults.project=").concat(project);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
function runAndroidWizard(options) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
return [2 /*return*/, (0, telemetry_1.withTelemetry)({
|
|
98
|
+
enabled: options.telemetryEnabled,
|
|
99
|
+
integration: 'android',
|
|
100
|
+
}, function () { return runAndroidWizardWithTelemetry(options); })];
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
exports.runAndroidWizard = runAndroidWizard;
|
|
105
|
+
function runAndroidWizardWithTelemetry(options) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var projectDir, buildGradleFiles, appFile, _a, selectedProject, authToken, pluginAdded, appDir, manifestFile, manifestUpdated, mainActivity, packageName, activityName, packageNameStable_1, activityFile_1, activityPatched;
|
|
108
|
+
return __generator(this, function (_b) {
|
|
109
|
+
switch (_b.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
(0, clack_utils_1.printWelcome)({
|
|
112
|
+
wizardName: 'Sentry Android Wizard',
|
|
113
|
+
promoCode: options.promoCode,
|
|
114
|
+
});
|
|
115
|
+
return [4 /*yield*/, (0, clack_utils_1.confirmContinueEvenThoughNoGitRepo)()];
|
|
116
|
+
case 1:
|
|
117
|
+
_b.sent();
|
|
118
|
+
projectDir = process.cwd();
|
|
119
|
+
buildGradleFiles = findFilesWithExtensions(projectDir, [
|
|
120
|
+
'.gradle',
|
|
121
|
+
'gradle.kts',
|
|
122
|
+
]);
|
|
123
|
+
if (!(!buildGradleFiles || buildGradleFiles.length === 0)) return [3 /*break*/, 3];
|
|
124
|
+
clack.log.error('No Gradle project found. Please run this command from the root of your project.');
|
|
125
|
+
return [4 /*yield*/, (0, clack_utils_1.abort)()];
|
|
126
|
+
case 2:
|
|
127
|
+
_b.sent();
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
case 3: return [4 /*yield*/, (0, telemetry_1.traceStep)('Select App File', function () {
|
|
130
|
+
return gradle.selectAppFile(buildGradleFiles);
|
|
131
|
+
})];
|
|
132
|
+
case 4:
|
|
133
|
+
appFile = _b.sent();
|
|
134
|
+
return [4 /*yield*/, (0, clack_utils_1.getOrAskForProjectData)(options, 'android')];
|
|
135
|
+
case 5:
|
|
136
|
+
_a = _b.sent(), selectedProject = _a.selectedProject, authToken = _a.authToken;
|
|
137
|
+
// ======== STEP 1. Add Sentry Gradle Plugin to build.gradle(.kts) ============
|
|
138
|
+
clack.log.step("Adding ".concat(chalk_1.default.bold('Sentry Gradle plugin'), " to your app's ").concat(chalk_1.default.cyan('build.gradle'), " file."));
|
|
139
|
+
return [4 /*yield*/, (0, telemetry_1.traceStep)('Add Gradle Plugin', function () {
|
|
140
|
+
return gradle.addGradlePlugin(appFile, selectedProject.organization.slug, selectedProject.slug);
|
|
141
|
+
})];
|
|
142
|
+
case 6:
|
|
143
|
+
pluginAdded = _b.sent();
|
|
144
|
+
if (!pluginAdded) {
|
|
145
|
+
clack.log.warn("Could not add Sentry Gradle plugin to your app's build.gradle file. You'll have to add it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#install");
|
|
146
|
+
}
|
|
147
|
+
// ======== STEP 2. Configure Sentry SDK via AndroidManifest ============
|
|
148
|
+
clack.log.step("Configuring Sentry SDK via ".concat(chalk_1.default.cyan('AndroidManifest.xml')));
|
|
149
|
+
appDir = path.dirname(appFile);
|
|
150
|
+
manifestFile = path.join(appDir, 'src', 'main', 'AndroidManifest.xml');
|
|
151
|
+
manifestUpdated = (0, telemetry_1.traceStep)('Update Android Manifest', function () {
|
|
152
|
+
return manifest.addManifestSnippet(manifestFile, selectedProject.keys[0].dsn.public);
|
|
153
|
+
});
|
|
154
|
+
if (!manifestUpdated) {
|
|
155
|
+
clack.log.warn("Could not configure the Sentry SDK. You'll have to do it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#configure");
|
|
156
|
+
}
|
|
157
|
+
// ======== STEP 3. Patch Main Activity with a test error snippet ============
|
|
158
|
+
clack.log.step("Patching ".concat(chalk_1.default.bold('Main Activity'), " with a test error snippet."));
|
|
159
|
+
mainActivity = (0, telemetry_1.traceStep)('Find Main Activity', function () {
|
|
160
|
+
return manifest.getMainActivity(manifestFile);
|
|
161
|
+
});
|
|
162
|
+
packageName = mainActivity.packageName;
|
|
163
|
+
if (!packageName) {
|
|
164
|
+
// if no package name in AndroidManifest, look into gradle script
|
|
165
|
+
packageName = gradle.getNamespace(appFile);
|
|
166
|
+
}
|
|
167
|
+
activityName = mainActivity.activityName;
|
|
168
|
+
if (!activityName || !packageName) {
|
|
169
|
+
clack.log.warn("Could not find Activity with intent action MAIN. You'll have to manually verify the setup.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify");
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
packageNameStable_1 = packageName;
|
|
173
|
+
activityFile_1 = (0, telemetry_1.traceStep)('Find Main Activity Source File', function () {
|
|
174
|
+
return codetools.findActivitySourceFile(appDir, packageNameStable_1, activityName);
|
|
175
|
+
});
|
|
176
|
+
activityPatched = (0, telemetry_1.traceStep)('Patch Main Activity', function () {
|
|
177
|
+
return codetools.patchMainActivity(activityFile_1);
|
|
178
|
+
});
|
|
179
|
+
if (!activityPatched) {
|
|
180
|
+
clack.log.warn("Could not patch main activity. You'll have to manually verify the setup.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// ======== STEP 4. Add sentry-cli config file ============
|
|
184
|
+
clack.log.step("Configuring ".concat(chalk_1.default.bold('proguard mappings upload'), " via the ").concat(chalk_1.default.cyan('sentry.properties'), " file."));
|
|
185
|
+
return [4 /*yield*/, (0, telemetry_1.traceStep)('Add SentryCli Config', function () {
|
|
186
|
+
return (0, clack_utils_1.addSentryCliConfig)(authToken, proguardMappingCliSetupConfig);
|
|
187
|
+
})];
|
|
188
|
+
case 7:
|
|
189
|
+
_b.sent();
|
|
190
|
+
// ======== OUTRO ========
|
|
191
|
+
clack.outro("\n".concat(chalk_1.default.greenBright('Successfully installed the Sentry Android SDK!'), "\n\n").concat(chalk_1.default.cyan('You can validate your setup by launching your application and checking Sentry issues page afterwards'), "\n\nCheck out the SDK documentation for further configuration:\nhttps://docs.sentry.io/platforms/android/\n "));
|
|
192
|
+
return [2 /*return*/];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
//find files with the given extension
|
|
198
|
+
function findFilesWithExtensions(dir, extensions, filesWithExtensions) {
|
|
199
|
+
if (filesWithExtensions === void 0) { filesWithExtensions = []; }
|
|
200
|
+
var cwd = process.cwd();
|
|
201
|
+
var files = fs.readdirSync(dir, { withFileTypes: true });
|
|
202
|
+
var _loop_1 = function (file) {
|
|
203
|
+
if (file.isDirectory()) {
|
|
204
|
+
var childDir = path.join(dir, file.name);
|
|
205
|
+
findFilesWithExtensions(childDir, extensions, filesWithExtensions);
|
|
206
|
+
}
|
|
207
|
+
else if (extensions.some(function (ext) { return file.name.endsWith(ext); })) {
|
|
208
|
+
filesWithExtensions.push(path.relative(cwd, path.join(dir, file.name)));
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
|
|
212
|
+
var file = files_1[_i];
|
|
213
|
+
_loop_1(file);
|
|
214
|
+
}
|
|
215
|
+
return filesWithExtensions;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=android-wizard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"android-wizard.js","sourceRoot":"","sources":["../../../src/android/android-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,qCAAyB;AACzB,yEAAyE;AACzE,oDAAwC;AACxC,yCAA6B;AAC7B,+CAAmC;AACnC,mDAAuC;AACvC,sDAA0C;AAC1C,oDAQ8B;AAE9B,0CAAwD;AACxD,gDAA0B;AAE1B,IAAM,6BAA6B,GAAmB;IACpD,QAAQ,EAAE,oCAAsB;IAChC,IAAI,EAAE,mBAAmB;IACzB,yBAAyB,YAAC,QAAgB;QACxC,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IACD,YAAY,YAAC,SAAiB;QAC5B,OAAO,qBAAc,SAAS,CAAE,CAAC;IACnC,CAAC;IACD,6BAA6B,YAAC,QAAgB;QAC5C,OAAO,CAAC,CAAC,CACP,QAAQ,CAAC,KAAK,CAAC,kBAAkB,CAAC;YAClC,QAAQ,CAAC,KAAK,CAAC,sBAAsB,CAAC,CACvC,CAAC;IACJ,CAAC;IACD,iBAAiB,YAAC,GAAW,EAAE,OAAe;QAC5C,OAAO,uBAAgB,GAAG,gCAAsB,OAAO,CAAE,CAAC;IAC5D,CAAC;CACF,CAAC;AAEF,SAAsB,gBAAgB,CAAC,OAAsB;;;YAC3D,sBAAO,IAAA,yBAAa,EAClB;oBACE,OAAO,EAAE,OAAO,CAAC,gBAAgB;oBACjC,WAAW,EAAE,SAAS;iBACvB,EACD,cAAM,OAAA,6BAA6B,CAAC,OAAO,CAAC,EAAtC,CAAsC,CAC7C,EAAC;;;CACH;AARD,4CAQC;AAED,SAAe,6BAA6B,CAC1C,OAAsB;;;;;;oBAEtB,IAA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Q,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3C,uBAAuB,CAAC,QAAQ,EAAE,UAAU,EAAE,mBAAmB,CAAC,CAAC;SACpE;aAAM,IAAI,UAAU,CAAC,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAvB,CAAuB,CAAC,EAAE;YAC5D,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACzE;;IANH,KAAmB,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK;QAAnB,IAAM,IAAI,cAAA;gBAAJ,IAAI;KAOd;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport * as fs from 'fs';\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport * as path from 'path';\nimport * as gradle from './gradle';\nimport * as manifest from './manifest';\nimport * as codetools from './code-tools';\nimport {\n CliSetupConfig,\n SENTRY_PROPERTIES_FILE,\n abort,\n addSentryCliConfig,\n confirmContinueEvenThoughNoGitRepo,\n getOrAskForProjectData,\n printWelcome,\n} from '../utils/clack-utils';\nimport { WizardOptions } from '../utils/types';\nimport { traceStep, withTelemetry } from '../telemetry';\nimport chalk from 'chalk';\n\nconst proguardMappingCliSetupConfig: CliSetupConfig = {\n filename: SENTRY_PROPERTIES_FILE,\n name: 'proguard mappings',\n likelyAlreadyHasAuthToken(contents: string): boolean {\n return !!contents.match(/auth\\.token=./g);\n },\n tokenContent(authToken: string): string {\n return `auth.token=${authToken}`;\n },\n likelyAlreadyHasOrgAndProject(contents: string): boolean {\n return !!(\n contents.match(/defaults\\.org=./g) &&\n contents.match(/defaults\\.project=./g)\n );\n },\n orgAndProjContent(org: string, project: string): string {\n return `defaults.org=${org}\\ndefaults.project=${project}`;\n },\n};\n\nexport async function runAndroidWizard(options: WizardOptions): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'android',\n },\n () => runAndroidWizardWithTelemetry(options),\n );\n}\n\nasync function runAndroidWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry Android Wizard',\n promoCode: options.promoCode,\n });\n\n await confirmContinueEvenThoughNoGitRepo();\n\n const projectDir = process.cwd();\n const buildGradleFiles = findFilesWithExtensions(projectDir, [\n '.gradle',\n 'gradle.kts',\n ]);\n\n if (!buildGradleFiles || buildGradleFiles.length === 0) {\n clack.log.error(\n 'No Gradle project found. Please run this command from the root of your project.',\n );\n await abort();\n return;\n }\n\n const appFile = await traceStep('Select App File', () =>\n gradle.selectAppFile(buildGradleFiles),\n );\n\n const { selectedProject, authToken } = await getOrAskForProjectData(\n options,\n 'android',\n );\n\n // ======== STEP 1. Add Sentry Gradle Plugin to build.gradle(.kts) ============\n clack.log.step(\n `Adding ${chalk.bold('Sentry Gradle plugin')} to your app's ${chalk.cyan(\n 'build.gradle',\n )} file.`,\n );\n const pluginAdded = await traceStep('Add Gradle Plugin', () =>\n gradle.addGradlePlugin(\n appFile,\n selectedProject.organization.slug,\n selectedProject.slug,\n ),\n );\n if (!pluginAdded) {\n clack.log.warn(\n \"Could not add Sentry Gradle plugin to your app's build.gradle file. You'll have to add it manually.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#install\",\n );\n }\n\n // ======== STEP 2. Configure Sentry SDK via AndroidManifest ============\n clack.log.step(\n `Configuring Sentry SDK via ${chalk.cyan('AndroidManifest.xml')}`,\n );\n const appDir = path.dirname(appFile);\n const manifestFile = path.join(appDir, 'src', 'main', 'AndroidManifest.xml');\n\n const manifestUpdated = traceStep('Update Android Manifest', () =>\n manifest.addManifestSnippet(\n manifestFile,\n selectedProject.keys[0].dsn.public,\n ),\n );\n if (!manifestUpdated) {\n clack.log.warn(\n \"Could not configure the Sentry SDK. You'll have to do it manually.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#configure\",\n );\n }\n\n // ======== STEP 3. Patch Main Activity with a test error snippet ============\n clack.log.step(\n `Patching ${chalk.bold('Main Activity')} with a test error snippet.`,\n );\n const mainActivity = traceStep('Find Main Activity', () =>\n manifest.getMainActivity(manifestFile),\n );\n let packageName = mainActivity.packageName;\n if (!packageName) {\n // if no package name in AndroidManifest, look into gradle script\n packageName = gradle.getNamespace(appFile);\n }\n const activityName = mainActivity.activityName;\n if (!activityName || !packageName) {\n clack.log.warn(\n \"Could not find Activity with intent action MAIN. You'll have to manually verify the setup.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify\",\n );\n } else {\n const packageNameStable = packageName;\n const activityFile = traceStep('Find Main Activity Source File', () =>\n codetools.findActivitySourceFile(appDir, packageNameStable, activityName),\n );\n\n const activityPatched = traceStep('Patch Main Activity', () =>\n codetools.patchMainActivity(activityFile),\n );\n if (!activityPatched) {\n clack.log.warn(\n \"Could not patch main activity. You'll have to manually verify the setup.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify\",\n );\n }\n }\n\n // ======== STEP 4. Add sentry-cli config file ============\n clack.log.step(\n `Configuring ${chalk.bold('proguard mappings upload')} via the ${chalk.cyan(\n 'sentry.properties',\n )} file.`,\n );\n await traceStep('Add SentryCli Config', () =>\n addSentryCliConfig(authToken, proguardMappingCliSetupConfig),\n );\n\n // ======== OUTRO ========\n clack.outro(`\n${chalk.greenBright('Successfully installed the Sentry Android SDK!')}\n\n${chalk.cyan(\n 'You can validate your setup by launching your application and checking Sentry issues page afterwards',\n)}\n\nCheck out the SDK documentation for further configuration:\nhttps://docs.sentry.io/platforms/android/\n `);\n}\n\n//find files with the given extension\nfunction findFilesWithExtensions(\n dir: string,\n extensions: string[],\n filesWithExtensions: string[] = [],\n): string[] {\n const cwd = process.cwd();\n const files = fs.readdirSync(dir, { withFileTypes: true });\n for (const file of files) {\n if (file.isDirectory()) {\n const childDir = path.join(dir, file.name);\n findFilesWithExtensions(childDir, extensions, filesWithExtensions);\n } else if (extensions.some((ext) => file.name.endsWith(ext))) {\n filesWithExtensions.push(path.relative(cwd, path.join(dir, file.name)));\n }\n }\n return filesWithExtensions;\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Looks in src/main/java or src/main/kotlin for the specified {@link packageName} and
|
|
3
|
+
* {@link activityName} by concatenating them. For example:
|
|
4
|
+
*
|
|
5
|
+
* src/
|
|
6
|
+
* main/
|
|
7
|
+
* java/ or kotlin/
|
|
8
|
+
* my.package.name/
|
|
9
|
+
* ui/
|
|
10
|
+
* MainActivity.kt
|
|
11
|
+
*
|
|
12
|
+
* src/main/java can contain both .java and .kt sources, whilst src/main/kotlin only .kt
|
|
13
|
+
*
|
|
14
|
+
* @param appDir
|
|
15
|
+
* @param packageName
|
|
16
|
+
* @param activityName
|
|
17
|
+
* @returns path to the Main Activity
|
|
18
|
+
*/
|
|
19
|
+
export declare function findActivitySourceFile(appDir: string, packageName: string, activityName: string): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Patches Main Activity with the test error code snippet by the specified path {@link activityFile}.
|
|
22
|
+
* Finds activity's `onCreate` method, adds the snippet and necessary imports.
|
|
23
|
+
*
|
|
24
|
+
* ```kotlin
|
|
25
|
+
* import something
|
|
26
|
+
* import something.something
|
|
27
|
+
* import io.sentry.Sentry <-- this is added by us
|
|
28
|
+
*
|
|
29
|
+
* override fun onCreate(savedInstanceState: Bundle?) {
|
|
30
|
+
* super.onCreate(savedInstanceState)
|
|
31
|
+
* // the snippet goes here <--
|
|
32
|
+
* doSomething()
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param activityFile
|
|
37
|
+
* @returns true if successfully patched, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export declare function patchMainActivity(activityFile: string | undefined): boolean;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
26
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
27
|
+
if (ar || !(i in from)) {
|
|
28
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
29
|
+
ar[i] = from[i];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.patchMainActivity = exports.findActivitySourceFile = void 0;
|
|
39
|
+
var fs = __importStar(require("fs"));
|
|
40
|
+
var path = __importStar(require("path"));
|
|
41
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
42
|
+
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
43
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
44
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
var templates_1 = require("./templates");
|
|
46
|
+
var ast_utils_1 = require("../utils/ast-utils");
|
|
47
|
+
/**
|
|
48
|
+
* Looks in src/main/java or src/main/kotlin for the specified {@link packageName} and
|
|
49
|
+
* {@link activityName} by concatenating them. For example:
|
|
50
|
+
*
|
|
51
|
+
* src/
|
|
52
|
+
* main/
|
|
53
|
+
* java/ or kotlin/
|
|
54
|
+
* my.package.name/
|
|
55
|
+
* ui/
|
|
56
|
+
* MainActivity.kt
|
|
57
|
+
*
|
|
58
|
+
* src/main/java can contain both .java and .kt sources, whilst src/main/kotlin only .kt
|
|
59
|
+
*
|
|
60
|
+
* @param appDir
|
|
61
|
+
* @param packageName
|
|
62
|
+
* @param activityName
|
|
63
|
+
* @returns path to the Main Activity
|
|
64
|
+
*/
|
|
65
|
+
function findActivitySourceFile(appDir, packageName, activityName) {
|
|
66
|
+
var javaSrcDir = path.join(appDir, 'src', 'main', 'java');
|
|
67
|
+
var possibleActivityPath;
|
|
68
|
+
// if activity name starts with a dot, this means we need to concat packagename with it, otherwise
|
|
69
|
+
// the package name is already specified in the activity name itself
|
|
70
|
+
var packageNameParts = activityName.startsWith('.')
|
|
71
|
+
? packageName.split('.')
|
|
72
|
+
: [];
|
|
73
|
+
var activityNameParts = activityName.split('.');
|
|
74
|
+
if (fs.existsSync(javaSrcDir)) {
|
|
75
|
+
possibleActivityPath = (0, ast_utils_1.findFile)(path.join.apply(path, __spreadArray(__spreadArray([javaSrcDir], packageNameParts, false), activityNameParts, false)), ['.kt', '.java']);
|
|
76
|
+
}
|
|
77
|
+
if (!possibleActivityPath || !fs.existsSync(possibleActivityPath)) {
|
|
78
|
+
var kotlinSrcDir = path.join(appDir, 'src', 'main', 'kotlin');
|
|
79
|
+
if (fs.existsSync(kotlinSrcDir)) {
|
|
80
|
+
possibleActivityPath = (0, ast_utils_1.findFile)(path.join.apply(path, __spreadArray(__spreadArray([kotlinSrcDir], packageNameParts, false), activityNameParts, false)), ['.kt']);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return possibleActivityPath;
|
|
84
|
+
}
|
|
85
|
+
exports.findActivitySourceFile = findActivitySourceFile;
|
|
86
|
+
/**
|
|
87
|
+
* Patches Main Activity with the test error code snippet by the specified path {@link activityFile}.
|
|
88
|
+
* Finds activity's `onCreate` method, adds the snippet and necessary imports.
|
|
89
|
+
*
|
|
90
|
+
* ```kotlin
|
|
91
|
+
* import something
|
|
92
|
+
* import something.something
|
|
93
|
+
* import io.sentry.Sentry <-- this is added by us
|
|
94
|
+
*
|
|
95
|
+
* override fun onCreate(savedInstanceState: Bundle?) {
|
|
96
|
+
* super.onCreate(savedInstanceState)
|
|
97
|
+
* // the snippet goes here <--
|
|
98
|
+
* doSomething()
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @param activityFile
|
|
103
|
+
* @returns true if successfully patched, false otherwise
|
|
104
|
+
*/
|
|
105
|
+
function patchMainActivity(activityFile) {
|
|
106
|
+
if (!activityFile || !fs.existsSync(activityFile)) {
|
|
107
|
+
clack.log.warn('No main activity source file found in filesystem.');
|
|
108
|
+
Sentry.captureException('No main activity source file');
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
var activityContent = fs.readFileSync(activityFile, 'utf8');
|
|
112
|
+
if (/import\s+io\.sentry\.Sentry;?/i.test(activityContent)) {
|
|
113
|
+
// sentry is already configured
|
|
114
|
+
clack.log.success(chalk_1.default.greenBright("".concat(chalk_1.default.bold('Main Activity'), " is already patched with test error snippet.")));
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
var importRegex = /import\s+[\w.]+;?/gim;
|
|
118
|
+
var importsMatch = importRegex.exec(activityContent);
|
|
119
|
+
var importIndex = 0;
|
|
120
|
+
while (importsMatch) {
|
|
121
|
+
importIndex = importsMatch.index + importsMatch[0].length + 1;
|
|
122
|
+
importsMatch = importRegex.exec(activityContent);
|
|
123
|
+
}
|
|
124
|
+
var newActivityContent;
|
|
125
|
+
if (activityFile.endsWith('.kt')) {
|
|
126
|
+
newActivityContent =
|
|
127
|
+
activityContent.slice(0, importIndex) +
|
|
128
|
+
templates_1.sentryImportKt +
|
|
129
|
+
activityContent.slice(importIndex);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
newActivityContent =
|
|
133
|
+
activityContent.slice(0, importIndex) +
|
|
134
|
+
templates_1.sentryImport +
|
|
135
|
+
activityContent.slice(importIndex);
|
|
136
|
+
}
|
|
137
|
+
var onCreateMatch = /super\.onCreate\(.*?\);?/i.exec(newActivityContent);
|
|
138
|
+
if (!onCreateMatch) {
|
|
139
|
+
clack.log.warn('No onCreate method found in main activity.');
|
|
140
|
+
Sentry.captureException('No onCreate method');
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
var onCreateIndex = onCreateMatch.index + onCreateMatch[0].length;
|
|
144
|
+
if (activityFile.endsWith('.kt')) {
|
|
145
|
+
newActivityContent =
|
|
146
|
+
newActivityContent.slice(0, onCreateIndex) +
|
|
147
|
+
templates_1.testErrorSnippetKt +
|
|
148
|
+
newActivityContent.slice(onCreateIndex);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
newActivityContent =
|
|
152
|
+
newActivityContent.slice(0, onCreateIndex) +
|
|
153
|
+
templates_1.testErrorSnippet +
|
|
154
|
+
newActivityContent.slice(onCreateIndex);
|
|
155
|
+
}
|
|
156
|
+
fs.writeFileSync(activityFile, newActivityContent, 'utf8');
|
|
157
|
+
clack.log.success(chalk_1.default.greenBright("Patched ".concat(chalk_1.default.bold('Main Activity'), " with the Sentry test error snippet.")));
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
exports.patchMainActivity = patchMainActivity;
|
|
161
|
+
//# sourceMappingURL=code-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-tools.js","sourceRoot":"","sources":["../../../src/android/code-tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,yCAA6B;AAC7B,mDAAuC;AACvC,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAC1B,yCAKqB;AACrB,gDAA8C;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,sBAAsB,CACpC,MAAc,EACd,WAAmB,EACnB,YAAoB;IAEpB,IAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5D,IAAI,oBAAoB,CAAC;IACzB,kGAAkG;IAClG,oEAAoE;IACpE,IAAM,gBAAgB,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;QACnD,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC;QACxB,CAAC,CAAC,EAAE,CAAC;IACP,IAAM,iBAAiB,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAElD,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;QAC7B,oBAAoB,GAAG,IAAA,oBAAQ,EAC7B,IAAI,CAAC,IAAI,OAAT,IAAI,+BAAM,UAAU,GAAK,gBAAgB,UAAK,iBAAiB,WAC/D,CAAC,KAAK,EAAE,OAAO,CAAC,CACjB,CAAC;KACH;IAED,IAAI,CAAC,oBAAoB,IAAI,CAAC,EAAE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AE3D,KAAK,CAAC,GAAG,CAAC,OAAO,CACf,eAAK,CAAC,WAAW,CACf,kBAAW,eAAK,CAAC,IAAI,CACnB,eAAe,CAChB,yCAAsC,CACxC,CACF,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAvED,8CAuEC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as Sentry from '@sentry/node';\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport {\n sentryImport,\n sentryImportKt,\n testErrorSnippet,\n testErrorSnippetKt,\n} from './templates';\nimport { findFile } from '../utils/ast-utils';\n\n/**\n * Looks in src/main/java or src/main/kotlin for the specified {@link packageName} and\n * {@link activityName} by concatenating them. For example:\n *\n * src/\n * main/\n * java/ or kotlin/\n * my.package.name/\n * ui/\n * MainActivity.kt\n *\n * src/main/java can contain both .java and .kt sources, whilst src/main/kotlin only .kt\n *\n * @param appDir\n * @param packageName\n * @param activityName\n * @returns path to the Main Activity\n */\nexport function findActivitySourceFile(\n appDir: string,\n packageName: string,\n activityName: string,\n): string | undefined {\n const javaSrcDir = path.join(appDir, 'src', 'main', 'java');\n let possibleActivityPath;\n // if activity name starts with a dot, this means we need to concat packagename with it, otherwise\n // the package name is already specified in the activity name itself\n const packageNameParts = activityName.startsWith('.')\n ? packageName.split('.')\n : [];\n const activityNameParts = activityName.split('.');\n\n if (fs.existsSync(javaSrcDir)) {\n possibleActivityPath = findFile(\n path.join(javaSrcDir, ...packageNameParts, ...activityNameParts),\n ['.kt', '.java'],\n );\n }\n\n if (!possibleActivityPath || !fs.existsSync(possibleActivityPath)) {\n const kotlinSrcDir = path.join(appDir, 'src', 'main', 'kotlin');\n if (fs.existsSync(kotlinSrcDir)) {\n possibleActivityPath = findFile(\n path.join(kotlinSrcDir, ...packageNameParts, ...activityNameParts),\n ['.kt'],\n );\n }\n }\n return possibleActivityPath;\n}\n\n/**\n * Patches Main Activity with the test error code snippet by the specified path {@link activityFile}.\n * Finds activity's `onCreate` method, adds the snippet and necessary imports.\n *\n * ```kotlin\n * import something\n * import something.something\n * import io.sentry.Sentry <-- this is added by us\n *\n * override fun onCreate(savedInstanceState: Bundle?) {\n * super.onCreate(savedInstanceState)\n * // the snippet goes here <--\n * doSomething()\n * }\n * ```\n *\n * @param activityFile\n * @returns true if successfully patched, false otherwise\n */\nexport function patchMainActivity(activityFile: string | undefined): boolean {\n if (!activityFile || !fs.existsSync(activityFile)) {\n clack.log.warn('No main activity source file found in filesystem.');\n Sentry.captureException('No main activity source file');\n return false;\n }\n\n const activityContent = fs.readFileSync(activityFile, 'utf8');\n\n if (/import\\s+io\\.sentry\\.Sentry;?/i.test(activityContent)) {\n // sentry is already configured\n clack.log.success(\n chalk.greenBright(\n `${chalk.bold(\n 'Main Activity',\n )} is already patched with test error snippet.`,\n ),\n );\n return true;\n }\n\n const importRegex = /import\\s+[\\w.]+;?/gim;\n let importsMatch = importRegex.exec(activityContent);\n let importIndex = 0;\n while (importsMatch) {\n importIndex = importsMatch.index + importsMatch[0].length + 1;\n importsMatch = importRegex.exec(activityContent);\n }\n let newActivityContent;\n if (activityFile.endsWith('.kt')) {\n newActivityContent =\n activityContent.slice(0, importIndex) +\n sentryImportKt +\n activityContent.slice(importIndex);\n } else {\n newActivityContent =\n activityContent.slice(0, importIndex) +\n sentryImport +\n activityContent.slice(importIndex);\n }\n\n const onCreateMatch = /super\\.onCreate\\(.*?\\);?/i.exec(newActivityContent);\n if (!onCreateMatch) {\n clack.log.warn('No onCreate method found in main activity.');\n Sentry.captureException('No onCreate method');\n return false;\n }\n\n const onCreateIndex = onCreateMatch.index + onCreateMatch[0].length;\n if (activityFile.endsWith('.kt')) {\n newActivityContent =\n newActivityContent.slice(0, onCreateIndex) +\n testErrorSnippetKt +\n newActivityContent.slice(onCreateIndex);\n } else {\n newActivityContent =\n newActivityContent.slice(0, onCreateIndex) +\n testErrorSnippet +\n newActivityContent.slice(onCreateIndex);\n }\n fs.writeFileSync(activityFile, newActivityContent, 'utf8');\n\n clack.log.success(\n chalk.greenBright(\n `Patched ${chalk.bold(\n 'Main Activity',\n )} with the Sentry test error snippet.`,\n ),\n );\n\n return true;\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Gradle project may contain multiple modules, some of them may be applications, some of them may be libraries.
|
|
3
|
+
* We are only interested in applications. For example:
|
|
4
|
+
*
|
|
5
|
+
* myproject/
|
|
6
|
+
* app/
|
|
7
|
+
* lib1/
|
|
8
|
+
* lib2/
|
|
9
|
+
* wearApp/
|
|
10
|
+
*
|
|
11
|
+
* In this case^ we are interested in app/ and wearApp/
|
|
12
|
+
*
|
|
13
|
+
* @param buildGradleFiles a list of build.gradle(.kts) paths that contain the com.android.application plugin
|
|
14
|
+
* @returns the selected project for setting up
|
|
15
|
+
*/
|
|
16
|
+
export declare function selectAppFile(buildGradleFiles: string[]): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Patches a build.gradle(.kts) file that contains `com.android.application` plugin.
|
|
19
|
+
* There are multiple cases we have to handle here:
|
|
20
|
+
* - An existing `plugins {}` block:
|
|
21
|
+
* - We just have to add our plugin inside the block
|
|
22
|
+
* - No existing `plugins {}` block
|
|
23
|
+
* - We have to add the entire block in the beginning of the file, BUT *after imports*
|
|
24
|
+
*
|
|
25
|
+
* For example (2nd case):
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* import net.ltgt.gradle.errorprone.errorprone
|
|
29
|
+
*
|
|
30
|
+
* // our plugins block goes here <--
|
|
31
|
+
* plugins {
|
|
32
|
+
* id("io.sentry.android.gradle") version "3.12.0"
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* apply(plugin = "com.android.application")
|
|
36
|
+
*
|
|
37
|
+
* android {
|
|
38
|
+
* ...
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* In the end we run `./gradlew` to verify the config is build-able and not broken.
|
|
43
|
+
*
|
|
44
|
+
* @param appFile the selected Gradle application project
|
|
45
|
+
* @returns true if successfully added Sentry Gradle config, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
export declare function addGradlePlugin(appFile: string, orgSlug: string, projectSlug: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Looks for the applications packageName (namespace) in the specified build.gradle(.kts) file.
|
|
50
|
+
*
|
|
51
|
+
* ```
|
|
52
|
+
* android {
|
|
53
|
+
* namespace 'my.package.name' <-- this is what we extract
|
|
54
|
+
*
|
|
55
|
+
* compileSdkVersion = 31
|
|
56
|
+
* ...
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
* @param appFile
|
|
60
|
+
* @returns the packageName(namespace) of the app if available
|
|
61
|
+
*/
|
|
62
|
+
export declare function getNamespace(appFile: string): string | undefined;
|