From b596c88a9b910115ed6e952b1bee12369dc3992a Mon Sep 17 00:00:00 2001 From: Victor Bo Date: Thu, 26 Oct 2023 09:18:47 +0800 Subject: [PATCH] ci: remove watch script (#35) * ci: remove watch script * ci: update lock --- package.json | 3 +- pnpm-lock.yaml | 3 -- scripts/utils.ts | 2 +- scripts/watch-package.ts | 89 ---------------------------------------- 4 files changed, 2 insertions(+), 95 deletions(-) delete mode 100644 scripts/watch-package.ts diff --git a/package.json b/package.json index e6cb96c..4c28f36 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ ], "scripts": { "create": "esno scripts/create-package.ts", - "watch": "esno scripts/watch-package.ts", + "dev": "pnpm build", "build": "pnpm build:packages && tsup", "build:packages": "pnpm -r --filter=!playground --filter=!docs build", "dev:playground": "pnpm -C playground dev", @@ -78,7 +78,6 @@ "@types/node": "^20.8.5", "@types/shelljs": "^0.8.13", "bumpp": "^9.2.0", - "chokidar": "^3.5.3", "eslint": "^8.51.0", "esno": "^0.17.0", "lint-staged": "^15.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cbd80f3..0d25b36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,9 +36,6 @@ importers: bumpp: specifier: ^9.2.0 version: 9.2.0 - chokidar: - specifier: ^3.5.3 - version: 3.5.3 eslint: specifier: ^8.51.0 version: 8.51.0 diff --git a/scripts/utils.ts b/scripts/utils.ts index a4fc61a..f63edfa 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -27,7 +27,7 @@ export function runCommand(command: string, dir = process.cwd(), options: Record ) } catch (error) { - reject(error.message) + reject((error as any).message) } }) } diff --git a/scripts/watch-package.ts b/scripts/watch-package.ts deleted file mode 100644 index 22dacc0..0000000 --- a/scripts/watch-package.ts +++ /dev/null @@ -1,89 +0,0 @@ -import path from 'node:path' -import process from 'node:process' -import chokidar from 'chokidar' -import { log, setLogPrefix } from '../packages/log' -import { runCommand } from './utils' - -function getFileRoot(filePath: string) { - return filePath.split(/[\\/]/)[0] -} - -function getPackageName(filePath: string) { - return filePath.split(/[\\/]/)[1] -} - -function runBuild() { - const runnerState = new RunnerState() - if (runnerState.value) - return - runnerState.value = true - runCommand(`pnpm build`, process.cwd(), { - silent: false, - }).then(() => { - log.success(`Build successfully.`) - runnerState.value = false - log.info('Ready for changes...') - }).catch((err) => { - log.error(`Failed to build.`) - log.error(err) - runnerState.value = false - }) -} - -function runWatchBuild(packagePath: string) { - const runnerState = new RunnerState() - if (runnerState.value) - return - runnerState.value = true - - const packageRoot = path.resolve(process.cwd(), packagePath) - runCommand(`pnpm build`, packageRoot, { - silent: false, - }).then(() => { - log.success(`Build ${packagePath} successfully.`) - runnerState.value = false - log.info('Ready for changes...') - }).catch((err) => { - log.error(`Failed to build ${packagePath}.`) - log.error(err) - runnerState.value = false - }) -} - -class RunnerState { - static instance: RunnerState | null = null - - private _value: boolean - - constructor() { - if (RunnerState.instance) - return RunnerState.instance - this._value = false - RunnerState.instance = this - } - - get value() { - return this._value - } - - set value(val) { - this._value = val - } -} - -setLogPrefix('@vtrbo/utils: ') - -chokidar - .watch(['./packages'], { - ignored: /(dist)|(node_modules)|(__test__)/, - }) - .on('ready', () => runBuild()) - .on('change', (filePath) => { - const fileRoot = getFileRoot(filePath) - const packageName = getPackageName(filePath) - const fullName = `${fileRoot}/${packageName}` - if (fullName) - runWatchBuild(fullName) - else - log.warn(`unexpected path ${filePath}`) - })