Skip to content

Commit

Permalink
feat(core): resolve forge.config.js by default if it exists (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored Sep 10, 2018
1 parent f37476b commit 5431dfa
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/api/core/src/api/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default async ({
dir = process.cwd(),
interactive = false,
arch = hostArch(),
platform = process.platform,
platform = process.platform as ForgePlatform,
outDir,
}: PackageOptions) => {
const ora = interactive ? realOra : fakeOra;
Expand Down
10 changes: 9 additions & 1 deletion packages/api/core/src/util/forge-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ export function fromBuildIdentifier<T>(map: { [key: string]: T | undefined }) {

export default async (dir: string) => {
const packageJSON = await readRawPackageJson(dir);
let forgeConfig: ForgeConfig | string = (packageJSON.config && packageJSON.config.forge) ? packageJSON.config.forge : {};
let forgeConfig: ForgeConfig | string | null = (packageJSON.config && packageJSON.config.forge) ? packageJSON.config.forge : null;

if (!forgeConfig) {
if (await fs.pathExists(path.resolve(dir, 'forge.config.js'))) {
forgeConfig = 'forge.config.js';
} else {
forgeConfig = {} as any as ForgeConfig;
}
}

if (typeof forgeConfig === 'string' && (await fs.pathExists(path.resolve(dir, forgeConfig)) || await fs.pathExists(path.resolve(dir, `${forgeConfig}.js`)))) {
try {
Expand Down
6 changes: 6 additions & 0 deletions packages/api/core/test/fast/forge-config_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ describe('forge-config', () => {
expect(conf.magicFn()).to.be.equal('magic result');
});

it('should resolve the JS file exports of forge.config.js if config.forge does not exist points', async () => {
const conf: any = await findConfig(path.resolve(__dirname, '../fixture/dummy_default_js_conf'));
expect(conf.buildIdentifier).to.equal('default');
expect(conf.defaultResolved).to.equal(true);
});

it('should magically map properties to environment variables', async () => {
const conf: any = await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf'));
expect(conf.s3.secretAccessKey).to.equal(undefined);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
buildIdentifier: 'default',
defaultResolved: true,
};
16 changes: 16 additions & 0 deletions packages/api/core/test/fixture/dummy_default_js_conf/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "",
"productName": "",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"electron-prebuilt": "9.9.9"
}
}
2 changes: 1 addition & 1 deletion packages/api/core/test/fixture/dummy_js_conf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "MIT",
"config": {
"forge": "./forge.config.js"
"forge": "./forge.different.config.js"
},
"devDependencies": {
"electron-prebuilt": "9.9.9"
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RebuildOptions } from 'electron-rebuild/lib/src/rebuild';

// declare module '@electron-forge/shared-types' {
export type ForgePlatform = 'darwin' | 'mas' | 'win32' | 'linux';
export type ForgeArch = 'ia32' | 'x64' | 'armv7l' | 'arm';
export type ForgeArch = 'ia32' | 'x64' | 'armv7l' | 'arm' | 'all';
export type ForgeHookFn = (forgeConfig: ForgeConfig, ...args: any[]) => Promise<any>;
export interface IForgePluginInterface {
triggerHook(hookName: string, hookArgs: any[]): Promise<void>;
Expand Down

0 comments on commit 5431dfa

Please sign in to comment.