feature(cloudcmd) rm support of node.js < 4.0.0

This commit is contained in:
coderaiser 2017-07-11 16:53:51 +03:00
parent 03dbb4489b
commit 7a43ae5e9d
12 changed files with 269 additions and 318 deletions

3
.gitignore vendored
View file

@ -19,9 +19,6 @@ modules/jquery-mousewheel
modules/execon
modules/emitify
legacy
server_
.nyc_output
*.swp

View file

@ -28,8 +28,5 @@ bin/legacy.js
client
legacy/bin/release.js
legacy/bin/legacy.js
webpack.config.js

View file

@ -1,29 +0,0 @@
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const dir = path.join(__dirname, '../server');
const dir_ = path.join(__dirname, '../legacy/server');
const setDir = (name) => {
return path.join(dir_, name);
};
fs.readdirSync(dir)
.map(fillFile)
.map(writeFile);
function fillFile(name) {
return {
name: setDir(name),
data: `module.exports = require('../../server_/${name}');`
};
}
function writeFile({name, data}) {
return fs.writeFileSync(name, data);
}

View file

@ -1,4 +1,231 @@
'use strict';
module.exports = require('../server/cloudfunc');
const rendy = require('rendy');
const store = require('fullstore/legacy');
const Entity = require('./entity');
/* КОНСТАНТЫ (общие для клиента и сервера)*/
/* название программы */
const NAME = 'Cloud Commander';
const FS = '/fs';
const Path = store();
Path('/');
module.exports.FS = FS;
module.exports.apiURL = '/api/v1';
module.exports.MAX_FILE_SIZE = 500 * 1024;
module.exports.Entity = Entity;
module.exports.formatMsg = (msg, name, status) => {
status = status || 'ok';
if (name)
name = '("' + name + '")';
else
name = '';
return msg + ': ' + status + name;
};
/**
* Функция возвращает заголовок веб страницы
* @path
*/
module.exports.getTitle = (path) => {
return NAME + ' - ' + (path || Path());
};
/** Функция получает адреса каждого каталога в пути
* возвращаеться массив каталогов
* @param url - адрес каталога
*/
function getPathLink(url, prefix, template) {
if (!url)
throw Error('url could not be empty!');
if (!template)
throw Error('template could not be empty!');
const names = url
.split('/')
.slice(1, -1);
const allNames = ['/', ...names];
const length = allNames.length - 1;
let path = '/';
const pathHTML = allNames.map((name, index) => {
const isLast = index === length;
if (index)
path += name + '/';
if (index && isLast)
return name + '/';
const slash = index ? '/' : '';
return rendy(template, {
path,
name,
slash,
prefix,
});
}).join('');
return pathHTML;
}
/**
* Функция строит таблицу файлв из JSON-информации о файлах
* @param params - информация о файлах
*
*/
module.exports.buildFromJSON = (params) => {
const prefix = params.prefix;
const template = params.template;
const templateFile = template.file;
const templateLink = template.link;
const json = params.data;
const {path, files} = json;
const sort = params.sort || 'name';
const order = params.order || 'asc';
/*
* Строим путь каталога в котором мы находимся
* со всеми подкаталогами
*/
const htmlPath = getPathLink(path, prefix, template.pathLink);
let fileTable = rendy(template.path, {
link : prefix + FS + path,
fullPath : path,
path : htmlPath
});
let name = 'name';
let size = 'size';
let date = 'date';
const owner = 'owner';
const mode = 'mode';
const arrow = order === 'asc' ? '↑' : '↓';
if (sort === 'name' && order !== 'asc')
name += arrow;
else if (sort === 'size')
size += arrow;
else if (sort === 'date')
date += arrow;
const header = rendy(templateFile, {
tag : 'div',
attribute : 'data-name="js-fm-header" ',
className : 'fm-header',
type : '',
name,
size,
date,
owner,
mode,
});
/* сохраняем путь */
Path(path);
fileTable += header + '<ul data-name="js-files" class="files">';
/* Если мы не в корне */
if (path !== '/') {
/* убираем последний слеш и каталог в котором мы сейчас находимся*/
const lastSlash = path.substr(path, path.lastIndexOf('/'));
const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/'));
const link = prefix + FS + (dotDot || '/');
const linkResult = rendy(template.link, {
link,
title : '..',
name : '..'
});
const dataName = 'data-name="js-file-.." ';
const attribute = 'draggable="true" ' + dataName;
/* Сохраняем путь к каталогу верхнего уровня*/
fileTable += rendy(template.file, {
tag : 'li',
attribute,
className : '',
type : 'directory',
name : linkResult,
size : '&lt;dir&gt;',
date : '--.--.----',
owner : '.',
mode : '--- --- ---'
});
}
fileTable += files.map((file) => {
const link = prefix + FS + path + file.name;
const type = getType(file.size);
const size = getSize(file.size);
const date = file.date || '--.--.----';
const owner = file.owner || 'root';
const mode = file.mode;
const linkResult = rendy(templateLink, {
link,
title: file.name,
name: Entity.encode(file.name),
attribute: getAttribute(file.size)
});
const dataName = 'data-name="js-file-' + file.name + '" ';
const attribute = 'draggable="true" ' + dataName;
return rendy(templateFile, {
tag: 'li',
attribute,
className: '',
type,
name: linkResult,
size,
date,
owner,
mode,
});
}).join('');
fileTable += '</ul>';
return fileTable;
};
function getType(size) {
if (size === 'dir')
return 'directory';
return 'text-file';
}
function getAttribute(size) {
if (size === 'dir')
return '';
return 'target="_blank" ';
}
function getSize(size) {
if (size === 'dir')
return '&lt;dir&gt;';
return size;
}

View file

@ -1,4 +1,32 @@
'use strict';
module.exports = require('../server/common/entity');
const Entities = {
'&nbsp;': ' ',
'&lt;': '<',
'&gt;': '>',
};
const keys = Object.keys(Entities);
module.exports.encode = (str) => {
keys.forEach((code) => {
const char = Entities[code];
const reg = RegExp(char, 'g');
str = str.replace(reg, code);
});
return str;
};
module.exports.decode = (str) => {
keys.forEach((code) => {
const char = Entities[code];
const reg = RegExp(code, 'g');
str = str.replace(reg, char);
});
return str;
};

View file

@ -36,8 +36,7 @@
"server"
],
"bin": {
"cloudcmd": "legacy/bin/cloudcmd.js",
"cloudcmd+": "bin/cloudcmd.js"
"cloudcmd": "bin/cloudcmd.js"
},
"config": {
"dirs": "bin server test webpack.config.js"
@ -80,8 +79,6 @@
"docker:rm-old": "redrun --parallel docker:rm:*",
"coverage": "nyc npm test",
"report": "nyc report --reporter=text-lcov | coveralls",
"6to5:bin": "babel bin -d legacy/bin",
"6to5:server": "babel server -d server_",
"6to5:client": "webpack --progress",
"6to5:client:dev": "NODE_ENV=development redrun 6to5:client",
"watch:client": "redrun 6to5:client -- --watch",
@ -93,16 +90,9 @@
"watch:coverage": "nodemon -w server -w test -w common -x \"npm run coverage\"",
"w:c": "redrun watch:client",
"w:c:d": "redrun watch:client:dev",
"build": "redrun rm:* 6to5:* mkdir:* legacy:*",
"build": "redrun 6to5:*",
"build:client": "redrun 6to5:client",
"build:client:dev": "redrun 6to5:client:dev",
"legacy:package": "echo \"module.exports = require('../package');\" > legacy/package.js",
"mkdir:server": "mkdirp legacy/server",
"mkdir:json": "mkdirp legacy/json",
"legacy:server": "bin/legacy.js",
"legacy:help": "cp json/help.json legacy/json/",
"rm:server": "rimraf server_ legacy",
"rm:client": "rimraf dist dist-dev",
"heroku-postbuild": "redrun 6to5:client",
"postheroku-postbuild": "npm i gritty"
},
@ -205,8 +195,8 @@
"yaspeller": "^3.0.0"
},
"engines": {
"node": ">=0.10"
"node": ">=4.0.0"
},
"license": "MIT",
"main": "legacy/server/cloudcmd.js"
"main": "server/cloudcmd.js"
}

View file

@ -2,8 +2,9 @@
const DIR = __dirname + '/';
const DIR_ROOT = DIR + '../';
const DIR_COMMON = DIR + '../common/';
const cloudfunc = require(DIR + 'cloudfunc');
const cloudfunc = require(DIR_COMMON + 'cloudfunc');
const auth = require(DIR + 'auth');
const config = require(DIR + 'config');
const modulas = require(DIR + 'modulas');

View file

@ -1,231 +0,0 @@
'use strict';
const rendy = require('rendy');
const store = require('fullstore/legacy');
const Entity = require('./common/entity');
/* КОНСТАНТЫ (общие для клиента и сервера)*/
/* название программы */
const NAME = 'Cloud Commander';
const FS = '/fs';
const Path = store();
Path('/');
module.exports.FS = FS;
module.exports.apiURL = '/api/v1';
module.exports.MAX_FILE_SIZE = 500 * 1024;
module.exports.Entity = Entity;
module.exports.formatMsg = (msg, name, status) => {
status = status || 'ok';
if (name)
name = '("' + name + '")';
else
name = '';
return msg + ': ' + status + name;
};
/**
* Функция возвращает заголовок веб страницы
* @path
*/
module.exports.getTitle = (path) => {
return NAME + ' - ' + (path || Path());
};
/** Функция получает адреса каждого каталога в пути
* возвращаеться массив каталогов
* @param url - адрес каталога
*/
function getPathLink(url, prefix, template) {
if (!url)
throw Error('url could not be empty!');
if (!template)
throw Error('template could not be empty!');
const names = url
.split('/')
.slice(1, -1);
const allNames = ['/', ...names];
const length = allNames.length - 1;
let path = '/';
const pathHTML = allNames.map((name, index) => {
const isLast = index === length;
if (index)
path += name + '/';
if (index && isLast)
return name + '/';
const slash = index ? '/' : '';
return rendy(template, {
path,
name,
slash,
prefix,
});
}).join('');
return pathHTML;
}
/**
* Функция строит таблицу файлв из JSON-информации о файлах
* @param params - информация о файлах
*
*/
module.exports.buildFromJSON = (params) => {
const prefix = params.prefix;
const template = params.template;
const templateFile = template.file;
const templateLink = template.link;
const json = params.data;
const {path, files} = json;
const sort = params.sort || 'name';
const order = params.order || 'asc';
/*
* Строим путь каталога в котором мы находимся
* со всеми подкаталогами
*/
const htmlPath = getPathLink(path, prefix, template.pathLink);
let fileTable = rendy(template.path, {
link : prefix + FS + path,
fullPath : path,
path : htmlPath
});
let name = 'name';
let size = 'size';
let date = 'date';
const owner = 'owner';
const mode = 'mode';
const arrow = order === 'asc' ? '↑' : '↓';
if (sort === 'name' && order !== 'asc')
name += arrow;
else if (sort === 'size')
size += arrow;
else if (sort === 'date')
date += arrow;
const header = rendy(templateFile, {
tag : 'div',
attribute : 'data-name="js-fm-header" ',
className : 'fm-header',
type : '',
name,
size,
date,
owner,
mode,
});
/* сохраняем путь */
Path(path);
fileTable += header + '<ul data-name="js-files" class="files">';
/* Если мы не в корне */
if (path !== '/') {
/* убираем последний слеш и каталог в котором мы сейчас находимся*/
const lastSlash = path.substr(path, path.lastIndexOf('/'));
const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/'));
const link = prefix + FS + (dotDot || '/');
const linkResult = rendy(template.link, {
link,
title : '..',
name : '..'
});
const dataName = 'data-name="js-file-.." ';
const attribute = 'draggable="true" ' + dataName;
/* Сохраняем путь к каталогу верхнего уровня*/
fileTable += rendy(template.file, {
tag : 'li',
attribute,
className : '',
type : 'directory',
name : linkResult,
size : '&lt;dir&gt;',
date : '--.--.----',
owner : '.',
mode : '--- --- ---'
});
}
fileTable += files.map((file) => {
const link = prefix + FS + path + file.name;
const type = getType(file.size);
const size = getSize(file.size);
const date = file.date || '--.--.----';
const owner = file.owner || 'root';
const mode = file.mode;
const linkResult = rendy(templateLink, {
link,
title: file.name,
name: Entity.encode(file.name),
attribute: getAttribute(file.size)
});
const dataName = 'data-name="js-file-' + file.name + '" ';
const attribute = 'draggable="true" ' + dataName;
return rendy(templateFile, {
tag: 'li',
attribute,
className: '',
type,
name: linkResult,
size,
date,
owner,
mode,
});
}).join('');
fileTable += '</ul>';
return fileTable;
};
function getType(size) {
if (size === 'dir')
return 'directory';
return 'text-file';
}
function getAttribute(size) {
if (size === 'dir')
return '';
return 'target="_blank" ';
}
function getSize(size) {
if (size === 'dir')
return '&lt;dir&gt;';
return size;
}

View file

@ -1,32 +0,0 @@
'use strict';
const Entities = {
'&nbsp;': ' ',
'&lt;': '<',
'&gt;': '>',
};
const keys = Object.keys(Entities);
module.exports.encode = (str) => {
keys.forEach((code) => {
const char = Entities[code];
const reg = RegExp(char, 'g');
str = str.replace(reg, code);
});
return str;
};
module.exports.decode = (str) => {
keys.forEach((code) => {
const char = Entities[code];
const reg = RegExp(code, 'g');
str = str.replace(reg, char);
});
return str;
};

View file

@ -1,13 +1,14 @@
'use strict';
const DIR_SERVER = __dirname + '/';
const DIR_COMMON = '../common/';
const DIR = DIR_SERVER + '../';
const path = require('path');
const fs = require('fs');
const exit = require(DIR_SERVER + 'exit');
const CloudFunc = require(DIR_SERVER + 'cloudfunc');
const CloudFunc = require(DIR_COMMON + 'cloudfunc');
const pullout = require('pullout/legacy');
const ponse = require('ponse');

View file

@ -1,11 +1,12 @@
'use strict';
const DIR = './';
const DIR_COMMON = '../common/';
const path = require('path');
const root = require(DIR + 'root');
const config = require(DIR + 'config');
const CloudFunc = require(DIR + 'cloudfunc');
const CloudFunc = require(DIR_COMMON + 'cloudfunc');
const markdown = require(DIR + 'markdown');
const jaguar = require('jaguar/legacy');

View file

@ -4,6 +4,7 @@ const DIR = __dirname + '/../';
const DIR_TMPL = DIR + 'tmpl/';
const DIR_HTML = DIR + 'html/';
const DIR_SERVER = './';
const DIR_COMMON = '../common/';
const DIR_FS = DIR_TMPL + 'fs/';
const fs = require('fs');
@ -20,7 +21,7 @@ const apart = require('apart');
const config = require(DIR_SERVER + 'config');
const root = require(DIR_SERVER + 'root');
const prefixer = require(DIR_SERVER + 'prefixer');
const CloudFunc = require(DIR_SERVER + 'cloudfunc');
const CloudFunc = require(DIR_COMMON + 'cloudfunc');
const prefix = squad(prefixer, apart(config, 'prefix'));
const isDev = process.env.NODE_ENV === 'development';