Procházet zdrojové kódy

feat(Builder): allow changing output naming pattern

evshiron před 8 roky
rodič
revize
905a448166

+ 2 - 1
assets/project/package.json

@@ -11,7 +11,7 @@
   "license": "MIT",
   "build": {
     "appId": "io.github.evshiron.nwjs-builder-phoenix.project",
-    "nwVersion": "lts",
+    "nwVersion": "0.14.7",
     "packed": true,
     "targets": [
       "zip",
@@ -20,6 +20,7 @@
     "strippedProperties": [
       "build"
     ],
+    "outputPattern": "${NAME} ${VERSION} ${PLATFORM} ${ARCH}",
     "win": {
       "versionStrings": {
         "ProductName": "Project",

+ 1 - 0
docs/Options.md

@@ -10,6 +10,7 @@ Name | Type | Description
 nwVersion | string | Used NW.js version. Support `lts`, `stable` and `latest` symbols. Defaults to `lts`.
 nwFlavor | string | Used NW.js flavor for builder. Runner will always use `sdk`. `normal` or `sdk`. Defaults to `normal`.
 output | string | Output directory relative to the project root. Defaults to `./dist/`.
+outputPattern | string | Output filename pattern. Defaults to `${NAME}-${VERSION}-${PLATFORM}-${ARCH}`.
 packed | boolean | Whether to pack app or not. Packed app needed to be extracted at launch time. Defaults to `false`.
 targets | string[] | Target formats to build. `zip`, `7z`, `nsis` and `nsis7z`, etc. Defaults to `[]`.
 files | string[] | Glob patterns for included files. Exclude `${ output }` automatically. Defaults to `[ '**/*' ]`.

+ 31 - 1
src/lib/Builder.ts

@@ -17,6 +17,13 @@ import { NsisVersionInfo } from './common';
 import { NsisComposer, NsisDiffer, Nsis7Zipper, nsisBuild } from './nsis-gen';
 import { mergeOptions, findExecutable, findFFmpeg, findRuntimeRoot, findExcludableDependencies, tmpName, tmpFile, tmpDir, fixWindowsVersion, copyFileAsync, extractGeneric, compress } from './util';
 
+interface IParseOutputPatternOptions {
+    name: string;
+    version: string;
+    platform: string;
+    arch: string;
+}
+
 interface IBuilderOptions {
     win?: boolean;
     mac?: boolean;
@@ -155,6 +162,25 @@ export class Builder {
 
     }
 
+    protected parseOutputPattern(pattern: string, options: IParseOutputPatternOptions, pkg: any, config: BuildConfig) {
+
+        return pattern.replace(/\$\{\s*(\w+)\s*\}/g, (match: string, key: string) => {
+            switch(key.toLowerCase()) {
+            case 'name':
+                return options.name;
+            case 'version':
+                return options.version;
+            case 'platform':
+                return options.platform;
+            case 'arch':
+                return options.arch;
+            default:
+                throw new Error('ERROR_KEY_UNKNOWN');
+            }
+        });
+
+    }
+
     protected combineExecutable(executable: string, nwFile: string) {
         return new Promise((resolve, reject) => {
 
@@ -486,7 +512,11 @@ export class Builder {
 
     protected async buildDirTarget(platform: string, arch: string, runtimeDir: string, pkg: any, config: BuildConfig): Promise<string> {
 
-        const targetDir = resolve(this.dir, config.output, `${ pkg.name }-${ pkg.version }-${ platform }-${ arch }`);
+        const targetDir = resolve(this.dir, config.output, this.parseOutputPattern(config.outputPattern, {
+            name: pkg.name,
+            version: pkg.version,
+            platform, arch,
+        }, pkg, config));
         const runtimeRoot = await findRuntimeRoot(platform, runtimeDir);
         const appRoot = resolve(targetDir, (() => {
             switch(platform) {

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

@@ -12,6 +12,7 @@ export class BuildConfig {
     public nwFlavor: string = 'normal';
 
     public output: string = './dist/';
+    public outputPattern: string = '${NAME}-${VERSION}-${PLATFORM}-${ARCH}';
     public packed: boolean = false;
     public targets: string[] = [];
     public files: string[] = [ '**/*' ];