From b71ec29db6f41643a71e0e04b424bd4f5c9074d5 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 13 Dec 2016 17:56:05 +0200 Subject: [PATCH] feature(cloudcmd) lib/client -> client Move lib/client and lib/server one level upper --- {legacy => .es5}/.eslintrc | 0 {legacy => .es5}/.jshintrc | 0 .gitignore | 5 +- .npmignore | 6 +- bin/cloudcmd.js | 8 +- bin/legacy.js | 30 ++++ {lib/client => client}/buffer.js | 0 {lib => client}/client.js | 2 +- {lib/client => client}/cloud.js | 0 client/cloudcmd.js | 93 +++++++++++ {lib/client => client}/config.js | 2 +- {lib/client => client}/contact.js | 0 {lib/client => client}/dialog.js | 0 {lib/client => client}/directory.js | 0 {lib/client => client}/dom.js | 0 {lib/client => client}/edit.js | 0 {lib/client => client}/events.js | 0 {lib/client => client}/files.js | 0 {lib/client => client}/help.js | 0 {lib/client => client}/input.js | 0 {lib/client => client}/key.js | 0 {lib/client => client}/konsole.js | 0 {lib/client => client}/listeners.js | 0 {lib/client => client}/load.js | 0 {lib/client => client}/markdown.js | 0 {lib/client => client}/menu.js | 0 {lib/client => client}/notify.js | 0 {lib/client => client}/operation.js | 0 {lib/client => client}/polyfill.js | 0 {lib/client => client}/rest.js | 0 {lib/client => client}/storage.js | 0 {lib/client => client}/upload.js | 0 {lib/client => client}/view.js | 0 {lib => common}/cloudfunc.js | 0 {lib => common}/util.js | 0 lib/client/cloudcmd.js | 97 ------------ lib/cloudcmd.js | 5 +- lib/server.js | 2 +- lib/server/config.js | 4 +- lib/server/markdown.js | 3 +- lib/server/rest.js | 4 +- lib/server/route.js | 4 +- package.json | 29 ++-- test/before.js | 2 +- test/lib/cloudcmd.js | 2 +- test/lib/cloudfunc.js | 234 ++++++++++++++-------------- test/lib/config.js | 7 +- test/lib/util.js | 2 +- 48 files changed, 286 insertions(+), 255 deletions(-) rename {legacy => .es5}/.eslintrc (100%) rename {legacy => .es5}/.jshintrc (100%) create mode 100755 bin/legacy.js rename {lib/client => client}/buffer.js (100%) rename {lib => client}/client.js (99%) rename {lib/client => client}/cloud.js (100%) create mode 100644 client/cloudcmd.js rename {lib/client => client}/config.js (99%) rename {lib/client => client}/contact.js (100%) rename {lib/client => client}/dialog.js (100%) rename {lib/client => client}/directory.js (100%) rename {lib/client => client}/dom.js (100%) rename {lib/client => client}/edit.js (100%) rename {lib/client => client}/events.js (100%) rename {lib/client => client}/files.js (100%) rename {lib/client => client}/help.js (100%) rename {lib/client => client}/input.js (100%) rename {lib/client => client}/key.js (100%) rename {lib/client => client}/konsole.js (100%) rename {lib/client => client}/listeners.js (100%) rename {lib/client => client}/load.js (100%) rename {lib/client => client}/markdown.js (100%) rename {lib/client => client}/menu.js (100%) rename {lib/client => client}/notify.js (100%) rename {lib/client => client}/operation.js (100%) rename {lib/client => client}/polyfill.js (100%) rename {lib/client => client}/rest.js (100%) rename {lib/client => client}/storage.js (100%) rename {lib/client => client}/upload.js (100%) rename {lib/client => client}/view.js (100%) rename {lib => common}/cloudfunc.js (100%) rename {lib => common}/util.js (100%) delete mode 100644 lib/client/cloudcmd.js diff --git a/legacy/.eslintrc b/.es5/.eslintrc similarity index 100% rename from legacy/.eslintrc rename to .es5/.eslintrc diff --git a/legacy/.jshintrc b/.es5/.jshintrc similarity index 100% rename from legacy/.jshintrc rename to .es5/.jshintrc diff --git a/.gitignore b/.gitignore index 606cacbc..876c9c88 100644 --- a/.gitignore +++ b/.gitignore @@ -14,9 +14,10 @@ modules/fancybox/sprite.psd modules/currify/dist/currify.js +legacy +lib_ + .nyc_output *.swp -bin_ - diff --git a/.npmignore b/.npmignore index 6ba911bf..0d915e6a 100644 --- a/.npmignore +++ b/.npmignore @@ -11,8 +11,10 @@ app.json circle.yml bin/release.js +bin/legacy.js -legacy +.es5 -bin-legacy/release.js +legacy/bin/release.js +legacy/bin/legacy.js diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index d5b71938..cbf12957 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -3,9 +3,7 @@ 'use strict'; const Info = require('../package'); -const DIR = __dirname + '/../'; -const DIR_LIB = DIR + 'lib/'; -const DIR_SERVER = DIR_LIB + 'server/'; +const DIR_SERVER = '../lib/server/'; const exit = require(DIR_SERVER + 'exit'); const config = require(DIR_SERVER + 'config'); @@ -119,7 +117,7 @@ if (args.version) { } function validateRoot(root) { - const validate = require('../lib/server/validate'); + const validate = require(DIR_SERVER + 'validate'); validate.root(root, console.log); } @@ -187,7 +185,7 @@ function help() { function repl() { console.log('REPL mode enabled (telnet localhost 1337)'); - require(DIR_LIB + '/server/repl'); + require(DIR_SERVER + 'repl'); } function checkUpdate() { diff --git a/bin/legacy.js b/bin/legacy.js new file mode 100755 index 00000000..cf282e70 --- /dev/null +++ b/bin/legacy.js @@ -0,0 +1,30 @@ +#!/usr/bin/env node + +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +const dir = path.join(__dirname, '../lib/server'); +const _dir = path.join(__dirname, '../legacy/lib/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(\'../../../lib_/server/${name}\');` + } +} + +function writeFile({name, data}) { + return fs.writeFileSync(name, data); +} + diff --git a/lib/client/buffer.js b/client/buffer.js similarity index 100% rename from lib/client/buffer.js rename to client/buffer.js diff --git a/lib/client.js b/client/client.js similarity index 99% rename from lib/client.js rename to client/client.js index fdbe78a0..f246ed0e 100644 --- a/lib/client.js +++ b/client/client.js @@ -26,7 +26,7 @@ var Util, DOM, CloudFunc, join; this.PREFIX = ''; this.PREFIX_URL = ''; this.LIBDIR = '/lib/'; - this.LIBDIRCLIENT = '/lib/client/'; + this.LIBDIRCLIENT = '/client/'; this.MIN_ONE_PANEL_WIDTH = 1155; this.HOST = location.origin || location.protocol + '//' + location.host; diff --git a/lib/client/cloud.js b/client/cloud.js similarity index 100% rename from lib/client/cloud.js rename to client/cloud.js diff --git a/client/cloudcmd.js b/client/cloudcmd.js new file mode 100644 index 00000000..5ea1fa56 --- /dev/null +++ b/client/cloudcmd.js @@ -0,0 +1,93 @@ +var CloudCmd; + +(function() { + 'use strict'; + + CloudCmd = load; + + function load(prefix) { + prefix = prefix || ''; + + var modules = '/modules/'; + var client = 'client/'; + var files = [ + 'common/util', + 'common/cloudfunc', + client + 'dom', + client + 'events', + client + 'rest', + client + 'load', + client + 'notify', + client + 'storage', + client + 'files', + client + 'dialog', + 'client/client', + client + 'buffer', + client + 'listeners', + client + 'key', + client + 'directory' + ]; + + var moduleFiles = [ + window.Promise ? '' : 'promise-polyfill/promise.min', + libDir('format', 'format-io'), + libDir('rendy'), + libDir('exec', 'execon'), + libDir('jonny'), + libDist('emitify'), + libDist('currify'), + ].filter(function(name) { + return name; + }).map(function(name) { + return modules + name; + }); + + var allFiles = moduleFiles + .concat(files) + .concat('/join/join') + .map(function(name) { + return name + '.js'; + }); + + var urlFiles = getJoinURL(allFiles); + + createScript(prefix + urlFiles, function() { + CloudCmd.init(prefix); + }); + } + + function libDir(name, dir) { + var lib = '/lib/'; + + if (!dir) + dir = name; + + return dir + lib + name; + } + + function libDist(name) { + return name + '/dist/' + name + '.min'; + } + + function createScript(url, callback) { + var script = document.createElement('script'); + + script.src = url; + script.async = true; + + script.addEventListener('load', function load(event) { + callback(event); + script.removeEventListener('load', load); + }); + + document.body.appendChild(script); + } + + function getJoinURL(names) { + var prefix = '/join:'; + var url = prefix + names.join(':'); + + return url; + } +})(); + diff --git a/lib/client/config.js b/client/config.js similarity index 99% rename from lib/client/config.js rename to client/config.js index 82a1988a..c30c821c 100644 --- a/lib/client/config.js +++ b/client/config.js @@ -118,7 +118,7 @@ var CloudCmd, Util, DOM, io; exec.with(Files.get, 'config-tmpl'), exec.with(DOM.load.parallel, [ prefix + '/css/config.css', - prefix + '/lib/client/input.js' + prefix + CloudCmd.LIBDIRCLIENT + '/input.js' ]) ]; diff --git a/lib/client/contact.js b/client/contact.js similarity index 100% rename from lib/client/contact.js rename to client/contact.js diff --git a/lib/client/dialog.js b/client/dialog.js similarity index 100% rename from lib/client/dialog.js rename to client/dialog.js diff --git a/lib/client/directory.js b/client/directory.js similarity index 100% rename from lib/client/directory.js rename to client/directory.js diff --git a/lib/client/dom.js b/client/dom.js similarity index 100% rename from lib/client/dom.js rename to client/dom.js diff --git a/lib/client/edit.js b/client/edit.js similarity index 100% rename from lib/client/edit.js rename to client/edit.js diff --git a/lib/client/events.js b/client/events.js similarity index 100% rename from lib/client/events.js rename to client/events.js diff --git a/lib/client/files.js b/client/files.js similarity index 100% rename from lib/client/files.js rename to client/files.js diff --git a/lib/client/help.js b/client/help.js similarity index 100% rename from lib/client/help.js rename to client/help.js diff --git a/lib/client/input.js b/client/input.js similarity index 100% rename from lib/client/input.js rename to client/input.js diff --git a/lib/client/key.js b/client/key.js similarity index 100% rename from lib/client/key.js rename to client/key.js diff --git a/lib/client/konsole.js b/client/konsole.js similarity index 100% rename from lib/client/konsole.js rename to client/konsole.js diff --git a/lib/client/listeners.js b/client/listeners.js similarity index 100% rename from lib/client/listeners.js rename to client/listeners.js diff --git a/lib/client/load.js b/client/load.js similarity index 100% rename from lib/client/load.js rename to client/load.js diff --git a/lib/client/markdown.js b/client/markdown.js similarity index 100% rename from lib/client/markdown.js rename to client/markdown.js diff --git a/lib/client/menu.js b/client/menu.js similarity index 100% rename from lib/client/menu.js rename to client/menu.js diff --git a/lib/client/notify.js b/client/notify.js similarity index 100% rename from lib/client/notify.js rename to client/notify.js diff --git a/lib/client/operation.js b/client/operation.js similarity index 100% rename from lib/client/operation.js rename to client/operation.js diff --git a/lib/client/polyfill.js b/client/polyfill.js similarity index 100% rename from lib/client/polyfill.js rename to client/polyfill.js diff --git a/lib/client/rest.js b/client/rest.js similarity index 100% rename from lib/client/rest.js rename to client/rest.js diff --git a/lib/client/storage.js b/client/storage.js similarity index 100% rename from lib/client/storage.js rename to client/storage.js diff --git a/lib/client/upload.js b/client/upload.js similarity index 100% rename from lib/client/upload.js rename to client/upload.js diff --git a/lib/client/view.js b/client/view.js similarity index 100% rename from lib/client/view.js rename to client/view.js diff --git a/lib/cloudfunc.js b/common/cloudfunc.js similarity index 100% rename from lib/cloudfunc.js rename to common/cloudfunc.js diff --git a/lib/util.js b/common/util.js similarity index 100% rename from lib/util.js rename to common/util.js diff --git a/lib/client/cloudcmd.js b/lib/client/cloudcmd.js deleted file mode 100644 index bf5a2c62..00000000 --- a/lib/client/cloudcmd.js +++ /dev/null @@ -1,97 +0,0 @@ -var CloudCmd; - -(function() { - 'use strict'; - - CloudCmd = load; - - function load(prefix) { - prefix = prefix || ''; - - var urlFiles, - modules = '/modules/', - lib = 'lib/', - client = 'client/', - files = [ - 'util', - 'cloudfunc', - client + 'dom', - client + 'events', - client + 'rest', - client + 'load', - client + 'notify', - client + 'storage', - client + 'files', - client + 'dialog', - 'client', - client + 'buffer', - client + 'listeners', - client + 'key', - client + 'directory' - ].map(function(name) { - return lib + name; - }), - - moduleFiles = [ - window.Promise ? '' : 'promise-polyfill/promise.min', - libDir('format', 'format-io'), - libDir('rendy'), - libDir('exec', 'execon'), - libDir('jonny'), - libDist('emitify'), - libDist('currify'), - ].filter(function(name) { - return name; - }).map(function(name) { - return modules + name; - }); - - files = moduleFiles - .concat(files) - .concat('/join/join') - .map(function(name) { - return name + '.js'; - }); - - urlFiles = getJoinURL(files); - - createScript(prefix + urlFiles, function() { - CloudCmd.init(prefix); - }); - } - - function libDir(name, dir) { - var lib = '/lib/'; - - if (!dir) - dir = name; - - return dir + lib + name; - } - - function libDist(name) { - return name + '/dist/' + name + '.min'; - } - - function createScript(url, callback) { - var script = document.createElement('script'); - - script.src = url; - script.async = true; - - script.addEventListener('load', function load(event) { - callback(event); - script.removeEventListener('load', load); - }); - - document.body.appendChild(script); - } - - function getJoinURL(names) { - var prefix = '/join:'; - var url = prefix + names.join(':'); - - return url; - } -})(); - diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js index ae61a8f2..88dfb1e1 100644 --- a/lib/cloudcmd.js +++ b/lib/cloudcmd.js @@ -3,8 +3,9 @@ var DIR = __dirname + '/'; var DIR_ROOT = DIR + '../'; var DIR_SERVER = DIR + 'server/'; +var DIR_COMMON = DIR + '../common/'; -var cloudfunc = require(DIR + 'cloudfunc'); +var cloudfunc = require(DIR_COMMON + 'cloudfunc'); var auth = require(DIR_SERVER + 'auth'); var config = require(DIR_SERVER + 'config'); @@ -290,7 +291,7 @@ function setUrl(pref) { req.url = req.url.replace(prefix, '') || '/'; if (req.url === '/cloudcmd.js') - req.url = '/lib/client/cloudcmd.js'; + req.url = '/client/cloudcmd.js'; next(); }; diff --git a/lib/server.js b/lib/server.js index bd7c56a7..0f951050 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,7 +1,7 @@ 'use strict'; var DIR_LIB = './', - DIR_SERVER = DIR_LIB + 'server/', + DIR_SERVER = DIR_LIB + 'server/', http = require('http'), opn = require('opn'), diff --git a/lib/server/config.js b/lib/server/config.js index 49367ed5..7296a5a0 100644 --- a/lib/server/config.js +++ b/lib/server/config.js @@ -1,13 +1,13 @@ 'use strict'; var DIR_SERVER = __dirname + '/', - DIR_LIB = DIR_SERVER + '../', + DIR_COMMON = DIR_SERVER + '../../common/', DIR = DIR_SERVER + '../../', path = require('path'), exit = require(DIR_SERVER + 'exit'), - CloudFunc = require(DIR_LIB + 'cloudfunc'), + CloudFunc = require(DIR_COMMON + 'cloudfunc'), pullout = require('pullout/legacy'), ponse = require('ponse'), diff --git a/lib/server/markdown.js b/lib/server/markdown.js index c8e6cdf1..2fa057fa 100644 --- a/lib/server/markdown.js +++ b/lib/server/markdown.js @@ -1,8 +1,7 @@ 'use strict'; var DIR = './', - DIR_LIB = '../', - DIR_ROOT = __dirname + '/' + DIR_LIB + '../', + DIR_ROOT = __dirname + '/../../', fs = require('fs'), diff --git a/lib/server/rest.js b/lib/server/rest.js index 66a28c11..fe3b4ec4 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -1,13 +1,13 @@ 'use strict'; var DIR = './', - DIR_LIB = DIR + '../', + DIR_COMMON = DIR + '../../common/', path = require('path'), root = require(DIR + 'root'), config = require(DIR + 'config'), - CloudFunc = require(DIR_LIB + 'cloudfunc'), + CloudFunc = require(DIR_COMMON + 'cloudfunc'), markdown = require(DIR + 'markdown'), diff --git a/lib/server/route.js b/lib/server/route.js index fea34365..97b111de 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -3,7 +3,7 @@ var DIR = __dirname + '/../../', DIR_TMPL = DIR + 'tmpl/', DIR_HTML = DIR + 'html/', - DIR_LIB = DIR + 'lib/', + DIR_COMMON = DIR + 'common/', DIR_JSON = DIR + 'json/', DIR_SERVER = __dirname + '/', DIR_FS = DIR_TMPL + 'fs/', @@ -26,7 +26,7 @@ var DIR = __dirname + '/../../', prefixer = require(DIR_SERVER + 'prefixer'), prefix = squad(prefixer, apart(config, 'prefix')), - CloudFunc = require(DIR_LIB + 'cloudfunc'), + CloudFunc = require(DIR_COMMON + 'cloudfunc'), PATH_INDEX = DIR_HTML + 'index.html', diff --git a/package.json b/package.json index 6773a584..14f67e10 100644 --- a/package.json +++ b/package.json @@ -35,11 +35,11 @@ "server" ], "bin": { - "cloudcmd": "bin_/cloudcmd.js", + "cloudcmd": "legacy/bin/cloudcmd.js", "cloudcmd+": "bin/cloudcmd.js" }, "config": { - "dirs_legacy": "bin lib", + "dirs_legacy": "client", "dirs": "bin lib test" }, "scripts": { @@ -50,13 +50,13 @@ "lint": "redrun lint:*", "lint:css": "recess css/*.css", "lint:style": "stylelint css/*.css", - "lint:js": "redrun jshint jscs eslint", - "lint:js:legacy": "redrun legacy:*", - "eslint": "eslint --rule 'no-console:0' test bin/release.js", + "lint:js": "redrun jshint jscs eslint:*", + "lint:js:es5": "redrun es5:*", + "eslint:bin": "eslint --rule 'no-console:0' bin test lib", "jshint": "jshint bin/release.js", "jscs": "jscs --esnext $npm_package_config_dirs", - "legacy:jshint": "jshint --config legacy/.jshintrc $npm_package_config_dirs_dirs_legacy --exclude bin/release.js", - "legacy:eslint": "eslint -c legacy/.eslintrc --rule 'no-console:0' $npm_package_config_dirs_legacy --ignore-path bin/release.js", + "es5:jshint": "jshint --config .es5/.jshintrc $npm_package_config_dirs_dirs_legacy --exclude bin/release.js", + "es5:eslint": "eslint -c .es5/.eslintrc --rule 'no-console:0' $npm_package_config_dirs_legacy --ignore-path bin/release.js", "test": "tape 'test/**/*.js'", "watch:test": "nodemon -w lib -w test -x \"npm run test\"", "spell": "yaspeller .", @@ -79,8 +79,15 @@ "docker:rm-old": "redrun --parallel docker:rm:*", "coverage": "nyc npm test", "report": "nyc report --reporter=text-lcov | coveralls", - "6to5:bin": "babel bin -d bin_", - "build": "redrun 6to5:*" + "6to5:bin": "babel bin -d legacy/bin", + "6to5:lib": "babel lib -d lib_", + "build": "redrun rm:* 6to5:* mkdir:* legacy:*", + "legacy:package": "echo \"module.exports = require('../package');\" > legacy/package.js", + "legacy:lib:cloudcmd": "echo \"module.exports = require('../../lib_/cloudcmd');\" > legacy/lib/cloudcmd.js", + "legacy:lib:server": "echo \"module.exports = require('../../lib_/server');\" > legacy/lib/server.js", + "mkdir:server": "mkdirp legacy/lib/server", + "legacy:server": "bin/legacy.js", + "rm:legacy": "rimraf legacy" }, "directories": { "man": "man" @@ -139,6 +146,7 @@ "jscs": "^3.0.1", "jshint": "^2.8.0", "minor": "^1.2.2", + "mkdirp": "^0.5.1", "morgan": "^1.6.1", "nodemon": "^1.9.1", "nsp": "^2.2.1", @@ -147,6 +155,7 @@ "recess": "^1.1.9", "redrun": "^5.0.0", "request": "^2.76.0", + "rimraf": "^2.5.4", "shortdate": "^1.0.1", "socket.io-client": "^1.5.1", "stylelint": "^7.0.2", @@ -160,5 +169,5 @@ "node": ">=0.10" }, "license": "MIT", - "main": "lib/cloudcmd.js" + "main": "legacy/lib/cloudcmd.js" } diff --git a/test/before.js b/test/before.js index b9167707..fb2b3d74 100644 --- a/test/before.js +++ b/test/before.js @@ -8,7 +8,7 @@ const io = require('socket.io'); const writejson = require('writejson'); const readjson = require('readjson'); -const cloudcmd = require('..'); +const cloudcmd = require('../lib/cloudcmd'); const {assign} = Object; const pathConfig = os.homedir() + '/.cloudcmd.json'; diff --git a/test/lib/cloudcmd.js b/test/lib/cloudcmd.js index ca113b82..9f6ce028 100644 --- a/test/lib/cloudcmd.js +++ b/test/lib/cloudcmd.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('tape'); -const cloudcmd = require('../..'); +const cloudcmd = require('../../lib/cloudcmd'); test('cloudcmd: args: no', (t) => { const fn = () => cloudcmd(); diff --git a/test/lib/cloudfunc.js b/test/lib/cloudfunc.js index 5aa886c1..799fb8c3 100644 --- a/test/lib/cloudfunc.js +++ b/test/lib/cloudfunc.js @@ -1,128 +1,126 @@ -(function() { - 'use strict'; +'use strict'; + +var DIR = __dirname + '/../../', + COMMONDIR = DIR + 'common/', + TMPLDIR = DIR + 'tmpl/', - var DIR = __dirname + '/../../', - LIBDIR = DIR + 'lib/', - TMPLDIR = DIR + 'tmpl/', - - Util = require(LIBDIR + 'util'), - CloudFunc = require(LIBDIR + 'cloudfunc'), - files = require('files-io'), - rendy = require('rendy'), - - test = require('tape'), - - FS_DIR = TMPLDIR + 'fs/', - EXPECT_PATH = DIR + 'test/lib/cloudfunc.html', - - TMPL_PATH = [ - 'file', - 'path', - 'pathLink', - 'link', - ], - - JSON_FILES = { - path : '/etc/X11/', - files : [{ - name: 'applnk', - size: 'dir', - date: '21.02.2016', - uid : 0, - mode: 'rwx r-x r-x' - }, { - name: 'prefdm', - size: '1.30kb', - date: '21.02.2016', - uid : 0, - mode: 'rwx r-x r-x' - }] - }, - - Expect = - '
' + - '' + - '' + - '' + - '' + - '/' + - '' + - 'etc' + - '/X11/' + - '' + - '
'; + Util = require(COMMONDIR + 'util'), + CloudFunc = require(COMMONDIR + 'cloudfunc'), + files = require('files-io'), + rendy = require('rendy'), - test(function(t) { - var paths = {}, - - filesList = TMPL_PATH.map(function(name) { - var path = FS_DIR + name + '.hbs'; - - paths[path] = name; - - return path; - }) - .concat(EXPECT_PATH); + test = require('tape'), + + FS_DIR = TMPLDIR + 'fs/', + EXPECT_PATH = DIR + 'test/lib/cloudfunc.html', + + TMPL_PATH = [ + 'file', + 'path', + 'pathLink', + 'link', + ], + + JSON_FILES = { + path : '/etc/X11/', + files : [{ + name: 'applnk', + size: 'dir', + date: '21.02.2016', + uid : 0, + mode: 'rwx r-x r-x' + }, { + name: 'prefdm', + size: '1.30kb', + date: '21.02.2016', + uid : 0, + mode: 'rwx r-x r-x' + }] + }, + + Expect = + '
' + + '' + + '' + + '' + + '' + + '/' + + '' + + 'etc' + + '/X11/' + + '' + + '
'; + +test(function(t) { + var paths = {}, - files.read(filesList, 'utf8', function(error, files) { - var isNotOk, expect, result, - i = 0, - template = {}; + filesList = TMPL_PATH.map(function(name) { + var path = FS_DIR + name + '.hbs'; - if (error) { - throw(new Error(error)); - } else { - Util.time('CloudFunc.buildFromJSON'); + paths[path] = name; + + return path; + }) + .concat(EXPECT_PATH); + + files.read(filesList, 'utf8', function(error, files) { + var isNotOk, expect, result, + i = 0, + template = {}; + + if (error) { + throw(new Error(error)); + } else { + Util.time('CloudFunc.buildFromJSON'); + + Object.keys(files).forEach(function(path) { + var name = paths[path]; - Object.keys(files).forEach(function(path) { - var name = paths[path]; - - if (path !== EXPECT_PATH) - template[name] = files[path]; - }); + if (path !== EXPECT_PATH) + template[name] = files[path]; + }); + + expect = files[EXPECT_PATH]; + + result = CloudFunc.buildFromJSON({ + prefix : '', + data : JSON_FILES, + template: template + }); + + Expect += expect; + + isNotOk = Expect.split('').some(function(item, number) { + var ret = result[number] !== item; - expect = files[EXPECT_PATH]; + if (ret) + i = number; - result = CloudFunc.buildFromJSON({ - prefix : '', - data : JSON_FILES, - template: template - }); + return ret; + }); + + Util.timeEnd('CloudFunc.buildFromJSON'); + + if (isNotOk) { + console.log(rendy([ + 'Error in char number: {{ number }}', + 'Expect: {{ expect }}', + 'Result: {{ result }}' + ].join('\n'), { + number: i, + expect: Expect.substr(i), + result: result.substr(i) + })); - Expect += expect; - - isNotOk = Expect.split('').some(function(item, number) { - var ret = result[number] !== item; - - if (ret) - i = number; - - return ret; - }); - - Util.timeEnd('CloudFunc.buildFromJSON'); - - if (isNotOk) { - console.log(rendy([ - 'Error in char number: {{ number }}', - 'Expect: {{ expect }}', - 'Result: {{ result }}' - ].join('\n'), { - number: i, - expect: Expect.substr(i), - result: result.substr(i) - })); - - console.log('buildFromJSON: Not OK'); - } - - t.equal(Expect, result, 'should be equal rendered json data'); - - t.end(); + console.log('buildFromJSON: Not OK'); } - }); + + t.equal(Expect, result, 'should be equal rendered json data'); + + t.end(); + } }); - -})(); +}); + diff --git a/test/lib/config.js b/test/lib/config.js index c1f0c326..baed7051 100644 --- a/test/lib/config.js +++ b/test/lib/config.js @@ -13,12 +13,9 @@ test('config: manage', (t) => { test('config: manage: get', (t) => { const editor = 'deepword'; - const conf = { - editor - }; - before({config: conf}, (port, after) => { - t.equal(editor, config('editor'), 'should get config'); + before({config: {editor}}, (port, after) => { + t.equal(config('editor'), editor, 'should get config'); t.end(); after(); }); diff --git a/test/lib/util.js b/test/lib/util.js index dde65b2c..60980f81 100644 --- a/test/lib/util.js +++ b/test/lib/util.js @@ -3,7 +3,7 @@ var test = require('tape'), DIR = '../../', - Util = require(DIR + 'lib/util'); + Util = require(DIR + 'common/util'); test('getExt: no extension', function(t) {