From 086b3a38771846e51f093dae3a51c0b19efc7633 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 30 Apr 2019 11:57:34 -0400 Subject: [PATCH] refactor (@embark/embark-api): move embark-api to its own module --- packages/embark-api/.npmrc | 4 ++ packages/embark-api/README.md | 7 +++ packages/embark-api/package.json | 62 +++++++++++++++++++ .../modules/api => embark-api/src}/index.ts | 0 .../modules/api => embark-api/src}/server.ts | 18 +++--- packages/embark-api/tsconfig.json | 4 ++ packages/embark-api/tslint.json | 3 + packages/embark/package.json | 1 + packages/embark/src/lib/core/engine.js | 2 +- 9 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 packages/embark-api/.npmrc create mode 100644 packages/embark-api/README.md create mode 100644 packages/embark-api/package.json rename packages/{embark/src/lib/modules/api => embark-api/src}/index.ts (100%) rename packages/{embark/src/lib/modules/api => embark-api/src}/server.ts (93%) create mode 100644 packages/embark-api/tsconfig.json create mode 100644 packages/embark-api/tslint.json diff --git a/packages/embark-api/.npmrc b/packages/embark-api/.npmrc new file mode 100644 index 000000000..e031d3432 --- /dev/null +++ b/packages/embark-api/.npmrc @@ -0,0 +1,4 @@ +engine-strict = true +package-lock = false +save-exact = true +scripts-prepend-node-path = true diff --git a/packages/embark-api/README.md b/packages/embark-api/README.md new file mode 100644 index 000000000..51931e8db --- /dev/null +++ b/packages/embark-api/README.md @@ -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). + diff --git a/packages/embark-api/package.json b/packages/embark-api/package.json new file mode 100644 index 000000000..bcdf8ae13 --- /dev/null +++ b/packages/embark-api/package.json @@ -0,0 +1,62 @@ +{ + "name": "embark-api", + "version": "4.1.0-beta.0", + "author": "Iuri Matias ", + "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" + } +} diff --git a/packages/embark/src/lib/modules/api/index.ts b/packages/embark-api/src/index.ts similarity index 100% rename from packages/embark/src/lib/modules/api/index.ts rename to packages/embark-api/src/index.ts diff --git a/packages/embark/src/lib/modules/api/server.ts b/packages/embark-api/src/server.ts similarity index 93% rename from packages/embark/src/lib/modules/api/server.ts rename to packages/embark-api/src/server.ts index a54c9eae8..af5a56740 100644 --- a/packages/embark/src/lib/modules/api/server.ts +++ b/packages/embark-api/src/server.ts @@ -9,8 +9,6 @@ import * as http from "http"; import {__} from "i18n"; import * as path from "path"; import * as ws from "ws"; -// @ts-ignore -import {embarkPath, existsSync} from "../../core/fs"; type Method = "get" | "post" | "ws" | "delete"; @@ -23,16 +21,14 @@ interface CallDescription { export default class Server { private _isInsideMonorepo: boolean | null = null; private _monorepoRootDir: string = ""; - private embarkUiBuildDir: string = ( - findUp.sync("node_modules/embark-ui/build", {cwd: embarkPath()}) || - embarkPath("node_modules/embark-ui/build") - ); + private embarkUiBuildDir: string = ""; private expressInstance: expressWs.Instance; private isLogging: boolean = false; private server?: http.Server; constructor(private embark: Embark, private port: number, private hostname: string, private plugins: Plugins) { 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() { @@ -45,16 +41,16 @@ export default class Server { private get isInsideMonorepo() { if (this._isInsideMonorepo === null) { - this._isInsideMonorepo = existsSync(embarkPath("../../packages/embark")) && - existsSync(embarkPath("../../lerna.json")) && - path.resolve(embarkPath("../../packages/embark")) === embarkPath(); + this._isInsideMonorepo = this.embark.fs.existsSync(this.embark.fs.embarkPath("../../packages/embark")) && + this.embark.fs.existsSync(this.embark.fs.embarkPath("../../lerna.json")) && + path.resolve(this.embark.fs.embarkPath("../../packages/embark")) === this.embark.fs.embarkPath(); } return this._isInsideMonorepo; } private get monorepoRootDir() { if (!this._monorepoRootDir && this.isInsideMonorepo) { - this._monorepoRootDir = path.resolve(embarkPath("../..")); + this._monorepoRootDir = path.resolve(this.embark.fs.embarkPath("../..")); } return this._monorepoRootDir; } @@ -220,7 +216,7 @@ export default class Server { this.embark.events.on("plugins:register:api", (callDescription: CallDescription) => this.registerCallDescription(instance, callDescription)); 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.get(/^\/(?!embark-api).*$/, (_req, res) => { res.sendFile(path.join(this.embarkUiBuildDir, "index.html")); diff --git a/packages/embark-api/tsconfig.json b/packages/embark-api/tsconfig.json new file mode 100644 index 000000000..52d43eaaa --- /dev/null +++ b/packages/embark-api/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/embark-api/tslint.json b/packages/embark-api/tslint.json new file mode 100644 index 000000000..0946f2096 --- /dev/null +++ b/packages/embark-api/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tslint.json" +} diff --git a/packages/embark/package.json b/packages/embark/package.json index e077e084e..2a6ce1c60 100644 --- a/packages/embark/package.json +++ b/packages/embark/package.json @@ -92,6 +92,7 @@ "deep-equal": "1.0.1", "ejs": "2.6.1", "embark-authenticator": "^4.1.0-beta.0", + "embark-api": "^4.1.0-beta.0", "embark-compiler": "^4.0.0", "embark-contracts-manager": "^4.1.0-beta.0", "embark-core": "^4.1.0-beta.0", diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index e485527aa..5814d5be9 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -265,7 +265,7 @@ class Engine { cockpitService() { this.registerModulePackage('embark-authenticator', {singleUseAuthToken: this.singleUseAuthToken}); - this.registerModule('api', {plugins: this.plugins}); + this.registerModulePackage('embark-api', {plugins: this.plugins}); } webServerService() {