Skip to content

Commit 6b5e428

Browse files
authored
Merge pull request #29 from joinflux/build-on-push
chore(ci): add build pipeline
2 parents e820ec9 + 7bf21f2 commit 6b5e428

File tree

8 files changed

+107
-38
lines changed

8 files changed

+107
-38
lines changed

.github/workflows/build.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches: ['**']
6+
7+
jobs:
8+
build:
9+
name: Lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v6
13+
14+
- uses: actions/setup-node@v6
15+
with:
16+
node-version: 20
17+
cache: 'npm'
18+
19+
- name: Install dependencies
20+
run: npm ci
21+
22+
- name: Lint
23+
run: npm run lint
24+
25+
verify-web:
26+
name: Verify Web
27+
runs-on: ubuntu-latest
28+
needs: build
29+
steps:
30+
- uses: actions/checkout@v6
31+
32+
- uses: actions/setup-node@v6
33+
with:
34+
node-version: 20
35+
cache: 'npm'
36+
37+
- name: Install dependencies
38+
run: npm ci
39+
40+
- name: Verify Web
41+
run: npm run verify:web
42+
43+
verify-android:
44+
name: Verify Android
45+
runs-on: ubuntu-latest
46+
needs: build
47+
steps:
48+
- uses: actions/checkout@v6
49+
50+
- uses: actions/setup-node@v6
51+
with:
52+
node-version: 20
53+
cache: 'npm'
54+
55+
- uses: actions/setup-java@v4
56+
with:
57+
distribution: 'temurin'
58+
java-version: '21'
59+
60+
- name: Install dependencies
61+
run: npm ci
62+
63+
- name: Verify Android
64+
run: npm run verify:android
65+
66+
verify-ios:
67+
name: Verify iOS
68+
runs-on: macos-latest
69+
needs: build
70+
steps:
71+
- uses: actions/checkout@v6
72+
73+
- uses: actions/setup-node@v6
74+
with:
75+
node-version: 20
76+
cache: 'npm'
77+
78+
- name: Install dependencies
79+
run: npm ci
80+
81+
- name: Verify iOS
82+
run: npm run verify:ios

android/src/main/java/com/joinflux/flux/segment/Segment.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package com.joinflux.flux.segment;
22

33
import android.util.Log;
4-
54
import com.getcapacitor.JSObject;
65
import com.segment.analytics.Analytics;
76
import com.segment.analytics.Options;
87
import com.segment.analytics.Properties;
98
import com.segment.analytics.Traits;
10-
11-
import org.json.JSONException;
12-
139
import java.util.HashMap;
1410
import java.util.Iterator;
1511
import java.util.Map;
12+
import org.json.JSONException;
1613

1714
public class Segment {
1815

android/src/main/java/com/joinflux/flux/segment/SegmentPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.joinflux.flux.segment;
22

33
import android.content.Context;
4-
54
import com.getcapacitor.JSObject;
65
import com.getcapacitor.Plugin;
76
import com.getcapacitor.PluginCall;
@@ -18,7 +17,7 @@ public class SegmentPlugin extends Plugin {
1817

1918
@PluginMethod
2019
public void initialize(PluginCall call) {
21-
synchronized(implementation) {
20+
synchronized (implementation) {
2221
// No-op
2322
if (initialized) {
2423
call.resolve();

ios/Plugin/Segment.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import Segment
44
@objc public class Segment: NSObject {
55
@objc public func initialize(key: String, trackLifecycle: Bool) {
66
let config = AnalyticsConfiguration.init(writeKey: key)
7-
config.trackApplicationLifecycleEvents = trackLifecycle;
8-
7+
config.trackApplicationLifecycleEvents = trackLifecycle
8+
99
Analytics.setup(with: config)
1010
print("CapacitorSegment: initialized")
1111
}
12-
13-
@objc public func identify(userId: String, traits: Dictionary<String, Any>) {
12+
13+
@objc public func identify(userId: String, traits: [String: Any]) {
1414
Analytics.shared().identify(userId, traits: traits)
1515
return
1616
}
1717

18-
@objc public func track(eventName: String, properties: Dictionary<String, Any>, options: Dictionary<String, Any>) {
18+
@objc public func track(eventName: String, properties: [String: Any], options: [String: Any]) {
1919
Analytics.shared().track(eventName, properties: properties, options: options)
2020
return
2121
}
@@ -24,7 +24,7 @@ import Segment
2424
Analytics.shared().screen(pathname)
2525
return
2626
}
27-
27+
2828
@objc func reset() {
2929
Analytics.shared().reset()
3030
return

ios/Plugin/SegmentPlugin.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class SegmentPlugin: CAPPlugin {
1111
private let implementation = Segment()
1212

1313
@objc func initialize(_ call: CAPPluginCall) {
14-
if (initialized == true) {
14+
if initialized == true {
1515
call.resolve()
1616
return
1717
}
@@ -24,58 +24,58 @@ public class SegmentPlugin: CAPPlugin {
2424
initialized = true
2525
call.resolve()
2626
}
27-
27+
2828
@objc func identify(_ call: CAPPluginCall) {
29-
if (initialized != true) {
29+
if initialized != true {
3030
call.reject("Segment is not initialized")
3131
return
3232
}
3333
guard let userId = call.getString("userId") else {
3434
call.reject("User ID is required for 'identify' but not supplied")
3535
return
3636
}
37-
37+
3838
let traits: Dictionary = call.getObject("traits") ?? [:]
3939
implementation.identify(userId: userId, traits: traits)
4040
call.resolve()
4141
}
42-
42+
4343
@objc func track(_ call: CAPPluginCall) {
44-
if (initialized != true) {
44+
if initialized != true {
4545
call.reject("Segment is not initialized")
4646
return
4747
}
4848
guard let eventName = call.getString("eventName") else {
4949
call.reject("Event name is not supplied")
5050
return
5151
}
52-
52+
5353
let properties: Dictionary = call.getObject("properties") ?? [:]
5454
let options: Dictionary = call.getObject("options") ?? [:]
5555
implementation.track(eventName: eventName, properties: properties, options: options)
5656
call.resolve()
5757
}
5858

5959
@objc func page(_ call: CAPPluginCall) {
60-
if (initialized != true) {
60+
if initialized != true {
6161
call.reject("Segment is not initialized")
6262
return
6363
}
6464
guard let pathname = call.getString("pathname") else {
6565
call.reject("Pathname was not supplied")
6666
return
6767
}
68-
68+
6969
implementation.page(pathname: pathname)
7070
call.resolve()
7171
}
72-
72+
7373
@objc func reset(_ call: CAPPluginCall) {
74-
if (initialized != true) {
74+
if initialized != true {
7575
call.reject("Segment is not initialized")
7676
return
7777
}
78-
78+
7979
implementation.reset()
8080
call.resolve()
8181
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"verify:android": "cd android && ./gradlew clean build test && cd ..",
3434
"verify:web": "npm run build",
3535
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36-
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- autocorrect --format",
36+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
3737
"eslint": "eslint . --ext ts",
3838
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
3939
"swiftlint": "node-swiftlint",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { registerPlugin } from '@capacitor/core';
33
import type { SegmentPlugin } from './definitions';
44

55
const Segment = registerPlugin<SegmentPlugin>('Segment', {
6-
web: () => import('./web').then(m => new m.SegmentWeb()),
6+
web: () => import('./web').then((m) => new m.SegmentWeb()),
77
});
88

99
export * from './definitions';

src/web.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { WebPlugin } from '@capacitor/core';
22

3-
import type {
4-
SegmentPlugin,
5-
IdentifyOptions,
6-
InitializeOptions,
7-
PageOptions,
8-
TrackOptions,
9-
} from './definitions';
3+
import type { SegmentPlugin, IdentifyOptions, InitializeOptions, PageOptions, TrackOptions } from './definitions';
104

115
const getSegmentScript = (
126
key: string,
@@ -27,10 +21,7 @@ export class SegmentWeb extends WebPlugin implements SegmentPlugin {
2721

2822
async identify(options: IdentifyOptions): Promise<void> {
2923
if (!window.analytics) return Promise.reject('Segment is not initialized');
30-
if (!options.userId)
31-
return Promise.reject(
32-
"User ID is required for 'identify' but not supplied",
33-
);
24+
if (!options.userId) return Promise.reject("User ID is required for 'identify' but not supplied");
3425
window.analytics.identify(options.userId, options.traits, options.options);
3526
}
3627

@@ -57,7 +48,7 @@ export class SegmentWeb extends WebPlugin implements SegmentPlugin {
5748
* @param src - source of the script
5849
*/
5950
private loadScript(id: string, script: string): Promise<any> {
60-
return new Promise(resolve => {
51+
return new Promise((resolve) => {
6152
if (document.getElementById(id)) {
6253
resolve(null);
6354
} else {

0 commit comments

Comments
 (0)