浏览代码

增加sdk type and core init

gemercheung 3 年之前
父节点
当前提交
cb7976cb66

+ 6 - 0
.changeset/short-pillows-poke.md

@@ -0,0 +1,6 @@
+---
+'@medici/core': major
+'@medici/types': major
+---
+
+测试 changesets version manageer

+ 5 - 4
packages/core/package.json

@@ -6,10 +6,10 @@
   "files": [
     "dist"
   ],
-  "author":  {
-    "name" : "gemercheung",
-    "email" : "gemercheung@gmail.com",
-    "url" : "http://gemer.xyz/"
+  "author": {
+    "name": "gemercheung",
+    "email": "gemercheung@gmail.com",
+    "url": "http://gemer.xyz/"
   },
   "scripts": {
     "build": "pnpm run clean && pnpm run compile",
@@ -20,6 +20,7 @@
   "dependencies": {
     "@medici/foo": "workspace:~0.0.1",
     "@medici/types": "workspace:^0.0.1",
+    "@medici/utils": "workspace:^0.0.1",
     "uuidv4": "^6.2.13"
   },
   "devDependencies": {

+ 2 - 1
packages/core/src/event.ts

@@ -2,4 +2,5 @@ import { GlobalEventType } from '@medici/types';
 
 export function TrackEvent() {
 
-}
+
+}

+ 1 - 1
packages/core/src/index.ts

@@ -1 +1 @@
-export { TrackEvent } from './event';
+export { TrackEvent } from './event';

+ 6 - 0
packages/core/src/sdk.ts

@@ -0,0 +1,6 @@
+import { getGlobalObject } from '@medici/utils';
+
+export function init() {
+    const global = getGlobalObject<Window>();
+}
+

+ 2 - 0
packages/types/src/event.ts

@@ -1,3 +1,5 @@
+export type EventNameEnumType = 'pageview' | '';
+
 export interface GlobalEventType {
     id: string;
     eventName: string;

+ 1 - 0
packages/types/src/index.ts

@@ -1,2 +1,3 @@
 export { BrowserTransportOptions } from './browser';
 export { GlobalEventType } from './event';
+export { SDKPlatformType, SDKconfigType } from './sdk';

+ 12 - 0
packages/types/src/sdk.ts

@@ -0,0 +1,12 @@
+export enum SDKPlatformType {
+    web = 0,
+    miniApp = 1,
+    webview = 2,
+}
+export interface SDKconfigType {
+    user: string;
+    version: string;
+    Platform: SDKPlatformType;
+    from?: string;
+    appId: string;
+}

+ 19 - 0
packages/utils/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@medici/utils",
+  "version": "0.0.1",
+  "main": "dist/index",
+  "types": "dist/index",
+  "files": [
+    "dist"
+  ],
+  "scripts": {
+    "build": "pnpm run clean && pnpm run compile",
+    "clean": "rimraf -rf ./dist",
+    "compile": "tsc -p tsconfig.build.json",
+    "prepublishOnly": "pnpm run build"
+  },
+  "devDependencies": {
+    "rimraf": "~3.0.2",
+    "typescript": "~4.7.4"
+  }
+}

+ 11 - 0
packages/utils/src/global.ts

@@ -0,0 +1,11 @@
+const fallbackGlobalObject = {};
+
+export function getGlobalObject<T>(): T {
+    return (
+        typeof window !== 'undefined' // eslint-disable-line no-restricted-globals
+            ? window // eslint-disable-line no-restricted-globals
+            : typeof self !== 'undefined'
+            ? self
+            : fallbackGlobalObject
+    ) as T;
+}

+ 10 - 0
packages/utils/src/hook.ts

@@ -0,0 +1,10 @@
+type CallbackType = (...args: string[]) => void;
+
+export const hook = (_this, method: string, callback: CallbackType) => {
+    const orig = _this[method];
+    return (...args) => {
+        // eslint-disable-next-line prefer-spread
+        callback.apply(null, args);
+        return orig.apply(_this, args);
+    };
+};

+ 2 - 0
packages/utils/src/index.ts

@@ -0,0 +1,2 @@
+export { hook } from './hook';
+export { getGlobalObject } from './global';

+ 11 - 0
packages/utils/tsconfig.build.json

@@ -0,0 +1,11 @@
+{
+  "extends": "../../tsconfig.build.json",
+
+  "compilerOptions": {
+    "outDir": "./dist"
+  },
+
+  "include": [
+    "src/**/*"
+  ]
+}

+ 3 - 0
packages/utils/tsconfig.json

@@ -0,0 +1,3 @@
+{
+  "extends": "../../tsconfig.json"
+}

+ 10 - 0
pnpm-lock.yaml

@@ -30,12 +30,14 @@ importers:
     specifiers:
       '@medici/foo': workspace:~0.0.1
       '@medici/types': workspace:^0.0.1
+      '@medici/utils': workspace:^0.0.1
       rimraf: ~3.0.2
       typescript: ~4.7.4
       uuidv4: ^6.2.13
     dependencies:
       '@medici/foo': link:../foo
       '@medici/types': link:../types
+      '@medici/utils': link:../utils
       uuidv4: 6.2.13
     devDependencies:
       rimraf: 3.0.2
@@ -57,6 +59,14 @@ importers:
       rimraf: 3.0.2
       typescript: 4.7.4
 
+  packages/utils:
+    specifiers:
+      rimraf: ~3.0.2
+      typescript: ~4.7.4
+    devDependencies:
+      rimraf: 3.0.2
+      typescript: 4.7.4
+
 packages:
 
   /@babel/code-frame/7.18.6: