feature(cloudcmd) --columns: add ability to set visible columns (#146)

This commit is contained in:
coderaiser 2018-03-02 18:00:15 +02:00
parent 6c9913e5f1
commit b5f98be162
18 changed files with 115 additions and 30 deletions

View file

@ -54,19 +54,8 @@ module.exports = (params) => {
keys.forEach((name) => {
const value = options[name];
switch(name) {
case 'root':
validate.root(value);
break;
case 'editor':
validate.editor(value);
break;
case 'packer':
validate.packer(value);
break;
}
if (/root|editor|packer|columns/.test(name))
validate[name](value);
config(name, value);
});

17
server/columns.js Normal file
View file

@ -0,0 +1,17 @@
'use strict';
const fs = require('fs');
const isDev = process.NODE_ENV === 'development';
const dir = getDirPath(isDev);
module.exports = {
'': '',
'name-size-date': fs.readFileSync(`${dir}/name-size-date.css`, 'utf8'),
'name-size-date-owner-mode': '',
};
function getDirPath (isDev) {
const dist = isDev ? 'dist-dev' : 'dist';
return `${__dirname}/../${dist}/columns`;
}

View file

@ -14,6 +14,7 @@ const format = require('format-io');
const squad = require('squad/legacy');
const apart = require('apart');
const columns = require(DIR_SERVER + 'columns');
const config = require(DIR_SERVER + 'config');
const root = require(DIR_SERVER + 'root');
const prefixer = require(DIR_SERVER + 'prefixer');
@ -99,6 +100,7 @@ function indexProcessing(options) {
fm: left + right,
prefix: prefix(),
config: JSON.stringify(config('*')),
columns: columns[config('columns')],
});
return data;

View file

@ -1,12 +1,9 @@
'use strict';
const exit = require('./exit');
const columns = require('./columns');
module.exports.root = root;
module.exports.editor = editor;
module.exports.packer = packer;
function root(dir, fn) {
module.exports.root = (dir, fn) => {
if (typeof dir !== 'string')
throw Error('dir should be a string');
@ -22,19 +19,28 @@ function root(dir, fn) {
if (typeof fn === 'function')
fn('root:', dir);
});
}
};
function editor(name) {
module.exports.editor = (name) => {
const reg = /^(dword|edward|deepword)$/;
if (!reg.test(name))
exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
}
};
function packer(name) {
module.exports.packer = (name) => {
const reg = /^(tar|zip)$/;
if (!reg.test(name))
exit('cloudcmd --packer: could be "tar" or "zip" only');
}
};
module.exports.columns = (type) => {
const all = Object
.keys(columns)
.concat('');
if (!~all.indexOf(type))
exit('cloudcmd --columns: could be "name-size-date" or "name-size-date-owner-mode"');
};