瀏覽代碼

fix(Builder): fix stripping for packed apps

Evshiron Magicka 8 年之前
父節點
當前提交
bc5f68e6d5
共有 1 個文件被更改,包括 26 次插入16 次删除
  1. 26 16
      src/lib/Builder.ts

+ 26 - 16
src/lib/Builder.ts

@@ -136,6 +136,20 @@ export class Builder {
         return ((Date.now() - started) / 1000).toFixed(2);
     }
 
+    protected async writeStrippedManifest(path: string, pkg: any, config: BuildConfig) {
+
+        const json: any = {};
+
+        for(const key in pkg) {
+            if(pkg.hasOwnProperty(key) && config.strippedProperties.indexOf(key) === -1) {
+                json[key] = pkg[key];
+            }
+        }
+
+        await writeFile(path, JSON.stringify(json));
+
+    }
+
     protected combineExecutable(executable: string, nwFile: string) {
         return new Promise((resolve, reject) => {
 
@@ -343,13 +357,23 @@ export class Builder {
             case 'win32':
             case 'win':
             case 'linux':
+
                 const nwFile = await tmpName({
                     postfix: '.zip',
                 });
+
                 await compress(this.dir, files, 'zip', nwFile);
+
+                const { path: tempDir } = await tmpDir();
+                await this.writeStrippedManifest(resolve(tempDir, 'package.json'), pkg, config);
+                await compress(tempDir, [ './package.json' ], 'zip', nwFile);
+                await remove(tempDir);
+
                 const executable = await findExecutable(platform, targetDir);
                 await this.combineExecutable(executable, nwFile);
+
                 await remove(nwFile);
+
                 break;
             case 'darwin':
             case 'osx':
@@ -369,23 +393,9 @@ export class Builder {
                 await copyFileAsync(resolve(this.dir, file), resolve(appRoot, file));
             }
 
-        }
-
-        // Here we overwrite `package.json` with a stripped one.
-
-        await writeFile(resolve(appRoot, 'package.json'), (() => {
-
-            const json: any = {};
-
-            for(const key in pkg) {
-                if(pkg.hasOwnProperty(key) && config.strippedProperties.indexOf(key) == -1) {
-                    json[key] = pkg[key];
-                }
-            }
-
-            return JSON.stringify(json);
+            await this.writeStrippedManifest(resolve(appRoot, 'package.json'), pkg, config);
 
-        })());
+        }
 
     }