Kaynağa Gözat

若干模块更新

gemercheung 3 yıl önce
ebeveyn
işleme
c412982952

+ 9 - 0
.eslintrc.js

@@ -21,5 +21,14 @@ module.exports = {
         '@typescript-eslint/explicit-function-return-type': 'off',
         '@typescript-eslint/explicit-module-boundary-types': 'off',
         '@typescript-eslint/no-explicit-any': 'off',
+        '@typescript-eslint/ban-types': [
+            'error',
+            {
+                extendDefaults: true,
+                types: {
+                    '{}': false,
+                },
+            },
+        ],
     },
 };

+ 0 - 1
packages/core/package.json

@@ -18,7 +18,6 @@
     "prepublishOnly": "pnpm run build"
   },
   "dependencies": {
-    "@medici/foo": "workspace:~0.0.1",
     "@medici/types": "workspace:^0.0.1",
     "@medici/utils": "workspace:^0.0.1",
     "rxjs": "^7.5.6",

+ 12 - 0
packages/core/src/basicTrack.ts

@@ -0,0 +1,12 @@
+import { IBaseAction } from '@medici/types';
+
+export class BaseTrack implements IBaseAction {
+    constructor() {}
+    public trackView(url: string, referrer: string, uuid: string): void {}
+    public TrackEvent(
+        value: string,
+        type: string,
+        url: string,
+        uuid: string,
+    ): void {}
+}

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

@@ -1,5 +1,5 @@
 import { BehaviorSubject } from 'rxjs';
-import { version } from './package.json';
+import { version } from '../package.json';
 
 export interface ProjectConfigType {
     serverUrl: string;

+ 3 - 3
packages/core/src/event.ts

@@ -1,5 +1,5 @@
 import { GlobalEventType } from '@medici/types';
+// export
+export class Eventer {
 
-export function TrackEvent() {}
-
-export function trackView() {}
+}

+ 48 - 3
packages/core/src/history.ts

@@ -1,4 +1,49 @@
-// export interface BrowserTransportOptions {
-//     url: string;
-//     data: any;
+import { getGlobalObject, hook } from '@medici/utils';
+import { SDK } from './sdk';
+import { HistoryEvent } from '@medici/types';
+
+const global = getGlobalObject<Window>();
+export class History {
+    protected _sdk: SDK;
+    private currentRef: string;
+    private currentUrl: string;
+    constructor(sdk: SDK) {
+        this._sdk = sdk;
+        this.init();
+    }
+
+    init(): void {
+        global.document.addEventListener(
+            'readystatechange',
+            this.handleReadystatechange,
+        );
+    }
+
+    handleReadystatechange(): void {
+
+    }
+
+}
+// const handlePush = (state, title, url) => {
+//     if (!url) return;
+
+//     currentRef = currentUrl;
+//     const newUrl = url.toString();
+
+//     if (newUrl.substring(0, 4) === 'http') {
+//       currentUrl = '/' + newUrl.split('/').splice(3).join('/');
+//     } else {
+//       currentUrl = newUrl;
+//     }
+
+//     if (currentUrl !== currentRef) {
+//       trackView();
+//     }
+//   };
+
+// export const InitHistoryListener = () => {
+//     const global = getGlobalObject<Window>();
+//     global.document.addEventListener('readystatechange', () => { })
+//     global.history.pushState =
+
 // }

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

@@ -1,2 +1,2 @@
-export { init } from './sdk';
-export { TrackEvent } from './event';
+export * from './sdk';
+export * from './event';

+ 14 - 10
packages/core/src/sdk.ts

@@ -1,11 +1,13 @@
-import { getGlobalObject } from '@medici/utils';
-import { projectConfig, ProjectConfigType } from './config';
+// import { getGlobalObject } from '@medici/utils';
+// import { projectConfig, ProjectConfigType } from './config';
+import { BaseTrack } from './basicTrack';
+import { History } from './history';
 
-export function init(config: ProjectConfigType) {
-    const global = getGlobalObject<Window>();
-    console.log('global', global);
-    projectConfig.next(config);
-}
+// export function init(config: ProjectConfigType) {
+//     const global = getGlobalObject<Window>();
+//     console.log('global', global);
+//     projectConfig.next(config);
+// }
 
 export type PlatformType = 'web' | 'miniApp';
 
@@ -16,15 +18,17 @@ export interface SDKInitConfig {
 }
 export interface SDKConfigType {
     platform?: PlatformType;
+    autoTrack?: boolean;
     config?: SDKInitConfig;
 }
-class SDK {
+export class SDK extends BaseTrack {
     protected _platform: PlatformType;
     protected _config: SDKInitConfig;
+    protected _history = new History(this);
 
     constructor(params: SDKConfigType) {
+        super();
         this._config = params.config;
         this._platform = params.platform;
     }
-
-}
+}

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

@@ -1,4 +1,5 @@
 export type EventNameEnumType = 'pageview' | '';
+export type Dict<T> = { [key: string]: T };
 
 export interface GlobalEventType {
     id: string;
@@ -6,3 +7,23 @@ export interface GlobalEventType {
     eventVariable: string;
     triggerTime: number;
 }
+export type TrackEventType = 'click' | 'menu';
+export interface TrackActionOption extends Dict<any> {
+    eventType: string;
+}
+export interface IBaseAction {
+    trackView(url: string, referrer: string, uuid: string): void;
+    TrackEvent(value: string, type: string, url: string, uuid: string): void;
+}
+
+export interface ICustomAction {
+    track(trackActionName: string, trackActionOption?: TrackActionOption): void;
+    startTrack(
+        trackActionName: string,
+        trackActionOption?: TrackActionOption,
+    ): void;
+    endTrack(
+        trackActionName: string,
+        trackActionOption?: TrackActionOption,
+    ): void;
+}

+ 4 - 0
packages/types/src/history.ts

@@ -0,0 +1,4 @@
+export interface HistoryEvent {
+    handlePush(state: string, title: string, url: string): void;
+    addEvent(): void;
+}

+ 4 - 3
packages/types/src/index.ts

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

+ 9 - 11
packages/types/tsconfig.build.json

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

+ 22 - 0
packages/web/package.json

@@ -0,0 +1,22 @@
+{
+  "name": "@medici/web",
+  "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"
+  },
+  "dependencies": {
+    "@medici/core": "workspace:^0.0.1"
+  }
+}

+ 0 - 0
packages/web/src/index.ts


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

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

+ 3 - 0
packages/web/tsconfig.json

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

+ 4 - 4
play/src/main.ts

@@ -1,5 +1,5 @@
-import { createApp } from 'vue'
-import './style.css'
-import App from './App.vue'
+import { createApp } from 'vue';
+import './style.css';
+import App from './App.vue';
 
-createApp(App).mount('#app')
+createApp(App).mount('#app');

+ 3 - 3
play/src/vite-env.d.ts

@@ -1,7 +1,7 @@
 /// <reference types="vite/client" />
 
 declare module '*.vue' {
-  import type { DefineComponent } from 'vue'
-  const component: DefineComponent<{}, {}, any>
-  export default component
+    import type { DefineComponent } from 'vue';
+    const component: DefineComponent<{}, {}, any>;
+    export default component;
 }

+ 4 - 4
play/vite.config.ts

@@ -1,7 +1,7 @@
-import { defineConfig } from 'vite'
-import vue from '@vitejs/plugin-vue'
+import { defineConfig } from 'vite';
+import vue from '@vitejs/plugin-vue';
 
 // https://vitejs.dev/config/
 export default defineConfig({
-  plugins: [vue()]
-})
+    plugins: [vue()],
+});

+ 28 - 2
pnpm-lock.yaml

@@ -28,7 +28,6 @@ importers:
 
   packages/core:
     specifiers:
-      '@medici/foo': workspace:~0.0.1
       '@medici/types': workspace:^0.0.1
       '@medici/utils': workspace:^0.0.1
       rimraf: ~3.0.2
@@ -36,7 +35,6 @@ importers:
       typescript: ~4.7.4
       uuidv4: ^6.2.13
     dependencies:
-      '@medici/foo': link:../foo
       '@medici/types': link:../types
       '@medici/utils': link:../utils
       rxjs: 7.5.6
@@ -45,6 +43,23 @@ importers:
       rimraf: 3.0.2
       typescript: 4.7.4
 
+  packages/core/dist:
+    specifiers:
+      '@medici/types': workspace:^0.0.1
+      '@medici/utils': workspace:^0.0.1
+      rimraf: ~3.0.2
+      rxjs: ^7.5.6
+      typescript: ~4.7.4
+      uuidv4: ^6.2.13
+    dependencies:
+      '@medici/types': link:../../types
+      '@medici/utils': link:../../utils
+      rxjs: 7.5.6
+      uuidv4: 6.2.13
+    devDependencies:
+      rimraf: 3.0.2
+      typescript: 4.7.4
+
   packages/foo:
     specifiers:
       rimraf: ~3.0.2
@@ -69,6 +84,17 @@ importers:
       rimraf: 3.0.2
       typescript: 4.7.4
 
+  packages/web:
+    specifiers:
+      '@medici/core': workspace:^0.0.1
+      rimraf: ~3.0.2
+      typescript: ~4.7.4
+    dependencies:
+      '@medici/core': link:../core/dist
+    devDependencies:
+      rimraf: 3.0.2
+      typescript: 4.7.4
+
   play:
     specifiers:
       '@vitejs/plugin-vue': ^3.0.0

+ 1 - 1
tsconfig.build.json

@@ -7,7 +7,7 @@
     "declarationMap": true,
     "noEmitOnError": true,
     "skipLibCheck": true,
-    "esModuleInterop": true,
+    // "esModuleInterop": true,
     "resolveJsonModule": true,
     "types": [],
     "jsx": "react",