mirror of https://github.com/embarklabs/embark.git
feat(@cmd): add very basic embark init to add an embark.json file
This commit is contained in:
parent
382a0b523d
commit
738ff8e41d
|
@ -111,5 +111,24 @@
|
|||
"environments": {
|
||||
"development": "development"
|
||||
},
|
||||
"defaultMigrationsDir": "migrations"
|
||||
"defaultMigrationsDir": "migrations",
|
||||
"defaultEmbarkConfig": {
|
||||
"contracts": ["contracts/**"],
|
||||
"app": {},
|
||||
"buildDir": "dist/",
|
||||
"config": "config/",
|
||||
"migrations": "migrations",
|
||||
"versions": {
|
||||
"solc": "0.6.1"
|
||||
},
|
||||
"plugins": {
|
||||
},
|
||||
"options": {
|
||||
"solc": {
|
||||
"optimize": true,
|
||||
"optimize-runs": 200
|
||||
}
|
||||
},
|
||||
"generationDir": "embarkArtifacts"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import { EmbarkEmitter as Events } from './events';
|
|||
import { filesMatchingPattern, fileMatchesPattern } from './utils/utils';
|
||||
const path = require('path');
|
||||
const deepEqual = require('deep-equal');
|
||||
const web3 = require('web3');
|
||||
import { __ } from 'embark-i18n';
|
||||
import {
|
||||
buildUrlFromConfig,
|
||||
|
@ -23,13 +22,12 @@ import {
|
|||
getExternalContractUrl
|
||||
} from 'embark-utils';
|
||||
import { Logger } from 'embark-logger';
|
||||
import { readJsonSync } from 'fs-extra';
|
||||
const cloneDeep = require('lodash.clonedeep');
|
||||
const { replaceZeroAddressShorthand } = AddressUtils;
|
||||
|
||||
import { getBlockchainDefaults, getContractDefaults, embarkConfigDefaults } from './configDefaults';
|
||||
import { getBlockchainDefaults, getContractDefaults } from './configDefaults';
|
||||
|
||||
const constants = readJsonSync(path.join(__dirname, '../constants.json'));
|
||||
const constants = require('../constants.json');
|
||||
|
||||
const DEFAULT_CONFIG_PATH = 'config/';
|
||||
|
||||
|
@ -84,7 +82,7 @@ export class Config {
|
|||
|
||||
events: Events;
|
||||
|
||||
embarkConfig: EmbarkConfig = embarkConfigDefaults;
|
||||
embarkConfig: EmbarkConfig = constants.defaultEmbarkConfig;
|
||||
|
||||
context: any;
|
||||
|
||||
|
@ -629,7 +627,7 @@ export class Config {
|
|||
}
|
||||
|
||||
loadEmbarkConfigFile() {
|
||||
this.embarkConfig = recursiveMerge(embarkConfigDefaults, this.embarkConfig);
|
||||
this.embarkConfig = recursiveMerge(constants.defaultEmbarkConfig, this.embarkConfig);
|
||||
|
||||
const contracts = this.embarkConfig.contracts;
|
||||
// determine contract 'root' directories
|
||||
|
|
|
@ -4,22 +4,6 @@ import { join } from "path";
|
|||
|
||||
const constants = readJsonSync(join(__dirname, '../constants.json'));
|
||||
|
||||
export const embarkConfigDefaults = {
|
||||
contracts: [],
|
||||
config: '',
|
||||
migrations: 'migrations',
|
||||
versions: {
|
||||
solc: "0.6.1"
|
||||
},
|
||||
options: {
|
||||
solc: {
|
||||
"optimize": true,
|
||||
"optimize-runs": 200
|
||||
}
|
||||
},
|
||||
generationDir: "embarkArtifacts"
|
||||
};
|
||||
|
||||
export function getBlockchainDefaults(env) {
|
||||
const defaults = {
|
||||
clientConfig: {
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
"embark-ethereum-blockchain-client": "^5.3.0-nightly.0",
|
||||
"embark-ganache": "^5.3.0-nightly.0",
|
||||
"embark-geth": "^5.3.0-nightly.0",
|
||||
"embark-i18n": "^5.2.3",
|
||||
"embark-library-manager": "^5.3.0-nightly.0",
|
||||
"embark-logger": "^5.3.0-nightly.0",
|
||||
"embark-mocha-tests": "^5.3.0-nightly.0",
|
||||
|
@ -87,7 +88,8 @@
|
|||
"embark-vyper": "^5.2.3",
|
||||
"embark-watcher": "^5.3.0-nightly.0",
|
||||
"embark-web3": "^5.3.0-nightly.0",
|
||||
"embark-webserver": "^5.3.0-nightly.0"
|
||||
"embark-webserver": "^5.3.0-nightly.0",
|
||||
"fs-extra": "8.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"embark-solo": "^5.2.3",
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
module.exports = {
|
||||
contracts: ["contracts/**"],
|
||||
app: {},
|
||||
buildDir: "dist/",
|
||||
config: "config/",
|
||||
versions: {
|
||||
solc: "0.6.1"
|
||||
},
|
||||
plugins: {
|
||||
},
|
||||
options: {
|
||||
solc: {
|
||||
"optimize": true,
|
||||
"optimize-runs": 200
|
||||
}
|
||||
},
|
||||
generationDir: "embarkArtifacts"
|
||||
};
|
|
@ -6,9 +6,11 @@ import {
|
|||
ProcessManager,
|
||||
ServicesMonitor
|
||||
} from 'embark-core';
|
||||
import fs from 'fs-extra';
|
||||
import { normalizeInput } from 'embark-utils';
|
||||
import { Logger } from 'embark-logger';
|
||||
import defaultEmbarkJson from './defaultEmbarkJson';
|
||||
import { __ } from 'embark-i18n';
|
||||
const constants = require('embark-core/constants');
|
||||
const EMBARK_PROCESS_NAME = 'embark';
|
||||
|
||||
export class Engine {
|
||||
|
@ -61,7 +63,7 @@ export class Engine {
|
|||
this.env = options.env;
|
||||
this.client = options.client;
|
||||
this.locale = options.locale;
|
||||
this.embarkConfig = options.embarkConfig || defaultEmbarkJson;
|
||||
this.embarkConfig = options.embarkConfig || constants.defaultEmbarkConfig;
|
||||
this.interceptLogs = options.interceptLogs;
|
||||
this.version = options.version;
|
||||
this.logFile = options.logFile;
|
||||
|
@ -118,6 +120,13 @@ export class Engine {
|
|||
callback();
|
||||
}
|
||||
|
||||
async generateEmbarkJSON() {
|
||||
if (fs.existsSync('embark.json')) {
|
||||
throw new Error(__('embark.json already there. Will not overwrite'));
|
||||
}
|
||||
return fs.writeFile('embark.json', JSON.stringify(constants.defaultEmbarkConfig, null, 2));
|
||||
}
|
||||
|
||||
loadDappPlugins() {
|
||||
if (this.config) {
|
||||
this.config.plugins.loadPlugins();
|
||||
|
|
|
@ -127,6 +127,9 @@
|
|||
{
|
||||
"path": "../core"
|
||||
},
|
||||
{
|
||||
"path": "../i18n"
|
||||
},
|
||||
{
|
||||
"path": "../logger"
|
||||
},
|
||||
|
|
|
@ -411,11 +411,9 @@ EmbarkJson.prototype.log = function () {
|
|||
|
||||
EmbarkJson.prototype.logMissingFile = function () {
|
||||
if (Json.prototype.logMissingFile.call(this, false)) {
|
||||
// Use default embark.json
|
||||
if (isDappCmd(this.cmd)) {
|
||||
// TODO add message about embark init once it's available
|
||||
embarklog['warn']('No embark.json file found.\n' +
|
||||
'You can find a basic embark.json file here: https://github.com/embarklabs/embark/blob/master/dapps/templates/boilerplate/embark.json');
|
||||
embarklog['error']('No embark.json file found.\n' +
|
||||
'Run `embark init` to generate one automatically.');
|
||||
exitWithError();
|
||||
}
|
||||
}
|
||||
|
@ -993,6 +991,7 @@ function isDappCmd(cmd) {
|
|||
'-h',
|
||||
'--help',
|
||||
'new',
|
||||
'init',
|
||||
'demo',
|
||||
'version',
|
||||
'help'
|
||||
|
|
|
@ -11,6 +11,7 @@ class Cmd {
|
|||
}
|
||||
|
||||
process(args) {
|
||||
this.init();
|
||||
this.newApp();
|
||||
this.demo();
|
||||
this.build();
|
||||
|
@ -37,6 +38,15 @@ class Cmd {
|
|||
program.parse(args);
|
||||
}
|
||||
|
||||
init() {
|
||||
program
|
||||
.command('init')
|
||||
.description(__('Creates a basic embark.json file'))
|
||||
.action(() => {
|
||||
this.embark.embarkInit();
|
||||
});
|
||||
}
|
||||
|
||||
newApp() {
|
||||
|
||||
let validateName = function (value) {
|
||||
|
@ -181,7 +191,7 @@ class Cmd {
|
|||
.option('-t, --track', __('Force tracking of migration script', false))
|
||||
.description(__("Executes specified scripts or all scripts in 'directory'"))
|
||||
.action((env, target, options) => {
|
||||
embark.exec({
|
||||
this.embark.exec({
|
||||
env,
|
||||
target,
|
||||
forceTracking: options.track
|
||||
|
|
|
@ -20,9 +20,6 @@ const pkg = readJsonSync(join(__dirname, '../../package.json'));
|
|||
class EmbarkController {
|
||||
|
||||
constructor(options) {
|
||||
if (!options.embarkConfig) {
|
||||
throw new Error('No embarkConfig found in options');
|
||||
}
|
||||
this.embarkConfig = options.embarkConfig;
|
||||
this.version = pkg.version;
|
||||
|
||||
|
@ -39,6 +36,19 @@ class EmbarkController {
|
|||
this.plugins = this.config.plugins;
|
||||
}
|
||||
|
||||
async embarkInit() {
|
||||
const engine = new Engine({});
|
||||
try {
|
||||
await engine.generateEmbarkJSON();
|
||||
} catch (e) {
|
||||
console.error(__('Error generating embark.json file'));
|
||||
console.error(e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
console.info(__('embark.json generated. You can now run all Embark commands.').green);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
blockchain(options) {
|
||||
this.context = options.context || [constants.contexts.blockchain];
|
||||
const webServerConfig = {};
|
||||
|
|
Loading…
Reference in New Issue