Skip to content

Commit 0ef4a93

Browse files
jamesnroktCopilot
andauthored
feat: update mparticle versions (#33)
* Copy relevant file when adding platform * Add a clean script * Bump mParticle versions * Update cordova versions and add instructions * Ensure folder exists before copy * Change import method to fix issue MPGDPRConsent * Adjust cocoapods and deployment target * Correct location of AppDelegate.m * Make logs and events cordova specific * Fix Invalid (non-string) key crash * Update pull request * Add package lock files * Update plugin/src/ios/CDVMParticle.m Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7523761 commit 0ef4a93

14 files changed

Lines changed: 2862 additions & 29 deletions

File tree

.github/workflows/pull-request.yml

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ jobs:
2323
node-version: [10.x, 12.x, 14.x, 15.x]
2424
steps:
2525
- name: Checkout Branch
26-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
2727
- name: Use Node.js ${{ matrix.node-version }}
28-
uses: actions/setup-node@v1
28+
uses: actions/setup-node@v4
2929
with:
3030
node-version: ${{ matrix.node-version }}
3131
- name: "NPM Build"
3232
run: npm ci; npm run build --if-present
3333
- name: "NPM Test"
3434
run: npm test
35+
3536
android-test:
3637
name: Android Unit Tests
3738
runs-on: ubuntu-latest
@@ -40,28 +41,79 @@ jobs:
4041
working-directory: ./plugin
4142
steps:
4243
- name: Checkout Branch
43-
uses: actions/checkout@v2
44+
uses: actions/checkout@v4
4445
- name: "Install JDK 11"
45-
uses: actions/setup-java@v2
46+
uses: actions/setup-java@v4
4647
with:
4748
distribution: zulu
4849
java-version: 11
4950
- name: Install NPM
50-
uses: actions/setup-node@v1
51+
uses: actions/setup-node@v4
5152
- name: NPM Build
5253
run: |
5354
npm ci
5455
npm run build --if-present
5556
- name: Run Unit Tests
5657
run: ./gradlew test
5758

59+
example-android:
60+
name: Build Example Android App
61+
runs-on: ubuntu-latest
62+
defaults:
63+
run:
64+
working-directory: ./example
65+
steps:
66+
- name: Checkout Branch
67+
uses: actions/checkout@v4
68+
- name: Setup Java
69+
uses: actions/setup-java@v4
70+
with:
71+
distribution: zulu
72+
java-version: 17
73+
- name: Setup Node.js
74+
uses: actions/setup-node@v4
75+
with:
76+
node-version: 22
77+
- name: Install Cordova
78+
run: npm install -g cordova
79+
- name: Install Dependencies
80+
run: npm ci
81+
- name: Add Android Platform
82+
run: cordova platform add android
83+
- name: Build Android
84+
run: cordova build android
85+
86+
example-ios:
87+
name: Build Example iOS App
88+
runs-on: macos-latest
89+
defaults:
90+
run:
91+
working-directory: ./example
92+
steps:
93+
- name: Checkout Branch
94+
uses: actions/checkout@v4
95+
- name: Setup Node.js
96+
uses: actions/setup-node@v4
97+
with:
98+
node-version: 22
99+
- name: Install Cordova
100+
run: npm install -g cordova
101+
- name: Install Dependencies
102+
run: npm ci
103+
- name: Add iOS Platform
104+
run: cordova platform add ios
105+
- name: Build iOS
106+
run: cordova build ios
107+
58108
pr-notify:
59109
if: >
60110
github.event_name == 'pull_request' &&
61111
github.event.pull_request.draft == false
62112
needs:
63113
- js-test
64114
- android-test
115+
- example-android
116+
- example-ios
65117
name: Notify GChat
66118
uses: ROKT/rokt-workflows/.github/workflows/oss_pr_opened_notification.yml@main
67119
secrets:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,3 @@ node_modules
6262

6363
example/platforms
6464
example/plugins
65-
package-lock.json

example/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# MParticle Cordova Example
2+
3+
This example demonstrates how to integrate the MParticle Cordova plugin into your application.
4+
5+
## Prerequisites
6+
7+
- Node.js and npm
8+
- Cordova CLI
9+
- Xcode (for iOS development)
10+
- Android Studio (for Android development)
11+
12+
## Setup
13+
14+
1. Install dependencies:
15+
```bash
16+
npm install
17+
```
18+
19+
2. Add your MParticle credentials:
20+
- In `platform_overrides/android/MainActivity.java`, replace:
21+
- `REPLACE_ME_API_KEY` with your Android API key
22+
- `REPLACE_ME_API_SECRET` with your Android API secret
23+
24+
- In `platform_overrides/ios/AppDelegate.m`, replace:
25+
- `REPLACE_ME_API_KEY` with your iOS API key
26+
- `REPLACE_ME_API_SECRET` with your iOS API secret
27+
28+
3. Add platforms:
29+
```bash
30+
cordova platform add android
31+
cordova platform add ios
32+
```
33+
34+
## Running the App
35+
36+
For Android:
37+
```bash
38+
cordova run android
39+
```
40+
41+
For iOS:
42+
```bash
43+
cordova run ios
44+
```
45+
46+
## Development
47+
48+
The example includes a clean script to help reset the project state:
49+
50+
```bash
51+
npm run clean
52+
```
53+
54+
This will:
55+
- Remove the platforms directory
56+
- Remove the plugins directory
57+
- Remove node_modules and package-lock.json
58+
- Reinstall dependencies
59+
60+
After cleaning, you'll need to re-add the platforms:
61+
```bash
62+
cordova platform add android ios
63+
```
64+
65+
## Project Structure
66+
67+
- `platform_overrides/` - Contains platform-specific customizations
68+
- `android/` - Android-specific files (MainActivity.java)
69+
- `ios/` - iOS-specific files (AppDelegate.m)
70+
- `www/` - Web assets and Cordova application code
71+
- `hooks/` - Scripts that run during Cordova commands

example/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
<allow-intent href="market:*" />
2121
</platform>
2222
<platform name="ios">
23+
<preference name="deployment-target" value="12.0" />
2324
<allow-intent href="itms:*" />
2425
<allow-intent href="itms-apps:*" />
2526
</platform>
27+
28+
<!-- Platform-specific file copy hook -->
29+
<hook type="after_platform_add" src="hooks/after_platform_add/010_copy_platform_specific_files.js" />
2630
<plugin name="cordova-plugin-mparticle" spec="../plugin" />
2731
</widget>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
3+
var fs = require('fs');
4+
var path = require('path');
5+
var shell = require('child_process');
6+
7+
module.exports = function(context) {
8+
// Get platform from context
9+
var platform = context.opts.platforms[0];
10+
11+
function ensureDirectoryExistence(filePath) {
12+
var dirname = path.dirname(filePath);
13+
if (fs.existsSync(dirname)) {
14+
return true;
15+
}
16+
fs.mkdirSync(dirname, { recursive: true });
17+
}
18+
19+
if (platform === 'android') {
20+
// Copy MainActivity.java
21+
var srcFile = path.join(context.opts.projectRoot, 'platform_overrides', 'android', 'MainActivity.java');
22+
var destFile = path.join(context.opts.projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'java', 'com', 'mparticle', 'example', 'MainActivity.java');
23+
24+
if (fs.existsSync(srcFile)) {
25+
try {
26+
ensureDirectoryExistence(destFile);
27+
fs.copyFileSync(srcFile, destFile);
28+
console.log('Copied custom MainActivity.java');
29+
} catch (err) {
30+
console.error('Error copying MainActivity.java:', err);
31+
process.exitCode = 1;
32+
}
33+
}
34+
} else if (platform === 'ios') {
35+
// Copy AppDelegate.m
36+
var srcFile = path.join(context.opts.projectRoot, 'platform_overrides', 'ios', 'AppDelegate.m');
37+
var destFile = path.join(context.opts.projectRoot, 'platforms', 'ios', 'MParticleExample', 'AppDelegate.m');
38+
39+
if (fs.existsSync(srcFile)) {
40+
try {
41+
ensureDirectoryExistence(destFile);
42+
fs.copyFileSync(srcFile, destFile);
43+
console.log('Copied custom AppDelegate.m');
44+
} catch (err) {
45+
console.error('Error copying AppDelegate.m:', err);
46+
process.exitCode = 1;
47+
}
48+
}
49+
}
50+
};

0 commit comments

Comments
 (0)