refactor: move `dappPath`, `ipcPath` and `embarkPath` into @embark/utils

This commit is contained in:
Pascal Precht 2019-05-16 12:03:19 +02:00
parent a519a5d527
commit 3df7f81732
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
53 changed files with 85 additions and 106 deletions

View File

@ -44,7 +44,6 @@
"@babel/runtime-corejs2": "7.3.1",
"colors": "1.3.2",
"embark-async-wrapper": "^4.1.0-beta.1",
"embark-core": "^4.1.0-beta.1",
"embark-i18n": "^4.1.0-beta.1",
"embark-utils": "^4.1.0-beta.1"
},

View File

@ -2,8 +2,8 @@ import bodyParser from "body-parser";
import "colors";
import cors from "cors";
import {Embark, Plugins} /* supplied by @types/embark in packages/embark-typings */ from "embark";
import { embarkPath } from "embark-core";
import { __ } from "embark-i18n";
import { embarkPath } from "embark-utils";
import express, {NextFunction, Request, Response} from "express";
import expressWs from "express-ws";
import findUp from "find-up";

View File

@ -1,4 +1,3 @@
import { dappPath } from 'embark-core';
import { __ } from 'embark-i18n';
const Web3 = require('web3');
const async = require('async');
@ -8,7 +7,7 @@ const constants = require('embark-core/constants');
const embarkJsUtils = require('embarkjs').Utils;
const {bigNumberify} = require('ethers/utils/bignumber');
const RLP = require('ethers/utils/rlp');
import { buildUrl } from 'embark-utils';
import { buildUrl, dappPath } from 'embark-utils';
const WEB3_READY = 'blockchain:ready';

View File

@ -1,7 +1,6 @@
import { dappPath } from 'embark-core';
import { __ } from 'embark-i18n';
const async = require('async');
const { AccountParser } = require('embark-utils');
const { AccountParser, dappPath } = require('embark-utils');
const fundAccount = require('./fundAccount');
const constants = require('embark-core/constants');
const Transaction = require('ethereumjs-tx');

View File

@ -1,4 +1,4 @@
import { dappPath } from 'embark-core';
import { dappPath } from 'embark-utils';
import { __ } from 'embark-i18n';
const async = require('async');
const DevTxs = require('./dev_txs');

View File

@ -7,9 +7,9 @@ const constants = require('embark-core/constants');
const GethClient = require('./gethClient.js');
const ParityClient = require('./parityClient.js');
import { Proxy } from './proxy';
import { IPC, dappPath, embarkPath } from 'embark-core';
import { IPC } from 'embark-core';
import { compact, defaultHost, dockerHostSwap, AccountParser} from 'embark-utils';
import { compact, dappPath, defaultHost, dockerHostSwap, embarkPath, AccountParser} from 'embark-utils';
const Logger = require('embark-logger');
// time between IPC connection attempts (in ms)

View File

@ -1,5 +1,5 @@
import { __ } from 'embark-i18n';
import { dappPath, ipcPath } from 'embark-core';
import { dappPath, ipcPath } from 'embark-utils';
const async = require('async');
const {exec, spawn} = require('child_process');
const path = require('path');

View File

@ -1,7 +1,7 @@
const async = require('async');
const NetcatClient = require('netcat/client');
import { ipcPath } from 'embark-core';
import { ipcPath } from 'embark-utils';
//Constants
const minerStart = 'miner_start';

View File

@ -1,5 +1,5 @@
import { __ } from 'embark-i18n';
import { dappPath } from 'embark-core';
import { dappPath } from 'embark-utils';
import * as fs from 'fs-extra';
const async = require('async');
const path = require('path');

View File

@ -2,10 +2,9 @@ const path = require('path');
const pkgUp = require('pkg-up');
let shelljs = require('shelljs');
import { Proxy } from './proxy';
import { IPC, embarkPath, dappPath } from 'embark-core';
import { IPC } from 'embark-core';
const constants = require('embark-core/constants');
import { defaultHost, dockerHostSwap } from 'embark-utils';
const { AccountParser } = require('embark-utils');
import { AccountParser, dappPath, defaultHost, dockerHostSwap, embarkPath } from 'embark-utils';
export class Simulator {
constructor(options) {

View File

@ -1,6 +1,5 @@
import { __ } from 'embark-i18n';
import { dappPath, embarkPath } from 'embark-core';
import { joinPath } from 'embark-utils';
import { dappPath, embarkPath, joinPath } from 'embark-utils';
import * as fs from 'fs-extra';
import { transform } from "@babel/core";
const async = require('async');

View File

@ -1,7 +1,6 @@
const async = require('async');
import { dappPath } from 'embark-core';
import { __ } from 'embark-i18n';
import { getAddressToContract, getTransactionParams, hexToNumber } from 'embark-utils';
import { dappPath, getAddressToContract, getTransactionParams, hexToNumber } from 'embark-utils';
class ConsoleListener {
constructor(embark, options) {

View File

@ -1,10 +1,9 @@
import { waterfall } from "async";
import chalk from "chalk";
import { Callback, Embark, Events } /* supplied by @types/embark in packages/embark-typings */ from "embark";
import { dappPath } from "embark-core";
import constants from "embark-core/constants.json";
import { __ } from "embark-i18n";
import { escapeHtml, exit, jsonFunctionReplacer } from "embark-utils";
import { dappPath, escapeHtml, exit, jsonFunctionReplacer } from "embark-utils";
import stringify from "json-stringify-safe";
import { dirname } from "path";
import Suggestions from "./suggestions";

View File

@ -1,10 +1,9 @@
import { dappPath } from 'embark-core';
import { __ } from 'embark-i18n';
const async = require('async');
const cloneDeep = require('clone-deep');
const constants = require('embark-core/constants');
const path = require('path');
const {proposeAlternative, toposort} = require('embark-utils');
const { dappPath, proposeAlternative, toposort } = require('embark-utils');
// TODO: create a contract object

View File

@ -1,5 +1,2 @@
declare module "embark-core" {
function dappPath(...names: string[]): string;
function embarkPath(...names: string[]): string;
function ipcPath(basename: string, usePipePathOnWindows?: boolean): string;
}

View File

@ -3,5 +3,3 @@ export { ProcessManager } from './processes/processManager';
export { ProcessWrapper } from './processes/processWrapper';
export { IPC } from './ipc';
export { embarkPath, dappPath, ipcPath } from './utils';

View File

@ -4,7 +4,7 @@ const ipc = require('node-ipc');
const {parse, stringify} = require('flatted/cjs');
const path = require('path');
const fs = require('fs-extra');
import { ipcPath } from './utils';
import { ipcPath } from 'embark-utils';
const EMBARK = 'embark';

View File

@ -1,28 +0,0 @@
import * as path from 'path';
import {joinPath, sha512, tmpDir} from 'embark-utils';
export function dappPath(...names) {
const DAPP_PATH = process.env.DAPP_PATH || process.cwd();
return path.join(DAPP_PATH, ...names);
}
export function ipcPath(basename, usePipePathOnWindows = false) {
if (!(basename && typeof basename === 'string')) {
throw new TypeError('first argument must be a non-empty string');
}
if (process.platform === 'win32' && usePipePathOnWindows) {
return `\\\\.\\pipe\\${basename}`;
}
return joinPath(
tmpDir(`embark-${sha512(dappPath()).slice(0, 8)}`),
basename
);
}
export function embarkPath(...names) {
const EMBARK_PATH = process.env.EMBARK_PATH;
if (!EMBARK_PATH) {
throw new Error('environment variable EMBARK_PATH was not set');
}
return path.join(EMBARK_PATH, ...names);
}

View File

@ -1,6 +1,5 @@
import { dappPath } from 'embark-core';
import { __ } from 'embark-i18n';
import { sha3 } from 'embark-utils';
import { dappPath, sha3 } from 'embark-utils';
import * as fs from 'fs-extra';
class DeployTracker {

View File

@ -49,6 +49,7 @@
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"async": "^2.6.1",
"embark-core": "^4.1.0-beta.1",
"embark-i18n": "^4.1.0-beta.1",
"embark-utils": "^4.1.0-beta.1",
"embarkjs": "^4.1.0-beta.1",

View File

@ -48,7 +48,7 @@
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"colors": "1.3.2",
"embark-core": "^4.1.0-beta.1",
"embark-utils": "^4.1.0-beta.1",
"embark-i18n": "^4.1.0-beta.1",
"live-plugin-manager-git-fix": "0.12.1"
},

View File

@ -1,5 +1,5 @@
import { dappPath, embarkPath } from 'embark-core';
import { __ } from 'embark-i18n';
import { dappPath, embarkPath } from 'embark-utils';
var Npm = require('./npm.js');
class LibraryManager {

View File

@ -1,8 +1,8 @@
const path = require('path');
const async = require('async');
import { __ } from 'embark-i18n';
import { joinPath, LongRunningProcessTimer, fileTreeSort } from 'embark-utils';
import { dappPath, ProcessLauncher } from 'embark-core';
import { dappPath, joinPath, LongRunningProcessTimer, fileTreeSort } from 'embark-utils';
import { ProcessLauncher } from 'embark-core';
const constants = require('embark-core/constants');
const WebpackConfigReader = require('./webpackConfigReader');

View File

@ -1,5 +1,4 @@
import { dappPath } from 'embark-core';
import { errorMessage } from 'embark-utils';
import { dappPath, errorMessage } from 'embark-utils';
const fs = require('fs-extra');
import * as path from 'path';

View File

@ -1,5 +1,5 @@
import { dappPath, ProcessWrapper } from 'embark-core';
import { errorMessage } from 'embark-utils';
import { ProcessWrapper } from 'embark-core';
import { dappPath, errorMessage } from 'embark-utils';
const constants = require('embark-core/constants');
const webpack = require('webpack');
const writeFile = require('util').promisify(require('fs').writeFile);

View File

@ -42,7 +42,6 @@
},
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"embark-core": "^4.1.0-beta.1",
"embark-i18n": "^4.1.0-beta.1",
"embark-utils": "^4.1.0-beta.1"
},

View File

@ -1,6 +1,6 @@
import { Embark } /* supplied by @types/embark in packages/embark-typings */ from "embark";
import { dappPath } from "embark-core";
import { __ } from "embark-i18n";
import { dappPath } from "embark-utils";
import Handlebars from "handlebars";
import * as path from "path";
import { Builder } from "../../builder";

View File

@ -1,5 +1,4 @@
import { Contract, Embark } /* supplied by @types/embark in packages/embark-typings */ from "embark";
import { dappPath } from "embark-core";
import { __ } from "embark-i18n";
import Handlebars from "handlebars";
import * as path from "path";
@ -46,7 +45,7 @@ export class ReactBuilder implements Builder {
}
private updateEmbarkJson(contractName: string, files: string[]) {
const embarkJsonPath = path.join(dappPath(), "embark.json");
const embarkJsonPath = path.join(utils.dappPath(), "embark.json");
const embarkJson = this.embark.fs.readJSONSync(embarkJsonPath);
embarkJson.app[`js/${contractName}.js`] = `app/${contractName}.js`;
embarkJson.app[`${contractName}.html`] = `app/${contractName}.html`;
@ -129,8 +128,8 @@ export class ReactBuilder implements Builder {
}
private saveFiles(contractName: string, indexCode: string, dappCode: string) {
const indexFilePath = path.join(dappPath(), "app", `${contractName}.html`);
const dappFilePath = path.join(dappPath(), "app", `${contractName}.js`);
const indexFilePath = path.join(utils.dappPath(), "app", `${contractName}.html`);
const dappFilePath = path.join(utils.dappPath(), "app", `${contractName}.js`);
if (!this.options.overwrite && (this.embark.fs.existsSync(indexFilePath) || this.embark.fs.existsSync(dappFilePath))) {
return [];

View File

@ -1,6 +1,6 @@
import { __ } from 'embark-i18n';
import { dappPath, ProcessLauncher } from 'embark-core';
import {joinPath} from 'embark-utils';
import { ProcessLauncher } from 'embark-core';
import { dappPath, joinPath } from 'embark-utils';
const uuid = require('uuid/v1');
class SolcW {

View File

@ -48,7 +48,6 @@
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"async": "2.6.1",
"embark-core": "^4.1.0-beta.1",
"embark-i18n": "^4.1.0-beta.1",
"embark-utils": "^4.1.0-beta.1",
"fs-extra": "7.0.1",

View File

@ -1,9 +1,8 @@
import { dappPath, embarkPath } from 'embark-core';
import { __ } from 'embark-i18n';
const async = require('async');
const Mocha = require('mocha');
const path = require('path');
const { runCmd, timer } = require('embark-utils');
const { dappPath, embarkPath, runCmd, timer } = require('embark-utils');
const assert = require('assert');
const Test = require('./test');
const {EmbarkSpec, EmbarkApiSpec} = require('./reporter');

View File

@ -254,11 +254,41 @@ function errorMessage(e) {
return e;
}
function dappPath(...names) {
const DAPP_PATH = process.env.DAPP_PATH || process.cwd();
return path.join(DAPP_PATH, ...names);
}
function ipcPath(basename, usePipePathOnWindows = false) {
if (!(basename && typeof basename === 'string')) {
throw new TypeError('first argument must be a non-empty string');
}
if (process.platform === 'win32' && usePipePathOnWindows) {
return `\\\\.\\pipe\\${basename}`;
}
return joinPath(
tmpDir(`embark-${sha512(dappPath()).slice(0, 8)}`),
basename
);
}
function embarkPath(...names) {
const EMBARK_PATH = process.env.EMBARK_PATH;
if (!EMBARK_PATH) {
throw new Error('environment variable EMBARK_PATH was not set');
}
return path.join(EMBARK_PATH, ...names);
}
const Utils = {
buildUrl,
buildUrlFromConfig,
joinPath,
tmpDir,
ipcPath,
dappPath,
embarkPath,
jsonFunctionReplacer,
fuzzySearch,
canonicalHost,

View File

@ -48,8 +48,8 @@
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"chokidar": "2.0.4",
"embark-core": "^4.1.0-beta.1",
"embark-i18n": "^4.1.0-beta.1"
"embark-i18n": "^4.1.0-beta.1",
"embark-utils": "^4.1.0-beta.1"
},
"devDependencies": {
"@babel/cli": "7.2.3",

View File

@ -1,5 +1,5 @@
import { dappPath } from 'embark-core';
import { __ } from 'embark-i18n';
import { dappPath } from 'embark-utils';
let chokidar = require('chokidar');
let path = require('path');

View File

@ -1,8 +1,7 @@
import { dappPath } from 'embark-core';
const async = require('async');
let serveStatic = require('serve-static');
import { __ } from 'embark-i18n';
import {canonicalHost, defaultHost, dockerHostSwap} from 'embark-utils';
import {canonicalHost, dappPath, defaultHost, dockerHostSwap} from 'embark-utils';
const expressWebSocket = require('express-ws');
const express = require('express');
const https = require('https');

View File

@ -1,6 +1,6 @@
import { BlockchainClient, Simulator } from 'embark-blockchain-process';
import { dappPath, embarkPath } from 'embark-core';
import { __ } from 'embark-i18n';
import { dappPath, embarkPath } from 'embark-utils';
import findUp from 'find-up';
let async = require('async');
const constants = require('embark-core/constants');

View File

@ -5,11 +5,11 @@ const path = require('path');
const deepEqual = require('deep-equal');
const web3 = require('web3');
const constants = require('embark-core/constants');
import { dappPath } from 'embark-core';
import { __ } from 'embark-i18n';
import {
buildUrlFromConfig,
canonicalHost,
dappPath,
defaultHost,
recursiveMerge,
AddressUtils,

View File

@ -1,5 +1,5 @@
import { dappPath, embarkPath } from "embark-core";
import { __ } from "embark-i18n";
import { dappPath, embarkPath } from "embark-utils";
import * as path from "path";
import { ImportRemapping, prepareForCompilation } from "../utils/solidity/remapImports";

View File

@ -1,7 +1,6 @@
const utils = require('../utils/utils.js');
import { dappPath, embarkPath } from 'embark-core';
import { __ } from 'embark-i18n';
import {joinPath} from 'embark-utils';
import { dappPath, embarkPath, joinPath } from 'embark-utils';
const constants = require('embark-core/constants');
const fs = require('fs-extra');
const deepEqual = require('deep-equal');

View File

@ -1,4 +1,4 @@
import { dappPath, embarkPath } from 'embark-core';
import { dappPath, embarkPath } from 'embark-utils';
const async = require('async');
var Plugin = require('./plugin.js');
var fs = require('../core/fs.js');

View File

@ -1,4 +1,4 @@
import { dappPath } from "embark-core";
import { dappPath } from "embark-utils";
import * as globule from "globule";
import * as path from "path";
import Web3Contract from "web3/eth/contract";

View File

@ -1,4 +1,3 @@
import { dappPath, embarkPath } from 'embark-core';
import { __ } from 'embark-i18n';
const UploadIPFS = require('./upload.js');
const utils = require('../../utils/utils.js');
@ -6,7 +5,7 @@ const IpfsApi = require('ipfs-api');
// TODO: not great, breaks module isolation
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
const constants = require('embark-core/constants');
import { buildUrlFromConfig } from 'embark-utils';
import { buildUrlFromConfig, dappPath, embarkPath } from 'embark-utils';
class IPFS {

View File

@ -1,4 +1,5 @@
import { dappPath, ProcessWrapper } from 'embark-core';
import { ProcessWrapper } from 'embark-core';
import { dappPath } from 'embark-utils';
const child_process = require('child_process');
const constants = require('embark-core/constants');

View File

@ -1,4 +1,4 @@
import { dappPath, embarkPath } from "embark-core";
import { dappPath, embarkPath } from "embark-utils";
import * as path from "path";
import { File, Types } from "../../core/file";
import { removePureView, replacePureView } from "./code";

View File

@ -1,10 +1,9 @@
import { embarkPath } from 'embark-core';
import { __ } from 'embark-i18n';
const findUp = require('find-up');
const fs = require('../core/fs.js');
const hostedGitInfo = require('hosted-git-info');
const utils = require('./utils.js');
import { joinPath, runCmd, errorMessage } from 'embark-utils';
import { embarkPath, joinPath, runCmd, errorMessage } from 'embark-utils';
const semver = require('semver');
const {promisify} = require('util');
const {execSync} = require('child_process');

View File

@ -1,12 +1,11 @@
/*global __dirname, describe, it, before, after, require*/
import { dappPath } from 'embark-core';
import * as i18n from 'embark-i18n';
const assert = require('assert');
const sinon = require('sinon');
let TestLogger = require('../lib/utils/test_logger');
const Web3 = require('web3');
const fs = require('../lib/core/fs');
import { getWeiBalanceFromString, getHexBalanceFromString, AccountParser } from 'embark-utils';
import { dappPath, getWeiBalanceFromString, getHexBalanceFromString, AccountParser } from 'embark-utils';
i18n.setOrDetectLocale('en');
describe('embark.AccountParser', function () {

View File

@ -1,8 +1,7 @@
/*globals describe, it*/
import { BlockchainClient } from 'embark-blockchain-process';
import { dappPath } from 'embark-core';
const constants = require('embark-core/constants');
import {defaultHost} from 'embark-utils';
import { dappPath, defaultHost} from 'embark-utils';
const path = require('path');
const fs = require('../lib/core/fs.js');

View File

@ -1,5 +1,5 @@
/*globals describe, it*/
const { dappPath } = require('embark-core');
const { dappPath } = require('embark-utils');
const Config = require('../lib/core/config.js');
const Plugins = require('../lib/core/plugins.js');
const assert = require('assert');

View File

@ -1,5 +1,5 @@
/*globals describe, it*/
const { dappPath } = require('embark-core');
const { dappPath } = require('embark-utils');
const {File, Types} = require("../lib/core/file");
const {expect} = require("chai");
const fs = require("../lib/core/fs");

View File

@ -1,5 +1,5 @@
/*globals describe, it, before*/
const { dappPath } = require('embark-core');
const { dappPath } = require('embark-utils');
const {File, Types} = require("../../../lib/core/file");
const path = require("path");
const remapImports = require("../../../lib/utils/solidity/remapImports");

View File

@ -1,5 +1,5 @@
/*global after, before, describe, it, require, process*/
const { embarkPath } = require('embark-core');
const { embarkPath } = require('embark-utils');
const {assert} = require('chai');
const os = require('os');
const path = require('path');

View File

@ -1,4 +1,4 @@
const { dappPath, embarkPath } = require('embark-core');
const { dappPath, embarkPath } = require('embark-utils');
const path = require('path');
class EmbarkJSConnectorWeb3 {

View File

@ -31,7 +31,7 @@
"reset": "npx rimraf embark-*.tgz package"
},
"dependencies": {
"embark-core": "^4.1.0-beta.1"
"embark-utils": "^4.1.0-beta.1"
},
"devDependencies": {
"rimraf": "2.6.3"