@@ -9,6 +9,8 @@ import { fileURLToPath } from "node:url";
99 * @typedef {import("../scripts/types.ts").JSONValue } JSONValue;
1010 */
1111
12+ const MAX_BUFFER = 16 * 1024 * 1024 ; // 16 MB because some plists can get big
13+
1214/**
1315 * @param {JSONValue } obj
1416 * @returns {obj is JSONObject }
@@ -66,10 +68,11 @@ export function jsonFromPlist(filename) {
6668 const args = [ "-convert" , "json" , "-o" , "-" , filename ] ;
6769 const plutil = spawnSync ( "/usr/bin/plutil" , args , {
6870 stdio : [ "ignore" , "pipe" , "inherit" ] ,
71+ maxBuffer : MAX_BUFFER ,
6972 } ) ;
7073
7174 if ( plutil . status !== 0 ) {
72- throw new Error ( `Failed to read '${ filename } '` ) ;
75+ throw plutil . error ?? new Error ( `Failed to read '${ filename } '` ) ;
7376 }
7477
7578 return JSON . parse ( plutil . stdout . toString ( ) ) ;
@@ -85,10 +88,11 @@ export function plistFromJSON(source, filename) {
8588 const plutil = spawnSync ( "/usr/bin/plutil" , args , {
8689 stdio : [ "pipe" , "pipe" , "inherit" ] ,
8790 input : JSON . stringify ( source ) ,
91+ maxBuffer : MAX_BUFFER ,
8892 } ) ;
8993
9094 if ( plutil . status !== 0 ) {
91- throw new Error ( `Failed to generate '${ filename } '` ) ;
95+ throw plutil . error ?? new Error ( `Failed to generate '${ filename } '` ) ;
9296 }
9397
9498 return plutil . stdout . toString ( ) ;
@@ -124,3 +128,20 @@ export function resolveResources(appConfig, targetPlatform) {
124128
125129 return undefined ;
126130}
131+
132+ /**
133+ * @param {string } destination
134+ * @param {JSONObject } source
135+ * @returns {void }
136+ */
137+ export function writePlistFromJSON ( destination , source ) {
138+ const args = [ "-convert" , "xml1" , "-r" , "-o" , destination , "--" , "-" ] ;
139+ const plutil = spawnSync ( "/usr/bin/plutil" , args , {
140+ stdio : [ "pipe" , "pipe" , "inherit" ] ,
141+ input : JSON . stringify ( source ) ,
142+ } ) ;
143+
144+ if ( plutil . status !== 0 ) {
145+ throw plutil . error ?? new Error ( `Failed to write '${ destination } '` ) ;
146+ }
147+ }
0 commit comments