Skip to content

Commit 7022de7

Browse files
committed
chore: migrate adev serve implementation
1 parent 3018f30 commit 7022de7

File tree

5 files changed

+29
-41
lines changed

5 files changed

+29
-41
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"textlint-rule-preset-ja-spacing": "2.4.3",
3333
"textlint-rule-preset-ja-technical-writing": "10.0.1",
3434
"textlint-rule-prh": "^6.0.0",
35-
"tree-kill": "^1.2.2",
3635
"tsx": "^4.16.2"
3736
}
3837
}

tools/lib/adev.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { consola } from 'consola';
22
import { $ } from 'execa';
3-
import kill from 'tree-kill';
43
import { buildDir } from './workspace';
54

65
const $$ = $({
@@ -18,10 +17,10 @@ export async function buildAdev() {
1817

1918
export function serveAdev() {
2019
const sh = $$({ cwd: buildDir, reject: false });
21-
const p = sh`npx bazel run //adev:serve --fast_adev`;
20+
const p = sh`yarn ibazel run //adev:serve`;
2221
const pid = p.pid!;
2322
consola.log(`adev process started: ${pid}`);
24-
const abort = () => kill(pid!);
23+
const abort = () => process.kill(pid!);
2524
p.finally(() => {
2625
consola.log(`adev process exited: ${pid}`);
2726
});

tools/lib/localize.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function copyLocalizedFiles() {
4040
}
4141

4242
export function watchLocalizedFiles() {
43-
return new Observable<string>((subscriber) => {
43+
const sub = new Observable<string>((subscriber) => {
4444
const watcher = watch(localizedFilePatterns, {
4545
cwd: adevJaDir,
4646
awaitWriteFinish: true,
@@ -53,12 +53,17 @@ export function watchLocalizedFiles() {
5353
return async () => {
5454
await watcher.close();
5555
};
56-
}).pipe(
57-
// 変更があったファイルをビルドディレクトリにコピーする
58-
mergeMap((file) => from(copyLocalizedFile(file))),
59-
// 1秒間の変更をまとめる
60-
debounceTime(1000)
61-
);
56+
})
57+
.pipe(
58+
// 変更があったファイルをビルドディレクトリにコピーする
59+
mergeMap((file) => from(copyLocalizedFile(file))),
60+
// 1秒間の変更をまとめる
61+
debounceTime(1000)
62+
)
63+
.subscribe();
64+
return {
65+
cancel: () => sub.unsubscribe(),
66+
};
6267
}
6368

6469
/**

tools/watch.ts

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { consola } from 'consola';
22
import { parseArgs } from 'node:util';
3-
import { Observable, startWith, switchMap } from 'rxjs';
43
import { serveAdev } from './lib/adev';
54
import { watchLocalizedFiles } from './lib/localize';
65
import setup from './lib/setup';
@@ -33,28 +32,19 @@ async function main() {
3332

3433
async function watch() {
3534
consola.start('Start watching adev-ja files...');
35+
const fileWatcher = watchLocalizedFiles();
3636

37-
const watcher = watchLocalizedFiles()
38-
.pipe(
39-
// 初回実行時に adev を起動する
40-
startWith(void 0),
41-
switchMap(
42-
() =>
43-
new Observable((subscriber) => {
44-
consola.start('Restarting adev...');
45-
const adevProcess = serveAdev();
46-
subscriber.next();
47-
48-
return async () => {
49-
await adevProcess.cancel();
50-
};
51-
})
52-
)
53-
)
54-
.subscribe();
55-
56-
process.on('SIGINT', watcher.unsubscribe);
57-
process.on('SIGTERM', watcher.unsubscribe);
37+
consola.start('Start adev server...');
38+
const adevServer = serveAdev();
39+
40+
const shutdown = () => {
41+
consola.info('Shutting down...');
42+
fileWatcher.cancel();
43+
adevServer.cancel();
44+
};
45+
46+
process.on('SIGINT', shutdown);
47+
process.on('SIGTERM', shutdown);
5848
}
5949

6050
main().catch((error) => {

yarn.lock

+3-8
Original file line numberDiff line numberDiff line change
@@ -3064,11 +3064,6 @@ traverse@^0.6.7, traverse@^0.6.8:
30643064
typedarray.prototype.slice "^1.0.3"
30653065
which-typed-array "^1.1.15"
30663066

3067-
tree-kill@^1.2.2:
3068-
version "1.2.2"
3069-
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
3070-
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
3071-
30723067
trough@^1.0.0:
30733068
version "1.0.3"
30743069
resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.3.tgz#e29bd1614c6458d44869fc28b255ab7857ef7c24"
@@ -3078,9 +3073,9 @@ try-resolve@^1.0.1:
30783073
resolved "https://registry.yarnpkg.com/try-resolve/-/try-resolve-1.0.1.tgz#cfde6fabd72d63e5797cfaab873abbe8e700e912"
30793074

30803075
tslib@^2.1.0:
3081-
version "2.6.3"
3082-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0"
3083-
integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==
3076+
version "2.7.0"
3077+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01"
3078+
integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==
30843079

30853080
tsx@^4.16.2:
30863081
version "4.16.2"

0 commit comments

Comments
 (0)