forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch.js
More file actions
61 lines (49 loc) · 2.03 KB
/
Copy pathwatch.js
File metadata and controls
61 lines (49 loc) · 2.03 KB
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
import { join } from 'node:path';
import concurrently from 'concurrently';
import { NULL_ROOT_ERROR } from '../utils/errors.js';
import { getClerkPackages } from '../utils/getClerkPackages.js';
import { getDependencies } from '../utils/getDependencies.js';
import { getMonorepoRoot } from '../utils/getMonorepoRoot.js';
/**
* Starts long-running watchers for Clerk dependencies.
* @param {object} args
* @param {boolean | undefined} args.js If `true`, only spawn the builder for `@clerk/clerk-js`.
* @returns {Promise<import('concurrently').CloseEvent[]>}
*/
export async function watch({ js }) {
const { dependencies, devDependencies } = await getDependencies(join(process.cwd(), 'package.json'));
const clerkPackages = Object.keys(await getClerkPackages());
const packagesInPackageJSON = [...Object.keys(dependencies ?? {}), ...Object.keys(devDependencies ?? {})];
const clerkPackagesInPackageJSON = packagesInPackageJSON.filter(p => clerkPackages.includes(p));
const filterArgs = clerkPackagesInPackageJSON.map(p => `--filter=${p}`);
const args = ['watch', 'build', ...filterArgs];
const cwd = await getMonorepoRoot();
if (!cwd) {
throw new Error(NULL_ROOT_ERROR);
}
/** @type {import('concurrently').ConcurrentlyCommandInput} */
const clerkJsCommand = {
name: 'clerk-js',
command: 'turbo run dev --filter=@clerk/clerk-js -- --env devOrigin=http://localhost:4000',
cwd,
env: { TURBO_UI: '0', ...process.env },
};
/** @type {import('concurrently').ConcurrentlyCommandInput} */
const packagesCommand = {
name: 'packages',
command: `turbo ${args.join(' ')}`,
cwd,
env: { TURBO_UI: '0', ...process.env },
};
if (js) {
const { result } = concurrently([clerkJsCommand], { prefixColors: 'auto' });
return result;
}
/** @type {import('concurrently').ConcurrentlyCommandInput[]} */
const commands = [packagesCommand];
if (typeof js === 'undefined') {
commands.push(clerkJsCommand);
}
const { result } = concurrently(commands, { prefixColors: 'auto' });
return result;
}