refactor (@embark/embark-api): move embark-api to its own module

This commit is contained in:
Iuri Matias 2019-04-30 11:57:34 -04:00
parent b5a9553599
commit 086b3a3877
9 changed files with 89 additions and 12 deletions

View File

@ -0,0 +1,4 @@
engine-strict = true
package-lock = false
save-exact = true
scripts-prepend-node-path = true

View File

@ -0,0 +1,7 @@
# `embark-api`
> Embark api module
Visit [embark.status.im](https://embark.status.im/) to get started with
[Embark](https://github.com/embark-framework/embark).

View File

@ -0,0 +1,62 @@
{
"name": "embark-api",
"version": "4.1.0-beta.0",
"author": "Iuri Matias <iuri.matias@gmail.com>",
"contributors": [],
"description": "Embark api module",
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-api#readme",
"bugs": "https://github.com/embark-framework/embark/issues",
"keywords": [
"blockchain",
"dapps",
"ethereum",
"ipfs",
"serverless",
"solc",
"solidity"
],
"license": "MIT",
"repository": {
"directory": "packages/embark-api",
"type": "git",
"url": "https://github.com/embark-framework/embark.git"
},
"main": "./dist/index.js",
"files": [
"dist"
],
"scripts": {
"build": "cross-env BABEL_ENV=node babel src --extensions \".js,.ts\" --out-dir dist --root-mode upward --source-maps",
"ci": "npm run qa",
"clean": "npm run reset",
"lint": "npm-run-all lint:*",
"lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
"package": "npm pack",
"qa": "npm-run-all lint typecheck build package",
"reset": "npx rimraf dist embark-*.tgz package",
"start": "npm run watch",
"typecheck": "tsc",
"watch": "run-p watch:*",
"watch:build": "npm run build -- --verbose --watch",
"watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch"
},
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"embark-async-wrapper": "^4.0.0",
"embark-utils": "^4.1.0-beta.0"
},
"devDependencies": {
"@babel/cli": "7.2.3",
"@babel/core": "7.2.2",
"cross-env": "5.2.0",
"npm-run-all": "4.1.5",
"rimraf": "2.6.3",
"tslint": "5.11.0",
"typescript": "3.3.1"
},
"engines": {
"node": ">=8.12.0",
"npm": ">=6.4.1",
"yarn": ">=1.12.3"
}
}

View File

@ -9,8 +9,6 @@ import * as http from "http";
import {__} from "i18n"; import {__} from "i18n";
import * as path from "path"; import * as path from "path";
import * as ws from "ws"; import * as ws from "ws";
// @ts-ignore
import {embarkPath, existsSync} from "../../core/fs";
type Method = "get" | "post" | "ws" | "delete"; type Method = "get" | "post" | "ws" | "delete";
@ -23,16 +21,14 @@ interface CallDescription {
export default class Server { export default class Server {
private _isInsideMonorepo: boolean | null = null; private _isInsideMonorepo: boolean | null = null;
private _monorepoRootDir: string = ""; private _monorepoRootDir: string = "";
private embarkUiBuildDir: string = ( private embarkUiBuildDir: string = "";
findUp.sync("node_modules/embark-ui/build", {cwd: embarkPath()}) ||
embarkPath("node_modules/embark-ui/build")
);
private expressInstance: expressWs.Instance; private expressInstance: expressWs.Instance;
private isLogging: boolean = false; private isLogging: boolean = false;
private server?: http.Server; private server?: http.Server;
constructor(private embark: Embark, private port: number, private hostname: string, private plugins: Plugins) { constructor(private embark: Embark, private port: number, private hostname: string, private plugins: Plugins) {
this.expressInstance = this.initApp(); this.expressInstance = this.initApp();
this.embarkUiBuildDir = (findUp.sync("node_modules/embark-ui/build", {cwd: embark.fs.embarkPath()}) || embark.fs.embarkPath("node_modules/embark-ui/build"));
} }
public enableLogging() { public enableLogging() {
@ -45,16 +41,16 @@ export default class Server {
private get isInsideMonorepo() { private get isInsideMonorepo() {
if (this._isInsideMonorepo === null) { if (this._isInsideMonorepo === null) {
this._isInsideMonorepo = existsSync(embarkPath("../../packages/embark")) && this._isInsideMonorepo = this.embark.fs.existsSync(this.embark.fs.embarkPath("../../packages/embark")) &&
existsSync(embarkPath("../../lerna.json")) && this.embark.fs.existsSync(this.embark.fs.embarkPath("../../lerna.json")) &&
path.resolve(embarkPath("../../packages/embark")) === embarkPath(); path.resolve(this.embark.fs.embarkPath("../../packages/embark")) === this.embark.fs.embarkPath();
} }
return this._isInsideMonorepo; return this._isInsideMonorepo;
} }
private get monorepoRootDir() { private get monorepoRootDir() {
if (!this._monorepoRootDir && this.isInsideMonorepo) { if (!this._monorepoRootDir && this.isInsideMonorepo) {
this._monorepoRootDir = path.resolve(embarkPath("../..")); this._monorepoRootDir = path.resolve(this.embark.fs.embarkPath("../.."));
} }
return this._monorepoRootDir; return this._monorepoRootDir;
} }
@ -220,7 +216,7 @@ export default class Server {
this.embark.events.on("plugins:register:api", (callDescription: CallDescription) => this.registerCallDescription(instance, callDescription)); this.embark.events.on("plugins:register:api", (callDescription: CallDescription) => this.registerCallDescription(instance, callDescription));
if (!this.isInsideMonorepo || process.env.EMBARK_UI_STATIC) { if (!this.isInsideMonorepo || process.env.EMBARK_UI_STATIC) {
if (existsSync(path.join(this.embarkUiBuildDir, "index.html"))) { if (this.embark.fs.existsSync(path.join(this.embarkUiBuildDir, "index.html"))) {
instance.app.use("/", express.static(this.embarkUiBuildDir)); instance.app.use("/", express.static(this.embarkUiBuildDir));
instance.app.get(/^\/(?!embark-api).*$/, (_req, res) => { instance.app.get(/^\/(?!embark-api).*$/, (_req, res) => {
res.sendFile(path.join(this.embarkUiBuildDir, "index.html")); res.sendFile(path.join(this.embarkUiBuildDir, "index.html"));

View File

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}

View File

@ -0,0 +1,3 @@
{
"extends": "../../tslint.json"
}

View File

@ -92,6 +92,7 @@
"deep-equal": "1.0.1", "deep-equal": "1.0.1",
"ejs": "2.6.1", "ejs": "2.6.1",
"embark-authenticator": "^4.1.0-beta.0", "embark-authenticator": "^4.1.0-beta.0",
"embark-api": "^4.1.0-beta.0",
"embark-compiler": "^4.0.0", "embark-compiler": "^4.0.0",
"embark-contracts-manager": "^4.1.0-beta.0", "embark-contracts-manager": "^4.1.0-beta.0",
"embark-core": "^4.1.0-beta.0", "embark-core": "^4.1.0-beta.0",

View File

@ -265,7 +265,7 @@ class Engine {
cockpitService() { cockpitService() {
this.registerModulePackage('embark-authenticator', {singleUseAuthToken: this.singleUseAuthToken}); this.registerModulePackage('embark-authenticator', {singleUseAuthToken: this.singleUseAuthToken});
this.registerModule('api', {plugins: this.plugins}); this.registerModulePackage('embark-api', {plugins: this.plugins});
} }
webServerService() { webServerService() {