This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
69 lines (54 loc) · 1.55 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type { AstroIntegration } from 'astro';
import path from 'node:path';
import fs from 'node:fs';
import concurrently from 'concurrently';
/* ========================================================================== */
interface Settings {
entryPoints: string[];
/**
* @default true
*/
watch?: boolean;
}
/* —————————————————————————————————————————————————————————————————————————— */
// HACK: Debounce double server setup (Astro bug?)
let created = false;
export const integration = ({
entryPoints,
watch = true,
}: Settings): AstroIntegration => ({
name: 'sidecar',
hooks: {
'astro:server:setup': async (/* { server } */) => {
if (!Array.isArray(entryPoints))
throw Error('Please setup the sidecar entrypoint.');
if (created) return;
created = true;
process.env.NODE_NO_WARNINGS = String(1);
const { result } = concurrently(
entryPoints.map((entryPoint) => {
if (!fs.statSync(entryPoint))
throw Error(`Incorrect path: ${entryPoint}`);
return {
command: `tsx watch ${entryPoint}`,
name: path.basename(entryPoint, path.extname(entryPoint)),
};
}),
{
prefix: 'name',
killOthers: ['failure', 'success'],
restartTries: 3,
},
);
result
.then((r) => {
// console.log(r);
})
.catch((e) => {
console.error(e);
});
process.env.NODE_NO_WARNINGS = String(0);
},
},
});
export default integration;