Skip to content

Commit 382a0b5

Browse files
jrainvilleiurimatias
authored andcommitted
feat(@embark/cmd): enable using engine with no embark.json
And show a message to run embark init if there is no embark.json
1 parent db10064 commit 382a0b5

File tree

10 files changed

+123
-94
lines changed

10 files changed

+123
-94
lines changed

packages/core/core/src/config.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export class Config {
107107
constructor(options) {
108108
this.env = options.env || 'default';
109109
this.webServerConfig = options.webServerConfig;
110+
this.embarkConfig = options.embarkConfig;
110111
this.configDir = options.configDir || DEFAULT_CONFIG_PATH;
111112
this.chainsFile = options.chainsFile;
112113
this.plugins = options.plugins;
@@ -181,12 +182,6 @@ export class Config {
181182
interceptLogs = true;
182183
}
183184

184-
if (!fs.existsSync(options.embarkConfig)) {
185-
this.logger.error(__('Cannot find file %s Please ensure you are running this command inside the Dapp folder', options.embarkConfig));
186-
process.exit(1);
187-
}
188-
189-
this.embarkConfig = fs.readJSONSync(options.embarkConfig);
190185
this.embarkConfig.plugins = this.embarkConfig.plugins || {};
191186

192187
this.plugins = new Plugins({
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
contracts: ["contracts/**"],
3+
app: {},
4+
buildDir: "dist/",
5+
config: "config/",
6+
versions: {
7+
solc: "0.6.1"
8+
},
9+
plugins: {
10+
},
11+
options: {
12+
solc: {
13+
"optimize": true,
14+
"optimize-runs": 200
15+
}
16+
},
17+
generationDir: "embarkArtifacts"
18+
};

packages/core/engine/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from 'embark-core';
99
import { normalizeInput } from 'embark-utils';
1010
import { Logger } from 'embark-logger';
11+
import defaultEmbarkJson from './defaultEmbarkJson';
1112
const EMBARK_PROCESS_NAME = 'embark';
1213

1314
export class Engine {
@@ -60,7 +61,7 @@ export class Engine {
6061
this.env = options.env;
6162
this.client = options.client;
6263
this.locale = options.locale;
63-
this.embarkConfig = options.embarkConfig;
64+
this.embarkConfig = options.embarkConfig || defaultEmbarkJson;
6465
this.interceptLogs = options.interceptLogs;
6566
this.version = options.version;
6667
this.logFile = options.logFile;
@@ -90,14 +91,15 @@ export class Engine {
9091
logger: this.logger,
9192
events: this.events,
9293
context: this.context,
94+
embarkConfig: this.embarkConfig,
9395
webServerConfig: this.webServerConfig,
9496
version: this.version,
9597
package: this.package,
9698
locale: this.locale,
9799
client: this.client,
98100
ipc: this.ipc
99101
});
100-
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
102+
this.config.loadConfigFiles({interceptLogs: this.interceptLogs});
101103
this.plugins = this.config.plugins;
102104

103105
if (this.interceptLogs || this.interceptLogs === undefined) {
@@ -194,7 +196,7 @@ export class Engine {
194196
});
195197
}
196198

197-
serviceMonitor(_options) {
199+
serviceMonitor() {
198200
this.servicesMonitor = new ServicesMonitor({ events: this.events, logger: this.logger, plugins: this.plugins });
199201

200202
if (this.servicesMonitor) {
@@ -212,7 +214,7 @@ export class Engine {
212214
}
213215
}
214216

215-
coreComponents(_options) {
217+
coreComponents() {
216218
// TODO: should be made into a component
217219
this.processManager = new ProcessManager({
218220
events: this.events,

packages/embark/src/bin/embark.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
// on babel to achieve the same goal.
55
// See: https://node.green/
66

7-
// KEY ASSUMPTION: for a DApp to be valid, from embark's perspective, it must
8-
// have a parsable embark.json file in its top-level directory; if that
9-
// requirement changes in the future then this script must be revised.
10-
// Hypothetical example of such a change: embark config info may be included in
11-
// package.json under `{"embark": {...}}` -or- stored in an embark.json file.
12-
137
function main() {
148
if (whenNoShim()) return;
159
var invoked = thisEmbark();
@@ -46,7 +40,7 @@ function main() {
4640
process.env.PKG_PATH = pkgJson.dirname;
4741
var embark = select(invoked, local);
4842
process.env.EMBARK_PATH = embark.pkgDir;
49-
embark.exec();
43+
embark.exec(embarkJson);
5044
}
5145

5246
// -----------------------------------------------------------------------------
@@ -77,9 +71,9 @@ function EmbarkBin(binpath, kind) {
7771
this.pkgJson = undefined;
7872
}
7973

80-
EmbarkBin.prototype.exec = function () {
74+
EmbarkBin.prototype.exec = function (embarkJson) {
8175
var Cmd = require('../cmd/cmd');
82-
var cli = new Cmd();
76+
var cli = new Cmd({embarkConfig: embarkJson.json});
8377
if(_logged) { console[this.loglevel](); }
8478
cli.process(process.argv);
8579
};
@@ -352,11 +346,16 @@ Json.prototype.log = function () {
352346

353347
Json.prototype.loglevel = 'warn';
354348

355-
Json.prototype.logMissingFile = function () {
349+
Json.prototype.logMissingFile = function (doReport) {
350+
if (doReport === undefined) {
351+
doReport = true;
352+
}
356353
var missing;
357354
if (!this.realpath) {
358355
missing = true;
359-
reportMissingFile(this.filepath, this.loglevel);
356+
if (doReport) {
357+
reportMissingFile(this.filepath, this.loglevel);
358+
}
360359
}
361360
return missing;
362361
};
@@ -411,9 +410,14 @@ EmbarkJson.prototype.log = function () {
411410
};
412411

413412
EmbarkJson.prototype.logMissingFile = function () {
414-
if (isDappCmd(this.cmd) && Json.prototype.logMissingFile.call(this)) {
415-
reportMissingFile_DappJson(this.cmd, this.loglevel, 'embark', 'in');
416-
exitWithError();
413+
if (Json.prototype.logMissingFile.call(this, false)) {
414+
// Use default embark.json
415+
if (isDappCmd(this.cmd)) {
416+
// TODO add message about embark init once it's available
417+
embarklog['warn']('No embark.json file found.\n' +
418+
'You can find a basic embark.json file here: https://github.com/embarklabs/embark/blob/master/dapps/templates/boilerplate/embark.json');
419+
exitWithError();
420+
}
417421
}
418422
};
419423

0 commit comments

Comments
 (0)