prepare sdk packages
This commit is contained in:
@@ -2,12 +2,21 @@ import Script from 'next/script';
|
||||
|
||||
import type {
|
||||
OpenpanelEventOptions,
|
||||
OpenpanelWebOptions,
|
||||
OpenpanelOptions,
|
||||
PostEventPayload,
|
||||
UpdateProfilePayload,
|
||||
} from '@openpanel/web';
|
||||
|
||||
const CDN_URL = 'http://localhost:3002/op.js';
|
||||
const CDN_URL = 'https://openpanel.dev/op.js';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
op: {
|
||||
q?: [string, ...any[]];
|
||||
(method: OpenpanelMethods, ...args: any[]): void;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
type OpenpanelMethods =
|
||||
| 'ctor'
|
||||
@@ -19,7 +28,7 @@ type OpenpanelMethods =
|
||||
| 'clear';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
interface window {
|
||||
op: {
|
||||
q?: [string, ...any[]];
|
||||
(method: OpenpanelMethods, ...args: any[]): void;
|
||||
@@ -27,7 +36,7 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
type OpenpanelProviderProps = OpenpanelWebOptions & {
|
||||
type OpenpanelProviderProps = OpenpanelOptions & {
|
||||
profileId?: string;
|
||||
cdnUrl?: string;
|
||||
};
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
"module": "index.ts",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && tsup",
|
||||
"build-for-openpanel": "pnpm build && cp dist/cdn.global.js ../../apps/public/public/op.js && cp dist/cdn.global.js ../../apps/test/public/op.js",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@openpanel/sdk": "workspace:*",
|
||||
"@openpanel/web": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
@@ -20,6 +18,7 @@
|
||||
"@openpanel/eslint-config": "workspace:*",
|
||||
"@openpanel/prettier-config": "workspace:*",
|
||||
"@openpanel/tsconfig": "workspace:*",
|
||||
"@types/react": "^18.2.20",
|
||||
"eslint": "^8.48.0",
|
||||
"prettier": "^3.0.3",
|
||||
"tsup": "^7.2.0",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import config from '@openpanel/tsconfig/tsup.config.json' assert { type: 'json'
|
||||
|
||||
export default defineConfig({
|
||||
...(config as any),
|
||||
entry: ['index.ts'],
|
||||
entry: ['index.tsx'],
|
||||
format: ['cjs', 'esm'],
|
||||
});
|
||||
|
||||
@@ -2,13 +2,13 @@ import { AppState, Platform } from 'react-native';
|
||||
import * as Application from 'expo-application';
|
||||
import Constants from 'expo-constants';
|
||||
|
||||
import type { OpenpanelOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel } from '@openpanel/sdk';
|
||||
import type { OpenpanelBaseOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel as OpenpanelBase } from '@openpanel/sdk';
|
||||
|
||||
type OpenpanelNativeOptions = OpenpanelOptions;
|
||||
export type OpenpanelOptions = OpenpanelBaseOptions;
|
||||
|
||||
export class OpenpanelNative extends Openpanel<OpenpanelNativeOptions> {
|
||||
constructor(options: OpenpanelNativeOptions) {
|
||||
export class OpenpanelRN extends OpenpanelBase<OpenpanelOptions> {
|
||||
constructor(options: OpenpanelOptions) {
|
||||
super(options);
|
||||
|
||||
this.api.headers['User-Agent'] = Constants.getWebViewUserAgentAsync();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/sdk.json",
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// NEW
|
||||
|
||||
export interface OpenpanelEventOptions {
|
||||
profileId?: string;
|
||||
}
|
||||
@@ -33,7 +31,7 @@ export interface DecrementProfilePayload {
|
||||
value: number;
|
||||
}
|
||||
|
||||
export interface OpenpanelOptions {
|
||||
export interface OpenpanelBaseOptions {
|
||||
url: string;
|
||||
clientId: string;
|
||||
clientSecret?: string;
|
||||
@@ -127,7 +125,9 @@ function createApi(_url: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export class Openpanel<Options extends OpenpanelOptions = OpenpanelOptions> {
|
||||
export class Openpanel<
|
||||
Options extends OpenpanelBaseOptions = OpenpanelBaseOptions,
|
||||
> {
|
||||
public options: Options;
|
||||
public api: ReturnType<typeof createApi>;
|
||||
private state: OpenpanelState = {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
f97a3167-8dc6-4bed-923b-3d118c544006
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/sdk.json",
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OpenpanelWeb as Openpanel } from './index';
|
||||
import { Openpanel } from './index';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { OpenpanelOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel } from '@openpanel/sdk';
|
||||
import type { OpenpanelBaseOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel as OpenpanelBase } from '@openpanel/sdk';
|
||||
|
||||
export * from '@openpanel/sdk';
|
||||
|
||||
export type OpenpanelWebOptions = OpenpanelOptions & {
|
||||
export type OpenpanelOptions = OpenpanelBaseOptions & {
|
||||
trackOutgoingLinks?: boolean;
|
||||
trackScreenViews?: boolean;
|
||||
trackAttributes?: boolean;
|
||||
@@ -16,10 +16,10 @@ function toCamelCase(str: string) {
|
||||
);
|
||||
}
|
||||
|
||||
export class OpenpanelWeb extends Openpanel<OpenpanelWebOptions> {
|
||||
export class Openpanel extends OpenpanelBase<OpenpanelOptions> {
|
||||
private lastPath = '';
|
||||
|
||||
constructor(options: OpenpanelWebOptions) {
|
||||
constructor(options: OpenpanelOptions) {
|
||||
super(options);
|
||||
|
||||
if (!this.isServer()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/sdk.json",
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -924,9 +924,6 @@ importers:
|
||||
|
||||
packages/sdks/nextjs:
|
||||
dependencies:
|
||||
'@openpanel/sdk':
|
||||
specifier: workspace:*
|
||||
version: link:../sdk
|
||||
'@openpanel/web':
|
||||
specifier: workspace:*
|
||||
version: link:../web
|
||||
@@ -943,6 +940,9 @@ importers:
|
||||
'@openpanel/tsconfig':
|
||||
specifier: workspace:*
|
||||
version: link:../../../tooling/typescript
|
||||
'@types/react':
|
||||
specifier: ^18.2.20
|
||||
version: 18.2.56
|
||||
eslint:
|
||||
specifier: ^8.48.0
|
||||
version: 8.56.0
|
||||
@@ -1152,6 +1152,9 @@ importers:
|
||||
|
||||
tooling/publish:
|
||||
dependencies:
|
||||
arg:
|
||||
specifier: ^5.0.2
|
||||
version: 5.0.2
|
||||
semver:
|
||||
specifier: ^7.5.4
|
||||
version: 7.6.0
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"arg": "^5.0.2",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
import { execSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import arg from 'arg';
|
||||
import semver from 'semver';
|
||||
|
||||
const sdkPackages = ['sdk', 'react-native', 'web', 'nextjs'];
|
||||
@@ -25,13 +25,18 @@ function exit(message: string, error?: unknown) {
|
||||
}
|
||||
|
||||
function main() {
|
||||
const [version] = process.argv.slice(2);
|
||||
const args = arg({
|
||||
// Types
|
||||
'--version': String,
|
||||
'--test': Boolean,
|
||||
// Aliases
|
||||
'-v': '--version',
|
||||
});
|
||||
|
||||
if (!version) {
|
||||
return console.error('Missing version');
|
||||
}
|
||||
const version = args['--version'];
|
||||
const test = args['--test'];
|
||||
|
||||
if (!semver.valid(version)) {
|
||||
if (version && !semver.valid(version)) {
|
||||
return console.error('Version is not valid');
|
||||
}
|
||||
|
||||
@@ -51,8 +56,10 @@ function main() {
|
||||
|
||||
try {
|
||||
for (const name of sdkPackages) {
|
||||
const pkgJson = require(workspacePath(`./packages/${name}/package.json`));
|
||||
savePackageJson(workspacePath(`./packages/${name}/package.json`), {
|
||||
const pkgJson = require(
|
||||
workspacePath(`./packages/sdks/${name}/package.json`)
|
||||
);
|
||||
savePackageJson(workspacePath(`./packages/sdks/${name}/package.json`), {
|
||||
...pkgJson,
|
||||
...properties,
|
||||
dependencies: Object.entries(pkgJson.dependencies).reduce(
|
||||
@@ -82,14 +89,16 @@ function main() {
|
||||
|
||||
console.log('✅ Built packages');
|
||||
|
||||
try {
|
||||
for (const name of sdkPackages) {
|
||||
execSync('npm publish --access=public', {
|
||||
cwd: workspacePath(`./packages/${name}`),
|
||||
});
|
||||
if (!test) {
|
||||
try {
|
||||
for (const name of sdkPackages) {
|
||||
execSync('npm publish --access=public', {
|
||||
cwd: workspacePath(`./packages/sdks/${name}`),
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
exit('Failed publish packages', error);
|
||||
}
|
||||
} catch (error) {
|
||||
exit('Failed publish packages', error);
|
||||
}
|
||||
|
||||
console.log('✅ All done!');
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"moduleDetection": "force",
|
||||
"composite": false,
|
||||
"strict": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react-jsx",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"allowImportingTsExtensions": false,
|
||||
"noEmit": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user