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

Commit

Permalink
fix(nsis-gen): use paths relative to cwd to specify files in nsis scr…
Browse files Browse the repository at this point in the history
…ipts
  • Loading branch information
evshiron committed Apr 3, 2017
1 parent 34c93e6 commit 15afb8f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 59 deletions.
7 changes: 2 additions & 5 deletions src/lib/Builder.ts
Expand Up @@ -367,7 +367,7 @@ export class Builder {
const script = await tmpName();
await writeFileAsync(script, data);

await nsisBuild(script, {
await nsisBuild(toDir, script, {
mute: false,
});

Expand Down Expand Up @@ -480,9 +480,6 @@ export class Builder {
modern: config.nsis.modern,
languages: config.nsis.languages,

// Files.
srcDir: targetDir,

// Output.
output: targetNsis,

Expand All @@ -491,7 +488,7 @@ export class Builder {
const script = await tmpName();
await writeFileAsync(script, data);

await nsisBuild(script, {
await nsisBuild(targetDir, script, {
mute: false,
});

Expand Down
47 changes: 2 additions & 45 deletions src/lib/nsis-gen/NsisComposer.ts
Expand Up @@ -21,9 +21,6 @@ export interface INsisComposerOptions {
modern: boolean;
languages: string[];

// Files.
srcDir?: string;

// Output.
output: string;

Expand Down Expand Up @@ -213,14 +210,8 @@ SectionEnd

protected async makeInstallerFiles(): Promise<string> {

if(!this.options.srcDir) {
throw new Error('ERROR_NO_SRCDIR');
}

const out: string[] = [];
await this.readdirLines(resolve(this.options.srcDir), resolve(this.options.srcDir), out);

return out.join('\n');
return `SetOutPath "$INSTDIR"
FILE /r .\\*.*`;

}

Expand All @@ -229,38 +220,4 @@ SectionEnd
return /^\d+\.\d+\.\d+$/.test(this.options.version) ? `${ this.options.version }.0` : this.options.version;
}

protected async readdirLines(dir: string, baseDir: string, out: string[]) {

const lines = [];
const pendingFiles = [];

const files = await readdirAsync(dir);

if(files.length > 0) {
const path = win32.normalize(relative(baseDir, dir));
lines.push(`SetOutPath "$INSTDIR${ path == '.' ? '' : `\\${ path }` }"`);
}

for(const file of files) {

const path = resolve(dir, file);
const stat = await lstatAsync(path);

if(stat.isFile()) {
lines.push(`File "${ win32.normalize(path) }"`);
}
else if(stat.isDirectory()) {
pendingFiles.push(path);
}

}

for(const file of pendingFiles) {
await this.readdirLines(resolve(dir, file), resolve(baseDir), lines);
}

out.push(...lines);

}

}
8 changes: 5 additions & 3 deletions src/lib/nsis-gen/index.ts
Expand Up @@ -12,16 +12,18 @@ interface INsisBuildOptions {
mute: boolean;
}

export async function nsisBuild(script: string, options: INsisBuildOptions = {
export async function nsisBuild(cwd: string, script: string, options: INsisBuildOptions = {
mute: false,
}) {

const args = [ win32.normalize(resolve(DIR_NSIS, 'makensis.exe')), win32.normalize(resolve(script)) ];
const args = [ win32.normalize(resolve(DIR_NSIS, 'makensis.exe')), '/NOCD', win32.normalize(resolve(script)) ];
if(process.platform != 'win32') {
args.unshift('wine');
}

const child = spawn(args.shift(), args);
const child = spawn(args.shift(), args, {
cwd,
});

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

Expand Down
15 changes: 9 additions & 6 deletions test/nsis-gen.js
Expand Up @@ -26,20 +26,23 @@ const options = {

};

test.skip('build', async (t) => {
test('build', async (t) => {

const output = await tmpName();
const output = await tmpName({
postfix: '.exe',
});

const data = await (new NsisComposer(Object.assign({}, options, {
srcDir: './src/',
output,
})))
.make();

const script = await tmpName();
const script = await tmpName({
postfix: '.nsi',
});

await writeFileAsync(script, data);
await nsisBuild(script);
await nsisBuild('./src/', script);

await removeAsync(output);
await removeAsync(script);
Expand All @@ -62,7 +65,7 @@ test('diff', async (t) => {
});

await writeFileAsync(script, data);
await nsisBuild(script);
await nsisBuild('./dist/', script);

await removeAsync(output);
await removeAsync(script);
Expand Down

0 comments on commit 15afb8f

Please sign in to comment.