11import type { Context } from "../../types/index.js" ;
22import type { Manifest } from "../../types/manifest.js" ;
33import { toMerged } from "es-toolkit" ;
4- import { outputJSON , readJSON } from "fs-extra/esm" ;
4+ import { outputJSON , pathExists , readJSON } from "fs-extra/esm" ;
55import { logger } from "../../utils/logger.js" ;
66
77export default async function buildManifest ( ctx : Context ) : Promise < void > {
@@ -10,13 +10,14 @@ export default async function buildManifest(ctx: Context): Promise<void> {
1010
1111 const { name, id, updateURL, dist, version } = ctx ;
1212
13- const userData = await readJSON (
14- `${ dist } /addon/manifest.json` ,
15- ) as Manifest ;
13+ const manifestPath = `${ dist } /addon/manifest.json` ;
14+ const manifestExists = await pathExists ( manifestPath ) ;
15+ const userData = ( manifestExists ? await readJSON ( manifestPath ) : { } ) as Partial < Manifest > ;
16+
1617 const template : Manifest = {
17- ...userData ,
18- ... ( ( ! userData . name && name ) && { name } ) ,
19- ... ( version && { version } ) ,
18+ ...( userData as Manifest ) ,
19+ name : userData . name || name ,
20+ version : userData . version || version ,
2021 manifest_version : 2 ,
2122 applications : {
2223 zotero : {
@@ -29,7 +30,7 @@ export default async function buildManifest(ctx: Context): Promise<void> {
2930 const data : Manifest = toMerged ( userData , template ) ;
3031 logger . debug ( `manifest: ${ JSON . stringify ( data , null , 2 ) } ` ) ;
3132
32- outputJSON ( ` ${ dist } /addon/manifest.json` , data , { spaces : 2 } ) ;
33+ outputJSON ( manifestPath , data , { spaces : 2 } ) ;
3334}
3435
3536// TODO: process i10n in manifest.json
0 commit comments