Skip to content

Commit

Permalink
feat(cordova-consent): generate constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ratson committed Jan 23, 2021
1 parent 5f1647d commit 6dd5091
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 2 deletions.
73 changes: 71 additions & 2 deletions internal/cli/src/gen/consent.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,84 @@
import _ from 'lodash'
import { pkgsDirJoin } from '../utils'
import { buildUtils, warnMessage } from './shared'
import {
buildUtils,
renderJavaContants,
renderSwiftContants,
renderTsContants,
warnMessage,
} from './shared'

const Actions = _.mapValues(
{
ready: null,
requestInfoUpdate: null,
isFormAvailable: null,
loadForm: null,
getStatus: null,
showForm: null,
reset: null,
},
(v, k) => (v === null ? k : v) as string,
)

const Events = _.mapValues(
{ ready: null },
(v, k) => `consent.${v === null ? k : v}`,
)

function buildJava(): string {
const linesActions = renderJavaContants(Actions)
const linesEvents = renderJavaContants(Events)

return `// ${warnMessage}
package cordova.plugin.consent;
public final class Generated {
public final class Actions {
${linesActions}
}
public final class Events {
${linesEvents}
}
}
`
}

function buildSwift(): string {
const linesEvents = renderSwiftContants(Events)

return `// ${warnMessage}
struct AMCEvents {
${linesEvents}
}
`
}

function buildTypeScript(): string {
return `// ${warnMessage}
import { exec } from 'cordova'
export enum NativeActions {
${renderTsContants(Actions)}
}
export enum Events {
${renderTsContants(Events)}
}
${buildUtils('Consent')}
`
}

export default () => ({
files: [{ path: 'cordova-consent/ts/generated.ts', f: buildTypeScript }],
files: [
{ path: 'cordova-consent/src/android/Generated.java', f: buildJava },
{
path: 'cordova-consent/src/ios/AMCGenerated.swift',
f: buildSwift,
},
{ path: 'cordova-consent/ts/generated.ts', f: buildTypeScript },
],
pkgDir: pkgsDirJoin('cordova-consent'),
tagertDir: 'src/cordova/plugin/consent',
})
2 changes: 2 additions & 0 deletions packages/cordova-consent/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<!-- AUTOGENERATED: ANDROID_BEGIN -->
<source-file src="src/android/Consent.java" target-dir="src/cordova/plugin/consent" />
<source-file src="src/android/Generated.java" target-dir="src/cordova/plugin/consent" />
<!-- AUTOGENERATED: ANDROID_END -->

<preference name="CONSENT_SDK_VERSION" default="+" />
Expand All @@ -33,6 +34,7 @@

<header-file src="src/ios/AMSConsent-Bridging-Header.h" type="BridgingHeader" />
<!-- AUTOGENERATED: IOS_BEGIN -->
<source-file src="src/ios/AMCGenerated.swift" />
<source-file src="src/ios/AMSConsent.swift" />
<!-- AUTOGENERATED: IOS_END -->

Expand Down
17 changes: 17 additions & 0 deletions packages/cordova-consent/src/android/Generated.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
package cordova.plugin.consent;

public final class Generated {
public final class Actions {
public static final String GET_STATUS = "getStatus";
public static final String IS_FORM_AVAILABLE = "isFormAvailable";
public static final String LOAD_FORM = "loadForm";
public static final String READY = "ready";
public static final String REQUEST_INFO_UPDATE = "requestInfoUpdate";
public static final String SHOW_FORM = "showForm";
}

public final class Events {
public static final String READY = "consent.ready";
}
}
4 changes: 4 additions & 0 deletions packages/cordova-consent/src/ios/AMCGenerated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
struct AMCEvents {
static let ready = "consent.ready"
}
13 changes: 13 additions & 0 deletions packages/cordova-consent/ts/generated.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import { exec } from 'cordova'

export enum NativeActions {
getStatus = 'getStatus',
isFormAvailable = 'isFormAvailable',
loadForm = 'loadForm',
ready = 'ready',
requestInfoUpdate = 'requestInfoUpdate',
showForm = 'showForm',
}

export enum Events {
ready = 'consent.ready',
}

export const execAsync = (action: string, args?: any[]) => {
return new Promise((resolve, reject) => {
exec(resolve, reject, 'Consent', action, args)
Expand Down

0 comments on commit 6dd5091

Please sign in to comment.