@@ -9,6 +9,8 @@ import { fileURLToPath } from "node:url";
9
9
* @typedef {import("../scripts/types.ts").JSONValue } JSONValue;
10
10
*/
11
11
12
+ const MAX_BUFFER = 16 * 1024 * 1024 ; // 16 MB because some plists can get big
13
+
12
14
/**
13
15
* @param {JSONValue } obj
14
16
* @returns {obj is JSONObject }
@@ -66,10 +68,11 @@ export function jsonFromPlist(filename) {
66
68
const args = [ "-convert" , "json" , "-o" , "-" , filename ] ;
67
69
const plutil = spawnSync ( "/usr/bin/plutil" , args , {
68
70
stdio : [ "ignore" , "pipe" , "inherit" ] ,
71
+ maxBuffer : MAX_BUFFER ,
69
72
} ) ;
70
73
71
74
if ( plutil . status !== 0 ) {
72
- throw new Error ( `Failed to read '${ filename } '` ) ;
75
+ throw plutil . error ?? new Error ( `Failed to read '${ filename } '` ) ;
73
76
}
74
77
75
78
return JSON . parse ( plutil . stdout . toString ( ) ) ;
@@ -85,10 +88,11 @@ export function plistFromJSON(source, filename) {
85
88
const plutil = spawnSync ( "/usr/bin/plutil" , args , {
86
89
stdio : [ "pipe" , "pipe" , "inherit" ] ,
87
90
input : JSON . stringify ( source ) ,
91
+ maxBuffer : MAX_BUFFER ,
88
92
} ) ;
89
93
90
94
if ( plutil . status !== 0 ) {
91
- throw new Error ( `Failed to generate '${ filename } '` ) ;
95
+ throw plutil . error ?? new Error ( `Failed to generate '${ filename } '` ) ;
92
96
}
93
97
94
98
return plutil . stdout . toString ( ) ;
@@ -124,3 +128,20 @@ export function resolveResources(appConfig, targetPlatform) {
124
128
125
129
return undefined ;
126
130
}
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