Selaa lähdekoodia

feat(Builder): strip some properties from package.json

evshiron 8 vuotta sitten
vanhempi
commit
c666496a2f
4 muutettua tiedostoa jossa 21 lisäystä ja 0 poistoa
  1. 3 0
      assets/project/package.json
  2. 1 0
      docs/Options.md
  3. 16 0
      src/lib/Builder.ts
  4. 1 0
      src/lib/config/BuildConfig.ts

+ 3 - 0
assets/project/package.json

@@ -15,6 +15,9 @@
       "zip",
       "nsis7z"
     ],
+    "strippedProperties": [
+      "build"
+    ],
     "win": {
       "versionStrings": {
         "ProductName": "Project",

+ 1 - 0
docs/Options.md

@@ -16,6 +16,7 @@ files | string[] | Glob patterns for included files. Exclude `${ output }` autom
 excludes | string[] | Glob patterns for excluded files. Defaults to `[]`.
 appId | string | App identity URI. Defaults to `io.github.nwjs.${ name }`.
 ffmpegIntegration | boolean | Whether to integrate `iteufel/nwjs-ffmpeg-prebuilt`. If `true`, you can NOT use symbols in `nwVersion`. Defaults to `false`.
+strippedProperties | string[] | Properties to be stripped from `package.json`. Defaults to `[ 'scripts', 'devDependencies', 'build' ]`.
 
 ## build.win <- [WinConfig](../src/lib/config/WinConfig.ts)
 

+ 16 - 0
src/lib/Builder.ts

@@ -352,6 +352,22 @@ export class Builder {
 
         }
 
+        // Here we overwrite `package.json` with a stripped one.
+
+        await writeFileAsync(join(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);
+
+        })());
+
     }
 
     protected async integrateFFmpeg(platform: string, arch: string, targetDir: string, pkg: any, config: BuildConfig) {

+ 1 - 0
src/lib/config/BuildConfig.ts

@@ -24,6 +24,7 @@ export class BuildConfig {
 
     public appId: string = undefined;
     public ffmpegIntegration: boolean = false;
+    public strippedProperties: string[] = [ 'scripts', 'devDependencies', 'build' ];
 
     constructor(pkg: any = {}) {