You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ra...@apache.org on 2017/05/06 20:35:37 UTC
[3/3] incubator-annotator git commit: Add monorepo boilerplate and
dev server
Add monorepo boilerplate and dev server
Project: http://git-wip-us.apache.org/repos/asf/incubator-annotator/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-annotator/commit/d8ec3801
Tree: http://git-wip-us.apache.org/repos/asf/incubator-annotator/tree/d8ec3801
Diff: http://git-wip-us.apache.org/repos/asf/incubator-annotator/diff/d8ec3801
Branch: refs/heads/master
Commit: d8ec38010e7cb05fa415dad0fe5c463b6eac90bc
Parents: f31d982
Author: Randall Leeds <ra...@apache.org>
Authored: Sat May 6 12:44:03 2017 -0700
Committer: Randall Leeds <ra...@apache.org>
Committed: Sat May 6 13:35:30 2017 -0700
----------------------------------------------------------------------
.babelrc | 3 +-
index.html | 22 +++++++++
package.json | 20 +++++++-
scripts/.eslintrc.json | 7 +++
scripts/serve.js | 118 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 168 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-annotator/blob/d8ec3801/.babelrc
----------------------------------------------------------------------
diff --git a/.babelrc b/.babelrc
index 4285ecf..732a5b7 100644
--- a/.babelrc
+++ b/.babelrc
@@ -1,3 +1,4 @@
{
- "presets": ["flow"]
+ "presets": ["flow"],
+ "plugins": ["transform-runtime"]
}
http://git-wip-us.apache.org/repos/asf/incubator-annotator/blob/d8ec3801/index.html
----------------------------------------------------------------------
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..57d5d3f
--- /dev/null
+++ b/index.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ <meta name="author" content="Apache Software Foundation">
+ <meta name="viewport" content="width=device-width,initial-scale=1">
+ <title>Apache Annotator Incubating</title>
+ <script>
+ </script>
+ <script src="system.js"></script>
+ <script src="system-config.js"></script>
+ <script>
+ System.import('systemjs-hot-reloader').then((connect) => {
+ connect({ host: window.location.origin });
+ });
+ </script>
+ </head>
+ <body>
+ Welcome to Apache Annotator (incubating).
+ </body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-annotator/blob/d8ec3801/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index ff177bb..0a3efca 100644
--- a/package.json
+++ b/package.json
@@ -9,11 +9,29 @@
"url": "https://git-wip-us.apache.org/repos/asf/incubator-annotator.git"
},
"devDependencies": {
+ "babel-eslint": "^7.2.3",
+ "babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-flow": "^6.23.0",
+ "chokidar-socket-emitter": "^0.6.0",
+ "core-js": "^2.4.1",
"eslint": "^3.19.0",
"eslint-config-babel": "^6.0.0",
"eslint-config-google": "^0.7.1",
"eslint-plugin-flowtype": "^2.32.1",
- "lerna": "^2.0.0-rc.3"
+ "express": "^4.15.2",
+ "lerna": "^2.0.0-rc.3",
+ "node-es-module-loader": "^0.3.8",
+ "resolve": "^1.3.3",
+ "rollup": "^0.41.6",
+ "rollup-plugin-babel": "^2.7.1",
+ "rollup-plugin-commonjs": "^8.0.2",
+ "rollup-plugin-node-resolve": "^3.0.0",
+ "source-map-support": "^0.4.15",
+ "systemjs": "^0.20.12",
+ "systemjs-hot-reloader": "^1.1.0",
+ "systemjs-plugin-babel": "^0.0.21"
+ },
+ "scripts": {
+ "serve": "node-esml ./scripts/serve"
}
}
http://git-wip-us.apache.org/repos/asf/incubator-annotator/blob/d8ec3801/scripts/.eslintrc.json
----------------------------------------------------------------------
diff --git a/scripts/.eslintrc.json b/scripts/.eslintrc.json
new file mode 100644
index 0000000..0874e6b
--- /dev/null
+++ b/scripts/.eslintrc.json
@@ -0,0 +1,7 @@
+{
+ "globals": {
+ "__dirname": false,
+ "__filname": false,
+ "__moduleName": true
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-annotator/blob/d8ec3801/scripts/serve.js
----------------------------------------------------------------------
diff --git a/scripts/serve.js b/scripts/serve.js
new file mode 100644
index 0000000..2bedacb
--- /dev/null
+++ b/scripts/serve.js
@@ -0,0 +1,118 @@
+// @flow
+/**
+ * @license
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import fs from 'fs';
+import path from 'path';
+import url from 'url';
+
+import chokidar from 'chokidar-socket-emitter';
+import express from 'express';
+import json from 'core-js/library/fn/json';
+import resolve from 'resolve';
+
+import rollup from 'rollup';
+import babel from 'rollup-plugin-babel';
+import commonjs from 'rollup-plugin-commonjs';
+import nodeResolve from 'rollup-plugin-node-resolve';
+
+const __filename = url.parse(__moduleName).pathname;
+const __dirname = path.dirname(__filename);
+
+const basedir = path.resolve(__dirname, '..');
+const packagesPath = path.resolve(basedir, 'packages');
+const packages = fs.readdirSync(packagesPath);
+
+const app = express();
+
+packages.forEach((name) => {
+ const root = path.join(packagesPath, name);
+ const entry = path.join(root, 'index.js');
+ const dest = path.join(basedir, name, 'index.js');
+ const external = (id) => /^@(annotator|hot)/.test(id);
+
+ const jail = path.join(root, 'node_modules');
+ const babelOptions = {
+ babelrc: false,
+ exclude: [jail],
+ runtimeHelpers: true,
+ };
+
+ const plugins = [
+ babel(babelOptions),
+ commonjs(),
+ nodeResolve({ jail }),
+ ];
+
+ const options = { entry, external, plugins };
+ const generateOptions = {
+ format: 'amd',
+ sourceMap: true,
+ };
+
+ const endpoint = path.relative(basedir, dest);
+ app.get(`/${endpoint}`, (req, res) => {
+ rollup.rollup(options)
+ .then((bundle) => {
+ const result = bundle.generate(generateOptions);
+ const { code, map } = result;
+ res.send(`${code}\n//# sourceMappingURL=${map.toUrl()}`);
+ })
+ .catch((err) => {
+ console.log(err);
+ })
+ ;
+ });
+});
+
+app.get('/system.js', (req, res) => {
+ const resolved = resolve.sync('systemjs', { basedir });
+ const content = fs.readFileSync(resolved);
+ res.send(content);
+});
+
+app.get('/system-config.js', (req, res) => {
+ const packageConfigs = packages.reduce((acc, name) => {
+ acc[name] = { main: 'index.js' };
+ return acc;
+ }, {});
+
+ const hmr = resolve.sync('systemjs-hmr', { basedir });
+ const hotReloader = resolve.sync('systemjs-hot-reloader', { basedir });
+
+ const map = {
+ 'systemjs-hmr': path.relative(basedir, hmr),
+ 'systemjs-hot-reloader': path.relative(basedir, hotReloader),
+ '@annotator': '',
+ '@hot': '@empty',
+ };
+
+ const systemConfig = json.stringify({ map, packages: packageConfigs });
+
+ res.setHeader('Content-Type', 'application/json');
+ res.send(`SystemJS.config(${systemConfig})`);
+});
+
+app.use(express.static(basedir));
+
+const server = app.listen(8080, (err) => {
+ if (err) return console.log(err);
+ chokidar({
+ app: server,
+ path: packagesPath,
+ relativeTo: packagesPath,
+ });
+ console.log('Development server running at http://localhost:8080');
+});