Skip to content
Permalink
Browse files

feat(generic): allow specifying a build identifier that segregates bu…

…ild artifacts
  • Loading branch information
MarshallOfSound committed Jan 8, 2018
1 parent 32f2bff commit 0e4836593ee7cd1db5a8f6aee8f348023171efe0
Showing with 48 additions and 5 deletions.
  1. +3 −1 src/api/make.js
  2. +2 −1 src/api/package.js
  3. +3 −3 src/api/publish.js
  4. +14 −0 src/util/out-dir.js
  5. +26 −0 test/fast/out-dir_spec.js
@@ -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';

@@ -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;
@@ -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)) {
@@ -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');

@@ -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;

@@ -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;
@@ -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';

@@ -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';
}
@@ -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');
@@ -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);
};
@@ -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.
You can’t perform that action at this time.