Skip to content
Permalink
Browse files

fix(core): re-implement the config fetcher syntax from forge, undocum…

…ented so we can remove at any t
  • Loading branch information
MarshallOfSound committed Jun 18, 2018
1 parent 17e3d2c commit ebac71c14694b025a94b74d20e634c7a9ab361bf
Showing with 30 additions and 3 deletions.
  1. +14 −0 packages/api/core/src/api/make.ts
  2. +16 −3 packages/maker/base/src/Maker.ts
@@ -167,6 +167,20 @@ export default async ({
// eslint-disable-next-line no-loop-func
await asyncOra(`Making for target: ${maker.name.green} - On platform: ${actualTargetPlatform.cyan} - For arch: ${targetArch.cyan}`, async () => {
try {
/**
* WARNING: DO NOT ATTEMPT TO PARALLELIZE MAKERS
*
* Currently it is assumed we have 1 maker per make call but that is
* not enforced. It is technically possible to have 1 maker be called
* multiple times. The "prepareConfig" method however implicitly
* requires a lock that is not enforced. There are two options:
*
* * Provide makers a getConfig() method
* * Remove support for config being provided as a method
* * Change the entire API of maker from a single constructor to
* providing a MakerFactory
*/
maker.prepareConfig(targetArch);
const artifacts = await maker.make({
appName,
forgeConfig,
@@ -37,13 +37,14 @@ export interface MakerOptions {
}

export default abstract class Maker<C> {
public config!: C;
public abstract name: string;
public abstract defaultPlatforms: ForgePlatform[];
/* tslint:disable variable-name */
__isElectronForgeMaker!: true;
/* tslint:enable variable-name */

constructor(public config: C = {} as C, protected providedPlatforms?: ForgePlatform[]) {
constructor(private configFetcher: (C | ((arch: ForgeArch) => C)) = {} as C, protected providedPlatforms?: ForgePlatform[]) {
Object.defineProperty(this, '__isElectronForgeMaker', {
value: true,
enumerable: false,
@@ -56,6 +57,12 @@ export default abstract class Maker<C> {
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) {
this.config = typeof this.configFetcher === 'function' ? this.configFetcher(targetArch) : this.configFetcher;
}

/**
* Makers must implement this method and return true or false indicating whether
* this maker can be run on the current platform. Normally this is just a process.platform
@@ -66,15 +73,21 @@ export default abstract class Maker<C> {
* telling the developer exactly what is missing and if possible how to get it.
*/
isSupportedOnCurrentPlatform(): boolean {
throw new Error(`Maker ${this.name} did not implement the isSupportedOnCurrentPlatform method`);
if (this.isSupportedOnCurrentPlatform === Maker.prototype.isSupportedOnCurrentPlatform) {
throw new Error(`Maker ${this.name} did not implement the isSupportedOnCurrentPlatform method`);
}
return true;
}

/**
* Makers must implement this method and return an array of absolute paths
* to the artifacts generated by your maker
*/
async make(opts: MakerOptions): Promise<string[]> {
throw new Error(`Maker ${this.name} did not implement the make method`);
if (this.make === Maker.prototype.make) {
throw new Error(`Maker ${this.name} did not implement the make method`);
}
return [];
}


0 comments on commit ebac71c

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