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 = - '