From 040b06903b1130bdbc6a32ae476b3aca1fa57fe3 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 10 Jul 2017 17:55:32 +0300 Subject: [PATCH 01/15] chore(route) rm unused DIR_JSON --- server/route.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/route.js b/server/route.js index 40b7ba9c..ccafe1fa 100644 --- a/server/route.js +++ b/server/route.js @@ -3,7 +3,6 @@ const DIR = __dirname + '/../'; const DIR_TMPL = DIR + 'tmpl/'; const DIR_HTML = DIR + 'html/'; -const DIR_JSON = DIR + 'json/'; const DIR_SERVER = './'; const DIR_FS = DIR_TMPL + 'fs/'; From 5c647bc372b0a76f67bbd3d8ee58f4886d1e2fc0 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 10 Jul 2017 17:56:23 +0300 Subject: [PATCH 02/15] chore(webpack) unnecessary escape character --- webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index 1cfb9f2f..c19fc153 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -119,7 +119,7 @@ function devtoolModuleFilenameTemplate(info) { function extract(name, extractCss) { return { - test: RegExp(`css\/${name}\.css`), + test: RegExp(`css/${name}.css`), use: extractCss.extract([ isDev ? 'css-loader' From 92bac91c6e9bb01132e24242f4be65eaace7bebc Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 10 Jul 2017 18:00:38 +0300 Subject: [PATCH 03/15] chore(terminal) rm new line --- test/server/terminal.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/server/terminal.js b/test/server/terminal.js index 42813006..777fcefd 100644 --- a/test/server/terminal.js +++ b/test/server/terminal.js @@ -7,7 +7,6 @@ const sinon = diff(require('sinon')); const configPath = '../../server/config'; const terminalPath = '../../server/terminal'; - test('cloudcmd: terminal: disabled', (t) => { clean(terminalPath); stub(configPath, () => { From 1d9b1177b8235a52f8859adfe8c545a62e1a923a Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Jul 2017 12:04:24 +0300 Subject: [PATCH 04/15] feature(package) extract-text-webpack-plugin v3.0.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9acae9c4..f0405018 100644 --- a/package.json +++ b/package.json @@ -171,7 +171,7 @@ "es6-promise": "^4.0.5", "es6-promisify": "^5.0.0", "eslint": "^4.0.0", - "extract-text-webpack-plugin": "^2.1.2", + "extract-text-webpack-plugin": "^3.0.0", "file-loader": "^0.11.2", "gunzip-maybe": "^1.3.1", "html-looks-like": "^1.0.2", @@ -207,4 +207,4 @@ }, "license": "MIT", "main": "legacy/server/cloudcmd.js" -} +} \ No newline at end of file From 1c1582b48b7bb930ef9c9779876a3e7ae1b2fb95 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Jul 2017 13:56:11 +0300 Subject: [PATCH 05/15] test(terminal) coverage --- package.json | 3 ++- test/server/terminal.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f0405018..5cd70049 100644 --- a/package.json +++ b/package.json @@ -179,6 +179,7 @@ "jshint": "^2.8.0", "minor": "^1.2.2", "mkdirp": "^0.5.1", + "mock-require": "^2.0.2", "morgan": "^1.6.1", "nodemon": "^1.9.1", "nsp": "^2.2.1", @@ -207,4 +208,4 @@ }, "license": "MIT", "main": "legacy/server/cloudcmd.js" -} \ No newline at end of file +} diff --git a/test/server/terminal.js b/test/server/terminal.js index 777fcefd..13dac032 100644 --- a/test/server/terminal.js +++ b/test/server/terminal.js @@ -1,6 +1,7 @@ 'use strict'; const test = require('tape'); +const mock = require('mock-require'); const diff = require('sinon-called-with-diff'); const sinon = diff(require('sinon')); @@ -58,6 +59,31 @@ test('cloudcmd: terminal: enabled', (t) => { console.log = log; clean(configPath); + require(configPath); + + t.end(); +}); + +test('cloudcmd: terminal: no arg', (t) => { + const gritty = {}; + + mock('gritty', gritty); + + clean(terminalPath); + stub(configPath, (a) => { + if (a === 'terminal') + return true; + + return 'gritty'; + }); + + const terminal = require(terminalPath); + const result = terminal(); + + t.equal(result, gritty, 'should equal'); + + clean(configPath); + require(configPath); t.end(); }); From 7e07f586c31510931071a4785f0afa7969279b27 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Jul 2017 16:20:45 +0300 Subject: [PATCH 06/15] feature(route) rm minify --- package.json | 3 ++- server/route.js | 65 ++++++++++++++++++++--------------------------- webpack.config.js | 34 +++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 5cd70049..3568ecac 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,6 @@ "jonny": "^1.0.0", "markdown-it": "^8.0.0", "mellow": "^2.0.0", - "minify": "^2.0.0", "minimist": "^1.2.0", "nomine": "^1.0.1", "omnes": "^1.0.3", @@ -175,6 +174,8 @@ "file-loader": "^0.11.2", "gunzip-maybe": "^1.3.1", "html-looks-like": "^1.0.2", + "html-webpack-exclude-assets-plugin": "^0.0.5", + "html-webpack-plugin": "^2.29.0", "jscs": "^3.0.1", "jshint": "^2.8.0", "minor": "^1.2.2", diff --git a/server/route.js b/server/route.js index ccafe1fa..f548abac 100644 --- a/server/route.js +++ b/server/route.js @@ -13,7 +13,6 @@ const ponse = require('ponse'); const files = require('files-io'); const rendy = require('rendy'); const exec = require('execon'); -const minify = require('minify'); const format = require('format-io'); const squad = require('squad'); const apart = require('apart'); @@ -24,7 +23,13 @@ const prefixer = require(DIR_SERVER + 'prefixer'); const CloudFunc = require(DIR_SERVER + 'cloudfunc'); const prefix = squad(prefixer, apart(config, 'prefix')); -const PATH_INDEX = DIR_HTML + 'index.html'; +const isDev = process.env.NODE_ENV === 'development'; + +const getIndexPath = () => { + const dist = isDev ? 'dist-dev' : 'dist'; + + return DIR + `${dist}/index.html`; +} const TMPL_PATH = [ 'file', @@ -153,26 +158,16 @@ function readFiles(callback) { function route(request, response, callback) { let name = ponse.getPathName(request); - const isAuth = RegExp('^(/auth|/auth/github)$').test(name); const isFS = RegExp('^/$|^' + FS).test(name); const p = { - request : request, - response : response, + request, + response, gzip : true, - name : name + name, }; - if (!isAuth && !isFS) - return callback(); - - if (isAuth) { - p.name = DIR_HTML + name + '.html'; - ponse.sendFile(p); - return; - } - if (!isFS) - return; + return callback(); name = name.replace(CloudFunc.FS, '') || '/'; const fullPath = root(name); @@ -183,7 +178,7 @@ function route(request, response, callback) { if (!error) return buildIndex(dir, (error, data) => { - p.name = PATH_INDEX; + p.name = getIndexPath(); if (error) return ponse.sendError(error, p); @@ -207,28 +202,22 @@ function route(request, response, callback) { } function buildIndex(json, callback) { - const isMinify = config('minify'); - - exec.if(!isMinify, (error, name) => { - fs.readFile(name || PATH_INDEX, 'utf8', (error, template) => { - if (error) - return; - - const panel = CloudFunc.buildFromJSON({ - data : json, - prefix : prefix(), - template : Template - }); - - const data = indexProcessing({ - panel : panel, - data : template - }); - - callback(error, data); + fs.readFile(getIndexPath(), 'utf8', (error, template) => { + if (error) + return; + + const panel = CloudFunc.buildFromJSON({ + data : json, + prefix : prefix(), + template : Template }); - }, (callback) => { - minify(PATH_INDEX, 'name', callback); + + const data = indexProcessing({ + panel : panel, + data : template + }); + + callback(error, data); }); } diff --git a/webpack.config.js b/webpack.config.js index c19fc153..adbb2a9e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,7 +17,10 @@ const distDev = path.resolve(__dirname, 'dist-dev'); const devtool = isDev ? 'eval' : 'source-map'; const notEmpty = (a) => a; const clean = (array) => array.filter(notEmpty); + +const HtmlWebpackPlugin = require('html-webpack-plugin'); const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const HtmlWebpackExcludeAssetsPlugin = require('html-webpack-exclude-assets-plugin') const extractMain = new ExtractTextPlugin('[name].css'); const extractNojs = new ExtractTextPlugin('nojs.css'); @@ -34,6 +37,12 @@ const plugins = clean([ name: 'cloudcmd', filename: 'cloudcmd.js', }), + new HtmlWebpackPlugin({ + template: 'html/index.html', + minify: !isDev && getMinifyHtmlOptions(), + excludeAssets: [/\\*/], + }), + new HtmlWebpackExcludeAssetsPlugin(), extractMain, extractNojs, extractView, @@ -129,3 +138,28 @@ function extract(name, extractCss) { }; } +function getMinifyHtmlOptions() { + return { + removeComments: true, + removeCommentsFromCDATA: true, + removeCDATASectionsFromCDATA: true, + collapseWhitespace: true, + collapseBooleanAttributes: true, + removeAttributeQuotes: true, + removeRedundantAttributes: true, + useShortDoctype: true, + removeEmptyAttributes: true, + /* оставляем, поскольку у нас + * в элемент fm генерируеться + * таблица файлов + */ + removeEmptyElements: false, + removeOptionalTags: true, + removeScriptTypeAttributes: true, + removeStyleLinkTypeAttributes: true, + + minifyJS: true, + minifyCSS: true + } +} + From 63ec716801899d9706ec222c09771f6a4dee61fc Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Jul 2017 16:39:03 +0300 Subject: [PATCH 07/15] feature(cloudcmd) rm config option: minify --- HELP.md | 3 --- bin/cloudcmd.js | 3 --- json/config.json | 1 - json/help.json | 2 -- man/cloudcmd.1 | 2 -- server/cloudcmd.js | 5 ++--- tmpl/config.hbs | 6 ------ 7 files changed, 2 insertions(+), 20 deletions(-) diff --git a/HELP.md b/HELP.md index 379aa7d9..26318468 100644 --- a/HELP.md +++ b/HELP.md @@ -77,7 +77,6 @@ Cloud Commander supports command line parameters: | `--root` | set root directory | `--prefix` | set url prefix | `--port` | set port number -| `--minify` | enable minification | `--progress` | show progress of file operations | `--html-dialogs` | use html dialogs | `--open` | open web browser when server started @@ -90,7 +89,6 @@ Cloud Commander supports command line parameters: | `--no-auth` | disable authorization | `--no-online` | load scripts from local server | `--no-open` | do not open web browser when server started -| `--no-minify` | disable minification | `--no-progress` | do not show progress of file operations | `--no-html-dialogs` | do not use html dialogs | `--no-one-panel-mode` | unset one panel mode @@ -309,7 +307,6 @@ Here is description of options: "localStorage" : true, /* local storage */ "buffer" : true, /* buffer for copying files */ "dirStorage" : true, /* store directory listing to localStorage */ - "minify" : false, /* minification of js,css,html and img */ "online" : true, /* load js files from cdn or local path */ "open" : false /* open web browser when server started */ "cache" : true, /* add cache-control */ diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 93006a2f..c279db61 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -36,7 +36,6 @@ const args = require('minimist')(argv.slice(2), { 'server', 'online', 'open', - 'minify', 'progress', 'config-dialog', 'console', @@ -49,7 +48,6 @@ const args = require('minimist')(argv.slice(2), { server : true, auth : choose(env('auth'), config('auth')), port : config('port'), - minify : config('minify'), online : config('online'), open : config('open'), editor : env('editor') || config('editor'), @@ -100,7 +98,6 @@ function main() { config('auth', args.auth); config('online', args.online); config('open', args.open); - config('minify', args.minify); config('username', args.username); config('progress', args.progress); config('console', args.console); diff --git a/json/config.json b/json/config.json index 4981a102..5728938a 100644 --- a/json/config.json +++ b/json/config.json @@ -10,7 +10,6 @@ "localStorage": true, "buffer": true, "dirStorage": false, - "minify": false, "online": true, "open": false, "cache": true, diff --git a/json/help.json b/json/help.json index 20b5ba54..7d9bfe0e 100644 --- a/json/help.json +++ b/json/help.json @@ -13,7 +13,6 @@ "--root ": "set root directory", "--prefix ": "set url prefix", "--port ": "set port number", - "--minify ": "enable minification", "--progress ": "show progress of file operations", "--html-dialogs ": "use html dialogs", "--one-panel-mode ": "set one panel mode", @@ -26,7 +25,6 @@ "--no-auth ": "disable authorization", "--no-online ": "load scripts from local server", "--no-open ": "do not open web browser when server started", - "--no-minify ": "disable minification", "--no-progress ": "do not show progress of file operations", "--no-html-dialogs ": "do not use html dialogs", "--no-one-panel-mode ": "unset one panel mode", diff --git a/man/cloudcmd.1 b/man/cloudcmd.1 index 2841a05f..e351052d 100644 --- a/man/cloudcmd.1 +++ b/man/cloudcmd.1 @@ -36,7 +36,6 @@ programs in browser from any computer, mobile or tablet device. --root set root directory --prefix set url prefix --port set port number - --minify enable minification --progress show progress of file operations --html-dialogs use html dialogs --open open web browser when server started @@ -49,7 +48,6 @@ programs in browser from any computer, mobile or tablet device. --no-server do not start server --no-online load scripts from local server --no-open do not open web browser when server started - --no-minify disable minification --no-progress do not show progress of file operations --no-html-dialogs do not use html dialogs --no-one-panel-mode unset one panel mode diff --git a/server/cloudcmd.js b/server/cloudcmd.js index 644d6af3..68a8f7ce 100644 --- a/server/cloudcmd.js +++ b/server/cloudcmd.js @@ -193,7 +193,6 @@ function cloudcmd(prefix, plugins, modules) { return config(name); }; - const minify = apart(isOption, 'minify'); const online = apart(isOption, 'online'); const cache = apart(isOption, 'cache'); const diff = apart(isOption, 'diff'); @@ -275,8 +274,8 @@ function cloudcmd(prefix, plugins, modules) { route, join({ - dir : DIR_ROOT, - minify, + dir: DIR_ROOT, + minify: false, }), pluginer(plugins), diff --git a/tmpl/config.hbs b/tmpl/config.hbs index 05824506..bd7c4c1a 100644 --- a/tmpl/config.hbs +++ b/tmpl/config.hbs @@ -70,12 +70,6 @@ Directory Storage -
  • - -