Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow a custom out dir from forge config #3458

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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