From cbee59b667f219a56500d09f05dcdc589f59c7e6 Mon Sep 17 00:00:00 2001 From: Daniel Holloway Date: Thu, 8 Mar 2018 15:58:15 -0800 Subject: [PATCH 1/3] Set up webpack to bundle js and a task to move the html file. Css is not yet being moved. --- bin/gitgraph.js | 2 +- bin/gitlost.js | 4 ++-- lib/graph.js | 16 +++++++-------- lib/server.js | 13 ++++++------ package.json | 13 ++++++++++-- web/client.js | 10 ++++++++- web/graph.html | 13 ++---------- webpack.config.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 91 insertions(+), 32 deletions(-) create mode 100644 webpack.config.js diff --git a/bin/gitgraph.js b/bin/gitgraph.js index 62b030d..ff9f360 100644 --- a/bin/gitgraph.js +++ b/bin/gitgraph.js @@ -1,4 +1,4 @@ -var gitlost = require('../lib/graph'); +import gitlost from '../lib/graph'; settings = JSON.parse(process.argv.slice(2).join(' ') || '{}'); gitlost.graph(settings).then(function (dot) { console.log(dot); diff --git a/bin/gitlost.js b/bin/gitlost.js index 48fecf9..c423f92 100644 --- a/bin/gitlost.js +++ b/bin/gitlost.js @@ -1,5 +1,5 @@ -var opn = require('opn'); -var server = require("../lib/server.js"); +import * as opn from 'opn'; +import server from "../lib/server"; opn('http://localhost:6776', {app: 'chrome'}); server.listen(6776); diff --git a/lib/graph.js b/lib/graph.js index e2b4f21..4bfb20b 100644 --- a/lib/graph.js +++ b/lib/graph.js @@ -1,5 +1,7 @@ -var child_process = require('child_process'); -var md5 = require('md5'); +"use strict"; + +import * as child_process from 'child_process'; +import * as md5 from 'md5'; var carot = '^'; if (process.platform === 'win32') { @@ -64,11 +66,11 @@ function hsl_to_rgb(h, s, l){ var color_hash = function(text) { text = text.match(/[^\/]+$/)[0]; - hash = parseInt('0x' + md5(text).slice(-5)); + var hash = parseInt('0x' + md5(text).slice(-5)); var h = (((hash >> 9) & 0x1ff) ^ 0x109) / 512; // map [0,127] to ~[ 0, 1) var s = ((((hash >> 5) & 0x3f) ^ 0x2f) + 36) / 100; // map [0, 63] to [.36, .99] var l = ((hash & 0x1f) + 24) / 100; // map [0, 31] to [.24, .55] - rgb = hsl_to_rgb(h, s, l); + var rgb = hsl_to_rgb(h, s, l); rgb = (rgb[0] << 16) + (rgb[1] << 8) + rgb[2]; //console.log('/* ' + hash.toString(16) + ' - ' + [h, s, l] + '*/') return '#' + ('000000' + rgb.toString(16)).slice(-6) @@ -165,6 +167,7 @@ function graph(settings) { }; }) .sort(function (a, b) { + var ax, bx; return ((ax = settings.branches.indexOf(a.ref_short)) !== -1 ? ax : settings.branches.length) - ((bx = settings.branches.indexOf(b.ref_short)) !== -1 ? bx : settings.branches.length); }); }); @@ -278,7 +281,4 @@ function graph(settings) { }); } -module.exports = { - graph: graph, - queue_cmd: queue_cmd -}; +export { graph, queue_cmd }; diff --git a/lib/server.js b/lib/server.js index 4a3bcbf..44e463a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,11 +1,10 @@ -var http = require('http'); -var child_process = require('child_process'); +import * as http from 'http'; var fs = require('fs'); -var path = require('path'); -var EventEmitter = require('events'); -var gitlost = require('./graph'); +import * as path from 'path'; +import * as EventEmitter from 'events'; +import * as gitlost from './graph'; -var webdir = path.join(__dirname, '../web'); +var webdir = __dirname; var vizjs = path.join(__dirname, '../node_modules/viz.js/viz.js'); var mimetypes = { @@ -280,4 +279,4 @@ server.on('request', function (request, response) { } }); -module.exports = server; +export default server; diff --git a/package.json b/package.json index fcfcec5..cabfc83 100644 --- a/package.json +++ b/package.json @@ -5,16 +5,25 @@ "main": "./lib/graph.js", "bin": "./bin/gitlost.js", "dependencies": { + "bootstrap": "^3.0.0", "bootstrap-menu": "^1.0.14", - "bootstrap3-dialog": "^1.35.3", + "bootstrap-select": "^1.12.4", + "bootstrap3-dialog": "^1.35.4", "d3": "^4.13.0", "d3-graphviz": "^1.3.4", + "jquery": "^3.3.1", "md5": "^2.2.1", "opn": "^4.0.2", "sortablejs": "^1.5.1" }, - "devDependencies": {}, + "devDependencies": { + "webpack": "^4.1.1", + "webpack-cli": "^2.0.10", + "webpack-node-externals": "^1.6.0" + }, "scripts": { + "build": "webpack && copy web\\graph.html dist\\graph.html && copy node_modules\\viz.js\\viz.js dist\\viz.js", + "start": "./dist/gitlost.js", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { diff --git a/web/client.js b/web/client.js index cfb21a4..77bb280 100644 --- a/web/client.js +++ b/web/client.js @@ -1,5 +1,13 @@ +import * as d3 from 'd3'; +import BootstrapDialog from 'bootstrap3-dialog'; +import BootstrapMenu from 'bootstrap-menu'; +import Sortable from 'sortablejs'; +import * as $ from 'jquery'; +require('bootstrap-select'); +require('d3-graphviz'); + $(function () { - settings = {}; + var settings = {}; // Configure UI $( "button[name=rankdir]") .click(function () { diff --git a/web/graph.html b/web/graph.html index 8fa439d..f9ac142 100644 --- a/web/graph.html +++ b/web/graph.html @@ -3,17 +3,8 @@ GitLost - - - - - - - - - - - + + diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..ed32e23 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,52 @@ +const path = require('path'); +const webpack = require('webpack'); + +var nodeExternals = require('webpack-node-externals'); + +const common = { + plugins: [ /* common plugins */ ], + resolve: { + extensions: ['.js'] // common extensions + }, + mode: 'development', + // other plugins, postcss config etc. common for frontend and backend +}; + +const frontend = { + entry: [ + './web/client.js' + ], + output: { + filename: 'web.bundle.js', + path: path.resolve(__dirname, 'dist') + }, + devtool: 'inline-source-map', + plugins: [ + new webpack.ProvidePlugin({ + jQuery: 'jquery' + }) + ] + // other loaders, plugins etc. specific for frontend +}; + +const backend = { + entry: [ + './bin/gitlost.js' + ], + output: { + filename: 'gitlost.js', + path: path.resolve(__dirname, 'dist') + }, + target: 'node', + stats: 'verbose', + externals: [nodeExternals()], + node: { + __dirname: false + } + // other loaders, plugins etc. specific for backend +}; + +module.exports = [ + Object.assign({} , common, frontend), + Object.assign({} , common, backend) +]; \ No newline at end of file From 258c13318d1d63e07ac6378ecee4f08ed1ed1377 Mon Sep 17 00:00:00 2001 From: Daniel Holloway Date: Mon, 12 Mar 2018 08:28:44 -0700 Subject: [PATCH 2/3] Set up css loading. Removed files not got by package. `yarn run build` will build and `yarn run start` will start. npm task running will also work. --- package.json | 5 + web/BootstrapMenu.js | 2589 -------------------------------------- web/Sortable.js | 1481 ---------------------- web/bootstrap-dialog.css | 111 -- web/bootstrap-dialog.js | 1391 -------------------- web/client.js | 1 + web/graph.css | 4 + web/graph.html | 6 +- webpack.config.js | 90 +- 9 files changed, 79 insertions(+), 5599 deletions(-) delete mode 100644 web/BootstrapMenu.js delete mode 100644 web/Sortable.js delete mode 100644 web/bootstrap-dialog.css delete mode 100644 web/bootstrap-dialog.js diff --git a/package.json b/package.json index cabfc83..0fbda3b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,11 @@ "sortablejs": "^1.5.1" }, "devDependencies": { + "babel-loader": "^7.1.4", + "css-loader": "^0.28.10", + "file-loader": "^1.1.11", + "style-loader": "^0.20.3", + "url-loader": "^1.0.1", "webpack": "^4.1.1", "webpack-cli": "^2.0.10", "webpack-node-externals": "^1.6.0" diff --git a/web/BootstrapMenu.js b/web/BootstrapMenu.js deleted file mode 100644 index baa3a0c..0000000 --- a/web/BootstrapMenu.js +++ /dev/null @@ -1,2589 +0,0 @@ -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; - -/******/ // The require function -/******/ function __webpack_require__(moduleId) { - -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; - -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; - -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - -/******/ // Flag the module as loaded -/******/ module.loaded = true; - -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } - - -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; - -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; - -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; - -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - /* webpack entry file to build a standalone browser script. */ - window.BootstrapMenu = __webpack_require__(1); - - -/***/ }, -/* 1 */ -/***/ function(module, exports, __webpack_require__) { - - 'use strict'; - - var classNames = __webpack_require__(2); - var $ = __webpack_require__(3); - __webpack_require__(4); - - // modular lodash requires - var _ = function() { - throw new Error('Custom lodash build for BootstrapMenu. lodash chaining is not included'); - }; - - _.noop = __webpack_require__(6); - _.each = __webpack_require__(7); - _.contains = __webpack_require__(34); - _.extend = __webpack_require__(42); - _.uniqueId = __webpack_require__(49); - _.isFunction = __webpack_require__(19); - - - var defaultOptions = { - /* container of the context menu, where it will be created and where - * event listeners will be installed. */ - container: 'body', - - /* user-defined function to obtain specific data about the currently - * opened element, to pass it to the rest of user-defined functions - * of an action. */ - fetchElementData: _.noop, - - /* what the source of the context menu should be when opened. - * Valid values are 'mouse' and 'element'. */ - menuSource: 'mouse', - - /* how to calculate the position of the context menu based on its source. - * Valid values are 'aboveLeft', 'aboveRight', 'belowLeft', and 'belowRight'. */ - menuPosition: 'belowLeft', - - /* the event to listen to open the menu. - * Valid values are 'click', 'right-click', 'hover' */ - menuEvent: 'right-click', // TODO rename to menuAction in next mayor version - - /* group actions to render them next to each other, with a separator - * between each group. */ - actionsGroups: [], - - /* message to show when there are no actions to show in a menu - * (isShown() returned false on all actions) */ - noActionsMessage: 'No available actions', - - /* In some weird cases, another plugin may be installing 'click' listeners - * in the anchors used for each action of the context menu, and stopping - * the event bubbling before it reachs this plugin's listener. - * - * For those cases, _actionSelectEvent can be used to change the event we - * listen to, for example to 'mousedown'. - * - * Unless the context menu is not working due to this and a workaround is - * needed, this option can be safely ignored. - */ - _actionSelectEvent: 'click' - }; - - function renderMenu(_this) { - var $menu = $('