11import type { Task } from '@grogarden/gro' ;
2- import { load_package_json , type PackageJson } from '@grogarden/gro/package_json.js' ;
2+ import { load_package_json } from '@grogarden/gro/package_json.js' ;
33import { z } from 'zod' ;
44import { writeFile } from 'node:fs/promises' ;
55import { format_file } from '@grogarden/gro/format_file.js' ;
66import { exists } from '@grogarden/gro/exists.js' ;
7+ import { join } from 'node:path' ;
8+ import { paths } from '@grogarden/gro/paths.js' ;
79
810import { fetch_packages , type FetchedPackage } from '$lib/fetch_packages.js' ;
911import { load_orc_config } from '$lib/config.js' ;
1012
13+ // TODO etags - cache?
1114// TODO refactor for reusability
1215
1316// TODO maybe support `--check` for CI
1417export const Args = z
1518 . object ( {
19+ dir : z
20+ . string ( {
21+ description : 'path to the directory containing the source package.json and orc.config.ts' ,
22+ } )
23+ . optional ( ) ,
1624 outfile : z
1725 . string ( { description : 'path to the generated packages.json file' } )
18- . default ( './src/ lib/ packages.json') ,
26+ . default ( join ( paths . lib , ' packages.json') ) ,
1927 } )
2028 . strict ( ) ;
2129export type Args = z . infer < typeof Args > ;
@@ -27,17 +35,14 @@ export const task: Task<Args> = {
2735 Args,
2836 summary : 'download metadata for the given packages' ,
2937 run : async ( { args, log} ) => {
30- const { outfile} = args ;
38+ const { dir , outfile} = args ;
3139
32- const orc_config = await load_orc_config ( ) ;
40+ const orc_config = await load_orc_config ( dir ) ;
3341 const package_urls = orc_config . repos ;
3442
3543 const fetched_packages = await fetch_packages ( package_urls , log ) ;
3644
37- let local_package_json : PackageJson | undefined ;
38- try {
39- local_package_json = await load_package_json ( ) ;
40- } catch ( err ) { }
45+ const local_package_json = await load_package_json ( dir ) ;
4146
4247 const packages : FetchedPackage [ ] = local_package_json ?. homepage
4348 ? [
0 commit comments