Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
feat(Builder): allow changing output naming pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
evshiron committed May 10, 2017
1 parent a3b3dce commit 905a448
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion assets/project/package.json
Expand Up @@ -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",
Expand All @@ -20,6 +20,7 @@
"strippedProperties": [
"build"
],
"outputPattern": "${NAME} ${VERSION} ${PLATFORM} ${ARCH}",
"win": {
"versionStrings": {
"ProductName": "Project",
Expand Down
1 change: 1 addition & 0 deletions docs/Options.md
Expand Up @@ -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 `[ '**/*' ]`.
Expand Down
32 changes: 31 additions & 1 deletion src/lib/Builder.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/config/BuildConfig.ts
Expand Up @@ -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[] = [ '**/*' ];
Expand Down

0 comments on commit 905a448

Please sign in to comment.