mirror of https://github.com/embarklabs/embark.git
refactor(@embark/embark-utils): move last fn into utils package
This commit is contained in:
parent
4c4c8ed1d6
commit
6308c82993
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
export function last(array: any) {
|
||||||
|
return array[array.length - 1];
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ const {findNextPort} = require('./network');
|
||||||
const logUtils = require('./log-utils');
|
const logUtils = require('./log-utils');
|
||||||
const toposortGraph = require('./toposort');
|
const toposortGraph = require('./toposort');
|
||||||
|
|
||||||
|
import { last } from './collections';
|
||||||
|
|
||||||
function checkIsAvailable(url, callback) {
|
function checkIsAvailable(url, callback) {
|
||||||
const protocol = url.split(':')[0];
|
const protocol = url.split(':')[0];
|
||||||
const httpObj = (protocol === 'https') ? https : http;
|
const httpObj = (protocol === 'https') ? https : http;
|
||||||
|
@ -125,6 +127,7 @@ const Utils = {
|
||||||
findNextPort,
|
findNextPort,
|
||||||
hashTo32ByteHexString,
|
hashTo32ByteHexString,
|
||||||
isHex,
|
isHex,
|
||||||
|
last,
|
||||||
soliditySha3,
|
soliditySha3,
|
||||||
recursiveMerge,
|
recursiveMerge,
|
||||||
sha512,
|
sha512,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import prettyMs from "pretty-ms";
|
||||||
|
|
||||||
import { Logger } from "embark";
|
import { Logger } from "embark";
|
||||||
|
|
||||||
const utils = require("./utils.js");
|
|
||||||
const ora = require("ora");
|
const ora = require("ora");
|
||||||
|
|
||||||
export interface LongRunningProcessTimerOptions {
|
export interface LongRunningProcessTimerOptions {
|
||||||
|
@ -63,7 +62,7 @@ export default class LongRunningProcessTimer {
|
||||||
let strDuration;
|
let strDuration;
|
||||||
|
|
||||||
// find any download ongoing measurements we"ve made
|
// find any download ongoing measurements we"ve made
|
||||||
entry = utils.last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadOngoing));
|
entry = last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadOngoing));
|
||||||
if (entry) {
|
if (entry) {
|
||||||
// ongoing performance mark
|
// ongoing performance mark
|
||||||
// TODO: add i18n
|
// TODO: add i18n
|
||||||
|
@ -73,7 +72,7 @@ export default class LongRunningProcessTimer {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// otherwise, find our download complete measurement
|
// otherwise, find our download complete measurement
|
||||||
entry = utils.last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadComplete));
|
entry = last(items.getEntries().filter((thisEntry) => thisEntry.name === this.downloadComplete));
|
||||||
if (entry) {
|
if (entry) {
|
||||||
// TODO: add i18n
|
// TODO: add i18n
|
||||||
strDuration = this.processFinishedMsg.replace("{{packageName}}", this.packageName).replace("{{version}}", this.version).replace("{{duration}}", prettyMs(entry.duration));
|
strDuration = this.processFinishedMsg.replace("{{packageName}}", this.packageName).replace("{{version}}", this.version).replace("{{duration}}", prettyMs(entry.duration));
|
||||||
|
|
|
@ -402,10 +402,6 @@ function groupBy(array, key) {
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
function last(array) {
|
|
||||||
return array[array.length - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
function interceptLogs(consoleContext, logger) {
|
function interceptLogs(consoleContext, logger) {
|
||||||
let context = {};
|
let context = {};
|
||||||
context.console = consoleContext;
|
context.console = consoleContext;
|
||||||
|
@ -541,7 +537,6 @@ module.exports = {
|
||||||
getHexBalanceFromString,
|
getHexBalanceFromString,
|
||||||
compact,
|
compact,
|
||||||
groupBy,
|
groupBy,
|
||||||
last,
|
|
||||||
interceptLogs,
|
interceptLogs,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
timer,
|
timer,
|
||||||
|
|
Loading…
Reference in New Issue