Skip to content

Commit

Permalink
WIP: optimize local kit debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
recoluan committed May 19, 2024
1 parent dd8cda7 commit 28de8c1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 25 deletions.
1 change: 0 additions & 1 deletion packages/@revili/shared/src/client/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './instance.js'
export * from './socket.js'
9 changes: 0 additions & 9 deletions packages/@revili/shared/src/client/composables/instance.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/@revili/shared/src/node/composables/socket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function useServerSocket(server: any) {
import type { ViteDevServer, WebSocketServer } from 'vite'

export function useServerSocket(server: ViteDevServer): WebSocketServer | null {
let socket = null;

if (server?.ws) {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import {
createInitKitCommand
} from './command/index.js'

/**
* todo :
* 1. 通过 process.argv 判断用户是否增加了参数 --dir
* 2. 如果带了参数,说明是本地套件,直接通过 dir 值来获取套件实例
* 3. 套件实例传递给 createKitCommands、createStartCommand
* 4. 增加一个 getCurrentKit 方法,判断获取本地 kit 或 cache kit
*/

const args = process.argv.slice(2);
console.log(args);

// import {getMergedConfig} from './config/getMergedConfig.js'

;(async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/node/command/createStartCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function createStartCommand(program: CAC) {
.command('start', 'Starting the service')
.option('--dev', 'Open develop mode')
.option('--dir <dir>', 'Specify the entry file path for kit')
.action(async ({ dev: devMode = false, dir: customKitDir }) => {
await createViteServer({ devMode, customKitDir })
.action(async ({ dir }) => {
await createViteServer(dir)
})
}
4 changes: 2 additions & 2 deletions packages/core/src/node/viteServer/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {createServer} from 'vite'
import { resolveViteConfig } from './resolveViteConfig.js'

export async function createViteServer({ devMode, customKitDir }: { devMode: boolean, customKitDir: string }) {
const viteConfig = await resolveViteConfig({ devMode, customKitDir })
export async function createViteServer(customKitDir: string) {
const viteConfig = await resolveViteConfig(customKitDir)

const server = await createServer(viteConfig)
await server.listen()
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/node/viteServer/resolveViteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import {virtualModulePlugin} from './plugins/vitePluginVirtualModule.js'

import type { Kit } from '@revili/shared/node'

export async function resolveViteConfig({ devMode, customKitDir }: { devMode: boolean, customKitDir: string }): Promise<UserConfig> {
export async function resolveViteConfig(customKitDir: string): Promise<UserConfig> {
const { activeKit: activeKitName } = await getReviliCache();

// const NODE_MODULES_PATH_OF_KIT = path.join(CACHE_FOLDER_PATH, `./node_modules`);
const ACTIVE_KIT_DIR = path.join(CACHE_FOLDER_PATH, `./node_modules/${activeKitName}`);
const CLIENT_DIR = customKitDir
? path.join(CWD, `${customKitDir}/client`)
: path.join(devMode ? CWD : ACTIVE_KIT_DIR, `./dist/client`);
: path.join(ACTIVE_KIT_DIR, `./dist/client`);
const ACTIVE_KIT_ENTRY = customKitDir
? path.join(CWD, `${customKitDir}/node/index.js`)
: path.join(devMode ? CWD : ACTIVE_KIT_DIR, `./dist/node/index.js`);
: path.join(ACTIVE_KIT_DIR, `./dist/node/index.js`);

const activeKit = (await import(pathToFileURL(ACTIVE_KIT_ENTRY) as unknown as string)).default as Kit;

Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/types/node.d.ts

This file was deleted.

0 comments on commit 28de8c1

Please sign in to comment.