commit a4fa670dc5c4443d9a90e84d4caa1c7a7170785d Author: Fabrice Marsaud Date: Tue Jan 26 16:01:03 2016 +0100 Initial commit diff --git a/packages/xo-remote-parser/.babelrc b/packages/xo-remote-parser/.babelrc new file mode 100644 index 000000000..df6800285 --- /dev/null +++ b/packages/xo-remote-parser/.babelrc @@ -0,0 +1,11 @@ +{ + "comments": false, + "compact": true, + "plugins": [ + "transform-runtime" + ], + "presets": [ + "stage-0", + "es2015" + ] +} diff --git a/packages/xo-remote-parser/.editorconfig b/packages/xo-remote-parser/.editorconfig new file mode 100644 index 000000000..da21ef4c5 --- /dev/null +++ b/packages/xo-remote-parser/.editorconfig @@ -0,0 +1,65 @@ +# http://EditorConfig.org +# +# Julien Fontanet's configuration +# https://gist.github.com/julien-f/8096213 + +# Top-most EditorConfig file. +root = true + +# Common config. +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespaces = true + +# CoffeeScript +# +# https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md +[*.{,lit}coffee] +indent_size = 2 +indent_style = space + +# Markdown +[*.{md,mdwn,mdown,markdown}] +indent_size = 4 +indent_style = space + +# Package.json +# +# This indentation style is the one used by npm. +[/package.json] +indent_size = 2 +indent_style = space + +# Jade +[*.jade] +indent_size = 2 +indent_style = space + +# JavaScript +# +# Two spaces seems to be the standard most common style, at least in +# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces). +[*.js] +indent_size = 2 +indent_style = space + +# Less +[*.less] +indent_size = 2 +indent_style = space + +# Sass +# +# Style used for http://libsass.com +[*.s[ac]ss] +indent_size = 2 +indent_style = space + +# YAML +# +# Only spaces are allowed. +[*.yaml] +indent_size = 2 +indent_style = space diff --git a/packages/xo-remote-parser/.gitignore b/packages/xo-remote-parser/.gitignore new file mode 100644 index 000000000..6959be1cf --- /dev/null +++ b/packages/xo-remote-parser/.gitignore @@ -0,0 +1,9 @@ +/.nyc_output/ +/bower_components/ +/dist/ + +npm-debug.log +npm-debug.log.* + +!node_modules/* +node_modules/*/ diff --git a/packages/xo-remote-parser/.mocha.js b/packages/xo-remote-parser/.mocha.js new file mode 100644 index 000000000..e6d84e403 --- /dev/null +++ b/packages/xo-remote-parser/.mocha.js @@ -0,0 +1,5 @@ +Error.stackTraceLimit = 100 + +try { require('trace') } catch (_) {} +try { require('clarify') } catch (_) {} +try { require('source-map-support/register') } catch (_) {} diff --git a/packages/xo-remote-parser/.mocha.opts b/packages/xo-remote-parser/.mocha.opts new file mode 100644 index 000000000..6cfd94898 --- /dev/null +++ b/packages/xo-remote-parser/.mocha.opts @@ -0,0 +1 @@ +--require ./.mocha.js diff --git a/packages/xo-remote-parser/.npmignore b/packages/xo-remote-parser/.npmignore new file mode 100644 index 000000000..c31ee82cb --- /dev/null +++ b/packages/xo-remote-parser/.npmignore @@ -0,0 +1,10 @@ +/examples/ +example.js +example.js.map +*.example.js +*.example.js.map + +/test/ +/tests/ +*.spec.js +*.spec.js.map diff --git a/packages/xo-remote-parser/.travis.yml b/packages/xo-remote-parser/.travis.yml new file mode 100644 index 000000000..a9b136ea6 --- /dev/null +++ b/packages/xo-remote-parser/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - 'stable' + - '4' + - '0.12' + +# Use containers. +# http://docs.travis-ci.com/user/workers/container-based-infrastructure/ +sudo: false diff --git a/packages/xo-remote-parser/README.md b/packages/xo-remote-parser/README.md new file mode 100644 index 000000000..d811985b1 --- /dev/null +++ b/packages/xo-remote-parser/README.md @@ -0,0 +1,52 @@ +# ${pkg.name} [![Build Status](https://travis-ci.org/${pkg.shortGitHubPath}.png?branch=master)](https://travis-ci.org/${pkg.shortGitHubPath}) + +> ${pkg.description} + +## Install + +Installation of the [npm package](https://npmjs.org/package/${pkg.name}): + +``` +> npm install --save ${pkg.name} +``` + +## Usage + +**TODO** + +## Development + +### Installing dependencies + +``` +> npm install +``` + +### Compilation + +The sources files are watched and automatically recompiled on changes. + +``` +> npm run dev +``` + +### Tests + +``` +> npm run test-dev +``` + +## Contributions + +Contributions are *very* welcomed, either on the documentation or on +the code. + +You may: + +- report any [issue](${pkg.bugs}) + you've encountered; +- fork and create a pull request. + +## License + +${pkg.license} © [${pkg.author.name}](${pkg.author.url}) diff --git a/packages/xo-remote-parser/package.json b/packages/xo-remote-parser/package.json new file mode 100644 index 000000000..50c38bb29 --- /dev/null +++ b/packages/xo-remote-parser/package.json @@ -0,0 +1,64 @@ +{ + "private": true, + "name": "", + "version": "0.0.0", + "license": "ISC", + "description": "", + "keywords": [], + "homepage": "", + "bugs": "", + "repository": { + "type": "git", + "url": "" + }, + "author": { + "name": "Julien Fontanet", + "email": "julien.fontanet@isonoe.net" + }, + "preferGlobal": false, + "main": "dist/", + "bin": {}, + "files": [ + "dist/" + ], + "engines": { + "node": ">=0.12" + }, + "dependencies": { + "babel-runtime": "^6.3.19" + }, + "devDependencies": { + "babel-cli": "^6.3.17", + "babel-eslint": "^5.0.0-beta6", + "babel-plugin-transform-runtime": "^6.3.13", + "babel-preset-es2015": "^6.3.13", + "babel-preset-stage-0": "^6.3.13", + "clarify": "^1.0.5", + "dependency-check": "^2.5.1", + "lodash.filter": "^4.0.1", + "lodash.map": "^4.0.1", + "lodash.trim": "^4.0.1", + "mocha": "^2.3.4", + "must": "^0.13.1", + "nyc": "^5.0.1", + "source-map-support": "^0.4.0", + "standard": "^5.4.1", + "trace": "^2.1.0" + }, + "scripts": { + "build": "babel --source-maps --out-dir=dist/ src/", + "dev": "babel --watch --source-maps --out-dir=dist/ src/", + "dev-test": "mocha --opts .mocha.opts --watch --reporter=min \"dist/**/*.spec.js\"", + "lint": "standard", + "depcheck": "dependency-check ./package.json", + "posttest": "npm run lint && npm run depcheck", + "prepublish": "npm run build", + "test": "nyc mocha --opts .mocha.opts \"dist/**/*.spec.js\"" + }, + "standard": { + "ignore": [ + "dist/**" + ], + "parser": "babel-eslint" + } +} diff --git a/packages/xo-remote-parser/src/index.js b/packages/xo-remote-parser/src/index.js new file mode 100644 index 000000000..51dcbdb05 --- /dev/null +++ b/packages/xo-remote-parser/src/index.js @@ -0,0 +1,50 @@ +import filter from 'lodash.filter' +import map from 'lodash.map' +import trim from 'lodash.trim' + +const sanitizePath = (...paths) => filter(map(paths, s => s && filter(map(s.split('/'), trim)).join('/'))).join('/') + +export const parse = (remote) => { + const [type, rest] = remote.url.split('://') + if (type === 'file') { + remote.type = 'local' + remote.path = `/${rest}` // FIXME the heading slash has been forgotten on client side first implementation + } else if (type === 'nfs') { + remote.type = 'nfs' + const [host, share] = rest.split(':') + remote.path = `/tmp/xo-server/mounts/${remote.id}` + remote.host = host + remote.share = share + } else if (type === 'smb') { + remote.type = 'smb' + const [auth, smb] = rest.split('@') + const [username, password] = auth.split(':') + const [domain, sh] = smb.split('\\\\') + const [host, path] = sh.split('\0') + remote.host = host + remote.path = path + remote.domain = domain + remote.username = username + remote.password = password + } + return remote +} + +export const compose = ({type, host, path, username, password, domain}) => { + let url = `${type}://` + if (type === 'nfs') { + url += `${host}:` + } + if (type === 'smb') { + url += `${username}:${password}@${domain}\\\\${host}` + } + path = sanitizePath(path) + if (type === 'smb') { + path = path.split('/') + path = '\0' + path.join('\\') // FIXME saving with the windows fashion \ was a bad idea :,( + } else { + type === 'smb' && (path = `/${path}`) // FIXME file type should have a / too, but it has been forgotten on client side first implementation... + } + url += path + return url +} diff --git a/packages/xo-remote-parser/src/index.spec.js b/packages/xo-remote-parser/src/index.spec.js new file mode 100644 index 000000000..6e9c776d2 --- /dev/null +++ b/packages/xo-remote-parser/src/index.spec.js @@ -0,0 +1,13 @@ +/* eslint-env mocha */ + +import expect from 'must' + +// =================================================================== + +import myLib from './' + +// =================================================================== + +describe('myLib', () => { + // TODO +})