From b232a936fbca36501a7cc3a5886f8ebb4e1c2139 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 14 Mar 2018 11:50:44 +0200 Subject: [PATCH] feature(columns) add name-size (#139) --- client/cloudcmd.js | 1 + css/columns/name-size.css | 15 +++++++++++++++ server/columns.js | 11 +++++++++-- server/validate.js | 8 +++++++- test/server/columns.js | 13 ++++++++++++- test/server/validate.js | 8 +++++++- tmpl/config.hbs | 1 + webpack.config.js | 1 - 8 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 css/columns/name-size.css diff --git a/client/cloudcmd.js b/client/cloudcmd.js index 2c21fbf4..bf15bd31 100644 --- a/client/cloudcmd.js +++ b/client/cloudcmd.js @@ -3,6 +3,7 @@ require('../css/main.css'); require('../css/nojs.css'); require('../css/columns/name-size-date.css'); +require('../css/columns/name-size.css'); // prevent additional loading of exec by spero, remedy, ishtar, salam, omnes window.exec = require('execon'); diff --git a/css/columns/name-size.css b/css/columns/name-size.css new file mode 100644 index 00000000..e5f1bc63 --- /dev/null +++ b/css/columns/name-size.css @@ -0,0 +1,15 @@ +.name { + width: 78%; +} + +.owner { + display: none; +} + +.mode { + display: none; +} + +.date { + display: none; +} diff --git a/server/columns.js b/server/columns.js index cbb77be3..5e49aaa3 100644 --- a/server/columns.js +++ b/server/columns.js @@ -1,19 +1,26 @@ 'use strict'; const path = require('path'); +const fs= require('fs'); const readFilesSync = require('@cloudcmd/read-files-sync'); +const isMap = (a) => /\.map$/.test(a); +const not = (fn) => (a) => !fn(a); const defaultColumns = { '': '', 'name-size-date-owner-mode': '', }; -const isDev = process.NODE_ENV === 'development'; +const isDev = process.env.NODE_ENV === 'development'; const getDist = (isDev) => isDev ? 'dist-dev' : 'dist'; const dist = getDist(isDev); const columnsDir = path.join(__dirname, '..', dist, 'columns'); -const columns = readFilesSync(columnsDir, 'utf8'); + +const names = fs.readdirSync(columnsDir) + .filter(not(isMap)); + +const columns = readFilesSync(columnsDir, names, 'utf8'); module.exports = Object.assign( columns, diff --git a/server/validate.js b/server/validate.js index e76c707f..9280b606 100644 --- a/server/validate.js +++ b/server/validate.js @@ -36,11 +36,17 @@ module.exports.packer = (name) => { }; module.exports.columns = (type) => { + const addQuotes = (a) => `"${a}"`; const all = Object .keys(columns) .concat(''); + const names = all + .filter(Boolean) + .map(addQuotes) + .join(', '); + if (!~all.indexOf(type)) - exit('cloudcmd --columns: could be "name-size-date" or "name-size-date-owner-mode"'); + exit(`cloudcmd --columns: can be only one of: ${names}`); }; diff --git a/test/server/columns.js b/test/server/columns.js index 8ec0a688..9248d585 100644 --- a/test/server/columns.js +++ b/test/server/columns.js @@ -6,18 +6,29 @@ const clean = require('clear-module'); const columnsPath = '../../server/columns'; test('columns', (t) => { + clean(columnsPath); + + const {NODE_ENV} = process.env; + process.env.NODE_ENV = ''; const columns = require(columnsPath); + t.equal(columns[''], '', 'should equal'); + process.env.NODE_ENV = NODE_ENV; + t.end(); }); test('columns: dev', (t) => { clean(columnsPath); - process.NODE_ENV = 'development'; + const {NODE_ENV} = process.env; + process.env.NODE_ENV = 'development'; const columns = require(columnsPath); const css = fs.readFileSync(`${__dirname}/../../css/columns/name-size-date.css`, 'utf8'); t.equal(columns['name-size-date'], css, 'should equal'); + process.env.NODE_ENV = NODE_ENV; + t.end(); }); + diff --git a/test/server/validate.js b/test/server/validate.js index 3f52b577..e68b2085 100644 --- a/test/server/validate.js +++ b/test/server/validate.js @@ -11,6 +11,7 @@ const dir = '../..'; const validatePath = `${dir}/server/validate`; const exitPath = `${dir}/server/exit`; +const columnsPath = `${dir}/server/columns`; const validate = require(validatePath); const stub = require('mock-require'); @@ -126,11 +127,16 @@ test('validate: columns: wrong', (t) => { const fn = sinon.stub(); clean(); + clear(columnsPath); require(exitPath); stub(exitPath, fn); + stub(columnsPath, { + 'name-size-date': '', + 'name-size': '', + }); const {columns} = require(validatePath); - const msg = 'cloudcmd --columns: could be "name-size-date" or "name-size-date-owner-mode"'; + const msg = 'cloudcmd --columns: can be only one of: "name-size-date", "name-size"'; columns('hello'); diff --git a/tmpl/config.hbs b/tmpl/config.hbs index 317f7f08..06c40af0 100644 --- a/tmpl/config.hbs +++ b/tmpl/config.hbs @@ -47,6 +47,7 @@
  • diff --git a/webpack.config.js b/webpack.config.js index 671f8829..efff36c8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -171,7 +171,6 @@ function getMinifyHtmlOptions() { removeStyleLinkTypeAttributes: true, minifyJS: true, - minifyCSS: false, }; }