-
Notifications
You must be signed in to change notification settings - Fork 0
/
turbotree.ts
77 lines (72 loc) · 1.82 KB
/
turbotree.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
70
71
72
73
74
75
76
77
import {
KickstartContext,
PackageInfo,
Trigger,
watchTree,
WatchExpression,
} from "turbotree";
import path from "path";
/**
* This function returns a watch expression that determines which files to watch for changes.
*/
const getWatchExpression = (p: PackageInfo): WatchExpression => [
"allof",
// don't watch files in dist, node_modules, or lib
[
"not",
[
"anyof",
["dirname", "dist"],
["dirname", "node_modules"],
["dirname", "lib"],
],
],
[
"anyof",
// watch index.html in the root
[
"allof",
["dirname", p.root],
["anyof", ["match", "index.html", "wholename"]],
],
// watch configuration files in the root
[
"allof",
["dirname", p.root],
[
"anyof",
["match", "*.json", "basename"],
["match", "*.mjs", "basename"],
["match", "*.cjs", "basename"],
["match", "*.js", "basename"],
["match", "*.env", "basename"],
["match", "*.env.local", "basename"],
],
],
// watch .css, .ts, and .tsx files in src
[
"allof",
["dirname", path.join(p.root, "src")],
[
"anyof",
["match", "*.ts", "basename"],
["match", "*.tsx", "basename"],
["match", "*.css", "basename"],
],
],
],
];
const triggers = (p: PackageInfo): Trigger[] => [
{
expression: getWatchExpression(p),
name: `${p.name}:build`,
initialRun: false,
onChange: async ({ spawn, files }) => {
console.log(`${p.root}: changes detected: ${files.map((f) => f.name)}`);
await spawn`turbo build --output-logs=new-only ${p.turboFilterFlags}`;
},
},
];
const kickstartCommand = async (k: KickstartContext) =>
k.$`pnpm turbo build --output-logs=new-only ${k.turboFilterFlags}`;
watchTree(__dirname, triggers, kickstartCommand);