Skip to content

Commit

Permalink
feat(generic): allow specifying a build identifier that segregates bu…
Browse files Browse the repository at this point in the history
…ild artifacts
  • Loading branch information
MarshallOfSound committed Jan 8, 2018
1 parent 32f2bff commit 0e48365
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/api/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import parseArchs from '../util/parse-archs';
import readPackageJSON from '../util/read-package-json';
import { requireSearchRaw } from '../util/require-search';
import resolveDir from '../util/resolve-dir';
import getCurrentOutDir from '../util/out-dir';

import packager from './package';

Expand Down Expand Up @@ -49,7 +50,6 @@ export default async (providedOptions = {}) => {
platform: process.platform,
}, providedOptions);

const outDir = providedOptions.outDir || path.resolve(dir, 'out');
asyncOra.interactive = interactive;

let forgeConfig;
Expand All @@ -62,6 +62,8 @@ export default async (providedOptions = {}) => {
forgeConfig = await getForgeConfig(dir);
});

const outDir = providedOptions.outDir || getCurrentOutDir(dir, forgeConfig);

const actualTargetPlatform = platform;
platform = platform === 'mas' ? 'darwin' : platform;
if (!['darwin', 'win32', 'linux', 'mas'].includes(actualTargetPlatform)) {
Expand Down
3 changes: 2 additions & 1 deletion src/api/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import readPackageJSON from '../util/read-package-json';
import rebuildHook from '../util/rebuild';
import requireSearch from '../util/require-search';
import resolveDir from '../util/resolve-dir';
import getCurrentOutDir from '../util/out-dir';

const d = debug('electron-forge:packager');

Expand Down Expand Up @@ -67,7 +68,6 @@ export default async (providedOptions = {}) => {

const ora = interactive ? realOra : fakeOra;

const outDir = providedOptions.outDir || path.resolve(dir, 'out');
let prepareSpinner = ora(`Preparing to Package Application for arch: ${(arch === 'all' ? 'ia32' : arch).cyan}`).start();
let prepareCounter = 0;

Expand All @@ -84,6 +84,7 @@ export default async (providedOptions = {}) => {
}

const forgeConfig = await getForgeConfig(dir);
const outDir = providedOptions.outDir || getCurrentOutDir(dir, forgeConfig);
let packagerSpinner;

const pruneEnabled = !('prune' in forgeConfig.electronPackagerConfig) || forgeConfig.electronPackagerConfig.prune;
Expand Down
6 changes: 3 additions & 3 deletions src/api/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import readPackageJSON from '../util/read-package-json';
import requireSearch from '../util/require-search';
import resolveDir from '../util/resolve-dir';
import PublishState from '../util/publish-state';
import getCurrentOutDir from '../util/out-dir';

import make from './make';

Expand Down Expand Up @@ -48,9 +49,6 @@ const publish = async (providedOptions = {}) => {
}, providedOptions);
asyncOra.interactive = interactive;

const outDir = providedOptions.outDir || path.resolve(dir, 'out');
const dryRunDir = path.resolve(outDir, 'publish-dry-run');

if (dryRun && dryRunResume) {
throw 'Can\'t dry run and resume a dry run at the same time';
}
Expand All @@ -61,6 +59,8 @@ const publish = async (providedOptions = {}) => {
let packageJSON = await readPackageJSON(dir);

const forgeConfig = await getForgeConfig(dir);
const outDir = providedOptions.outDir || getCurrentOutDir(dir, forgeConfig);
const dryRunDir = path.resolve(outDir, 'publish-dry-run');

if (dryRunResume) {
d('attempting to resume from dry run');
Expand Down
14 changes: 14 additions & 0 deletions src/util/out-dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path');

const BASE_OUT_DIR = 'out';

export default (baseDir, forgeConfig) => {
if (forgeConfig.buildIdentifier) {
let identifier = forgeConfig.buildIdentifier;
if (typeof identifier === 'function') {
identifier = identifier();
}
if (identifier) return path.resolve(baseDir, BASE_OUT_DIR, identifier);
}
return path.resolve(baseDir, BASE_OUT_DIR);
};
26 changes: 26 additions & 0 deletions test/fast/out-dir_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from 'chai';
import path from 'path';

import getCurrentOutDir from '../../src/util/out-dir';

describe('out-dir', () => {
const DIR = __dirname;

describe('getCurrentOutDir', () => {
it('resolves to the default out directory when nothing extra is declared', () => {
expect(getCurrentOutDir(DIR, {})).to.equal(`${DIR}${path.sep}out`);
});

it('resolves to the provided identifier', () => {
expect(getCurrentOutDir(DIR, {
buildIdentifier: 'bar',
})).to.equal(`${DIR}${path.sep}out${path.sep}bar`);
});

it('resolves to the return value of provided identifier getter', () => {
expect(getCurrentOutDir(DIR, {
buildIdentifier: () => 'thing',
})).to.equal(`${DIR}${path.sep}out${path.sep}thing`);
});
});
});

0 comments on commit 0e48365

Please sign in to comment.