Skip to content

Commit

Permalink
feat: allow a custom out dir from forge config (#3458)
Browse files Browse the repository at this point in the history
Co-authored-by: Keeley Hammond <khammond@slack-corp.com>
  • Loading branch information
lutzroeder and VerteDinde authored Feb 21, 2024
1 parent a02a5e3 commit 50c40f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/api/core/src/util/out-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { ResolvedForgeConfig } from '@electron-forge/shared-types';
const BASE_OUT_DIR = 'out';

export default (baseDir: string, forgeConfig: ResolvedForgeConfig): string => {
const baseOutDir = forgeConfig.outDir || BASE_OUT_DIR;

if (forgeConfig.buildIdentifier) {
let identifier = forgeConfig.buildIdentifier;
if (typeof identifier === 'function') {
identifier = identifier();
}
if (identifier) return path.resolve(baseDir, BASE_OUT_DIR, identifier);
if (identifier) return path.resolve(baseDir, baseOutDir, identifier);
}
return path.resolve(baseDir, BASE_OUT_DIR);

return path.resolve(baseDir, baseOutDir);
};
32 changes: 32 additions & 0 deletions packages/api/core/test/fast/out-dir_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,35 @@ describe('out-dir', () => {
});
});
});

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

describe('getCurrentOutDir', () => {
it('resolves to the dist directory when dist is declared', () => {
expect(
getCurrentOutDir(DIR, {
outDir: 'dist',
} as ResolvedForgeConfig)
).to.equal(`${DIR}${path.sep}dist`);
});

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

it('resolves to the return value of provided identifier getter', () => {
expect(
getCurrentOutDir(DIR, {
buildIdentifier: () => 'thing',
outDir: 'dist',
} as ResolvedForgeConfig)
).to.equal(`${DIR}${path.sep}dist${path.sep}thing`);
});
});
});
4 changes: 4 additions & 0 deletions packages/utils/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export interface ResolvedForgeConfig {
* If a function is provided, it must synchronously return the buildIdentifier
*/
buildIdentifier?: string | (() => string);
/**
* Output directory. Default is './out'.
*/
outDir?: string;
hooks?: ForgeHookMap;
/**
* @internal
Expand Down

0 comments on commit 50c40f3

Please sign in to comment.