Skip to content

Commit e0f7913

Browse files
feat: add support for embark.config.js
This commit introduces support for using `embark.config.js` to calculate the embark configuration object that is otherwise provided via `embark.json`. If an `embark.config.js` file is present, it will be used over the `embark.json` file. The `embark.config.js` module needs to export either an object or a function that can be asynchronous and has to return or resolve with an embark configuration object: ```js // embark.config.js module.exports = async function () { let config = ...; // do lazy calculation of `embarkConfig`; return config; } ```
1 parent b19a58b commit e0f7913

File tree

13 files changed

+281
-54
lines changed

13 files changed

+281
-54
lines changed

packages/core/console/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export default class Console {
169169
return this.ipc.request("console:executeCmd", cmd, callback);
170170
}
171171

172-
if (cmd.indexOf("profile") === 0 && warnIfPackageNotDefinedLocally("embark-profiler", this.embark.logger.warn) !== true) {
172+
if (cmd.indexOf("profile") === 0 && warnIfPackageNotDefinedLocally("embark-profiler", this.embark.logger.warn, this.embark.config.embarkConfig) !== true) {
173173
return callback(null, "please install embark-profiler plugin");
174174
}
175175
if (!(cmd.split(" ")[0] === "history" || cmd === __("history"))) {

packages/core/engine/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ export class Engine {
121121
}
122122

123123
async generateEmbarkJSON() {
124-
if (fs.existsSync('embark.json')) {
125-
throw new Error(__('embark.json already there. Will not overwrite'));
124+
if (fs.existsSync('embark.json') || fs.existsSync('embark.config.js')) {
125+
throw new Error(__('embark.json or embark.config.js already exist. Will not overwrite'));
126126
}
127127
return fs.writeFile('embark.json', JSON.stringify(constants.defaultEmbarkConfig, null, 2));
128128
}

packages/core/utils/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export function isEs6Module(module) {
313313
return (typeof module === 'function' && isConstructor(module)) || (typeof module === 'object' && typeof module.default === 'function' && module.__esModule);
314314
}
315315

316-
export function warnIfPackageNotDefinedLocally(packageName, warnFunc) {
316+
export function warnIfPackageNotDefinedLocally(packageName, warnFunc, embarkConfig) {
317317
const packageIsResolvable = findUp.sync("node_modules/" + packageName, {cwd: dappPath()});
318318
if (!packageIsResolvable) {
319319
return warnFunc("== WARNING: " + packageName + " could not be resolved; ensure it is defined in your dapp's package.json dependencies and then run npm or yarn install; in future versions of embark this package should be a local dependency and configured as a plugin");
@@ -325,7 +325,6 @@ export function warnIfPackageNotDefinedLocally(packageName, warnFunc) {
325325
return warnFunc("== WARNING: it seems " + packageName + " is not defined in your dapp's package.json dependencies; In future versions of embark this package should be a local dependency and configured as a plugin");
326326
}
327327

328-
const embarkConfig = fs.readJSONSync(dappPath("embark.json"));
329328
if (!embarkConfig.plugins[packageName]) {
330329
return warnFunc(
331330
__("== WARNING: it seems %s is not defined in your Dapp's embark.json plugins;\nIn future versions of Embark, this package should be a local dependency and configured as a plugin", packageName)

0 commit comments

Comments
 (0)