Skip to content
Permalink
Browse files

feat(core): resolve forge.config.js by default if it exists (#569)

  • Loading branch information
MarshallOfSound committed Sep 10, 2018
1 parent f37476b commit 5431dfa14d4de274cdae07efd4c5e88df1a2d0dc
@@ -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;
@@ -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 {
@@ -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);
@@ -0,0 +1,4 @@
module.exports = {
buildIdentifier: 'default',
defaultResolved: true,
};
@@ -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"
}
}
@@ -11,7 +11,7 @@
"author": "",
"license": "MIT",
"config": {
"forge": "./forge.config.js"
"forge": "./forge.different.config.js"
},
"devDependencies": {
"electron-prebuilt": "9.9.9"
@@ -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>;

0 comments on commit 5431dfa

Please sign in to comment.
You can’t perform that action at this time.