diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..d982b50 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,82 @@ +name: Build + +on: + pull_request: + branches: ['**'] + +jobs: + build: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-node@v6 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Lint + run: npm run lint + + verify-web: + name: Verify Web + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-node@v6 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Verify Web + run: npm run verify:web + + verify-android: + name: Verify Android + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-node@v6 + with: + node-version: 20 + cache: 'npm' + + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Install dependencies + run: npm ci + + - name: Verify Android + run: npm run verify:android + + verify-ios: + name: Verify iOS + runs-on: macos-latest + needs: build + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-node@v6 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Verify iOS + run: npm run verify:ios diff --git a/android/src/main/java/com/joinflux/flux/segment/Segment.java b/android/src/main/java/com/joinflux/flux/segment/Segment.java index 05ac32a..497ff27 100644 --- a/android/src/main/java/com/joinflux/flux/segment/Segment.java +++ b/android/src/main/java/com/joinflux/flux/segment/Segment.java @@ -1,18 +1,15 @@ package com.joinflux.flux.segment; import android.util.Log; - import com.getcapacitor.JSObject; import com.segment.analytics.Analytics; import com.segment.analytics.Options; import com.segment.analytics.Properties; import com.segment.analytics.Traits; - -import org.json.JSONException; - import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import org.json.JSONException; public class Segment { diff --git a/android/src/main/java/com/joinflux/flux/segment/SegmentPlugin.java b/android/src/main/java/com/joinflux/flux/segment/SegmentPlugin.java index 1f5dc9c..fdeeafe 100644 --- a/android/src/main/java/com/joinflux/flux/segment/SegmentPlugin.java +++ b/android/src/main/java/com/joinflux/flux/segment/SegmentPlugin.java @@ -1,7 +1,6 @@ package com.joinflux.flux.segment; import android.content.Context; - import com.getcapacitor.JSObject; import com.getcapacitor.Plugin; import com.getcapacitor.PluginCall; @@ -18,7 +17,7 @@ public class SegmentPlugin extends Plugin { @PluginMethod public void initialize(PluginCall call) { - synchronized(implementation) { + synchronized (implementation) { // No-op if (initialized) { call.resolve(); diff --git a/ios/Plugin/Segment.swift b/ios/Plugin/Segment.swift index 2db562c..ce7aef9 100644 --- a/ios/Plugin/Segment.swift +++ b/ios/Plugin/Segment.swift @@ -4,18 +4,18 @@ import Segment @objc public class Segment: NSObject { @objc public func initialize(key: String, trackLifecycle: Bool) { let config = AnalyticsConfiguration.init(writeKey: key) - config.trackApplicationLifecycleEvents = trackLifecycle; - + config.trackApplicationLifecycleEvents = trackLifecycle + Analytics.setup(with: config) print("CapacitorSegment: initialized") } - - @objc public func identify(userId: String, traits: Dictionary) { + + @objc public func identify(userId: String, traits: [String: Any]) { Analytics.shared().identify(userId, traits: traits) return } - @objc public func track(eventName: String, properties: Dictionary, options: Dictionary) { + @objc public func track(eventName: String, properties: [String: Any], options: [String: Any]) { Analytics.shared().track(eventName, properties: properties, options: options) return } @@ -24,7 +24,7 @@ import Segment Analytics.shared().screen(pathname) return } - + @objc func reset() { Analytics.shared().reset() return diff --git a/ios/Plugin/SegmentPlugin.swift b/ios/Plugin/SegmentPlugin.swift index 0612d41..def4554 100644 --- a/ios/Plugin/SegmentPlugin.swift +++ b/ios/Plugin/SegmentPlugin.swift @@ -11,7 +11,7 @@ public class SegmentPlugin: CAPPlugin { private let implementation = Segment() @objc func initialize(_ call: CAPPluginCall) { - if (initialized == true) { + if initialized == true { call.resolve() return } @@ -24,9 +24,9 @@ public class SegmentPlugin: CAPPlugin { initialized = true call.resolve() } - + @objc func identify(_ call: CAPPluginCall) { - if (initialized != true) { + if initialized != true { call.reject("Segment is not initialized") return } @@ -34,14 +34,14 @@ public class SegmentPlugin: CAPPlugin { call.reject("User ID is required for 'identify' but not supplied") return } - + let traits: Dictionary = call.getObject("traits") ?? [:] implementation.identify(userId: userId, traits: traits) call.resolve() } - + @objc func track(_ call: CAPPluginCall) { - if (initialized != true) { + if initialized != true { call.reject("Segment is not initialized") return } @@ -49,7 +49,7 @@ public class SegmentPlugin: CAPPlugin { call.reject("Event name is not supplied") return } - + let properties: Dictionary = call.getObject("properties") ?? [:] let options: Dictionary = call.getObject("options") ?? [:] implementation.track(eventName: eventName, properties: properties, options: options) @@ -57,7 +57,7 @@ public class SegmentPlugin: CAPPlugin { } @objc func page(_ call: CAPPluginCall) { - if (initialized != true) { + if initialized != true { call.reject("Segment is not initialized") return } @@ -65,17 +65,17 @@ public class SegmentPlugin: CAPPlugin { call.reject("Pathname was not supplied") return } - + implementation.page(pathname: pathname) call.resolve() } - + @objc func reset(_ call: CAPPluginCall) { - if (initialized != true) { + if initialized != true { call.reject("Segment is not initialized") return } - + implementation.reset() call.resolve() } diff --git a/package.json b/package.json index 4c71cf6..300c00d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "verify:android": "cd android && ./gradlew clean build test && cd ..", "verify:web": "npm run build", "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint", - "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- autocorrect --format", + "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format", "eslint": "eslint . --ext ts", "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java", "swiftlint": "node-swiftlint", diff --git a/src/index.ts b/src/index.ts index 121fe40..a6004dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { registerPlugin } from '@capacitor/core'; import type { SegmentPlugin } from './definitions'; const Segment = registerPlugin('Segment', { - web: () => import('./web').then(m => new m.SegmentWeb()), + web: () => import('./web').then((m) => new m.SegmentWeb()), }); export * from './definitions'; diff --git a/src/web.ts b/src/web.ts index f47c792..1a406af 100644 --- a/src/web.ts +++ b/src/web.ts @@ -1,12 +1,6 @@ import { WebPlugin } from '@capacitor/core'; -import type { - SegmentPlugin, - IdentifyOptions, - InitializeOptions, - PageOptions, - TrackOptions, -} from './definitions'; +import type { SegmentPlugin, IdentifyOptions, InitializeOptions, PageOptions, TrackOptions } from './definitions'; const getSegmentScript = ( key: string, @@ -27,10 +21,7 @@ export class SegmentWeb extends WebPlugin implements SegmentPlugin { async identify(options: IdentifyOptions): Promise { if (!window.analytics) return Promise.reject('Segment is not initialized'); - if (!options.userId) - return Promise.reject( - "User ID is required for 'identify' but not supplied", - ); + if (!options.userId) return Promise.reject("User ID is required for 'identify' but not supplied"); window.analytics.identify(options.userId, options.traits, options.options); } @@ -57,7 +48,7 @@ export class SegmentWeb extends WebPlugin implements SegmentPlugin { * @param src - source of the script */ private loadScript(id: string, script: string): Promise { - return new Promise(resolve => { + return new Promise((resolve) => { if (document.getElementById(id)) { resolve(null); } else {