mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-18 00:27:17 +00:00
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": {
|
"environments": {
|
||||||
"development": "development"
|
"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';
|
import { filesMatchingPattern, fileMatchesPattern } from './utils/utils';
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const deepEqual = require('deep-equal');
|
const deepEqual = require('deep-equal');
|
||||||
const web3 = require('web3');
|
|
||||||
import { __ } from 'embark-i18n';
|
import { __ } from 'embark-i18n';
|
||||||
import {
|
import {
|
||||||
buildUrlFromConfig,
|
buildUrlFromConfig,
|
||||||
@ -23,13 +22,12 @@ import {
|
|||||||
getExternalContractUrl
|
getExternalContractUrl
|
||||||
} from 'embark-utils';
|
} from 'embark-utils';
|
||||||
import { Logger } from 'embark-logger';
|
import { Logger } from 'embark-logger';
|
||||||
import { readJsonSync } from 'fs-extra';
|
|
||||||
const cloneDeep = require('lodash.clonedeep');
|
const cloneDeep = require('lodash.clonedeep');
|
||||||
const { replaceZeroAddressShorthand } = AddressUtils;
|
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/';
|
const DEFAULT_CONFIG_PATH = 'config/';
|
||||||
|
|
||||||
@ -84,7 +82,7 @@ export class Config {
|
|||||||
|
|
||||||
events: Events;
|
events: Events;
|
||||||
|
|
||||||
embarkConfig: EmbarkConfig = embarkConfigDefaults;
|
embarkConfig: EmbarkConfig = constants.defaultEmbarkConfig;
|
||||||
|
|
||||||
context: any;
|
context: any;
|
||||||
|
|
||||||
@ -629,7 +627,7 @@ export class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadEmbarkConfigFile() {
|
loadEmbarkConfigFile() {
|
||||||
this.embarkConfig = recursiveMerge(embarkConfigDefaults, this.embarkConfig);
|
this.embarkConfig = recursiveMerge(constants.defaultEmbarkConfig, this.embarkConfig);
|
||||||
|
|
||||||
const contracts = this.embarkConfig.contracts;
|
const contracts = this.embarkConfig.contracts;
|
||||||
// determine contract 'root' directories
|
// determine contract 'root' directories
|
||||||
|
@ -4,22 +4,6 @@ import { join } from "path";
|
|||||||
|
|
||||||
const constants = readJsonSync(join(__dirname, '../constants.json'));
|
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) {
|
export function getBlockchainDefaults(env) {
|
||||||
const defaults = {
|
const defaults = {
|
||||||
clientConfig: {
|
clientConfig: {
|
||||||
|
@ -66,6 +66,7 @@
|
|||||||
"embark-ethereum-blockchain-client": "^5.3.0-nightly.0",
|
"embark-ethereum-blockchain-client": "^5.3.0-nightly.0",
|
||||||
"embark-ganache": "^5.3.0-nightly.0",
|
"embark-ganache": "^5.3.0-nightly.0",
|
||||||
"embark-geth": "^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-library-manager": "^5.3.0-nightly.0",
|
||||||
"embark-logger": "^5.3.0-nightly.0",
|
"embark-logger": "^5.3.0-nightly.0",
|
||||||
"embark-mocha-tests": "^5.3.0-nightly.0",
|
"embark-mocha-tests": "^5.3.0-nightly.0",
|
||||||
@ -87,7 +88,8 @@
|
|||||||
"embark-vyper": "^5.2.3",
|
"embark-vyper": "^5.2.3",
|
||||||
"embark-watcher": "^5.3.0-nightly.0",
|
"embark-watcher": "^5.3.0-nightly.0",
|
||||||
"embark-web3": "^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": {
|
"devDependencies": {
|
||||||
"embark-solo": "^5.2.3",
|
"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,
|
ProcessManager,
|
||||||
ServicesMonitor
|
ServicesMonitor
|
||||||
} from 'embark-core';
|
} from 'embark-core';
|
||||||
|
import fs from 'fs-extra';
|
||||||
import { normalizeInput } from 'embark-utils';
|
import { normalizeInput } from 'embark-utils';
|
||||||
import { Logger } from 'embark-logger';
|
import { Logger } from 'embark-logger';
|
||||||
import defaultEmbarkJson from './defaultEmbarkJson';
|
import { __ } from 'embark-i18n';
|
||||||
|
const constants = require('embark-core/constants');
|
||||||
const EMBARK_PROCESS_NAME = 'embark';
|
const EMBARK_PROCESS_NAME = 'embark';
|
||||||
|
|
||||||
export class Engine {
|
export class Engine {
|
||||||
@ -61,7 +63,7 @@ export class Engine {
|
|||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
this.client = options.client;
|
this.client = options.client;
|
||||||
this.locale = options.locale;
|
this.locale = options.locale;
|
||||||
this.embarkConfig = options.embarkConfig || defaultEmbarkJson;
|
this.embarkConfig = options.embarkConfig || constants.defaultEmbarkConfig;
|
||||||
this.interceptLogs = options.interceptLogs;
|
this.interceptLogs = options.interceptLogs;
|
||||||
this.version = options.version;
|
this.version = options.version;
|
||||||
this.logFile = options.logFile;
|
this.logFile = options.logFile;
|
||||||
@ -118,6 +120,13 @@ export class Engine {
|
|||||||
callback();
|
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() {
|
loadDappPlugins() {
|
||||||
if (this.config) {
|
if (this.config) {
|
||||||
this.config.plugins.loadPlugins();
|
this.config.plugins.loadPlugins();
|
||||||
|
@ -127,6 +127,9 @@
|
|||||||
{
|
{
|
||||||
"path": "../core"
|
"path": "../core"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "../i18n"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "../logger"
|
"path": "../logger"
|
||||||
},
|
},
|
||||||
|
@ -411,11 +411,9 @@ EmbarkJson.prototype.log = function () {
|
|||||||
|
|
||||||
EmbarkJson.prototype.logMissingFile = function () {
|
EmbarkJson.prototype.logMissingFile = function () {
|
||||||
if (Json.prototype.logMissingFile.call(this, false)) {
|
if (Json.prototype.logMissingFile.call(this, false)) {
|
||||||
// Use default embark.json
|
|
||||||
if (isDappCmd(this.cmd)) {
|
if (isDappCmd(this.cmd)) {
|
||||||
// TODO add message about embark init once it's available
|
embarklog['error']('No embark.json file found.\n' +
|
||||||
embarklog['warn']('No embark.json file found.\n' +
|
'Run `embark init` to generate one automatically.');
|
||||||
'You can find a basic embark.json file here: https://github.com/embarklabs/embark/blob/master/dapps/templates/boilerplate/embark.json');
|
|
||||||
exitWithError();
|
exitWithError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -993,6 +991,7 @@ function isDappCmd(cmd) {
|
|||||||
'-h',
|
'-h',
|
||||||
'--help',
|
'--help',
|
||||||
'new',
|
'new',
|
||||||
|
'init',
|
||||||
'demo',
|
'demo',
|
||||||
'version',
|
'version',
|
||||||
'help'
|
'help'
|
||||||
|
@ -11,6 +11,7 @@ class Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process(args) {
|
process(args) {
|
||||||
|
this.init();
|
||||||
this.newApp();
|
this.newApp();
|
||||||
this.demo();
|
this.demo();
|
||||||
this.build();
|
this.build();
|
||||||
@ -37,6 +38,15 @@ class Cmd {
|
|||||||
program.parse(args);
|
program.parse(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
program
|
||||||
|
.command('init')
|
||||||
|
.description(__('Creates a basic embark.json file'))
|
||||||
|
.action(() => {
|
||||||
|
this.embark.embarkInit();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
newApp() {
|
newApp() {
|
||||||
|
|
||||||
let validateName = function (value) {
|
let validateName = function (value) {
|
||||||
@ -181,7 +191,7 @@ class Cmd {
|
|||||||
.option('-t, --track', __('Force tracking of migration script', false))
|
.option('-t, --track', __('Force tracking of migration script', false))
|
||||||
.description(__("Executes specified scripts or all scripts in 'directory'"))
|
.description(__("Executes specified scripts or all scripts in 'directory'"))
|
||||||
.action((env, target, options) => {
|
.action((env, target, options) => {
|
||||||
embark.exec({
|
this.embark.exec({
|
||||||
env,
|
env,
|
||||||
target,
|
target,
|
||||||
forceTracking: options.track
|
forceTracking: options.track
|
||||||
|
@ -20,9 +20,6 @@ const pkg = readJsonSync(join(__dirname, '../../package.json'));
|
|||||||
class EmbarkController {
|
class EmbarkController {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
if (!options.embarkConfig) {
|
|
||||||
throw new Error('No embarkConfig found in options');
|
|
||||||
}
|
|
||||||
this.embarkConfig = options.embarkConfig;
|
this.embarkConfig = options.embarkConfig;
|
||||||
this.version = pkg.version;
|
this.version = pkg.version;
|
||||||
|
|
||||||
@ -39,6 +36,19 @@ class EmbarkController {
|
|||||||
this.plugins = this.config.plugins;
|
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) {
|
blockchain(options) {
|
||||||
this.context = options.context || [constants.contexts.blockchain];
|
this.context = options.context || [constants.contexts.blockchain];
|
||||||
const webServerConfig = {};
|
const webServerConfig = {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user