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(core): resolve forge.config.js by default if it exists #569

Merged
merged 1 commit into from
Sep 10, 2018
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
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