onesignal-expo-plugin 1.3.0 → 1.3.2

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.
@@ -0,0 +1,27 @@
1
+ name-template: $RESOLVED_VERSION
2
+ tag-template: $RESOLVED_VERSION
3
+ categories:
4
+ - title: 🚀 Features
5
+ label: Enhancement / Feature
6
+ - title: 🐛 Bug Fixes
7
+ label: Bug
8
+ - title: 🧰 Improvements
9
+ label: Improvement
10
+ - title: down arrow Dependency Updates
11
+ label: Dependencies
12
+ change-template: '- $TITLE (#$NUMBER)'
13
+ version-resolver:
14
+ major:
15
+ labels:
16
+ - 'major'
17
+ minor:
18
+ labels:
19
+ - 'minor'
20
+ patch:
21
+ labels:
22
+ - 'patch'
23
+ default: patch
24
+ template: |
25
+ ## Other Changes
26
+
27
+ $CHANGES
@@ -0,0 +1,34 @@
1
+ # This is an action to close asana tasks that were generated by Github issues
2
+
3
+ name: Zapier web hook
4
+
5
+ # Controls when the workflow will run
6
+ on:
7
+ # Triggers the workflow on push or pull request events but only for the "main" branch
8
+ issues:
9
+ types: [closed]
10
+
11
+ permissions:
12
+ issues: read
13
+
14
+ # A workflow run is made up of one or more jobs that can run sequentially or in parallel
15
+ jobs:
16
+ # This workflow contains a single job called "build"
17
+ build:
18
+ # The type of runner that the job will run on
19
+ runs-on: ubuntu-latest
20
+
21
+ # Steps represent a sequence of tasks that will be executed as part of the job
22
+ steps:
23
+ # Runs a set of commands using the runners shell
24
+ - name: Call Zapier web hook to close Asana task
25
+ if: ${{ !github.event.issue.pull_request }}
26
+ env:
27
+ ISSUE_TITLE: ${{ github.event.issue.title }}
28
+ run: |
29
+ curl --location --request POST 'https://hooks.zapier.com/hooks/catch/12728683/b7009qc/' \
30
+ --header 'Content-Type: application/json' \
31
+ --header 'Accept: application/json' \
32
+ --data-raw '{
33
+ "task_name" : "$ISSUE_TITLE"
34
+ }'
@@ -0,0 +1,42 @@
1
+
2
+ name: Release Drafter
3
+
4
+ on:
5
+ push:
6
+ # branches to consider in the event; optional, defaults to all
7
+ branches:
8
+ - main
9
+ # pull_request event is required only for autolabeler
10
+ pull_request:
11
+ # Only following types are handled by the action, but one can default to all as well
12
+ types: [opened, reopened, synchronize]
13
+ # pull_request_target event is required for autolabeler to support PRs from forks
14
+ # pull_request_target:
15
+ # types: [opened, reopened, synchronize]
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ update_release_draft:
22
+ permissions:
23
+ # write permission is required to create a github release
24
+ contents: write
25
+ # write permission is required for autolabeler
26
+ # otherwise, read permission is required at least
27
+ pull-requests: write
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ # (Optional) GitHub Enterprise requires GHE_HOST variable set
31
+ #- name: Set GHE_HOST
32
+ # run: |
33
+ # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV
34
+
35
+ # Drafts your next Release notes as Pull Requests are merged into "master"
36
+ - uses: release-drafter/release-drafter@v5
37
+ # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
38
+ # with:
39
+ # config-name: my-config.yml
40
+ # disable-autolabeler: true
41
+ env:
42
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## April 2023
5
+ ### `1.3.2` - 04/18/23
6
+ #### Changes
7
+ - Update iOS generation to write xcode project via expo mod rather than directly to file system.
8
+ - Bump qs from 6.5.2 to 6.5.3
9
+ - Bump decode-uri-component from 0.2.0 to 0.2.2
10
+ - Bump @xmldom/xmldom from 0.7.5 to 0.7.10
11
+ - Bump multiple dependency versions in OneSignal Example App (ua-parser-js, decode-uri-component, @sideway/formula, @xmldom/xmldom)
12
+
13
+ ## March 2023
14
+ ### `1.3.1` - 03/03/23
15
+ #### Changes
16
+ - Update monorepo logic to rely on the more reliable `require.resolve` to find the `onesignal-expo-plugin` package.
17
+
4
18
  ## November 2022
5
19
  ### `1.3.0` - 11/30/22
6
20
  #### Changes
package/EAS.md CHANGED
@@ -18,4 +18,4 @@ For development/internal distribution builds, you will need to install a [develo
18
18
  2. In the terminal, run `expo start --dev-client` to be able to serve the application to the client.
19
19
  3. Scan the generated QR code to open the dev client and fetch the app bundle from the running Expo process.
20
20
  4. You may be prompted to allow the app to find local area network devices. Approve.
21
- 5. Rescan the QR code & open the app. At this point, you should see the mero bundler working. As soon as the bundle is complete, your working app should open!
21
+ 5. Rescan the QR code & open the app. At this point, you should see the metro bundler working. As soon as the bundle is complete, your working app should open!
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <h1 align="center">Welcome to onesignal-expo-plugin 👋</h1>
1
+ <h1 align="center">Welcome to the onesignal-expo-plugin 👋</h1>
2
2
  <p>
3
3
  <a href="https://www.npmjs.com/package/onesignal-expo-plugin" target="_blank">
4
4
  <img alt="Version" src="https://img.shields.io/npm/v/onesignal-expo-plugin.svg">
@@ -30,9 +30,10 @@ This plugin is an [Expo Config Plugin](https://docs.expo.dev/guides/config-plugi
30
30
  ---
31
31
 
32
32
  ## Install
33
+ You need both the `onesignal-expo-plugin` *and* the `react-native-onesignal` npm package.
33
34
 
34
35
  ```sh
35
- expo install onesignal-expo-plugin
36
+ npx expo install onesignal-expo-plugin
36
37
 
37
38
  # npm
38
39
  npm install react-native-onesignal
@@ -43,7 +44,7 @@ yarn add react-native-onesignal
43
44
 
44
45
  ## Configuration in app.json / app.config.js
45
46
  ### Plugin
46
- Add the plugin to the **front** of the [plugin array](https://docs.expo.dev/versions/latest/config/app/). It should be added automatically if you ran `expo install`. Just make sure it is the first plugin in the array and to configure any desired plugin props:
47
+ Add the plugin to the **front** of the [plugin array](https://docs.expo.dev/versions/latest/config/app/). It should be added automatically if you ran `npx expo install`. Just make sure it is the first plugin in the array and to configure any desired plugin props:
47
48
 
48
49
  **app.json**
49
50
  ```json
@@ -119,9 +120,9 @@ In your configuration file, make sure you set:
119
120
 
120
121
  | Property | Details |
121
122
  |-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
122
- | `version` | Your app version. Corresponds to `CFBundleShortVersionString` on iOS. This value will be used in your NSE* target's plist file. |
123
- | `ios.buildNumber` | Build number for your iOS standalone app. Corresponds to `CFBundleVersion` and must match Apple's specified format. This value will be used in your NSE* target's plist file. |
124
- | `ios.bundleIdentifier` | Bundle identifier for your iOS standalone app. Corresponds to `CFBundleIdentifier`. This value will be used in your NSE* target's plist and entitlements file. |
123
+ | `version` | Your app version. Corresponds to `CFBundleShortVersionString` on iOS. It is a human-readable version number of an iOS app, and is typically in the format of "X.X.X" (e.g. "1.0" or "2.3.1"). It is the version number that is typically displayed to users in the App Store and in the app itself. This value will be used in your NSE* target's plist file. |
124
+ | `ios.buildNumber` | Build number for your iOS standalone app. Corresponds to `CFBundleVersion` and must match Apple's specified format (e.g: "42" or "100"). The build number is used by the App Store and iOS to identify and track different versions of an app, and is typically incremented for each new release. It is a number typically used for the developer's and system reference. This value will be used in your NSE* target's plist file. |
125
+ | `ios.bundleIdentifier` | Bundle identifier for your iOS standalone app. Corresponds to `CFBundleIdentifier`. It's a unique identifier string that is used to identify an iOS app or bundle. It is typically in the format of `"com.companyname.appname"` (e.g. `"com.example.myapp"`). This value will be used in your NSE* target's plist and entitlements file. |
125
126
 
126
127
  \* NSE = Notification Service Extension. Learn more about the NSE [here](https://documentation.onesignal.com/docs/service-extensions).
127
128
 
@@ -141,24 +142,24 @@ It may make sense to prebuild locally to inspect config plugin changes and help
141
142
 
142
143
  #### Run
143
144
  ```sh
144
- expo prebuild
145
+ npx expo prebuild
145
146
  ```
146
147
 
147
148
  ```sh
148
149
  # nukes changes and rebuilds
149
- expo prebuild --clean
150
+ npx expo prebuild --clean
150
151
  ```
151
152
 
152
- **EAS Note:** if you choose to stay in a fully managed workflow by not prebuilding, EAS will still run `expo prebuild` at build time. You can also prebuild locally but remain in a fully managed workflow by adding the `android` and `ios` directories to your .gitignore.
153
+ **EAS Note:** if you choose to stay in a fully managed workflow by not prebuilding, EAS will still run `npx expo prebuild` at build time. You can also prebuild locally but remain in a fully managed workflow by adding the `android` and `ios` directories to your .gitignore.
153
154
 
154
155
  ## Run
155
156
  The following commands will prebuild *and* run your application. Note that for iOS, push notifications will **not** work in the Simulator.
156
157
  ```sh
157
158
  # Build and run your native iOS project
158
- expo run:ios
159
+ npx expo run:ios
159
160
 
160
161
  # Build and run your native Android project
161
- expo run:android
162
+ npx expo run:android
162
163
  ```
163
164
 
164
165
  ---
@@ -180,5 +181,5 @@ Give a ⭐️ if this project helped you!
180
181
 
181
182
  ## 📝 License
182
183
 
183
- Copyright © 2022 [OneSignal](https://github.com/OneSignal).<br />
184
+ Copyright © 2023 [OneSignal](https://github.com/OneSignal).<br />
184
185
  This project is [MIT](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/LICENSE) licensed.
@@ -30,10 +30,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
30
  return (mod && mod.__esModule) ? mod : { "default": mod };
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.xcodeProjectAddNse = exports.withOneSignalIos = void 0;
33
+ exports.withOneSignalIos = void 0;
34
34
  const config_plugins_1 = require("@expo/config-plugins");
35
35
  const fs = __importStar(require("fs"));
36
- const xcode_1 = __importDefault(require("xcode"));
36
+ const path = __importStar(require("path"));
37
37
  const iosConstants_1 = require("../support/iosConstants");
38
38
  const updatePodfile_1 = require("../support/updatePodfile");
39
39
  const NseUpdaterManager_1 = __importDefault(require("../support/NseUpdaterManager"));
@@ -95,79 +95,58 @@ const withAppGroupPermissions = (config) => {
95
95
  return newConfig;
96
96
  });
97
97
  };
98
- const withOneSignalNSE = (config, onesignalProps) => {
99
- return (0, config_plugins_1.withXcodeProject)(config, async (props) => {
100
- var _a, _b;
101
- const options = {
102
- iosPath: props.modRequest.platformProjectRoot,
103
- bundleIdentifier: (_a = props.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier,
104
- devTeam: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.devTeam,
105
- bundleVersion: (_b = props.ios) === null || _b === void 0 ? void 0 : _b.buildNumber,
106
- bundleShortVersion: props === null || props === void 0 ? void 0 : props.version,
107
- mode: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.mode,
108
- iPhoneDeploymentTarget: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.iPhoneDeploymentTarget,
109
- iosNSEFilePath: onesignalProps.iosNSEFilePath
110
- };
111
- // support for monorepos where node_modules can be up to 5 parents
112
- // above the project directory.
113
- let dir = "node_modules";
114
- for (let x = 0; x < 5 && !FileManager_1.FileManager.dirExists(dir); x++) {
115
- dir = "../" + dir;
116
- }
117
- xcodeProjectAddNse(props.modRequest.projectName || "", options, dir + "/onesignal-expo-plugin/build/support/serviceExtensionFiles/");
118
- return props;
119
- });
120
- };
121
98
  const withEasManagedCredentials = (config) => {
122
99
  var _a;
123
100
  (0, assert_1.default)((_a = config.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier, "Missing 'ios.bundleIdentifier' in app config.");
124
101
  config.extra = (0, getEasManagedCredentialsConfigExtra_1.default)(config);
125
102
  return config;
126
103
  };
127
- const withOneSignalIos = (config, props) => {
128
- withAppEnvironment(config, props);
129
- withRemoteNotificationsPermissions(config, props);
130
- withAppGroupPermissions(config, props);
131
- withOneSignalNSE(config, props);
132
- withEasManagedCredentials(config, props);
133
- return config;
104
+ const withOneSignalPodfile = (config) => {
105
+ return (0, config_plugins_1.withDangerousMod)(config, [
106
+ 'ios',
107
+ async (config) => {
108
+ // not awaiting in order to not block main thread
109
+ const iosRoot = path.join(config.modRequest.projectRoot, "ios");
110
+ (0, updatePodfile_1.updatePodfile)(iosRoot).catch(err => { OneSignalLog_1.OneSignalLog.error(err); });
111
+ return config;
112
+ },
113
+ ]);
134
114
  };
135
- exports.withOneSignalIos = withOneSignalIos;
136
- function xcodeProjectAddNse(appName, options, sourceDir) {
137
- const { iosPath, devTeam, bundleIdentifier, bundleVersion, bundleShortVersion, iPhoneDeploymentTarget, iosNSEFilePath } = options;
138
- // not awaiting in order to not block main thread
139
- (0, updatePodfile_1.updatePodfile)(iosPath).catch(err => { OneSignalLog_1.OneSignalLog.error(err); });
140
- const projPath = `${iosPath}/${appName}.xcodeproj/project.pbxproj`;
141
- const sourceFile = "NotificationService.m";
142
- const extFiles = [
143
- "NotificationService.h",
144
- `${iosConstants_1.NSE_TARGET_NAME}.entitlements`,
145
- `${iosConstants_1.NSE_TARGET_NAME}-Info.plist`
146
- ];
147
- const xcodeProject = xcode_1.default.project(projPath);
148
- xcodeProject.parse(async function (err) {
149
- if (err) {
150
- OneSignalLog_1.OneSignalLog.log(`Error parsing iOS project: ${JSON.stringify(err)}`);
151
- return;
152
- }
153
- /* COPY OVER EXTENSION FILES */
154
- fs.mkdirSync(`${iosPath}/${iosConstants_1.NSE_TARGET_NAME}`, { recursive: true });
155
- for (let i = 0; i < extFiles.length; i++) {
156
- const extFile = extFiles[i];
157
- const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${extFile}`;
158
- await FileManager_1.FileManager.copyFile(`${sourceDir}${extFile}`, targetFile);
159
- }
160
- // Copy NSE source file either from configuration-provided location, falling back to the default one.
161
- const sourcePath = iosNSEFilePath !== null && iosNSEFilePath !== void 0 ? iosNSEFilePath : `${sourceDir}${sourceFile}`;
162
- const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${sourceFile}`;
163
- await FileManager_1.FileManager.copyFile(`${sourcePath}`, targetFile);
164
- /* MODIFY COPIED EXTENSION FILES */
165
- const nseUpdater = new NseUpdaterManager_1.default(iosPath);
166
- await nseUpdater.updateNSEEntitlements(`group.${bundleIdentifier}.onesignal`);
167
- await nseUpdater.updateNSEBundleVersion(bundleVersion !== null && bundleVersion !== void 0 ? bundleVersion : iosConstants_1.DEFAULT_BUNDLE_VERSION);
168
- await nseUpdater.updateNSEBundleShortVersion(bundleShortVersion !== null && bundleShortVersion !== void 0 ? bundleShortVersion : iosConstants_1.DEFAULT_BUNDLE_SHORT_VERSION);
115
+ const withOneSignalNSE = (config, props) => {
116
+ // support for monorepos where node_modules can be above the project directory.
117
+ const pluginDir = require.resolve("onesignal-expo-plugin/package.json");
118
+ const sourceDir = path.join(pluginDir, "../build/support/serviceExtensionFiles/");
119
+ return (0, config_plugins_1.withDangerousMod)(config, [
120
+ 'ios',
121
+ async (config) => {
122
+ var _a, _b, _c, _d, _e;
123
+ const iosPath = path.join(config.modRequest.projectRoot, "ios");
124
+ /* COPY OVER EXTENSION FILES */
125
+ fs.mkdirSync(`${iosPath}/${iosConstants_1.NSE_TARGET_NAME}`, { recursive: true });
126
+ for (let i = 0; i < iosConstants_1.NSE_EXT_FILES.length; i++) {
127
+ const extFile = iosConstants_1.NSE_EXT_FILES[i];
128
+ const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${extFile}`;
129
+ await FileManager_1.FileManager.copyFile(`${sourceDir}${extFile}`, targetFile);
130
+ }
131
+ // Copy NSE source file either from configuration-provided location, falling back to the default one.
132
+ const sourcePath = (_a = props.iosNSEFilePath) !== null && _a !== void 0 ? _a : `${sourceDir}${iosConstants_1.NSE_SOURCE_FILE}`;
133
+ const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${iosConstants_1.NSE_SOURCE_FILE}`;
134
+ await FileManager_1.FileManager.copyFile(`${sourcePath}`, targetFile);
135
+ /* MODIFY COPIED EXTENSION FILES */
136
+ const nseUpdater = new NseUpdaterManager_1.default(iosPath);
137
+ await nseUpdater.updateNSEEntitlements(`group.${(_b = config.ios) === null || _b === void 0 ? void 0 : _b.bundleIdentifier}.onesignal`);
138
+ await nseUpdater.updateNSEBundleVersion((_d = (_c = config.ios) === null || _c === void 0 ? void 0 : _c.buildNumber) !== null && _d !== void 0 ? _d : iosConstants_1.DEFAULT_BUNDLE_VERSION);
139
+ await nseUpdater.updateNSEBundleShortVersion((_e = config === null || config === void 0 ? void 0 : config.version) !== null && _e !== void 0 ? _e : iosConstants_1.DEFAULT_BUNDLE_SHORT_VERSION);
140
+ return config;
141
+ },
142
+ ]);
143
+ };
144
+ const withOneSignalXcodeProject = (config, props) => {
145
+ return (0, config_plugins_1.withXcodeProject)(config, newConfig => {
146
+ var _a, _b;
147
+ const xcodeProject = newConfig.modResults;
169
148
  // Create new PBXGroup for the extension
170
- const extGroup = xcodeProject.addPbxGroup([...extFiles, sourceFile], iosConstants_1.NSE_TARGET_NAME, iosConstants_1.NSE_TARGET_NAME);
149
+ const extGroup = xcodeProject.addPbxGroup([...iosConstants_1.NSE_EXT_FILES, iosConstants_1.NSE_SOURCE_FILE], iosConstants_1.NSE_TARGET_NAME, iosConstants_1.NSE_TARGET_NAME);
171
150
  // Add the new PBXGroup to the top level group. This makes the
172
151
  // files / folder appear in the file explorer in Xcode.
173
152
  const groups = xcodeProject.hash.project.objects["PBXGroup"];
@@ -185,11 +164,11 @@ function xcodeProjectAddNse(appName, options, sourceDir) {
185
164
  projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};
186
165
  if (!!xcodeProject.pbxTargetByName(iosConstants_1.NSE_TARGET_NAME)) {
187
166
  OneSignalLog_1.OneSignalLog.log(`${iosConstants_1.NSE_TARGET_NAME} already exists in project. Skipping...`);
188
- return;
167
+ return newConfig;
189
168
  }
190
169
  // Add the NSE target
191
170
  // This adds PBXTargetDependency and PBXContainerItemProxy for you
192
- const nseTarget = xcodeProject.addTarget(iosConstants_1.NSE_TARGET_NAME, "app_extension", iosConstants_1.NSE_TARGET_NAME, `${bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`);
171
+ const nseTarget = xcodeProject.addTarget(iosConstants_1.NSE_TARGET_NAME, "app_extension", iosConstants_1.NSE_TARGET_NAME, `${(_a = config.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`);
193
172
  // Add build phases to the new target
194
173
  xcodeProject.addBuildPhase(["NotificationService.m"], "PBXSourcesBuildPhase", "Sources", nseTarget.uuid);
195
174
  xcodeProject.addBuildPhase([], "PBXResourcesBuildPhase", "Resources", nseTarget.uuid);
@@ -201,17 +180,27 @@ function xcodeProjectAddNse(appName, options, sourceDir) {
201
180
  if (typeof configurations[key].buildSettings !== "undefined" &&
202
181
  configurations[key].buildSettings.PRODUCT_NAME == `"${iosConstants_1.NSE_TARGET_NAME}"`) {
203
182
  const buildSettingsObj = configurations[key].buildSettings;
204
- buildSettingsObj.DEVELOPMENT_TEAM = devTeam;
205
- buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = iPhoneDeploymentTarget !== null && iPhoneDeploymentTarget !== void 0 ? iPhoneDeploymentTarget : iosConstants_1.IPHONEOS_DEPLOYMENT_TARGET;
183
+ buildSettingsObj.DEVELOPMENT_TEAM = props === null || props === void 0 ? void 0 : props.devTeam;
184
+ buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = (_b = props === null || props === void 0 ? void 0 : props.iPhoneDeploymentTarget) !== null && _b !== void 0 ? _b : iosConstants_1.IPHONEOS_DEPLOYMENT_TARGET;
206
185
  buildSettingsObj.TARGETED_DEVICE_FAMILY = iosConstants_1.TARGETED_DEVICE_FAMILY;
207
186
  buildSettingsObj.CODE_SIGN_ENTITLEMENTS = `${iosConstants_1.NSE_TARGET_NAME}/${iosConstants_1.NSE_TARGET_NAME}.entitlements`;
208
187
  buildSettingsObj.CODE_SIGN_STYLE = "Automatic";
209
188
  }
210
189
  }
211
190
  // Add development teams to both your target and the original project
212
- xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam, nseTarget);
213
- xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam);
214
- fs.writeFileSync(projPath, xcodeProject.writeSync());
191
+ xcodeProject.addTargetAttribute("DevelopmentTeam", props === null || props === void 0 ? void 0 : props.devTeam, nseTarget);
192
+ xcodeProject.addTargetAttribute("DevelopmentTeam", props === null || props === void 0 ? void 0 : props.devTeam);
193
+ return newConfig;
215
194
  });
216
- }
217
- exports.xcodeProjectAddNse = xcodeProjectAddNse;
195
+ };
196
+ const withOneSignalIos = (config, props) => {
197
+ config = withAppEnvironment(config, props);
198
+ config = withRemoteNotificationsPermissions(config, props);
199
+ config = withAppGroupPermissions(config, props);
200
+ config = withOneSignalPodfile(config, props);
201
+ config = withOneSignalNSE(config, props);
202
+ config = withOneSignalXcodeProject(config, props);
203
+ config = withEasManagedCredentials(config, props);
204
+ return config;
205
+ };
206
+ exports.withOneSignalIos = withOneSignalIos;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NSE_TARGET_NAME = exports.DEFAULT_BUNDLE_SHORT_VERSION = exports.DEFAULT_BUNDLE_VERSION = exports.BUNDLE_VERSION_TEMPLATE_REGEX = exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = exports.NSE_PODFILE_REGEX = exports.NSE_PODFILE_SNIPPET = exports.TARGETED_DEVICE_FAMILY = exports.IPHONEOS_DEPLOYMENT_TARGET = void 0;
3
+ exports.NSE_EXT_FILES = exports.NSE_SOURCE_FILE = exports.NSE_TARGET_NAME = exports.DEFAULT_BUNDLE_SHORT_VERSION = exports.DEFAULT_BUNDLE_VERSION = exports.BUNDLE_VERSION_TEMPLATE_REGEX = exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = exports.NSE_PODFILE_REGEX = exports.NSE_PODFILE_SNIPPET = exports.TARGETED_DEVICE_FAMILY = exports.IPHONEOS_DEPLOYMENT_TARGET = void 0;
4
4
  exports.IPHONEOS_DEPLOYMENT_TARGET = "11.0";
5
5
  exports.TARGETED_DEVICE_FAMILY = `"1,2"`;
6
6
  exports.NSE_PODFILE_SNIPPET = `
@@ -15,3 +15,9 @@ exports.BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;
15
15
  exports.DEFAULT_BUNDLE_VERSION = '1';
16
16
  exports.DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
17
17
  exports.NSE_TARGET_NAME = "OneSignalNotificationServiceExtension";
18
+ exports.NSE_SOURCE_FILE = "NotificationService.m";
19
+ exports.NSE_EXT_FILES = [
20
+ "NotificationService.h",
21
+ `${exports.NSE_TARGET_NAME}.entitlements`,
22
+ `${exports.NSE_TARGET_NAME}-Info.plist`
23
+ ];
@@ -8,21 +8,24 @@ import {
8
8
  withEntitlementsPlist,
9
9
  withInfoPlist,
10
10
  withXcodeProject,
11
+ withDangerousMod
11
12
  } from "@expo/config-plugins";
12
13
  import * as fs from 'fs';
13
- import xcode from 'xcode';
14
+ import * as path from 'path';
14
15
  import {
15
16
  DEFAULT_BUNDLE_SHORT_VERSION,
16
17
  DEFAULT_BUNDLE_VERSION,
17
18
  IPHONEOS_DEPLOYMENT_TARGET,
18
19
  NSE_TARGET_NAME,
20
+ NSE_SOURCE_FILE,
21
+ NSE_EXT_FILES,
19
22
  TARGETED_DEVICE_FAMILY
20
23
  } from "../support/iosConstants";
21
24
  import { updatePodfile } from "../support/updatePodfile";
22
25
  import NseUpdaterManager from "../support/NseUpdaterManager";
23
26
  import { OneSignalLog } from "../support/OneSignalLog";
24
27
  import { FileManager } from "../support/FileManager";
25
- import { OneSignalPluginProps, PluginOptions } from "../types/types";
28
+ import { OneSignalPluginProps } from "../types/types";
26
29
  import assert from 'assert';
27
30
  import getEasManagedCredentialsConfigExtra from "../support/eas/getEasManagedCredentialsConfigExtra";
28
31
  import { ExpoConfig } from '@expo/config-types';
@@ -93,104 +96,67 @@ const withAppGroupPermissions: ConfigPlugin<OneSignalPluginProps> = (
93
96
  });
94
97
  };
95
98
 
96
- const withOneSignalNSE: ConfigPlugin<OneSignalPluginProps> = (config, onesignalProps) => {
97
- return withXcodeProject(config, async props => {
98
- const options: PluginOptions = {
99
- iosPath: props.modRequest.platformProjectRoot,
100
- bundleIdentifier: props.ios?.bundleIdentifier,
101
- devTeam: onesignalProps?.devTeam,
102
- bundleVersion: props.ios?.buildNumber,
103
- bundleShortVersion: props?.version,
104
- mode: onesignalProps?.mode,
105
- iPhoneDeploymentTarget: onesignalProps?.iPhoneDeploymentTarget,
106
- iosNSEFilePath: onesignalProps.iosNSEFilePath
107
- };
108
-
109
- // support for monorepos where node_modules can be up to 5 parents
110
- // above the project directory.
111
- let dir = "node_modules"
112
- for(let x=0; x < 5 && !FileManager.dirExists(dir); x++) {
113
- dir = "../" + dir
114
- }
115
-
116
- xcodeProjectAddNse(
117
- props.modRequest.projectName || "",
118
- options,
119
- dir + "/onesignal-expo-plugin/build/support/serviceExtensionFiles/"
120
- );
121
-
122
- return props;
123
- });
124
- }
125
-
126
99
  const withEasManagedCredentials: ConfigPlugin<OneSignalPluginProps> = (config) => {
127
100
  assert(config.ios?.bundleIdentifier, "Missing 'ios.bundleIdentifier' in app config.")
128
101
  config.extra = getEasManagedCredentialsConfigExtra(config as ExpoConfig);
129
102
  return config;
130
103
  }
131
104
 
132
- export const withOneSignalIos: ConfigPlugin<OneSignalPluginProps> = (
133
- config,
134
- props
135
- ) => {
136
- withAppEnvironment(config, props);
137
- withRemoteNotificationsPermissions(config, props);
138
- withAppGroupPermissions(config, props);
139
- withOneSignalNSE(config, props);
140
- withEasManagedCredentials(config, props);
141
- return config;
142
- };
143
-
144
- export function xcodeProjectAddNse(
145
- appName: string,
146
- options: PluginOptions,
147
- sourceDir: string
148
- ): void {
149
- const { iosPath, devTeam, bundleIdentifier, bundleVersion, bundleShortVersion, iPhoneDeploymentTarget, iosNSEFilePath } = options;
150
-
151
- // not awaiting in order to not block main thread
152
- updatePodfile(iosPath).catch(err => { OneSignalLog.error(err) });
105
+ const withOneSignalPodfile: ConfigPlugin<OneSignalPluginProps> = (config) => {
106
+ return withDangerousMod(config, [
107
+ 'ios',
108
+ async config => {
109
+ // not awaiting in order to not block main thread
110
+ const iosRoot = path.join(config.modRequest.projectRoot, "ios")
111
+ updatePodfile(iosRoot).catch(err => { OneSignalLog.error(err) });
112
+
113
+ return config;
114
+ },
115
+ ]);
116
+ }
153
117
 
154
- const projPath = `${iosPath}/${appName}.xcodeproj/project.pbxproj`;
118
+ const withOneSignalNSE: ConfigPlugin<OneSignalPluginProps> = (config, props) => {
119
+ // support for monorepos where node_modules can be above the project directory.
120
+ const pluginDir = require.resolve("onesignal-expo-plugin/package.json")
121
+ const sourceDir = path.join(pluginDir, "../build/support/serviceExtensionFiles/")
155
122
 
156
- const sourceFile = "NotificationService.m"
157
- const extFiles = [
158
- "NotificationService.h",
159
- `${NSE_TARGET_NAME}.entitlements`,
160
- `${NSE_TARGET_NAME}-Info.plist`
161
- ];
123
+ return withDangerousMod(config, [
124
+ 'ios',
125
+ async config => {
126
+ const iosPath = path.join(config.modRequest.projectRoot, "ios")
162
127
 
163
- const xcodeProject = xcode.project(projPath);
128
+ /* COPY OVER EXTENSION FILES */
129
+ fs.mkdirSync(`${iosPath}/${NSE_TARGET_NAME}`, { recursive: true });
164
130
 
165
- xcodeProject.parse(async function(err: Error) {
166
- if (err) {
167
- OneSignalLog.log(`Error parsing iOS project: ${JSON.stringify(err)}`);
168
- return;
169
- }
131
+ for (let i = 0; i < NSE_EXT_FILES.length; i++) {
132
+ const extFile = NSE_EXT_FILES[i];
133
+ const targetFile = `${iosPath}/${NSE_TARGET_NAME}/${extFile}`;
134
+ await FileManager.copyFile(`${sourceDir}${extFile}`, targetFile);
135
+ }
170
136
 
171
- /* COPY OVER EXTENSION FILES */
172
- fs.mkdirSync(`${iosPath}/${NSE_TARGET_NAME}`, { recursive: true });
137
+ // Copy NSE source file either from configuration-provided location, falling back to the default one.
138
+ const sourcePath = props.iosNSEFilePath ?? `${sourceDir}${NSE_SOURCE_FILE}`
139
+ const targetFile = `${iosPath}/${NSE_TARGET_NAME}/${NSE_SOURCE_FILE}`;
140
+ await FileManager.copyFile(`${sourcePath}`, targetFile);
173
141
 
174
- for (let i = 0; i < extFiles.length; i++) {
175
- const extFile = extFiles[i];
176
- const targetFile = `${iosPath}/${NSE_TARGET_NAME}/${extFile}`;
177
- await FileManager.copyFile(`${sourceDir}${extFile}`, targetFile);
178
- }
142
+ /* MODIFY COPIED EXTENSION FILES */
143
+ const nseUpdater = new NseUpdaterManager(iosPath);
144
+ await nseUpdater.updateNSEEntitlements(`group.${config.ios?.bundleIdentifier}.onesignal`)
145
+ await nseUpdater.updateNSEBundleVersion(config.ios?.buildNumber ?? DEFAULT_BUNDLE_VERSION);
146
+ await nseUpdater.updateNSEBundleShortVersion(config?.version ?? DEFAULT_BUNDLE_SHORT_VERSION);
179
147
 
180
- // Copy NSE source file either from configuration-provided location, falling back to the default one.
181
- const sourcePath = iosNSEFilePath ?? `${sourceDir}${sourceFile}`
182
- const targetFile = `${iosPath}/${NSE_TARGET_NAME}/${sourceFile}`;
183
- await FileManager.copyFile(`${sourcePath}`, targetFile);
148
+ return config;
149
+ },
150
+ ]);
151
+ }
184
152
 
185
- /* MODIFY COPIED EXTENSION FILES */
186
- const nseUpdater = new NseUpdaterManager(iosPath);
187
- await nseUpdater.updateNSEEntitlements(`group.${bundleIdentifier}.onesignal`)
188
- await nseUpdater.updateNSEBundleVersion(bundleVersion ?? DEFAULT_BUNDLE_VERSION);
189
- await nseUpdater.updateNSEBundleShortVersion(bundleShortVersion ?? DEFAULT_BUNDLE_SHORT_VERSION);
153
+ const withOneSignalXcodeProject: ConfigPlugin<OneSignalPluginProps> = (config, props) => {
154
+ return withXcodeProject(config, newConfig => {
155
+ const xcodeProject = newConfig.modResults
190
156
 
191
157
  // Create new PBXGroup for the extension
192
- const extGroup = xcodeProject.addPbxGroup([...extFiles, sourceFile], NSE_TARGET_NAME, NSE_TARGET_NAME);
193
-
158
+ const extGroup = xcodeProject.addPbxGroup([...NSE_EXT_FILES, NSE_SOURCE_FILE], NSE_TARGET_NAME, NSE_TARGET_NAME);
159
+
194
160
  // Add the new PBXGroup to the top level group. This makes the
195
161
  // files / folder appear in the file explorer in Xcode.
196
162
  const groups = xcodeProject.hash.project.objects["PBXGroup"];
@@ -210,12 +176,12 @@ export function xcodeProjectAddNse(
210
176
 
211
177
  if (!!xcodeProject.pbxTargetByName(NSE_TARGET_NAME)) {
212
178
  OneSignalLog.log(`${NSE_TARGET_NAME} already exists in project. Skipping...`);
213
- return;
179
+ return newConfig;
214
180
  }
215
181
 
216
182
  // Add the NSE target
217
183
  // This adds PBXTargetDependency and PBXContainerItemProxy for you
218
- const nseTarget = xcodeProject.addTarget(NSE_TARGET_NAME, "app_extension", NSE_TARGET_NAME, `${bundleIdentifier}.${NSE_TARGET_NAME}`);
184
+ const nseTarget = xcodeProject.addTarget(NSE_TARGET_NAME, "app_extension", NSE_TARGET_NAME, `${config.ios?.bundleIdentifier}.${NSE_TARGET_NAME}`);
219
185
 
220
186
  // Add build phases to the new target
221
187
  xcodeProject.addBuildPhase(
@@ -242,8 +208,8 @@ export function xcodeProjectAddNse(
242
208
  configurations[key].buildSettings.PRODUCT_NAME == `"${NSE_TARGET_NAME}"`
243
209
  ) {
244
210
  const buildSettingsObj = configurations[key].buildSettings;
245
- buildSettingsObj.DEVELOPMENT_TEAM = devTeam;
246
- buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = iPhoneDeploymentTarget ?? IPHONEOS_DEPLOYMENT_TARGET;
211
+ buildSettingsObj.DEVELOPMENT_TEAM = props?.devTeam;
212
+ buildSettingsObj.IPHONEOS_DEPLOYMENT_TARGET = props?.iPhoneDeploymentTarget ?? IPHONEOS_DEPLOYMENT_TARGET;
247
213
  buildSettingsObj.TARGETED_DEVICE_FAMILY = TARGETED_DEVICE_FAMILY;
248
214
  buildSettingsObj.CODE_SIGN_ENTITLEMENTS = `${NSE_TARGET_NAME}/${NSE_TARGET_NAME}.entitlements`;
249
215
  buildSettingsObj.CODE_SIGN_STYLE = "Automatic";
@@ -251,9 +217,19 @@ export function xcodeProjectAddNse(
251
217
  }
252
218
 
253
219
  // Add development teams to both your target and the original project
254
- xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam, nseTarget);
255
- xcodeProject.addTargetAttribute("DevelopmentTeam", devTeam);
256
-
257
- fs.writeFileSync(projPath, xcodeProject.writeSync());
220
+ xcodeProject.addTargetAttribute("DevelopmentTeam", props?.devTeam, nseTarget);
221
+ xcodeProject.addTargetAttribute("DevelopmentTeam", props?.devTeam);
222
+ return newConfig;
258
223
  })
259
224
  }
225
+
226
+ export const withOneSignalIos: ConfigPlugin<OneSignalPluginProps> = (config, props) => {
227
+ config = withAppEnvironment(config, props);
228
+ config = withRemoteNotificationsPermissions(config, props);
229
+ config = withAppGroupPermissions(config, props);
230
+ config = withOneSignalPodfile(config, props)
231
+ config = withOneSignalNSE(config, props)
232
+ config = withOneSignalXcodeProject(config, props)
233
+ config = withEasManagedCredentials(config, props);
234
+ return config;
235
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onesignal-expo-plugin",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.",
5
5
  "main": "./app.plugin.js",
6
6
  "scripts": {
@@ -41,7 +41,6 @@
41
41
  "typescript": "^4.5.5"
42
42
  },
43
43
  "dependencies": {
44
- "xcode": "^3.0.1",
45
44
  "@expo/image-utils": "^0.3.22"
46
45
  }
47
46
  }
@@ -17,3 +17,9 @@ export const DEFAULT_BUNDLE_VERSION = '1';
17
17
  export const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
18
18
 
19
19
  export const NSE_TARGET_NAME = "OneSignalNotificationServiceExtension";
20
+ export const NSE_SOURCE_FILE = "NotificationService.m"
21
+ export const NSE_EXT_FILES = [
22
+ "NotificationService.h",
23
+ `${NSE_TARGET_NAME}.entitlements`,
24
+ `${NSE_TARGET_NAME}-Info.plist`
25
+ ];
package/types/types.ts CHANGED
@@ -37,21 +37,6 @@
37
37
  iosNSEFilePath?: string;
38
38
  };
39
39
 
40
- /**
41
- * Not to be confused with OneSignalPluginProps, PluginOptions are the *internal* properties used by the config plugin
42
- * These include a combination of user-defined properties (from OneSignalPluginProps) and other data to pass between functions
43
- */
44
- export type PluginOptions = {
45
- iosPath: string,
46
- mode: Mode,
47
- devTeam?: string,
48
- bundleVersion?: string,
49
- bundleShortVersion?: string,
50
- bundleIdentifier?: string,
51
- iPhoneDeploymentTarget?: string,
52
- iosNSEFilePath?: string
53
- }
54
-
55
40
  export enum Mode {
56
41
  Dev = "development",
57
42
  Prod = "production"
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const withOneSignalIos_1 = require("./onesignal/withOneSignalIos");
4
- const types_1 = require("./types/types");
5
- // Quick testing on any Xcode project
6
- // 1. Update values for your project
7
- // 2. Run `yarn build` from here
8
- // 3. Open a terminal to the root of your Xcode project
9
- // 4. Run `node ~/WHERE_YOU_CLONED_ME/onesignal-expo-plugin/build/testRuniOS.js`
10
- // 5. Run `pod init`, if you haven't already.
11
- // - Make sure you are testing with 2 targets in your Podfile, your main target AND your NSE
12
- // - If you forget your main target in your Podfile you will get the
13
- // "Please add the host targets for the embedded targets to the Podfile." error
14
- // even if your .xcodeproj is correct.
15
- const options = {
16
- iosPath: '.',
17
- mode: types_1.Mode.Dev,
18
- bundleIdentifier: "com.onesignal.XcodeTestProj",
19
- devTeam: "99SW8E36CT",
20
- iPhoneDeploymentTarget: '12.0'
21
- };
22
- (0, withOneSignalIos_1.xcodeProjectAddNse)("XcodeTestProj", options, "../../repos/onesignal-expo-plugin/support/serviceExtensionFiles/");
package/testRuniOS.ts DELETED
@@ -1,28 +0,0 @@
1
- import { xcodeProjectAddNse } from "./onesignal/withOneSignalIos";
2
- import { Mode } from "./types/types";
3
-
4
- // Quick testing on any Xcode project
5
-
6
- // 1. Update values for your project
7
- // 2. Run `yarn build` from here
8
- // 3. Open a terminal to the root of your Xcode project
9
- // 4. Run `node ~/WHERE_YOU_CLONED_ME/onesignal-expo-plugin/build/testRuniOS.js`
10
- // 5. Run `pod init`, if you haven't already.
11
- // - Make sure you are testing with 2 targets in your Podfile, your main target AND your NSE
12
- // - If you forget your main target in your Podfile you will get the
13
- // "Please add the host targets for the embedded targets to the Podfile." error
14
- // even if your .xcodeproj is correct.
15
-
16
- const options = {
17
- iosPath: '.',
18
- mode: Mode.Dev,
19
- bundleIdentifier: "com.onesignal.XcodeTestProj",
20
- devTeam: "99SW8E36CT",
21
- iPhoneDeploymentTarget: '12.0'
22
- };
23
-
24
- xcodeProjectAddNse(
25
- "XcodeTestProj",
26
- options,
27
- "../../repos/onesignal-expo-plugin/support/serviceExtensionFiles/"
28
- );
package/types/xcode.d.ts DELETED
@@ -1,8 +0,0 @@
1
- declare module 'xcode' {
2
- interface xcode {
3
- project(projPath: string): any;
4
- }
5
-
6
- const xcode: xcode;
7
- export default xcode;
8
- }