-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): js sdk feeds module (#5688)
* feat(js): improve the package json exports and tsup config * feat(js): lazy session initialization and interface fixes * feat(js): js sdk feeds module
- Loading branch information
Showing
28 changed files
with
1,271 additions
and
1,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export enum ButtonTypeEnum { | ||
PRIMARY = 'primary', | ||
SECONDARY = 'secondary', | ||
CLICKED = 'clicked', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,68 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import sizeLimit from 'size-limit'; | ||
import filePlugin from '@size-limit/file'; | ||
import esbuildPlugin from '@size-limit/esbuild'; | ||
import bytes from "bytes-iec" | ||
import chalk from "chalk" | ||
import bytes from 'bytes-iec'; | ||
import chalk from 'chalk'; | ||
|
||
const LIMIT = '10 kb'; | ||
const LIMIT_IN_BYTES = 10_000; | ||
const baseDir = process.cwd(); | ||
const esmPath = path.resolve(baseDir, './dist/index.js'); | ||
const cjsPath = path.resolve(baseDir, './dist/index.cjs'); | ||
const umdPath = path.resolve(baseDir, './dist/novu.min.js'); | ||
const umdGzipPath = path.resolve(baseDir, './dist/novu.min.js.gz'); | ||
|
||
const formatBytes = (size) => { | ||
return bytes.format(size, { unitSeparator: " " }) | ||
} | ||
return bytes.format(size, { unitSeparator: ' ' }); | ||
}; | ||
|
||
const checks = [ | ||
{ | ||
name: 'ESM', | ||
path: esmPath, | ||
limit: LIMIT, | ||
files: [esmPath], | ||
sizeLimit: LIMIT_IN_BYTES, | ||
}, | ||
const modules = [ | ||
{ | ||
name: 'CJS', | ||
path: cjsPath, | ||
limit: LIMIT, | ||
files: [cjsPath], | ||
sizeLimit: LIMIT_IN_BYTES, | ||
name: 'UMD minified', | ||
filePath: umdPath, | ||
limit: '10 kb', | ||
limitInBytes: 20_000, | ||
}, | ||
{ | ||
name: 'UMD', | ||
path: umdPath, | ||
limit: LIMIT, | ||
files: [umdPath], | ||
sizeLimit: LIMIT_IN_BYTES, | ||
name: 'UMD gzip', | ||
filePath: umdGzipPath, | ||
limit: '10 kb', | ||
limitInBytes: 10_000, | ||
}, | ||
]; | ||
|
||
const config = { | ||
cwd: process.cwd(), | ||
checks, | ||
const checkFiles = async () => { | ||
const result = []; | ||
for (const module of modules) { | ||
const { name, filePath, limitInBytes } = module; | ||
const stats = await fs.stat(filePath); | ||
const passed = stats.size <= limitInBytes; | ||
result.push({ name, passed, size: formatBytes(stats.size), limit: formatBytes(limitInBytes) }); | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
const calculateSizes = async () => { | ||
console.log(chalk.gray("Checking the build dist files...")); | ||
|
||
const results = await sizeLimit([filePlugin, esbuildPlugin], config); | ||
if (config.failed) { | ||
console.log(chalk.bold.red("\nThe build has reached the dist files size limits! 🚨\n")); | ||
console.log(chalk.gray('🚧 Checking the build dist files...\n')); | ||
|
||
results.filter((_, index) => { | ||
const check = checks[index] | ||
const { passed } = check | ||
const checks = await checkFiles(); | ||
const anyFailed = checks.some((check) => !check.passed); | ||
|
||
return !passed; | ||
}).forEach((result, index) => { | ||
const check = checks[index] | ||
const { size } = result | ||
const { name } = check | ||
checks.forEach((check) => { | ||
const { name, passed, size, limit } = check; | ||
|
||
if (!passed) { | ||
console.log(chalk.yellow(`The ${name} file has failed the size limit.`)); | ||
console.log(chalk.yellow(`Current size is "${formatBytes(size)}" and the limit is "${check.limit}".\n`)); | ||
}) | ||
console.log(chalk.yellow(`Current size is "${size}" and the limit is "${limit}".\n`)); | ||
} else { | ||
console.log(chalk.green(`The ${name} file has passed the size limit.`)); | ||
console.log(chalk.green(`Current size is "${size}" and the limit is "${limit}".\n`)); | ||
} | ||
}); | ||
|
||
if (anyFailed) { | ||
console.log(chalk.bold.red('\nThe build has reached the dist files size limits! 🚨\n')); | ||
|
||
process.exit(1); | ||
} else { | ||
console.log(chalk.green("All good! 🙌")); | ||
console.log(chalk.green('All good! 🙌')); | ||
} | ||
} | ||
}; | ||
|
||
calculateSizes(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
import mitt, { Emitter } from 'mitt'; | ||
|
||
import { Events, EventHandler, EventNames } from './types'; | ||
import { EventHandler, Events, EventNames } from './types'; | ||
|
||
type SingletonOptions = { recreate: true }; | ||
|
||
export class NovuEventEmitter { | ||
private emitter: Emitter<Events>; | ||
static #instance: NovuEventEmitter; | ||
#mittEmitter: Emitter<Events>; | ||
|
||
static getInstance(options?: SingletonOptions): NovuEventEmitter { | ||
if (options?.recreate) { | ||
NovuEventEmitter.#instance = new NovuEventEmitter(); | ||
} | ||
|
||
return NovuEventEmitter.#instance; | ||
} | ||
|
||
constructor() { | ||
this.emitter = mitt(); | ||
private constructor() { | ||
this.#mittEmitter = mitt(); | ||
} | ||
|
||
on<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void { | ||
this.emitter.on(eventName, listener); | ||
this.#mittEmitter.on(eventName, listener); | ||
} | ||
|
||
off<Key extends EventNames>(eventName: Key, listener: EventHandler<Events[Key]>): void { | ||
this.emitter.on(eventName, listener); | ||
this.#mittEmitter.on(eventName, listener); | ||
} | ||
|
||
emit<Key extends EventNames>(type: Key, event?: Events[Key]): void { | ||
this.emitter.emit(type, event); | ||
this.#mittEmitter.emit(type, event as Events[Key]); | ||
} | ||
} |
Oops, something went wrong.
9088aab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://novu-web-component-dev.netlify.app as production
🚀 Deployed on https://667433db076d6e5ed8666a4a--novu-web-component-dev.netlify.app