Skip to content

Commit

Permalink
Merge pull request #13 from rudderlabs/feat/refactor-js-generator
Browse files Browse the repository at this point in the history
feat: refactor javascript generator
  • Loading branch information
akashrpo authored Feb 19, 2024
2 parents 961b872 + 3ca8c08 commit 716a87e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/generators/javascript/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type ViolationHandler = (
* a warning message to the console.
{{/if}}
*/
{{#if isDevelopment}}
export const defaultValidationErrorHandler: ViolationHandler = (message, violations) => {
const msg = JSON.stringify({
type: 'RudderTyper JSON Schema Validation Error',
Expand All @@ -75,7 +76,6 @@ export const defaultValidationErrorHandler: ViolationHandler = (message, violati
console.warn(msg)
}

{{#if isDevelopment}}
let onViolation = defaultValidationErrorHandler
{{/if}}

Expand Down Expand Up @@ -274,16 +274,18 @@ const clientAPI = {
{{/each}}
}

export default new Proxy<typeof clientAPI>(clientAPI, {
export const RudderTyperAnalytics = new Proxy<typeof clientAPI>(clientAPI, {
get(target, method) {
if (typeof method === 'string' && target.hasOwnProperty(method)) {
if (typeof method === 'string' && Object.keys(target).includes(method)) {
return target[method as keyof typeof clientAPI]
}

return () => {
{{#if isDevelopment}}
console.warn(`⚠️ You made an analytics call (${String(method)}) that can't be found. Either:
a) Re-generate your ruddertyper client: \`npx rudder-typer\`
b) Add it to your Tracking Plan: {{trackingPlanURL}}`)
{{/if}}
const a = analytics()
if (a) {
{{#if isBrowser}}
Expand Down

0 comments on commit 716a87e

Please sign in to comment.