Skip to content

Commit

Permalink
refactor: rename some constructor params for MakerBase and PublisherB…
Browse files Browse the repository at this point in the history
…ase (#2994)
  • Loading branch information
MarshallOfSound authored Oct 26, 2022
1 parent 493368c commit b97c906
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/maker/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"typings": "dist/Maker.d.ts",
"devDependencies": {
"chai": "^4.3.3",
"mocha": "^9.0.1"
"mocha": "^9.0.1",
"sinon": "^13.0.1"
},
"engines": {
"node": ">= 14.17.5"
Expand Down
14 changes: 9 additions & 5 deletions packages/maker/base/src/Maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export default abstract class Maker<C> implements IForgeMaker {
/** @internal */
__isElectronForgeMaker!: true;

constructor(private configFetcher: C | ((arch: ForgeArch) => C) = {} as C, protected providedPlatforms?: ForgePlatform[]) {
/**
* @param configOrConfigFetcher - Either a configuration object for this maker or a simple method that returns such a configuration for a given target architecture
* @param platformsToMakeOn - If you want this maker to run on platforms different from `defaultPlatforms` you can provide those platforms here
*/
constructor(private configOrConfigFetcher: C | ((arch: ForgeArch) => C) = {} as C, protected platformsToMakeOn?: ForgePlatform[]) {
Object.defineProperty(this, '__isElectronForgeMaker', {
value: true,
enumerable: false,
Expand All @@ -59,17 +63,17 @@ export default abstract class Maker<C> implements IForgeMaker {
}

get platforms(): ForgePlatform[] {
if (this.providedPlatforms) return this.providedPlatforms;
if (this.platformsToMakeOn) return this.platformsToMakeOn;
return this.defaultPlatforms;
}

// TODO: Remove this, it is an eye-sore and is a nasty hack to provide forge
// v5 style functionality in the new API
prepareConfig(targetArch: ForgeArch): void {
if (typeof this.configFetcher === 'function') {
this.config = (this.configFetcher as unknown as (arch: ForgeArch) => C)(targetArch);
if (typeof this.configOrConfigFetcher === 'function') {
this.config = (this.configOrConfigFetcher as unknown as (arch: ForgeArch) => C)(targetArch);
} else {
this.config = this.configFetcher as C;
this.config = this.configOrConfigFetcher as C;
}
}

Expand Down
42 changes: 42 additions & 0 deletions packages/maker/base/test/config-fetcher_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'chai';
import { stub } from 'sinon';

import MakerBase from '../src/Maker';

class MakerImpl extends MakerBase<{ a: number }> {
name = 'test';

defaultPlatforms = [];
}

describe('prepareConfig', () => {
it('should call the provided configure function', () => {
const fetcher = stub();
fetcher.returns({
a: 123,
});
const maker = new MakerImpl(fetcher, []);
expect(maker.config).to.be.undefined;
expect(fetcher.callCount).to.equal(0);
maker.prepareConfig('x64');
expect(maker.config).to.deep.equal({
a: 123,
});
expect(fetcher.callCount).to.equal(1);
expect(fetcher.firstCall.args).to.deep.equal(['x64']);
});

it('should hand through the provided object', () => {
const maker = new MakerImpl(
{
a: 234,
},
[]
);
expect(maker.config).to.be.undefined;
maker.prepareConfig('x64');
expect(maker.config).to.deep.equal({
a: 234,
});
});
});
8 changes: 6 additions & 2 deletions packages/publisher/base/src/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export default abstract class Publisher<C> implements IForgePublisher {
/** @internal */
__isElectronForgePublisher!: true;

constructor(public config: C, protected providedPlatforms?: ForgePlatform[]) {
/**
* @param config - A configuration object for this publisher
* @param platformsToPublishOn - If you want this maker to run on platforms different from `defaultPlatforms` you can provide those platforms here
*/
constructor(public config: C, protected platformsToPublishOn?: ForgePlatform[]) {
this.config = config;
Object.defineProperty(this, '__isElectronForgePublisher', {
value: true,
Expand All @@ -35,7 +39,7 @@ export default abstract class Publisher<C> implements IForgePublisher {
}

get platforms(): ForgePlatform[] {
if (this.providedPlatforms) return this.providedPlatforms;
if (this.platformsToPublishOn) return this.platformsToPublishOn;
if (this.defaultPlatforms) return this.defaultPlatforms;
return ['win32', 'linux', 'darwin', 'mas'];
}
Expand Down

0 comments on commit b97c906

Please sign in to comment.