@sentry/wizard 3.5.0 → 3.6.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/bin.ts +8 -9
  3. package/dist/bin.js +8 -5
  4. package/dist/bin.js.map +1 -1
  5. package/dist/lib/Constants.d.ts +2 -0
  6. package/dist/lib/Constants.js +5 -0
  7. package/dist/lib/Constants.js.map +1 -1
  8. package/dist/lib/Helper/Wizard.js +2 -0
  9. package/dist/lib/Helper/Wizard.js.map +1 -1
  10. package/dist/lib/Helper/__tests__/SentryCli.js +1 -0
  11. package/dist/lib/Helper/__tests__/SentryCli.js.map +1 -1
  12. package/dist/lib/Steps/ChooseIntegration.js +4 -0
  13. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  14. package/dist/lib/Steps/Integrations/Apple.d.ts +10 -0
  15. package/dist/lib/Steps/Integrations/Apple.js +92 -0
  16. package/dist/lib/Steps/Integrations/Apple.js.map +1 -0
  17. package/dist/lib/Steps/Integrations/NextJsShim.js +1 -0
  18. package/dist/lib/Steps/Integrations/NextJsShim.js.map +1 -1
  19. package/dist/lib/Steps/Integrations/SourceMapsShim.js +1 -0
  20. package/dist/lib/Steps/Integrations/SourceMapsShim.js.map +1 -1
  21. package/dist/lib/Steps/Integrations/SvelteKitShim.js +1 -0
  22. package/dist/lib/Steps/Integrations/SvelteKitShim.js.map +1 -1
  23. package/dist/package.json +2 -2
  24. package/dist/src/apple/apple-wizard.d.ts +2 -0
  25. package/dist/src/apple/apple-wizard.js +197 -0
  26. package/dist/src/apple/apple-wizard.js.map +1 -0
  27. package/dist/src/apple/code-tools.d.ts +1 -0
  28. package/dist/src/apple/code-tools.js +100 -0
  29. package/dist/src/apple/code-tools.js.map +1 -0
  30. package/dist/src/apple/templates.d.ts +4 -0
  31. package/dist/src/apple/templates.js +19 -0
  32. package/dist/src/apple/templates.js.map +1 -0
  33. package/dist/src/apple/xcode-manager.d.ts +4 -0
  34. package/dist/src/apple/xcode-manager.js +145 -0
  35. package/dist/src/apple/xcode-manager.js.map +1 -0
  36. package/dist/src/sourcemaps/sourcemaps-wizard.js +143 -71
  37. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  38. package/dist/src/sourcemaps/tools/angular.d.ts +1 -0
  39. package/dist/src/sourcemaps/tools/angular.js +76 -0
  40. package/dist/src/sourcemaps/tools/angular.js.map +1 -0
  41. package/dist/src/sourcemaps/tools/esbuild.js +2 -1
  42. package/dist/src/sourcemaps/tools/esbuild.js.map +1 -1
  43. package/dist/src/sourcemaps/tools/rollup.js +2 -1
  44. package/dist/src/sourcemaps/tools/rollup.js.map +1 -1
  45. package/dist/src/sourcemaps/tools/sentry-cli.js +2 -1
  46. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  47. package/dist/src/sourcemaps/tools/vite.js +2 -1
  48. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  49. package/dist/src/sourcemaps/tools/webpack.js +2 -1
  50. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  51. package/dist/src/sourcemaps/utils/detect-tool.d.ts +3 -0
  52. package/dist/src/sourcemaps/utils/detect-tool.js +73 -0
  53. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -0
  54. package/dist/src/sourcemaps/utils/other-wizards.d.ts +4 -0
  55. package/dist/src/sourcemaps/utils/other-wizards.js +183 -0
  56. package/dist/src/sourcemaps/utils/other-wizards.js.map +1 -0
  57. package/dist/src/sourcemaps/utils/sdk-version.js +14 -13
  58. package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
  59. package/dist/src/sveltekit/sveltekit-wizard.js +2 -1
  60. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  61. package/dist/src/telemetry.d.ts +1 -0
  62. package/dist/src/telemetry.js +7 -1
  63. package/dist/src/telemetry.js.map +1 -1
  64. package/dist/src/utils/bash.d.ts +3 -0
  65. package/dist/src/utils/bash.js +118 -0
  66. package/dist/src/utils/bash.js.map +1 -0
  67. package/dist/src/utils/clack-utils.d.ts +9 -8
  68. package/dist/src/utils/clack-utils.js +54 -21
  69. package/dist/src/utils/clack-utils.js.map +1 -1
  70. package/dist/src/utils/package-json.d.ts +19 -0
  71. package/dist/src/utils/package-json.js +29 -0
  72. package/dist/src/utils/package-json.js.map +1 -0
  73. package/dist/src/utils/types.d.ts +4 -0
  74. package/dist/src/utils/types.js.map +1 -1
  75. package/lib/Constants.ts +6 -0
  76. package/lib/Helper/Wizard.ts +3 -0
  77. package/lib/Helper/__tests__/SentryCli.ts +2 -1
  78. package/lib/Steps/ChooseIntegration.ts +4 -0
  79. package/lib/Steps/Integrations/Apple.ts +27 -0
  80. package/lib/Steps/Integrations/NextJsShim.ts +1 -0
  81. package/lib/Steps/Integrations/SourceMapsShim.ts +1 -0
  82. package/lib/Steps/Integrations/SvelteKitShim.ts +1 -0
  83. package/package-lock.json +8910 -0
  84. package/package.json +2 -2
  85. package/src/apple/apple-wizard.ts +150 -0
  86. package/src/apple/code-tools.ts +81 -0
  87. package/src/apple/templates.ts +39 -0
  88. package/src/apple/xcode-manager.ts +147 -0
  89. package/src/sourcemaps/sourcemaps-wizard.ts +156 -91
  90. package/src/sourcemaps/tools/angular.ts +42 -0
  91. package/src/sourcemaps/tools/esbuild.ts +1 -1
  92. package/src/sourcemaps/tools/rollup.ts +2 -4
  93. package/src/sourcemaps/tools/sentry-cli.ts +1 -1
  94. package/src/sourcemaps/tools/vite.ts +1 -1
  95. package/src/sourcemaps/tools/webpack.ts +1 -1
  96. package/src/sourcemaps/utils/detect-tool.ts +41 -0
  97. package/src/sourcemaps/utils/other-wizards.ts +148 -0
  98. package/src/sourcemaps/utils/sdk-version.ts +9 -16
  99. package/src/sveltekit/sveltekit-wizard.ts +1 -1
  100. package/src/telemetry.ts +8 -0
  101. package/src/utils/bash.ts +44 -0
  102. package/src/utils/clack-utils.ts +44 -37
  103. package/src/utils/package-json.ts +45 -0
  104. package/src/utils/types.ts +5 -0
@@ -0,0 +1,197 @@
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.runAppleWizard = void 0;
66
+ /* eslint-disable max-lines */
67
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
68
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
69
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
70
+ /* eslint-disable @typescript-eslint/no-unused-vars */
71
+ // @ts-ignore - clack is ESM and TS complains about that. It works though
72
+ var prompts_1 = __importDefault(require("@clack/prompts"));
73
+ var fs = __importStar(require("fs"));
74
+ var path = __importStar(require("path"));
75
+ var xcManager = __importStar(require("./xcode-manager"));
76
+ var codeTools = __importStar(require("./code-tools"));
77
+ var bash = __importStar(require("../utils/bash"));
78
+ var Sentry = __importStar(require("@sentry/node"));
79
+ var telemetry_1 = require("../telemetry");
80
+ var xcode = require('xcode');
81
+ /* eslint-enable @typescript-eslint/no-unused-vars */
82
+ var clack_utils_1 = require("../utils/clack-utils");
83
+ function runAppleWizard(options) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ return __generator(this, function (_a) {
86
+ return [2 /*return*/, (0, telemetry_1.withTelemetry)({
87
+ enabled: options.telemetryEnabled,
88
+ integration: 'ios',
89
+ }, function () { return runAppleWizardWithTelementry(options); })];
90
+ });
91
+ });
92
+ }
93
+ exports.runAppleWizard = runAppleWizard;
94
+ function runAppleWizardWithTelementry(options) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var hasCli, projectDir, xcodeProjFiles, xcodeProjFile, pbxproj, _a, project, apiKey, projSource, codeAdded;
97
+ return __generator(this, function (_b) {
98
+ switch (_b.label) {
99
+ case 0:
100
+ (0, clack_utils_1.printWelcome)({
101
+ wizardName: 'Sentry Apple Wizard',
102
+ promoCode: options.promoCode,
103
+ });
104
+ hasCli = bash.hasSentryCLI();
105
+ Sentry.setTag('has-cli', hasCli);
106
+ if (!!hasCli) return [3 /*break*/, 4];
107
+ return [4 /*yield*/, (0, telemetry_1.traceStep)('Ask for SentryCLI', function () { return (0, clack_utils_1.askToInstallSentryCLI)(); })];
108
+ case 1:
109
+ if (!!(_b.sent())) return [3 /*break*/, 2];
110
+ prompts_1.default.log.warn("Without sentry-cli, you won't be able to upload debug symbols to Sentry. You can install it later by following the instructions at https://docs.sentry.io/cli/");
111
+ Sentry.setTag('CLI-Installed', false);
112
+ return [3 /*break*/, 4];
113
+ case 2: return [4 /*yield*/, bash.installSentryCLI()];
114
+ case 3:
115
+ _b.sent();
116
+ Sentry.setTag('CLI-Installed', true);
117
+ _b.label = 4;
118
+ case 4:
119
+ projectDir = process.cwd();
120
+ xcodeProjFiles = findFilesWithExtension(projectDir, '.xcodeproj');
121
+ if (!(!xcodeProjFiles || xcodeProjFiles.length === 0)) return [3 /*break*/, 6];
122
+ prompts_1.default.log.error('No Xcode project found. Please run this command from the root of your project.');
123
+ return [4 /*yield*/, (0, clack_utils_1.abort)()];
124
+ case 5:
125
+ _b.sent();
126
+ return [2 /*return*/];
127
+ case 6:
128
+ if (!(xcodeProjFiles.length === 1)) return [3 /*break*/, 7];
129
+ xcodeProjFile = xcodeProjFiles[0];
130
+ Sentry.setTag('multiple-projects', false);
131
+ return [3 /*break*/, 9];
132
+ case 7:
133
+ Sentry.setTag('multiple-projects', true);
134
+ return [4 /*yield*/, (0, telemetry_1.traceStep)('Choose Xcode project', function () {
135
+ return (0, clack_utils_1.askForItemSelection)(xcodeProjFiles, 'Which project do you want to add Sentry to?');
136
+ })];
137
+ case 8:
138
+ xcodeProjFile = (_b.sent()).value;
139
+ _b.label = 9;
140
+ case 9:
141
+ pbxproj = path.join(projectDir, xcodeProjFile, 'project.pbxproj');
142
+ if (!!fs.existsSync(pbxproj)) return [3 /*break*/, 11];
143
+ prompts_1.default.log.error("No pbxproj found at ".concat(pbxproj));
144
+ return [4 /*yield*/, (0, clack_utils_1.abort)()];
145
+ case 10:
146
+ _b.sent();
147
+ return [2 /*return*/];
148
+ case 11: return [4 /*yield*/, getSentryProjectAndApiKey(options.promoCode, options.url)];
149
+ case 12:
150
+ _a = _b.sent(), project = _a.project, apiKey = _a.apiKey;
151
+ (0, telemetry_1.traceStep)('Update Xcode project', function () {
152
+ xcManager.updateXcodeProject(pbxproj, project, apiKey, true, true);
153
+ });
154
+ projSource = path.join(projectDir, xcodeProjFile.replace('.xcodeproj', ''));
155
+ codeAdded = (0, telemetry_1.traceStep)('Add code snippet', function () {
156
+ return codeTools.addCodeSnippetToProject(projSource, project.keys[0].dsn.public);
157
+ });
158
+ if (!codeAdded) {
159
+ prompts_1.default.log.warn('Added the Sentry dependency to your project but could not add the Sentry code snippet. Please add the code snipped manually by following the docs: https://docs.sentry.io/platforms/apple/guides/ios/#configure');
160
+ return [2 /*return*/];
161
+ }
162
+ prompts_1.default.log.success('Sentry was successfully added to your project!');
163
+ return [2 /*return*/];
164
+ }
165
+ });
166
+ });
167
+ }
168
+ //Prompt for Sentry project and API key
169
+ function getSentryProjectAndApiKey(promoCode, url) {
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ var sentryUrl, _a, projects, apiKeys, selectedProject;
172
+ return __generator(this, function (_b) {
173
+ switch (_b.label) {
174
+ case 0: return [4 /*yield*/, (0, clack_utils_1.askForSelfHosted)(url)];
175
+ case 1:
176
+ sentryUrl = (_b.sent()).url;
177
+ return [4 /*yield*/, (0, clack_utils_1.askForWizardLogin)({
178
+ promoCode: promoCode,
179
+ url: sentryUrl,
180
+ platform: 'apple-ios',
181
+ })];
182
+ case 2:
183
+ _a = _b.sent(), projects = _a.projects, apiKeys = _a.apiKeys;
184
+ return [4 /*yield*/, (0, clack_utils_1.askForProjectSelection)(projects)];
185
+ case 3:
186
+ selectedProject = _b.sent();
187
+ return [2 /*return*/, { project: selectedProject, apiKey: apiKeys }];
188
+ }
189
+ });
190
+ });
191
+ }
192
+ //find files with the given extension
193
+ function findFilesWithExtension(dir, extension) {
194
+ var files = fs.readdirSync(dir);
195
+ return files.filter(function (file) { return file.endsWith(extension); });
196
+ }
197
+ //# sourceMappingURL=apple-wizard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apple-wizard.js","sourceRoot":"","sources":["../../../src/apple/apple-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,+DAA+D;AAC/D,4DAA4D;AAC5D,sDAAsD;AACtD,sDAAsD;AACtD,yEAAyE;AACzE,2DAAmC;AACnC,qCAAyB;AACzB,yCAA6B;AAC7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OAAA,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAxB,CAAwB,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["/* eslint-disable max-lines */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as xcManager from './xcode-manager';\nimport * as codeTools from './code-tools';\nimport * as bash from '../utils/bash';\nimport { WizardOptions } from '../utils/types';\nimport * as Sentry from '@sentry/node';\nimport { traceStep, withTelemetry } from '../telemetry';\n\nconst xcode = require('xcode');\n/* eslint-enable @typescript-eslint/no-unused-vars */\n\nimport {\n askForProjectSelection,\n askForSelfHosted,\n askForWizardLogin,\n askToInstallSentryCLI,\n SentryProjectData,\n printWelcome,\n abort,\n askForItemSelection,\n} from '../utils/clack-utils';\n\nexport async function runAppleWizard(options: WizardOptions): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'ios',\n },\n () => runAppleWizardWithTelementry(options),\n );\n}\n\nasync function runAppleWizardWithTelementry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry Apple Wizard',\n promoCode: options.promoCode,\n });\n\n const hasCli = bash.hasSentryCLI();\n Sentry.setTag('has-cli', hasCli);\n if (!hasCli) {\n if (\n !(await traceStep('Ask for SentryCLI', () => askToInstallSentryCLI()))\n ) {\n clack.log.warn(\n \"Without sentry-cli, you won't be able to upload debug symbols to Sentry. You can install it later by following the instructions at https://docs.sentry.io/cli/\",\n );\n Sentry.setTag('CLI-Installed', false);\n } else {\n await bash.installSentryCLI();\n Sentry.setTag('CLI-Installed', true);\n }\n }\n\n const projectDir = process.cwd();\n const xcodeProjFiles = findFilesWithExtension(projectDir, '.xcodeproj');\n\n if (!xcodeProjFiles || xcodeProjFiles.length === 0) {\n clack.log.error(\n 'No Xcode project found. Please run this command from the root of your project.',\n );\n await abort();\n return;\n }\n\n let xcodeProjFile;\n\n if (xcodeProjFiles.length === 1) {\n xcodeProjFile = xcodeProjFiles[0];\n Sentry.setTag('multiple-projects', false);\n } else {\n Sentry.setTag('multiple-projects', true);\n xcodeProjFile = (\n await traceStep('Choose Xcode project', () =>\n askForItemSelection(\n xcodeProjFiles,\n 'Which project do you want to add Sentry to?',\n ),\n )\n ).value;\n }\n\n const pbxproj = path.join(projectDir, xcodeProjFile, 'project.pbxproj');\n if (!fs.existsSync(pbxproj)) {\n clack.log.error(`No pbxproj found at ${pbxproj}`);\n await abort();\n return;\n }\n\n const { project, apiKey } = await getSentryProjectAndApiKey(\n options.promoCode,\n options.url,\n );\n\n traceStep('Update Xcode project', () => {\n xcManager.updateXcodeProject(pbxproj, project, apiKey, true, true);\n });\n\n const projSource = path.join(\n projectDir,\n xcodeProjFile.replace('.xcodeproj', ''),\n );\n const codeAdded = traceStep('Add code snippet', () => {\n return codeTools.addCodeSnippetToProject(\n projSource,\n project.keys[0].dsn.public,\n );\n });\n if (!codeAdded) {\n clack.log.warn(\n 'Added the Sentry dependency to your project but could not add the Sentry code snippet. Please add the code snipped manually by following the docs: https://docs.sentry.io/platforms/apple/guides/ios/#configure',\n );\n return;\n }\n\n clack.log.success('Sentry was successfully added to your project!');\n}\n\n//Prompt for Sentry project and API key\nasync function getSentryProjectAndApiKey(\n promoCode?: string,\n url?: string,\n): Promise<{ project: SentryProjectData; apiKey: { token: string } }> {\n const { url: sentryUrl } = await askForSelfHosted(url);\n\n const { projects, apiKeys } = await askForWizardLogin({\n promoCode: promoCode,\n url: sentryUrl,\n platform: 'apple-ios',\n });\n\n const selectedProject = await askForProjectSelection(projects);\n return { project: selectedProject, apiKey: apiKeys };\n}\n\n//find files with the given extension\nfunction findFilesWithExtension(dir: string, extension: string): string[] {\n const files = fs.readdirSync(dir);\n return files.filter((file) => file.endsWith(extension));\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function addCodeSnippetToProject(projPath: string, dsn: string): boolean;
@@ -0,0 +1,100 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.addCodeSnippetToProject = void 0;
27
+ var fs = __importStar(require("fs"));
28
+ var path = __importStar(require("path"));
29
+ var templates = __importStar(require("./templates"));
30
+ var Sentry = __importStar(require("@sentry/node"));
31
+ var swiftAppLaunchRegex = /(func\s+application\s*\(_\sapplication:[^,]+,\s*didFinishLaunchingWithOptions[^,]+:[^)]+\)\s+->\s+Bool\s+{)|(init\s*\([^)]*\)\s*{)/im;
32
+ var objcAppLaunchRegex = /-\s*\(BOOL\)\s*application:\s*\(UIApplication\s*\*\)\s*application\s+didFinishLaunchingWithOptions:\s*\(NSDictionary\s*\*\)\s*launchOptions\s*{/im;
33
+ var swiftUIRegex = /struct[^:]+:\s*App\s*{/im;
34
+ function isAppDelegateFile(filePath) {
35
+ var appLaunchRegex = filePath.toLowerCase().endsWith(".swift") ? swiftAppLaunchRegex : objcAppLaunchRegex;
36
+ var fileContent = fs.readFileSync(filePath, 'utf8');
37
+ return appLaunchRegex.test(fileContent) || swiftUIRegex.test(fileContent);
38
+ }
39
+ function findAppDidFinishLaunchingWithOptions(dir) {
40
+ var files = fs.readdirSync(dir);
41
+ //iterate over subdirectories later,
42
+ //the appdelegate usually is in the top level
43
+ var dirs = [];
44
+ for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
45
+ var file = files_1[_i];
46
+ var filePath = path.join(dir, file);
47
+ if (file.endsWith(".swift") || file.endsWith(".m") || file.endsWith(".mm")) {
48
+ if (isAppDelegateFile(filePath)) {
49
+ return filePath;
50
+ }
51
+ }
52
+ else if (!file.startsWith(".") && !file.endsWith(".xcodeproj") && !file.endsWith(".xcassets") && fs.lstatSync(filePath).isDirectory()) {
53
+ dirs.push(file);
54
+ }
55
+ }
56
+ for (var _a = 0, dirs_1 = dirs; _a < dirs_1.length; _a++) {
57
+ var dr = dirs_1[_a];
58
+ var result = findAppDidFinishLaunchingWithOptions(path.join(dir, dr));
59
+ if (result)
60
+ return result;
61
+ }
62
+ return null;
63
+ }
64
+ function addCodeSnippetToProject(projPath, dsn) {
65
+ var appDelegate = findAppDidFinishLaunchingWithOptions(projPath);
66
+ if (!appDelegate) {
67
+ return false;
68
+ }
69
+ var fileContent = fs.readFileSync(appDelegate, 'utf8');
70
+ var isSwift = appDelegate.toLowerCase().endsWith(".swift");
71
+ var appLaunchRegex = isSwift ? swiftAppLaunchRegex : objcAppLaunchRegex;
72
+ var importStatement = isSwift ? "import Sentry\n" : "@import Sentry;\n";
73
+ var checkForSentryInit = isSwift ? "SentrySDK.start" : "[SentrySDK start";
74
+ var codeSnippet = isSwift ? templates.getSwiftSnippet(dsn) : templates.getObjcSnippet(dsn);
75
+ Sentry.setTag("code-language", isSwift ? "swift" : "objc");
76
+ Sentry.setTag("ui-engine", swiftUIRegex.test(fileContent) ? "swiftui" : "uikit");
77
+ if (fileContent.includes(checkForSentryInit)) {
78
+ //already initialized
79
+ return true;
80
+ }
81
+ var match = appLaunchRegex.exec(fileContent);
82
+ if (!match) {
83
+ var swiftUIMatch = swiftUIRegex.exec(fileContent);
84
+ if (!swiftUIMatch) {
85
+ return false;
86
+ }
87
+ //Is SwiftUI with no init
88
+ match = swiftUIMatch;
89
+ codeSnippet = " init() {\n".concat(codeSnippet, " }");
90
+ }
91
+ var insertIndex = match.index + match[0].length;
92
+ var newFileContent = (fileContent.indexOf(importStatement) >= 0 ? "" : importStatement) +
93
+ fileContent.slice(0, insertIndex) + "\n" +
94
+ codeSnippet +
95
+ fileContent.slice(insertIndex);
96
+ fs.writeFileSync(appDelegate, newFileContent, 'utf8');
97
+ return true;
98
+ }
99
+ exports.addCodeSnippetToProject = addCodeSnippetToProject;
100
+ //# sourceMappingURL=code-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-tools.js","sourceRoot":"","sources":["../../../src/apple/code-tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,yCAA6B;AAC7B,qDAAyC;AACzC,mDAAuC;AAEvC,IAAM,mBAAmB,GAAG,sIAAsI,CAAC;AACnK,IAAM,kBAAkB,GAAG,mJAAmJ,CAAC;AAC/K,IAAM,YAAY,GAAG,0BAA0B,CAAC;AAEhD,SAAS,iBAAiB,CAAC,QAAgB;IACvC,IAAM,cAAc,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAE5G,IAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtD,OAAO,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC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AAG,YAAY,CAAC;QACrB,WAAW,GAAG,wBAAiB,WAAW,UAAO,CAAC;KACrD;IAED,IAAM,WAAW,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAClD,IAAM,cAAc,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;QACrF,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,IAAI;QACxC,WAAW;QACX,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACnC,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAEtD,OAAO,IAAI,CAAC;AAChB,CAAC;AAxCD,0DAwCC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as templates from './templates';\nimport * as Sentry from '@sentry/node';\n\nconst swiftAppLaunchRegex = /(func\\s+application\\s*\\(_\\sapplication:[^,]+,\\s*didFinishLaunchingWithOptions[^,]+:[^)]+\\)\\s+->\\s+Bool\\s+{)|(init\\s*\\([^)]*\\)\\s*{)/im;\nconst objcAppLaunchRegex = /-\\s*\\(BOOL\\)\\s*application:\\s*\\(UIApplication\\s*\\*\\)\\s*application\\s+didFinishLaunchingWithOptions:\\s*\\(NSDictionary\\s*\\*\\)\\s*launchOptions\\s*{/im;\nconst swiftUIRegex = /struct[^:]+:\\s*App\\s*{/im;\n\nfunction isAppDelegateFile(filePath: string): boolean {\n const appLaunchRegex = filePath.toLowerCase().endsWith(\".swift\") ? swiftAppLaunchRegex : objcAppLaunchRegex;\n\n const fileContent = fs.readFileSync(filePath, 'utf8');\n return appLaunchRegex.test(fileContent) || swiftUIRegex.test(fileContent);\n}\n\nfunction findAppDidFinishLaunchingWithOptions(dir: string): string | null {\n const files = fs.readdirSync(dir);\n //iterate over subdirectories later, \n //the appdelegate usually is in the top level\n const dirs: string[] = [];\n\n for (const file of files) {\n const filePath = path.join(dir, file);\n if (file.endsWith(\".swift\") || file.endsWith(\".m\") || file.endsWith(\".mm\")) {\n if (isAppDelegateFile(filePath)) {\n return filePath;\n }\n } else if (!file.startsWith(\".\") && !file.endsWith(\".xcodeproj\") && !file.endsWith(\".xcassets\") && fs.lstatSync(filePath).isDirectory()) {\n dirs.push(file);\n }\n }\n\n for (const dr of dirs) {\n const result = findAppDidFinishLaunchingWithOptions(path.join(dir, dr));\n if (result) return result;\n }\n return null;\n}\n\nexport function addCodeSnippetToProject(projPath: string, dsn: string): boolean {\n const appDelegate = findAppDidFinishLaunchingWithOptions(projPath);\n if (!appDelegate) {\n return false;\n }\n\n const fileContent = fs.readFileSync(appDelegate, 'utf8');\n const isSwift = appDelegate.toLowerCase().endsWith(\".swift\");\n const appLaunchRegex = isSwift ? swiftAppLaunchRegex : objcAppLaunchRegex;\n const importStatement = isSwift ? \"import Sentry\\n\" : \"@import Sentry;\\n\";\n const checkForSentryInit = isSwift ? \"SentrySDK.start\" : \"[SentrySDK start\";\n let codeSnippet = isSwift ? templates.getSwiftSnippet(dsn) : templates.getObjcSnippet(dsn);\n\n Sentry.setTag(\"code-language\", isSwift ? \"swift\" : \"objc\");\n Sentry.setTag(\"ui-engine\", swiftUIRegex.test(fileContent) ? \"swiftui\" : \"uikit\");\n\n if (fileContent.includes(checkForSentryInit)) {\n //already initialized\n return true;\n }\n\n let match = appLaunchRegex.exec(fileContent);\n if (!match) {\n const swiftUIMatch = swiftUIRegex.exec(fileContent)\n if (!swiftUIMatch) {\n return false;\n }\n //Is SwiftUI with no init\n match = swiftUIMatch;\n codeSnippet = ` init() {\\n${codeSnippet} }`;\n }\n\n const insertIndex = match.index + match[0].length;\n const newFileContent = (fileContent.indexOf(importStatement) >= 0 ? \"\" : importStatement) +\n fileContent.slice(0, insertIndex) + \"\\n\" +\n codeSnippet +\n fileContent.slice(insertIndex);\n fs.writeFileSync(appDelegate, newFileContent, 'utf8');\n\n return true;\n}"]}
@@ -0,0 +1,4 @@
1
+ export declare function getRunScriptTemplate(orgSlug: string, projectSlug: string, apiKey: string, uploadSource?: boolean): string;
2
+ export declare const scriptInputPath = "\"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}\"";
3
+ export declare function getSwiftSnippet(dsn: string): string;
4
+ export declare function getObjcSnippet(dsn: string): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getObjcSnippet = exports.getSwiftSnippet = exports.scriptInputPath = exports.getRunScriptTemplate = void 0;
4
+ function getRunScriptTemplate(orgSlug, projectSlug, apiKey, uploadSource) {
5
+ if (uploadSource === void 0) { uploadSource = true; }
6
+ // eslint-disable-next-line no-useless-escape
7
+ return "# This script is responsable to upload debug symbols and source context for Sentry.\\nif which sentry-cli >/dev/null; then\\nexport SENTRY_ORG=".concat(orgSlug, "\\nexport SENTRY_PROJECT=").concat(projectSlug, "\\nexport SENTRY_AUTH_TOKEN=").concat(apiKey, "\\nERROR=$(sentry-cli debug-files upload ").concat(uploadSource ? "--include-sources " : "", "\"$DWARF_DSYM_FOLDER_PATH\" 2>&1 >/dev/null)\\nif [ ! $? -eq 0 ]; then\\necho \"warning: sentry-cli - $ERROR\"\\nfi\\nelse\\necho \"warning: sentry-cli not installed, download from https://github.com/getsentry/sentry-cli/releases\"\\nfi\\n");
8
+ }
9
+ exports.getRunScriptTemplate = getRunScriptTemplate;
10
+ exports.scriptInputPath = "\"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}\"";
11
+ function getSwiftSnippet(dsn) {
12
+ return " SentrySDK.start { options in\n options.dsn = \"".concat(dsn, "\"\n options.debug = true // Enabled debug when first installing is always helpful\n options.enableTracing = true \n\n // Uncomment the following lines to add more data to your events\n // options.attachScreenshot = true // This adds a screenshot to the error events\n // options.attachViewHierarchy = true // This adds the view hierarchy to the error events\n }\n // Remove the next line after confirming that your Sentry integration is working.\n SentrySDK.capture(message: \"This app uses Sentry! :)\")\n");
13
+ }
14
+ exports.getSwiftSnippet = getSwiftSnippet;
15
+ function getObjcSnippet(dsn) {
16
+ return " [SentrySDK startWithConfigureOptions:^(SentryOptions * options) {\n options.dsn = @\"".concat(dsn, "\";\n options.debug = YES; // Enabled debug when first installing is always helpful\n options.enableTracing = YES;\n\n //Uncomment the following lines to add more data to your events\n //options.attachScreenshot = YES; //This will add a screenshot to the error events\n //options.attachViewHierarchy = YES; //This will add the view hierarchy to the error events\n }];\n //Remove the next line after confirming that your Sentry integration is working.\n [SentrySDK captureMessage:@\"This app uses Sentry!\"];\n");
17
+ }
18
+ exports.getObjcSnippet = getObjcSnippet;
19
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/apple/templates.ts"],"names":[],"mappings":";;;AAAA,SAAgB,oBAAoB,CAChC,OAAe,EACf,WAAmB,EACnB,MAAc,EACd,YAAmB;IAAnB,6BAAA,EAAA,mBAAmB;IAEnB,6CAA6C;IAC7C,OAAO,yJAAkJ,OAAO,sCAA4B,WAAW,yCAA+B,MAAM,sDAA4C,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oPAAiP,CAAC;AACtjB,CAAC;AARD,oDAQC;AAEY,QAAA,eAAe,GAAG,+FAA+F,CAAC;AAE/H,SAAgB,eAAe,CAAC,GAAW;IACvC,OAAO,4EACkB,GAAG,4kBASiC,CAAC;AAClE,CAAC;AAZD,0CAYC;AAED,SAAgB,cAAc,CAAC,GAAW;IACtC,OAAO,0GACe,GAAG,8iBAS8B,CAAC;AAC5D,CAAC;AAZD,wCAYC","sourcesContent":["export function getRunScriptTemplate(\n orgSlug: string,\n projectSlug: string,\n apiKey: string,\n uploadSource = true,\n): string {\n // eslint-disable-next-line no-useless-escape\n return `# This script is responsable to upload debug symbols and source context for Sentry.\\\\nif which sentry-cli >/dev/null; then\\\\nexport SENTRY_ORG=${orgSlug}\\\\nexport SENTRY_PROJECT=${projectSlug}\\\\nexport SENTRY_AUTH_TOKEN=${apiKey}\\\\nERROR=$(sentry-cli debug-files upload ${uploadSource ? \"--include-sources \" : \"\"}\\\"$DWARF_DSYM_FOLDER_PATH\\\" 2>&1 >/dev/null)\\\\nif [ ! $? -eq 0 ]; then\\\\necho \\\"warning: sentry-cli - $ERROR\\\"\\\\nfi\\\\nelse\\\\necho \\\"warning: sentry-cli not installed, download from https://github.com/getsentry/sentry-cli/releases\\\"\\\\nfi\\\\n`;\n}\n\nexport const scriptInputPath = \"\\\"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}\\\"\";\n\nexport function getSwiftSnippet(dsn: string): string {\n return ` SentrySDK.start { options in\n options.dsn = \"${dsn}\"\n options.debug = true // Enabled debug when first installing is always helpful\n options.enableTracing = true \n\n // Uncomment the following lines to add more data to your events\n // options.attachScreenshot = true // This adds a screenshot to the error events\n // options.attachViewHierarchy = true // This adds the view hierarchy to the error events\n }\n // Remove the next line after confirming that your Sentry integration is working.\n SentrySDK.capture(message: \"This app uses Sentry! :)\")\\n`;\n}\n\nexport function getObjcSnippet(dsn: string): string {\n return ` [SentrySDK startWithConfigureOptions:^(SentryOptions * options) {\n options.dsn = @\"${dsn}\";\n options.debug = YES; // Enabled debug when first installing is always helpful\n options.enableTracing = YES;\n\n //Uncomment the following lines to add more data to your events\n //options.attachScreenshot = YES; //This will add a screenshot to the error events\n //options.attachViewHierarchy = YES; //This will add the view hierarchy to the error events\n }];\n //Remove the next line after confirming that your Sentry integration is working.\n [SentrySDK captureMessage:@\"This app uses Sentry!\"];\\n`;\n}"]}
@@ -0,0 +1,4 @@
1
+ import { SentryProjectData } from '../utils/clack-utils';
2
+ export declare function updateXcodeProject(projectPath: string, sentryProject: SentryProjectData, apiKeys: {
3
+ token: string;
4
+ }, addSPMReference: boolean, uploadSource?: boolean): void;
@@ -0,0 +1,145 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.updateXcodeProject = void 0;
27
+ var fs = __importStar(require("fs"));
28
+ var templates = __importStar(require("./templates"));
29
+ var xcode = require('xcode');
30
+ /* eslint-enable @typescript-eslint/no-unused-vars */
31
+ function setDebugInformationFormat(proj) {
32
+ var xcObjects = proj.hash.project.objects;
33
+ var target = proj.getFirstTarget().firstTarget;
34
+ xcObjects.XCConfigurationList[target.buildConfigurationList].buildConfigurations.forEach(function (buildConfig) {
35
+ xcObjects.XCBuildConfiguration[buildConfig.value].buildSettings.DEBUG_INFORMATION_FORMAT = "\"dwarf-with-dsym\"";
36
+ });
37
+ }
38
+ function addSentrySPM(proj) {
39
+ var xcObjects = proj.hash.project.objects;
40
+ var sentryFrameworkUUID = proj.generateUuid();
41
+ var sentrySPMUUID = proj.generateUuid();
42
+ //Check whether xcObjects already have sentry framework
43
+ if (xcObjects.PBXFrameworksBuildPhase) {
44
+ for (var key in xcObjects.PBXFrameworksBuildPhase || {}) {
45
+ if (!key.endsWith("_comment")) {
46
+ var frameworks = xcObjects.PBXFrameworksBuildPhase[key].files;
47
+ for (var _i = 0, frameworks_1 = frameworks; _i < frameworks_1.length; _i++) {
48
+ var framework = frameworks_1[_i];
49
+ if (framework.comment === "Sentry in Frameworks") {
50
+ return;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ xcObjects.PBXBuildFile[sentryFrameworkUUID] = {
57
+ isa: "PBXBuildFile",
58
+ productRef: sentrySPMUUID,
59
+ productRef_comment: "Sentry",
60
+ };
61
+ xcObjects.PBXBuildFile[sentryFrameworkUUID + "_comment"] = "Sentry in Frameworks";
62
+ for (var key in xcObjects.PBXFrameworksBuildPhase || {}) {
63
+ if (!key.endsWith("_comment")) {
64
+ var frameworks = xcObjects.PBXFrameworksBuildPhase[key].files;
65
+ frameworks.push({
66
+ value: sentryFrameworkUUID,
67
+ comment: "Sentry in Frameworks",
68
+ });
69
+ }
70
+ }
71
+ var target = proj.getFirstTarget().firstTarget;
72
+ if (!target.packageProductDependencies) {
73
+ target.packageProductDependencies = [];
74
+ }
75
+ target.packageProductDependencies.push({
76
+ value: sentrySPMUUID,
77
+ comment: "Sentry",
78
+ });
79
+ var sentrySwiftPackageUUID = proj.generateUuid();
80
+ var xcProject = proj.getFirstProject().firstProject;
81
+ if (!xcProject.packageReferences) {
82
+ xcProject.packageReferences = [];
83
+ }
84
+ xcProject.packageReferences.push({
85
+ value: sentrySwiftPackageUUID,
86
+ comment: "XCRemoteSwiftPackageReference \"sentry-cocoa\"",
87
+ });
88
+ xcObjects.XCRemoteSwiftPackageReference = {};
89
+ xcObjects.XCRemoteSwiftPackageReference[sentrySwiftPackageUUID] = {
90
+ isa: "XCRemoteSwiftPackageReference",
91
+ repositoryURL: "\"https://github.com/getsentry/sentry-cocoa/\"",
92
+ requirement: {
93
+ kind: "upToNextMajorVersion",
94
+ minimumVersion: "8.0.0",
95
+ }
96
+ };
97
+ xcObjects.XCRemoteSwiftPackageReference[sentrySwiftPackageUUID + "_comment"] = "XCRemoteSwiftPackageReference \"sentry-cocoa\"";
98
+ xcObjects.XCSwiftPackageProductDependency = {};
99
+ xcObjects.XCSwiftPackageProductDependency[sentrySPMUUID] =
100
+ {
101
+ isa: "XCSwiftPackageProductDependency",
102
+ package: sentrySwiftPackageUUID,
103
+ package_comment: "XCRemoteSwiftPackageReference \"sentry-cocoa\"",
104
+ productName: "Sentry",
105
+ };
106
+ xcObjects.XCSwiftPackageProductDependency[sentrySPMUUID + "_comment"] = "Sentry";
107
+ }
108
+ function addUploadSymbolsScript(xcodeProject, sentryProject, apiKeys, uploadSource) {
109
+ if (uploadSource === void 0) { uploadSource = true; }
110
+ var xcObjects = xcodeProject.hash.project.objects;
111
+ for (var scriptKey in xcObjects.PBXShellScriptBuildPhase || {}) {
112
+ if (!scriptKey.endsWith("_comment")) {
113
+ var script = xcObjects.PBXShellScriptBuildPhase[scriptKey].shellScript;
114
+ //Sentry script already exists, update it
115
+ if (script.includes("sentry-cli")) {
116
+ delete xcObjects.PBXShellScriptBuildPhase[scriptKey];
117
+ delete xcObjects.PBXShellScriptBuildPhase[scriptKey + "_comment"];
118
+ break;
119
+ }
120
+ }
121
+ }
122
+ xcodeProject.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Upload Debug Symbols to Sentry', null, {
123
+ inputFileListPaths: [],
124
+ outputFileListPaths: [],
125
+ inputPaths: [templates.scriptInputPath],
126
+ shellPath: '/bin/sh',
127
+ shellScript: templates.getRunScriptTemplate(sentryProject.organization.slug, sentryProject.slug, apiKeys.token, uploadSource)
128
+ });
129
+ }
130
+ function updateXcodeProject(projectPath, sentryProject, apiKeys, addSPMReference, uploadSource) {
131
+ if (uploadSource === void 0) { uploadSource = true; }
132
+ var proj = xcode.project(projectPath);
133
+ proj.parseSync();
134
+ addUploadSymbolsScript(proj, sentryProject, apiKeys, uploadSource);
135
+ if (uploadSource) {
136
+ setDebugInformationFormat(proj);
137
+ }
138
+ if (addSPMReference) {
139
+ addSentrySPM(proj);
140
+ }
141
+ var newContent = proj.writeSync();
142
+ fs.writeFileSync(projectPath, newContent);
143
+ }
144
+ exports.updateXcodeProject = updateXcodeProject;
145
+ //# sourceMappingURL=xcode-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xcode-manager.js","sourceRoot":"","sources":["../../../src/apple/xcode-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AASA,qCAAyB;AAEzB,qDAAyC;AACzC,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAG/B,qDAAqD;AAErD,SAAS,yBAAyB,CAAC,IAAS;IACxC,IAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IAC5C,IAAM,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,WAAW,CAAC;IAEjD,SAAS,CAAC,mBAAmB,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,UAAC,WAA8B;QACpH,SAAS,CAAC,oBAAoB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,wBAAwB,GAAG,qBAAqB,CAAC;IACrH,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,YAAY,CAAC,IAAS;IAC3B,IAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IAE5C,IAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,EAAY,CAAC;IAC1D,IAAM,aAAa,GAAG,IAAI,CAAC,YAAY,EAAY,CAAC;IAEpD,uDAAuD;IACvD,IAAI,SAAS,CAAC,uBAAuB,EAAE;QACnC,KAAK,IAAM,GAAG,IAAI,SAAS,CAAC,uBAAuB,IAAI,EAAE,E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/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { SentryCli } from '../../lib/Helper/SentryCli';\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as templates from './templates';\nconst xcode = require('xcode');\n\nimport { SentryProjectData } from '../utils/clack-utils';\n/* eslint-enable @typescript-eslint/no-unused-vars */\n\nfunction setDebugInformationFormat(proj: any): void {\n const xcObjects = proj.hash.project.objects;\n const target = proj.getFirstTarget().firstTarget;\n\n xcObjects.XCConfigurationList[target.buildConfigurationList].buildConfigurations.forEach((buildConfig: { value: string }) => {\n xcObjects.XCBuildConfiguration[buildConfig.value].buildSettings.DEBUG_INFORMATION_FORMAT = \"\\\"dwarf-with-dsym\\\"\";\n });\n}\n\nfunction addSentrySPM(proj: any): void {\n const xcObjects = proj.hash.project.objects;\n\n const sentryFrameworkUUID = proj.generateUuid() as string;\n const sentrySPMUUID = proj.generateUuid() as string;\n\n //Check whether xcObjects already have sentry framework\n if (xcObjects.PBXFrameworksBuildPhase) {\n for (const key in xcObjects.PBXFrameworksBuildPhase || {}) {\n if (!key.endsWith(\"_comment\")) {\n const frameworks = xcObjects.PBXFrameworksBuildPhase[key].files;\n for (const framework of frameworks) {\n if (framework.comment === \"Sentry in Frameworks\") {\n return;\n }\n }\n }\n }\n }\n\n xcObjects.PBXBuildFile[sentryFrameworkUUID] = {\n isa: \"PBXBuildFile\",\n productRef: sentrySPMUUID,\n productRef_comment: \"Sentry\",\n };\n xcObjects.PBXBuildFile[sentryFrameworkUUID + \"_comment\"] = \"Sentry in Frameworks\";\n\n for (const key in xcObjects.PBXFrameworksBuildPhase || {}) {\n if (!key.endsWith(\"_comment\")) {\n const frameworks = xcObjects.PBXFrameworksBuildPhase[key].files;\n frameworks.push({\n value: sentryFrameworkUUID,\n comment: \"Sentry in Frameworks\",\n });\n }\n }\n\n const target = proj.getFirstTarget().firstTarget;\n if (!target.packageProductDependencies) {\n target.packageProductDependencies = [];\n }\n target.packageProductDependencies.push({\n value: sentrySPMUUID,\n comment: \"Sentry\",\n });\n\n const sentrySwiftPackageUUID = proj.generateUuid() as string;\n const xcProject = proj.getFirstProject().firstProject;\n if (!xcProject.packageReferences) {\n xcProject.packageReferences = [];\n }\n xcProject.packageReferences.push({\n value: sentrySwiftPackageUUID,\n comment: \"XCRemoteSwiftPackageReference \\\"sentry-cocoa\\\"\",\n });\n\n xcObjects.XCRemoteSwiftPackageReference = {};\n xcObjects.XCRemoteSwiftPackageReference[sentrySwiftPackageUUID] = {\n isa: \"XCRemoteSwiftPackageReference\",\n repositoryURL: \"\\\"https://github.com/getsentry/sentry-cocoa/\\\"\",\n requirement: {\n kind: \"upToNextMajorVersion\",\n minimumVersion: \"8.0.0\",\n }\n };\n xcObjects.XCRemoteSwiftPackageReference[sentrySwiftPackageUUID + \"_comment\"] = \"XCRemoteSwiftPackageReference \\\"sentry-cocoa\\\"\";\n\n xcObjects.XCSwiftPackageProductDependency = {};\n xcObjects.XCSwiftPackageProductDependency[sentrySPMUUID] =\n {\n isa: \"XCSwiftPackageProductDependency\",\n package: sentrySwiftPackageUUID,\n package_comment: \"XCRemoteSwiftPackageReference \\\"sentry-cocoa\\\"\",\n productName: \"Sentry\",\n };\n xcObjects.XCSwiftPackageProductDependency[sentrySPMUUID + \"_comment\"] = \"Sentry\";\n}\n\nfunction addUploadSymbolsScript(xcodeProject: any, sentryProject: SentryProjectData, apiKeys: { token: string }, uploadSource = true): void {\n const xcObjects = xcodeProject.hash.project.objects;\n\n for (const scriptKey in xcObjects.PBXShellScriptBuildPhase || {}) {\n if (!scriptKey.endsWith(\"_comment\")) {\n const script = xcObjects.PBXShellScriptBuildPhase[scriptKey].shellScript;\n //Sentry script already exists, update it\n if (script.includes(\"sentry-cli\")) {\n delete xcObjects.PBXShellScriptBuildPhase[scriptKey];\n delete xcObjects.PBXShellScriptBuildPhase[scriptKey + \"_comment\"];\n break;\n }\n }\n }\n\n xcodeProject.addBuildPhase(\n [],\n 'PBXShellScriptBuildPhase',\n 'Upload Debug Symbols to Sentry',\n null,\n {\n inputFileListPaths: [],\n outputFileListPaths: [],\n inputPaths: [templates.scriptInputPath],\n shellPath: '/bin/sh',\n shellScript: templates.getRunScriptTemplate(sentryProject.organization.slug, sentryProject.slug, apiKeys.token, uploadSource)\n },\n );\n}\n\nexport function updateXcodeProject(projectPath: string, sentryProject: SentryProjectData, apiKeys: { token: string }, addSPMReference: boolean, uploadSource = true): void {\n const proj = xcode.project(projectPath);\n proj.parseSync();\n addUploadSymbolsScript(proj, sentryProject, apiKeys, uploadSource);\n if (uploadSource) {\n setDebugInformationFormat(proj);\n }\n if (addSPMReference) {\n addSentrySPM(proj);\n }\n const newContent = proj.writeSync();\n fs.writeFileSync(projectPath, newContent);\n}"]}