mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-22 11:40:09 +00:00
refactor(@embark/utils): move proposeAlternative, toposort into embark-utils package
This commit is contained in:
parent
60ff097406
commit
65f3a270c0
@ -6,6 +6,7 @@ const clipboardy = require('clipboardy');
|
||||
const {canonicalHost, defaultCorsHost, defaultHost, dockerHostSwap, isDocker} = require('./host');
|
||||
const {findNextPort} = require('./network');
|
||||
const logUtils = require('./log-utils');
|
||||
const toposortGraph = require('./toposort');
|
||||
|
||||
function checkIsAvailable(url, callback) {
|
||||
const protocol = url.split(':')[0];
|
||||
@ -95,6 +96,18 @@ function copyToClipboard(text) {
|
||||
clipboardy.writeSync(text);
|
||||
}
|
||||
|
||||
function proposeAlternative(word, _dictionary, _exceptions) {
|
||||
const propose = require('propose');
|
||||
let exceptions = _exceptions || [];
|
||||
let dictionary = _dictionary.filter((entry) => {
|
||||
return exceptions.indexOf(entry) < 0;
|
||||
});
|
||||
return propose(word, dictionary, {threshold: 0.3});
|
||||
}
|
||||
|
||||
function toposort(graph) {
|
||||
return toposortGraph(graph);
|
||||
}
|
||||
|
||||
const Utils = {
|
||||
joinPath: function() {
|
||||
@ -119,7 +132,9 @@ const Utils = {
|
||||
escapeHtml: logUtils.escapeHtml,
|
||||
normalizeInput: logUtils.normalizeInput,
|
||||
LogHandler: require('./logHandler'),
|
||||
AddressUtils: require('./addressUtils')
|
||||
AddressUtils: require('./addressUtils'),
|
||||
proposeAlternative,
|
||||
toposort
|
||||
};
|
||||
|
||||
module.exports = Utils;
|
||||
|
@ -406,13 +406,13 @@ class Cmd {
|
||||
let suggestion;
|
||||
|
||||
if (cmd === 'compile') {
|
||||
// we bypass `utils.proposeAlternative()` here as `build` isn't
|
||||
// we bypass `proposeAlternative()` here as `build` isn't
|
||||
// similar enough
|
||||
suggestion = 'build --contracts';
|
||||
} else {
|
||||
let utils = require('../lib/utils/utils.js');
|
||||
const {proposeAlternative} = require('embark-utils');
|
||||
let dictionary = ['new', 'demo', 'build', 'run', 'blockchain', 'simulator', 'test', 'upload', 'version', 'console', 'eject-webpack', 'graph', 'help', 'reset'];
|
||||
suggestion = utils.proposeAlternative(cmd, dictionary);
|
||||
suggestion = proposeAlternative(cmd, dictionary);
|
||||
}
|
||||
if (suggestion) {
|
||||
console.log((__('did you mean') + ' "%s"?').green, suggestion);
|
||||
|
@ -1,8 +1,8 @@
|
||||
let async = require('async');
|
||||
const cloneDeep = require('clone-deep');
|
||||
const path = require('path');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const constants = require('embark-core/constants');
|
||||
const path = require('path');
|
||||
const {proposeAlternative, toposort} = require('embark-utils');
|
||||
|
||||
// TODO: create a contract object
|
||||
|
||||
@ -423,7 +423,7 @@ class ContractsManager {
|
||||
className: className,
|
||||
parentContractName: parentContractName
|
||||
}));
|
||||
let suggestion = utils.proposeAlternative(parentContractName, dictionary, [className, parentContractName]);
|
||||
let suggestion = proposeAlternative(parentContractName, dictionary, [className, parentContractName]);
|
||||
if (suggestion) {
|
||||
self.logger.warn(__('did you mean "%s"?', suggestion));
|
||||
}
|
||||
@ -467,7 +467,7 @@ class ContractsManager {
|
||||
|
||||
if (contract.code === undefined && !contract.abiDefinition) {
|
||||
self.logger.error(__("%s has no code associated", className));
|
||||
let suggestion = utils.proposeAlternative(className, dictionary, [className]);
|
||||
let suggestion = proposeAlternative(className, dictionary, [className]);
|
||||
if (suggestion) {
|
||||
self.logger.warn(__('did you mean "%s"?', suggestion));
|
||||
}
|
||||
@ -614,7 +614,7 @@ class ContractsManager {
|
||||
let orderedDependencies;
|
||||
|
||||
try {
|
||||
orderedDependencies = utils.toposort(converted_dependencies.filter((x) => x[0] !== x[1])).reverse();
|
||||
orderedDependencies = toposort(converted_dependencies.filter((x) => x[0] !== x[1])).reverse();
|
||||
} catch (e) {
|
||||
this.logger.error((__("Error: ") + e.message).red);
|
||||
this.logger.error(__("there are two or more contracts that depend on each other in a cyclic manner").bold.red);
|
||||
|
@ -1,6 +1,5 @@
|
||||
let http = require('follow-redirects').http;
|
||||
let https = require('follow-redirects').https;
|
||||
let toposortGraph = require('./toposort.js');
|
||||
import {canonicalHost, normalizeInput} from 'embark-utils';
|
||||
|
||||
const balanceRegex = /([0-9]+) ?([a-zA-Z]*)/;
|
||||
@ -178,15 +177,6 @@ function extractZip(filename, packageDirectory, opts, cb) {
|
||||
});
|
||||
}
|
||||
|
||||
function proposeAlternative(word, _dictionary, _exceptions) {
|
||||
const propose = require('propose');
|
||||
let exceptions = _exceptions || [];
|
||||
let dictionary = _dictionary.filter((entry) => {
|
||||
return exceptions.indexOf(entry) < 0;
|
||||
});
|
||||
return propose(word, dictionary, {threshold: 0.3});
|
||||
}
|
||||
|
||||
function getExternalContractUrl(file,providerUrl) {
|
||||
const constants = require('embark-core/constants');
|
||||
let url;
|
||||
@ -498,10 +488,6 @@ function getWindowSize() {
|
||||
return {width: 240, height: 75};
|
||||
}
|
||||
|
||||
function toposort(graph) {
|
||||
return toposortGraph(graph);
|
||||
}
|
||||
|
||||
function isConstructor(obj) {
|
||||
return !!obj.prototype && !!obj.prototype.constructor.name;
|
||||
}
|
||||
@ -544,7 +530,6 @@ module.exports = {
|
||||
downloadFile,
|
||||
extractTar,
|
||||
extractZip,
|
||||
proposeAlternative,
|
||||
getExternalContractUrl,
|
||||
toChecksumAddress,
|
||||
sha3,
|
||||
@ -564,7 +549,6 @@ module.exports = {
|
||||
fuzzySearch,
|
||||
jsonFunctionReplacer,
|
||||
getWindowSize,
|
||||
toposort,
|
||||
isEs6Module,
|
||||
urlJoin
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user