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

Enhance builder creation from the factory #37

Merged
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
12 changes: 8 additions & 4 deletions documentation/extensions/develop-an-extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Below is the package directory of the ``webinizer-extension-demo``.

The extension directory has the following properties;

* ``package.json`` & ``tsconfig.ts`` are required to all extension packages.
* ``package.json`` & ``tsconfig.json`` are required to all extension packages.
* ``package.json`` contains the npm package config data and the metadata of the extension.
* ``tsconfig.json`` contains the typescript project config data of the extension.
* ``src`` folder contains the source code of extension, while ``tests`` folder contains the test code of the extension.
Expand Down Expand Up @@ -218,9 +218,13 @@ Below is the example code of a new builder DemoBuilder of ``webinizer-extension-
return null;
}

createDefault(proj: webinizer.Project, args?: string): DemoBuilder {
// use project root as default rootBuildFilePath
return new DemoBuilder(proj, 0, "${projectRoot}", args || "");
createDefault(proj: webinizer.Project, options?: webinizer.IBuilderOptions): DemoBuilder {
return new DemoBuilder(
proj,
0,
options?.rootBuildFilePath || "${projectRoot}",
options?.args || ""
);
}

fromJson(proj: webinizer.Project, o: webinizer.IJsonObject, index: number): webinizer.IBuilder {
Expand Down
10 changes: 7 additions & 3 deletions extensions/webinizer-extension-demo/src/builders/demo_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class DemoBuilderFactory implements webinizer.IBuilderFactory {
return null;
}

createDefault(proj: webinizer.Project, args?: string): DemoBuilder {
// use project root as default rootBuildFilePath
return new DemoBuilder(proj, 0, "${projectRoot}", args || "");
createDefault(proj: webinizer.Project, options?: webinizer.IBuilderOptions): DemoBuilder {
return new DemoBuilder(
proj,
0,
options?.rootBuildFilePath || "${projectRoot}",
options?.args || ""
);
}

fromJson(proj: webinizer.Project, o: webinizer.IJsonObject, index: number): webinizer.IBuilder {
Expand Down
11 changes: 8 additions & 3 deletions src/builders/cmake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
IBuilder,
IBuilderFactory,
IBuilderJson,
IBuilderOptions,
IJsonObject,
AdviseManager as IAdviseManager,
Project as IProject,
Expand All @@ -41,9 +42,13 @@ class CMakeBuilderFactory implements IBuilderFactory {
return null;
}

createDefault(proj: IProject, args?: string): CMakeBuilder {
// use project root as default rootBuildFilePath
return new CMakeBuilder(proj, 0, "${projectRoot}", args || "");
createDefault(proj: IProject, options?: IBuilderOptions): CMakeBuilder {
return new CMakeBuilder(
proj,
0,
options?.rootBuildFilePath || "${projectRoot}",
options?.args || ""
);
}

fromJson(proj: IProject, o: IJsonObject, index: number): IBuilder {
Expand Down
11 changes: 8 additions & 3 deletions src/builders/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
IBuilder,
IBuilderFactory,
IBuilderJson,
IBuilderOptions,
IJsonObject,
AdviseManager as IAdviseManager,
Project as IProject,
Expand All @@ -41,9 +42,13 @@ class ConfigureBuilderFactory implements IBuilderFactory {
return null;
}

createDefault(proj: IProject, args?: string): ConfigureBuilder {
// use project root as default rootBuildFilePath
return new ConfigureBuilder(proj, 0, "${projectRoot}", args || "");
createDefault(proj: IProject, options?: IBuilderOptions): ConfigureBuilder {
return new ConfigureBuilder(
proj,
0,
options?.rootBuildFilePath || "${projectRoot}",
options?.args || ""
);
}

fromJson(proj: IProject, o: IJsonObject, index: number): IBuilder {
Expand Down
11 changes: 8 additions & 3 deletions src/builders/emcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IBuilder,
IBuilderFactory,
IBuilderJson,
IBuilderOptions,
IJsonObject,
AdviseManager as IAdviseManager,
Project as IProject,
Expand All @@ -28,9 +29,13 @@ class EmccBuilderFactory implements IBuilderFactory {
return null;
}

createDefault(proj: IProject, args?: string): EmccBuilder {
// use project root as default rootBuildFilePath
return new EmccBuilder(proj, 0, "${projectRoot}", args || "");
createDefault(proj: IProject, options?: IBuilderOptions): EmccBuilder {
return new EmccBuilder(
proj,
0,
options?.rootBuildFilePath || "${projectRoot}",
options?.args || ""
);
}

fromJson(proj: IProject, o: IJsonObject, index: number): IBuilder {
Expand Down
11 changes: 8 additions & 3 deletions src/builders/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
IBuilder,
IBuilderFactory,
IBuilderJson,
IBuilderOptions,
IJsonObject,
AdviseManager as IAdviseManager,
Project as IProject,
Expand All @@ -40,9 +41,13 @@ class MakeBuilderFactory implements IBuilderFactory {
return null;
}

createDefault(proj: IProject, args?: string): MakeBuilder {
// use project root as default rootBuildFilePath
return new MakeBuilder(proj, 0, "${projectRoot}", args || "");
createDefault(proj: IProject, options?: IBuilderOptions): MakeBuilder {
return new MakeBuilder(
proj,
0,
options?.rootBuildFilePath || "${projectRoot}",
options?.args || ""
);
}

fromJson(proj: IProject, o: IJsonObject, index: number): IBuilder {
Expand Down
11 changes: 8 additions & 3 deletions src/builders/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IBuilder,
IBuilderFactory,
IBuilderJson,
IBuilderOptions,
IJsonObject,
AdviseManager as IAdviseManager,
Project as IProject,
Expand All @@ -27,9 +28,13 @@ class NativeBuilderFactory implements IBuilderFactory {
return null;
}

createDefault(proj: IProject, args?: string): NativeBuilder {
// use project root as default rootBuildFilePath
return new NativeBuilder(proj, 0, "${projectRoot}", args || "");
createDefault(proj: IProject, options?: IBuilderOptions): NativeBuilder {
return new NativeBuilder(
proj,
0,
options?.rootBuildFilePath || "${projectRoot}",
options?.args || ""
);
}

fromJson(proj: IProject, o: IJsonObject, index: number): IBuilder {
Expand Down
20 changes: 17 additions & 3 deletions src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
import path from "path";
import fs from "graceful-fs";
import { cloneDeep } from "lodash";
import { AdviseManager } from "./advisor";
import { ALL_BUILDER_FACTORIES } from "./builder";
import * as H from "./helper";
Expand Down Expand Up @@ -76,13 +77,26 @@ export class Project implements IProject {
if (builder) {
builders.push(builder);
if (builder.type === "CMakeBuilder" || builder.type === "ConfigureBuilder") {
// add MakeBuilder with a clean step ahead
const m = ALL_BUILDER_FACTORIES.factoriesMap().get("MakeBuilder");
if (m) builders.push(...[m.createDefault(this, "clean"), m.createDefault(this)]);
if (m) {
// create the following builders with the same rootBuildFilePath as the detected
// one, and add MakeBuilder with a clean step ahead
builders.push(
...[
m.createDefault(this, {
rootBuildFilePath: builder.toJson().rootBuildFilePath,
args: "clean",
}),
m.createDefault(this, {
rootBuildFilePath: builder.toJson().rootBuildFilePath,
}),
]
);
}
}
if (builder.type === "MakeBuilder") {
// add MakeBuilder with a clean step ahead at the same build path
const m = builder.toJson();
const m = cloneDeep(builder.toJson());
m.args = "clean";
const mBuilder = ALL_BUILDER_FACTORIES.fromJsonArray(this, [m]);
builders.splice(0, 0, ...mBuilder);
Expand Down
1 change: 0 additions & 1 deletion src/project_caches/project_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ class ProjectBuildConfig implements IProjectBuildConfig {
log.info("updateBuildConfig", jsonParts, updateEnvParts, updateOptParts);
if (refresh) {
const jsonKeys = Object.keys(jsonParts);
log.info(`jsonKeys are ${jsonKeys.join(", ")}`);
if (jsonKeys.includes("builders")) {
this._builders = null;
this.convertBuildersToMeta();
Expand Down
19 changes: 16 additions & 3 deletions typings/webinizer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ declare module "webinizer" {
/**
* An object represents a recipe from Webinizer.
*/

export class Recipe {
/**
* Create a `Recipe` object.
Expand Down Expand Up @@ -573,6 +572,20 @@ declare module "webinizer" {
toJson(): IJsonObject;
}

/**
* An object represents the Builder creation options.
*/
export interface IBuilderOptions {
/**
* The overall arguments string of the builder.
*/
args?: string;
/**
* The working directory of the builder.
*/
rootBuildFilePath?: string;
}

/**
* An object represents the JSON object of a Builder.
*/
Expand Down Expand Up @@ -659,10 +672,10 @@ declare module "webinizer" {
/**
* Create a default builder object from the factory.
* @param proj The project instance.
* @param args The arguments of the builder.
* @param options The options to create a builder object.
* @returns A builder object.
*/
createDefault(proj: Project, args?: string): IBuilder;
createDefault(proj: Project, options?: IBuilderOptions): IBuilder;
}

/**
Expand Down