From c41447b02125b8ef53174d8b5e954e0400c25cc3 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Mon, 15 Jan 2024 17:22:04 +0100 Subject: [PATCH 1/3] feat(context tracking): add secondary sdk name and version --- packages/screeb-sdk-browser/docs/README.md | 2 ++ packages/screeb-sdk-browser/src/index.ts | 7 +++++++ packages/screeb-sdk-browser/src/types.ts | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/packages/screeb-sdk-browser/docs/README.md b/packages/screeb-sdk-browser/docs/README.md index 6c3bb5a..4e6aad2 100644 --- a/packages/screeb-sdk-browser/docs/README.md +++ b/packages/screeb-sdk-browser/docs/README.md @@ -354,6 +354,8 @@ This is the Screeb tag options object. | Name | Type | Description | | :------ | :------ | :------ | | `screebEndpoint?` | `string` | Please don't do this. | +| `sdkName?` | `string` | SDK name (eg: sdk-browser, sdk-react, sdk-angular, etc...) | +| `sdkVersion?` | `string` | SDK version (eg: 1.2.3) | | `window?` | `Window` | If you're running Screeb tag in an iframe, please set the inner window here. | ___ diff --git a/packages/screeb-sdk-browser/src/index.ts b/packages/screeb-sdk-browser/src/index.ts index 476bfdb..e930ad9 100644 --- a/packages/screeb-sdk-browser/src/index.ts +++ b/packages/screeb-sdk-browser/src/index.ts @@ -7,6 +7,7 @@ import { ScreebOptions, } from "./types"; +import { version } from "../package.json"; export * from "./types"; export * from "./hooks.types"; @@ -69,6 +70,12 @@ export const load = (options: ScreebOptions = {}) => }; _window.document.head.appendChild(scriptElement); + + const context = { + secondary_sdk_name: options.sdkName ?? "sdk-browser", + secondary_sdk_version: options.sdkVersion ?? version, + }; + callScreebCommand("client.internal.web", context); }); /** diff --git a/packages/screeb-sdk-browser/src/types.ts b/packages/screeb-sdk-browser/src/types.ts index fa6f489..e10e249 100644 --- a/packages/screeb-sdk-browser/src/types.ts +++ b/packages/screeb-sdk-browser/src/types.ts @@ -19,6 +19,12 @@ export type PropertyRecord = { export type ScreebOptions = { /** If you're running Screeb tag in an iframe, please set the inner window here. */ window?: Window; + + /** SDK name (eg: sdk-browser, sdk-react, sdk-angular, etc...) */ + sdkName?: string; + /** SDK version (eg: 1.2.3) */ + sdkVersion?: string; + /** Please don't do this. */ screebEndpoint?: string; }; From 232e9a99a9482cd9e9e1bd0dba17190a2d731ebe Mon Sep 17 00:00:00 2001 From: MD4 Date: Tue, 16 Jan 2024 14:00:50 +0100 Subject: [PATCH 2/3] feat(*): bubble up version to context tracking --- package-lock.json | 316 ++++++++++++++++++ .../screeb-sdk-angular/docs/classes/Screeb.md | 8 +- packages/screeb-sdk-angular/package.json | 8 +- .../screeb-sdk-angular/src/lib/constants.ts | 1 + .../screeb-sdk-angular/src/lib/screeb.ts | 9 +- packages/screeb-sdk-browser/src/index.ts | 5 +- packages/screeb-sdk-react/src/provider.tsx | 8 +- .../src/rollup.config.js | 33 +- 8 files changed, 375 insertions(+), 13 deletions(-) create mode 100644 packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/constants.ts diff --git a/package-lock.json b/package-lock.json index 4494b9a..1eb8935 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12155,6 +12155,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", + "dev": true + }, "node_modules/is-unicode-supported": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", @@ -17207,6 +17213,287 @@ "jsesc": "bin/jsesc" } }, + "node_modules/replace-in-files-cli": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/replace-in-files-cli/-/replace-in-files-cli-2.2.0.tgz", + "integrity": "sha512-EI2Psum9Ay9y2IDWx36+hOvn+BX6LdQ8HXZ06L32obGrJb9w7YDMTywIQgysOXwQo5MsORtIA4l/g25r2Cp1gA==", + "dev": true, + "dependencies": { + "escape-string-regexp": "^5.0.0", + "globby": "^12.0.2", + "meow": "^10.1.1", + "normalize-path": "^3.0.0", + "write-file-atomic": "^3.0.3" + }, + "bin": { + "replace-in-files": "cli.js" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/array-union": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-3.0.1.tgz", + "integrity": "sha512-1OvF9IbWwaeiM9VhzYXVQacMibxpXOMYVNIvMtKRyX9SImBXpKcFr8XvFDeEslCyuH/t6KRt7HEO94AlP8Iatw==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/camelcase-keys": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-7.0.2.tgz", + "integrity": "sha512-Rjs1H+A9R+Ig+4E/9oyB66UC5Mj9Xq3N//vcLf2WzgdTi/3gUu3Z9KoqmlrEG4VuuLK8wJHofxzdQXz/knhiYg==", + "dev": true, + "dependencies": { + "camelcase": "^6.3.0", + "map-obj": "^4.1.0", + "quick-lru": "^5.1.1", + "type-fest": "^1.2.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/decamelize": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-5.0.1.tgz", + "integrity": "sha512-VfxadyCECXgQlkoEAjeghAr5gY3Hf+IKjKb+X8tGVDtveCjN+USwprd2q3QXBR9T1+x2DG0XZF5/w+7HAtSaXA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/escape-string-regexp": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", + "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/globby": { + "version": "12.2.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-12.2.0.tgz", + "integrity": "sha512-wiSuFQLZ+urS9x2gGPl1H5drc5twabmm4m2gTR27XDFyjUHJUNsS8o/2aKyIF6IoBaR630atdher0XJ5g6OMmA==", + "dev": true, + "dependencies": { + "array-union": "^3.0.1", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.7", + "ignore": "^5.1.9", + "merge2": "^1.4.1", + "slash": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/indent-string": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-5.0.0.tgz", + "integrity": "sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/meow": { + "version": "10.1.5", + "resolved": "https://registry.npmjs.org/meow/-/meow-10.1.5.tgz", + "integrity": "sha512-/d+PQ4GKmGvM9Bee/DPa8z3mXs/pkvJE2KEThngVNOqtmljC6K7NMPxtc2JeZYTmpWb9k/TmxjeL18ez3h7vCw==", + "dev": true, + "dependencies": { + "@types/minimist": "^1.2.2", + "camelcase-keys": "^7.0.0", + "decamelize": "^5.0.0", + "decamelize-keys": "^1.1.0", + "hard-rejection": "^2.1.0", + "minimist-options": "4.1.0", + "normalize-package-data": "^3.0.2", + "read-pkg-up": "^8.0.0", + "redent": "^4.0.0", + "trim-newlines": "^4.0.2", + "type-fest": "^1.2.2", + "yargs-parser": "^20.2.9" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/quick-lru": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", + "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/read-pkg": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-6.0.0.tgz", + "integrity": "sha512-X1Fu3dPuk/8ZLsMhEj5f4wFAF0DWoK7qhGJvgaijocXxBmSToKfbFtqbxMO7bVjNA1dmE5huAzjXj/ey86iw9Q==", + "dev": true, + "dependencies": { + "@types/normalize-package-data": "^2.4.0", + "normalize-package-data": "^3.0.2", + "parse-json": "^5.2.0", + "type-fest": "^1.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/read-pkg-up": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-8.0.0.tgz", + "integrity": "sha512-snVCqPczksT0HS2EC+SxUndvSzn6LRCwpfSvLrIfR5BKDQQZMaI6jPRC9dYvYFDRAuFEAnkwww8kBBNE/3VvzQ==", + "dev": true, + "dependencies": { + "find-up": "^5.0.0", + "read-pkg": "^6.0.0", + "type-fest": "^1.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/redent": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/redent/-/redent-4.0.0.tgz", + "integrity": "sha512-tYkDkVVtYkSVhuQ4zBgfvciymHaeuel+zFKXShfDnFP5SyVEP7qo70Rf1jTOTCx3vGNAbnEi/xFkcfQVMIBWag==", + "dev": true, + "dependencies": { + "indent-string": "^5.0.0", + "strip-indent": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/slash": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", + "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/strip-indent": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-4.0.0.tgz", + "integrity": "sha512-mnVSV2l+Zv6BLpSD/8V87CW/y9EmmbYzGCIavsnsI6/nwn26DwffM/yztm30Z/I2DY9wdS3vXVCMnHDgZaVNoA==", + "dev": true, + "dependencies": { + "min-indent": "^1.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/trim-newlines": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-4.1.1.tgz", + "integrity": "sha512-jRKj0n0jXWo6kh62nA5TEh3+4igKDXLvzBJcPpiizP7oOolUrYIxmVBG9TOtHYFHoddUk6YvAkGeGoSVTXfQXQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/type-fest": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", + "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/replace-in-files-cli/node_modules/write-file-atomic": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", + "integrity": "sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==", + "dev": true, + "dependencies": { + "imurmurhash": "^0.1.4", + "is-typedarray": "^1.0.0", + "signal-exit": "^3.0.2", + "typedarray-to-buffer": "^3.1.5" + } + }, + "node_modules/replace-in-files-cli/node_modules/yargs-parser": { + "version": "20.2.9", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", + "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -19443,6 +19730,15 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, + "node_modules/typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "dev": true, + "dependencies": { + "is-typedarray": "^1.0.0" + } + }, "node_modules/typedoc": { "version": "0.25.2", "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.25.2.tgz", @@ -20695,6 +20991,7 @@ "karma-jasmine-html-reporter": "~2.1.0", "ng-packagr": "^16.2.3", "prettier": "^3.0.3", + "replace-in-files-cli": "^2.2.0", "rxjs": "~7.8.1", "tslib": "^2.6.2", "typedoc": "^0.25.2", @@ -21397,6 +21694,17 @@ "webpack": "^5.54.0" } }, + "packages/screeb-sdk-angular/node_modules/@types/node": { + "version": "20.11.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.4.tgz", + "integrity": "sha512-6I0fMH8Aoy2lOejL3s4LhyIYX34DPwY8bl5xlNjBvUEk8OHrcuzsFt+Ied4LvJihbtXPM+8zUqdydfIti86v9g==", + "dev": true, + "optional": true, + "peer": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "packages/screeb-sdk-angular/node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -22091,6 +22399,14 @@ "node": ">=14.17" } }, + "packages/screeb-sdk-angular/node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "optional": true, + "peer": true + }, "packages/screeb-sdk-angular/node_modules/vite": { "version": "4.4.7", "resolved": "https://registry.npmjs.org/vite/-/vite-4.4.7.tgz", diff --git a/packages/screeb-sdk-angular/docs/classes/Screeb.md b/packages/screeb-sdk-angular/docs/classes/Screeb.md index 9d9515a..ce95a22 100644 --- a/packages/screeb-sdk-angular/docs/classes/Screeb.md +++ b/packages/screeb-sdk-angular/docs/classes/Screeb.md @@ -394,10 +394,16 @@ ___ ### load -▸ **load**(): `Promise`<`undefined`\> +▸ **load**(`options?`): `Promise`<`undefined`\> Appends Screeb tag into your dom. +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `options?` | `ScreebOptions` | Screeb module options. | + #### Returns `Promise`<`undefined`\> diff --git a/packages/screeb-sdk-angular/package.json b/packages/screeb-sdk-angular/package.json index 73f6636..aa6fa60 100644 --- a/packages/screeb-sdk-angular/package.json +++ b/packages/screeb-sdk-angular/package.json @@ -41,12 +41,13 @@ ], "scripts": { "ng": "ng", - "build": "ng build", + "build": "npm run replace-version && ng build", "build:watch": "ng build --watch --configuration development", "build:doc": "typedoc projects/screeb-sdk-angular/src/public-api.ts", "clean": "rm -Rf dist", "lint": "eslint .", - "test": "echo '@TODO'" + "test": "echo '@TODO'", + "replace-version": "replace-in-files --string='0.0.0-dev' --replacement=$npm_package_version projects/screeb-sdk-angular/src/lib/constants.ts" }, "dependencies": { "@screeb/sdk-browser": "^0.1.14" @@ -80,6 +81,7 @@ "karma-jasmine-html-reporter": "~2.1.0", "ng-packagr": "^16.2.3", "prettier": "^3.0.3", + "replace-in-files-cli": "^2.2.0", "rxjs": "~7.8.1", "tslib": "^2.6.2", "typedoc": "^0.25.2", @@ -94,4 +96,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/constants.ts b/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/constants.ts new file mode 100644 index 0000000..0bc5a48 --- /dev/null +++ b/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/constants.ts @@ -0,0 +1 @@ +export default { version: "0.0.0-dev" }; diff --git a/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts b/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts index 2e589a1..af604fa 100644 --- a/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts +++ b/packages/screeb-sdk-angular/projects/screeb-sdk-angular/src/lib/screeb.ts @@ -1,6 +1,7 @@ import { Inject, Injectable } from "@angular/core"; import * as _Screeb from "@screeb/sdk-browser"; +import CONSTANTS from "./constants"; import * as logger from "./logger"; import { ScreebConfig } from "./screeb-config"; @@ -431,7 +432,11 @@ export class Screeb { * this.screeb.load(); * ``` */ - public async load() { - return _Screeb.load(); + public async load(options?: _Screeb.ScreebOptions) { + return _Screeb.load({ + sdkName: "sdk-angular", + sdkVersion: CONSTANTS.version, + ...options, + }); } } diff --git a/packages/screeb-sdk-browser/src/index.ts b/packages/screeb-sdk-browser/src/index.ts index e930ad9..55ab3de 100644 --- a/packages/screeb-sdk-browser/src/index.ts +++ b/packages/screeb-sdk-browser/src/index.ts @@ -7,13 +7,13 @@ import { ScreebOptions, } from "./types"; -import { version } from "../package.json"; export * from "./types"; export * from "./hooks.types"; declare const window: Window & { $screeb?: ScreebObject }; const SCREEB_TAG_ENDPOINT = "https://t.screeb.app/tag.js"; +const CONSTANTS = { version: "0.0.0-dev" }; let _window = typeof window === "undefined" ? undefined : window; @@ -73,8 +73,9 @@ export const load = (options: ScreebOptions = {}) => const context = { secondary_sdk_name: options.sdkName ?? "sdk-browser", - secondary_sdk_version: options.sdkVersion ?? version, + secondary_sdk_version: options.sdkVersion ?? CONSTANTS.version, }; + callScreebCommand("client.internal.web", context); }); diff --git a/packages/screeb-sdk-react/src/provider.tsx b/packages/screeb-sdk-react/src/provider.tsx index 89620ae..d00cc88 100644 --- a/packages/screeb-sdk-react/src/provider.tsx +++ b/packages/screeb-sdk-react/src/provider.tsx @@ -6,6 +6,8 @@ import * as logger from "./logger"; import { ScreebContextValues, ScreebProviderProps } from "./types"; import { isSSR } from "./utils"; +export const CONSTANTS = { version: "0.0.0-dev" }; + let isInitialized = false; export const ScreebProvider: React.FC< @@ -162,7 +164,11 @@ export const ScreebProvider: React.FC< const load = React.useCallback( async (options?: Screeb.ScreebOptions) => { if (!isLoaded.current) { - Screeb.load(options); + Screeb.load({ + sdkName: "sdk-react", + sdkVersion: CONSTANTS.version, + ...options, + }); isLoaded.current = true; diff --git a/packages/screeb-typescript-config/src/rollup.config.js b/packages/screeb-typescript-config/src/rollup.config.js index 506a2c8..ce476e2 100644 --- a/packages/screeb-typescript-config/src/rollup.config.js +++ b/packages/screeb-typescript-config/src/rollup.config.js @@ -1,17 +1,42 @@ +import glob from 'glob' +import path from 'path' +import fs from 'fs' + import typescript from '@rollup/plugin-typescript'; +const watcher = (globs) => ({ + buildStart () { + for (const item of globs) { + glob.sync(path.resolve(item)).forEach((filename) => { this.addWatchFile(filename) }) + } + } +}) + +const updateVersion = () => ({ + renderStart (outputOptions, inputOptions) { + outputOptions.footer = () => `CONSTANTS.version = '${JSON.parse(fs.readFileSync('package.json', 'utf8')).version}'` + } +}) + export default { input: "src/index.ts", output: [ { + plugins: [ + updateVersion() + ], file: "dist/es/index.mjs", format: "esm" }, { + plugins: [ + updateVersion() + ], file: "dist/cjs/index.cjs", format: "cjs" }, ], - plugins: [typescript({ - tsconfig: './tsconfig.json' - })] -}; \ No newline at end of file + plugins: [ + watcher(['package.json']), + typescript({ tsconfig: './tsconfig.json' }), + ] +}; From e76592b7ec874f4a60f8dac57288a21b45eac3fd Mon Sep 17 00:00:00 2001 From: MD4 Date: Tue, 16 Jan 2024 15:00:08 +0100 Subject: [PATCH 3/3] feat(screeb-sdk-angular): undo constants.ts changes after build --- packages/screeb-sdk-angular/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/screeb-sdk-angular/package.json b/packages/screeb-sdk-angular/package.json index aa6fa60..938f55a 100644 --- a/packages/screeb-sdk-angular/package.json +++ b/packages/screeb-sdk-angular/package.json @@ -41,7 +41,7 @@ ], "scripts": { "ng": "ng", - "build": "npm run replace-version && ng build", + "build": "npm run replace-version && ng build && git checkout -f projects/screeb-sdk-angular/src/lib/constants.ts", "build:watch": "ng build --watch --configuration development", "build:doc": "typedoc projects/screeb-sdk-angular/src/public-api.ts", "clean": "rm -Rf dist",