From 45a9fee20ba36d167d606f248985ce84b7fcb716 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Thu, 2 May 2019 12:54:34 +0200 Subject: [PATCH] refactor(@embark/code-generator): move code-generator into own package --- packages/embark-code-generator/.npmrc | 4 ++ packages/embark-code-generator/README.md | 6 ++ packages/embark-code-generator/package.json | 71 +++++++++++++++++++ .../src}/code/reload-on-change.js | 0 .../define-when-env-loaded.js.ejs | 0 .../src}/code_templates/do-when-loaded.js.ejs | 0 .../code_templates/embarkjs-contract.js.ejs | 0 .../exec-when-env-loaded.js.ejs | 0 .../code_templates/exec-when-ready.js.ejs | 0 .../src}/code_templates/load-manager.js.ejs | 0 .../src}/code_templates/main-context.js.ejs | 0 .../code_templates/vanilla-contract.js.ejs | 0 .../src}/index.js | 4 +- packages/embark-code-generator/tsconfig.json | 4 ++ packages/embark-code-generator/tslint.json | 3 + packages/embark/package.json | 1 + packages/embark/src/lib/core/engine.js | 2 +- packages/embark/src/test/code_generator.js | 2 +- 18 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 packages/embark-code-generator/.npmrc create mode 100644 packages/embark-code-generator/README.md create mode 100644 packages/embark-code-generator/package.json rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code/reload-on-change.js (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/define-when-env-loaded.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/do-when-loaded.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/embarkjs-contract.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/exec-when-env-loaded.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/exec-when-ready.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/load-manager.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/main-context.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/code_templates/vanilla-contract.js.ejs (100%) rename packages/{embark/src/lib/modules/code_generator => embark-code-generator/src}/index.js (98%) create mode 100644 packages/embark-code-generator/tsconfig.json create mode 100644 packages/embark-code-generator/tslint.json diff --git a/packages/embark-code-generator/.npmrc b/packages/embark-code-generator/.npmrc new file mode 100644 index 000000000..e031d3432 --- /dev/null +++ b/packages/embark-code-generator/.npmrc @@ -0,0 +1,4 @@ +engine-strict = true +package-lock = false +save-exact = true +scripts-prepend-node-path = true diff --git a/packages/embark-code-generator/README.md b/packages/embark-code-generator/README.md new file mode 100644 index 000000000..95dd2a34c --- /dev/null +++ b/packages/embark-code-generator/README.md @@ -0,0 +1,6 @@ +# `embark-code-generator` + +Embark code generator + +Visit [embark.status.im](https://embark.status.im/) to get started with +[Embark](https://github.com/embark-framework/embark). diff --git a/packages/embark-code-generator/package.json b/packages/embark-code-generator/package.json new file mode 100644 index 000000000..392a0ec9b --- /dev/null +++ b/packages/embark-code-generator/package.json @@ -0,0 +1,71 @@ +{ + "name": "embark-code-generator", + "version": "4.1.0-beta.0", + "author": "Iuri Matias ", + "contributors": [], + "description": "Embark code generator", + "homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-code-generator#readme", + "bugs": "https://github.com/embark-framework/embark/issues", + "keywords": [ + "blockchain", + "dapps", + "ethereum", + "ipfs", + "serverless", + "solc", + "solidity" + ], + "files": [ + "dist" + ], + "license": "MIT", + "repository": { + "directory": "packages/embark-code-generator", + "type": "git", + "url": "https://github.com/embark-framework/embark.git" + }, + "main": "./dist/index.js", + "scripts": { + "build": "cross-env BABEL_ENV=node babel src --extensions \".js\" --out-dir dist --root-mode upward --source-maps --copy-files", + "ci": "npm run qa", + "clean": "npm run reset", + "lint": "npm-run-all lint:*", + "lint:js": "eslint src/", + "// lint:ts": "tslint -c tslint.json \"src/**/*.ts\"", + "package": "npm pack", + "// qa": "npm-run-all lint typecheck build package", + "qa": "npm-run-all lint 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" + }, + "eslintConfig": { + "extends": "../../.eslintrc.json" + }, + "dependencies": { + "@babel/core": "7.2.2", + "@babel/runtime-corejs2": "7.3.1", + "async": "2.6.1", + "ejs": "2.6.1", + "embark-core": "^4.1.0-beta.0", + "embark-utils": "^4.1.0-beta.0" + }, + "devDependencies": { + "@babel/cli": "7.2.3", + "@babel/core": "7.2.2", + "cross-env": "5.2.0", + "eslint": "5.7.0", + "npm-run-all": "4.1.5", + "rimraf": "2.6.3", + "tslint": "5.16.0", + "typescript": "3.4.5" + }, + "engines": { + "node": ">=8.12.0", + "npm": ">=6.4.1", + "yarn": ">=1.12.3" + } +} diff --git a/packages/embark/src/lib/modules/code_generator/code/reload-on-change.js b/packages/embark-code-generator/src/code/reload-on-change.js similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code/reload-on-change.js rename to packages/embark-code-generator/src/code/reload-on-change.js diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/define-when-env-loaded.js.ejs b/packages/embark-code-generator/src/code_templates/define-when-env-loaded.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/define-when-env-loaded.js.ejs rename to packages/embark-code-generator/src/code_templates/define-when-env-loaded.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/do-when-loaded.js.ejs b/packages/embark-code-generator/src/code_templates/do-when-loaded.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/do-when-loaded.js.ejs rename to packages/embark-code-generator/src/code_templates/do-when-loaded.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/embarkjs-contract.js.ejs b/packages/embark-code-generator/src/code_templates/embarkjs-contract.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/embarkjs-contract.js.ejs rename to packages/embark-code-generator/src/code_templates/embarkjs-contract.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/exec-when-env-loaded.js.ejs b/packages/embark-code-generator/src/code_templates/exec-when-env-loaded.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/exec-when-env-loaded.js.ejs rename to packages/embark-code-generator/src/code_templates/exec-when-env-loaded.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/exec-when-ready.js.ejs b/packages/embark-code-generator/src/code_templates/exec-when-ready.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/exec-when-ready.js.ejs rename to packages/embark-code-generator/src/code_templates/exec-when-ready.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/load-manager.js.ejs b/packages/embark-code-generator/src/code_templates/load-manager.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/load-manager.js.ejs rename to packages/embark-code-generator/src/code_templates/load-manager.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/main-context.js.ejs b/packages/embark-code-generator/src/code_templates/main-context.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/main-context.js.ejs rename to packages/embark-code-generator/src/code_templates/main-context.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/code_templates/vanilla-contract.js.ejs b/packages/embark-code-generator/src/code_templates/vanilla-contract.js.ejs similarity index 100% rename from packages/embark/src/lib/modules/code_generator/code_templates/vanilla-contract.js.ejs rename to packages/embark-code-generator/src/code_templates/vanilla-contract.js.ejs diff --git a/packages/embark/src/lib/modules/code_generator/index.js b/packages/embark-code-generator/src/index.js similarity index 98% rename from packages/embark/src/lib/modules/code_generator/index.js rename to packages/embark-code-generator/src/index.js index fbdafcd33..76a9df915 100644 --- a/packages/embark/src/lib/modules/code_generator/index.js +++ b/packages/embark-code-generator/src/index.js @@ -1,6 +1,6 @@ -let async = require('async'); import {joinPath} from 'embark-utils'; import { transform } from "@babel/core"; +const async = require('async'); const constants = require('embark-core/constants'); const path = require('path'); @@ -390,7 +390,7 @@ class CodeGenerator { } getReloadPageCode() { - return this.env === 'development' ? this.fs.readFileSync(require('path').join(__dirname, '/code/reload-on-change.js'), 'utf8') : ''; + return this.env === 'development' ? this.fs.readFileSync(path.join(__dirname, '/code/reload-on-change.js'), 'utf8') : ''; } getEmbarkJsProviderCode() { diff --git a/packages/embark-code-generator/tsconfig.json b/packages/embark-code-generator/tsconfig.json new file mode 100644 index 000000000..52d43eaaa --- /dev/null +++ b/packages/embark-code-generator/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/embark-code-generator/tslint.json b/packages/embark-code-generator/tslint.json new file mode 100644 index 000000000..0946f2096 --- /dev/null +++ b/packages/embark-code-generator/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tslint.json" +} diff --git a/packages/embark/package.json b/packages/embark/package.json index 3ef93e8dc..d8ba23b3d 100644 --- a/packages/embark/package.json +++ b/packages/embark/package.json @@ -93,6 +93,7 @@ "ejs": "2.6.1", "embark-authenticator": "^4.1.0-beta.0", "embark-api": "^4.1.0-beta.0", + "embark-code-generator": "^4.1.0-beta.0", "embark-compiler": "^4.0.0", "embark-console": "^4.1.0-beta.0", "embark-contracts-manager": "^4.1.0-beta.0", diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index b29504162..d8207fdf4 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -189,7 +189,7 @@ class Engine { codeGeneratorService(_options) { let self = this; - this.registerModule('code_generator', {plugins: self.plugins, env: self.env}); + this.registerModulePackage('embark-code-generator', {plugins: self.plugins, env: self.env}); const generateCode = function (modifiedAssets) { self.events.request("module:storage:onReady", () => { diff --git a/packages/embark/src/test/code_generator.js b/packages/embark/src/test/code_generator.js index 75713db0a..b99586ec4 100644 --- a/packages/embark/src/test/code_generator.js +++ b/packages/embark/src/test/code_generator.js @@ -1,5 +1,5 @@ /*globals describe, it*/ -let CodeGenerator = require('../lib/modules/code_generator'); +let CodeGenerator = require('embark-code-generator'); let assert = require('assert'); function replaceCRLF(string) {