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

Commit

Permalink
fix(Builder): replace join with resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
evshiron committed Apr 19, 2017
1 parent 553ea3c commit 4ec3028
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
55 changes: 29 additions & 26 deletions src/lib/Builder.ts
@@ -1,5 +1,5 @@

import { dirname, basename, join, resolve } from 'path';
import { dirname, basename, resolve } from 'path';

import * as semver from 'semver';
import { ensureDirAsync, emptyDir, readFileAsync, readJsonAsync, writeFileAsync, copyAsync, removeAsync, createReadStream, createWriteStream, renameAsync } from 'fs-extra-promise';
Expand Down Expand Up @@ -103,7 +103,7 @@ export class Builder {
}
else {

const pkg: any = await readJsonAsync(join(this.dir, this.options.chromeApp ? 'manifest.json' : 'package.json'));
const pkg: any = await readJsonAsync(resolve(this.dir, this.options.chromeApp ? 'manifest.json' : 'package.json'));
const config = new BuildConfig(pkg);

debug('in build', 'config', config);
Expand Down Expand Up @@ -158,15 +158,18 @@ export class Builder {
}

protected updateWinResources(targetDir: string, appRoot: string, pkg: any, config: BuildConfig) {

const pathResolve = resolve;

return new Promise((resolve, reject) => {

const path = join(targetDir, './nw.exe');
const path = pathResolve(targetDir, 'nw.exe');

const rc = {
'product-version': fixWindowsVersion(config.win.productVersion),
'file-version': fixWindowsVersion(config.win.fileVersion),
'version-string': config.win.versionStrings,
'icon': config.win.icon,
'icon': config.win.icon ? pathResolve(this.dir, config.win.icon) : undefined,
};

rcedit(path, rc, (err: Error) => err ? reject(err) : resolve());
Expand All @@ -176,16 +179,16 @@ export class Builder {

protected renameWinApp(targetDir: string, appRoot: string, pkg: any, config: BuildConfig) {

const src = join(targetDir, 'nw.exe');
const dest = join(targetDir, `${ config.win.versionStrings.ProductName }.exe`);
const src = resolve(targetDir, 'nw.exe');
const dest = resolve(targetDir, `${ config.win.versionStrings.ProductName }.exe`);

return renameAsync(src, dest);

}

protected async updatePlist(targetDir: string, appRoot: string, pkg: any, config: BuildConfig) {

const path = join(targetDir, './nwjs.app/Contents/Info.plist');
const path = resolve(targetDir, './nwjs.app/Contents/Info.plist');

const plist = await this.readPlist(path);

Expand All @@ -201,13 +204,13 @@ export class Builder {

protected async updateMacIcon(targetDir: string, appRoot: string, pkg: any, config: BuildConfig) {

const path = join(targetDir, './nwjs.app/Contents/Resources/app.icns');
const path = resolve(targetDir, './nwjs.app/Contents/Resources/app.icns');

if(!config.mac.icon) {
return;
}

await copyAsync(config.mac.icon, path);
await copyAsync(resolve(this.dir, config.mac.icon), path);

}

Expand All @@ -219,7 +222,7 @@ export class Builder {

for(const file of files) {

const path = join(targetDir, file);
const path = resolve(targetDir, file);

const strings = <string>(await readFileAsync(path, {
encoding: 'ucs2',
Expand Down Expand Up @@ -250,17 +253,17 @@ export class Builder {

protected renameMacApp(targetDir: string, appRoot: string, pkg: any, config: BuildConfig) {

const src = join(targetDir, 'nwjs.app');
const dest = join(targetDir, `${ config.mac.displayName }.app`);
const src = resolve(targetDir, 'nwjs.app');
const dest = resolve(targetDir, `${ config.mac.displayName }.app`);

return renameAsync(src, dest);

}

protected renameLinuxApp(targetDir: string, appRoot: string, pkg: any, config: BuildConfig) {

const src = join(targetDir, 'nw');
const dest = join(targetDir, `${ pkg.name }`);
const src = resolve(targetDir, 'nw');
const dest = resolve(targetDir, `${ pkg.name }`);

return renameAsync(src, dest);

Expand Down Expand Up @@ -336,7 +339,7 @@ export class Builder {
case 'osx':
case 'mac':
for(const file of files) {
await copyFileAsync(join(this.dir, file), join(appRoot, file));
await copyFileAsync(resolve(this.dir, file), resolve(appRoot, file));
}
break;
default:
Expand All @@ -347,14 +350,14 @@ export class Builder {
else {

for(const file of files) {
await copyFileAsync(join(this.dir, file), join(appRoot, file));
await copyFileAsync(resolve(this.dir, file), resolve(appRoot, file));
}

}

// Here we overwrite `package.json` with a stripped one.

await writeFileAsync(join(appRoot, 'package.json'), (() => {
await writeFileAsync(resolve(appRoot, 'package.json'), (() => {

const json: any = {};

Expand Down Expand Up @@ -412,8 +415,8 @@ export class Builder {
version: fixWindowsVersion(config.win.productVersion),
copyright: config.win.versionStrings.LegalCopyright,

icon: config.nsis.icon,
unIcon: config.nsis.unIcon,
icon: config.nsis.icon ? resolve(this.dir, config.nsis.icon) : undefined,
unIcon: config.nsis.unIcon ? resolve(this.dir, config.nsis.unIcon) : undefined,

// Compression.
compression: 'lzma',
Expand Down Expand Up @@ -441,9 +444,9 @@ export class Builder {

protected async buildDirTarget(platform: string, arch: string, runtimeDir: string, pkg: any, config: BuildConfig): Promise<string> {

const targetDir = join(this.dir, config.output, `${ pkg.name }-${ pkg.version }-${ platform }-${ arch }`);
const targetDir = resolve(this.dir, config.output, `${ pkg.name }-${ pkg.version }-${ platform }-${ arch }`);
const runtimeRoot = await findRuntimeRoot(platform, runtimeDir);
const appRoot = join(targetDir, (() => {
const appRoot = resolve(targetDir, (() => {
switch(platform) {
case 'win32':
case 'win':
Expand Down Expand Up @@ -501,7 +504,7 @@ export class Builder {

protected async buildArchiveTarget(type: string, sourceDir: string) {

const targetArchive = join(dirname(sourceDir), `${ basename(sourceDir) }.${ type }`);
const targetArchive = resolve(dirname(sourceDir), `${ basename(sourceDir) }.${ type }`);

await removeAsync(targetArchive);

Expand Down Expand Up @@ -537,8 +540,8 @@ export class Builder {
version: fixWindowsVersion(config.win.productVersion),
copyright: config.win.versionStrings.LegalCopyright,

icon: config.nsis.icon,
unIcon: config.nsis.unIcon,
icon: config.nsis.icon ? resolve(this.dir, config.nsis.icon) : undefined,
unIcon: config.nsis.unIcon ? resolve(this.dir, config.nsis.unIcon) : undefined,

// Compression.
compression: 'lzma',
Expand Down Expand Up @@ -601,8 +604,8 @@ export class Builder {
version: fixWindowsVersion(config.win.productVersion),
copyright: config.win.versionStrings.LegalCopyright,

icon: config.nsis.icon,
unIcon: config.nsis.unIcon,
icon: config.nsis.icon ? resolve(this.dir, config.nsis.icon) : undefined,
unIcon: config.nsis.unIcon ? resolve(this.dir, config.nsis.unIcon) : undefined,

// Compression.
compression: 'lzma',
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Runner.ts
@@ -1,5 +1,5 @@

import { join } from 'path';
import { resolve } from 'path';
import { spawn } from 'child_process';

import { copyAsync, readJsonAsync, chmodAsync } from 'fs-extra-promise';
Expand Down Expand Up @@ -49,7 +49,7 @@ export class Runner {
? (this.options.x86 ? 'ia32' : 'x64')
: process.arch;

const pkg: any = await readJsonAsync(join(this.args[0], this.options.chromeApp ? 'manifest.json' : 'package.json'));
const pkg: any = await readJsonAsync(resolve(this.args[0], this.options.chromeApp ? 'manifest.json' : 'package.json'));
const config = new BuildConfig(pkg);

debug('in run', 'config', config);
Expand Down

0 comments on commit 4ec3028

Please sign in to comment.