-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.task.ts
More file actions
47 lines (40 loc) · 1.62 KB
/
sync.task.ts
File metadata and controls
47 lines (40 loc) · 1.62 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
import {z} from 'zod';
import {spawn} from '@fuzdev/fuz_util/process.js';
import {TaskError, type Task} from './task.ts';
import {package_json_sync} from './package_json.ts';
import {sveltekit_sync} from './sveltekit_helpers.ts';
/** @nodocs */
export const Args = z.strictObject({
sveltekit: z.boolean().meta({description: 'dual of no-sveltekit'}).default(true),
'no-sveltekit': z.boolean().meta({description: 'opt out of svelte-kit sync'}).default(false),
package_json: z.boolean().meta({description: 'dual of no-package_json'}).default(true),
'no-package_json': z.boolean().meta({description: 'opt out of package.json sync'}).default(false),
gen: z.boolean().meta({description: 'dual of no-gen'}).default(true),
'no-gen': z.boolean().meta({description: 'opt out of running gen'}).default(false),
install: z.boolean().meta({description: 'opt into installing packages'}).default(false),
});
export type Args = z.infer<typeof Args>;
/** @nodocs */
export const task: Task<Args> = {
summary: 'run `gro gen`, update `package.json`, and optionally install packages to sync up',
Args,
run: async ({args, invoke_task, config, log}): Promise<void> => {
const {sveltekit, package_json, gen, install} = args;
if (install) {
const result = await spawn(config.pm_cli, ['install']);
if (!result.ok) {
throw new TaskError(`Failed \`${config.pm_cli} install\``);
}
}
if (sveltekit) {
await sveltekit_sync(undefined, config.pm_cli);
log.info('synced SvelteKit');
}
if (package_json && config.map_package_json) {
await package_json_sync(config.map_package_json, log);
}
if (gen) {
await invoke_task('gen');
}
},
};