Initial commit
This commit is contained in:
commit
a4fa670dc5
11
packages/xo-remote-parser/.babelrc
Normal file
11
packages/xo-remote-parser/.babelrc
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"comments": false,
|
||||
"compact": true,
|
||||
"plugins": [
|
||||
"transform-runtime"
|
||||
],
|
||||
"presets": [
|
||||
"stage-0",
|
||||
"es2015"
|
||||
]
|
||||
}
|
65
packages/xo-remote-parser/.editorconfig
Normal file
65
packages/xo-remote-parser/.editorconfig
Normal file
@ -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
|
9
packages/xo-remote-parser/.gitignore
vendored
Normal file
9
packages/xo-remote-parser/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/.nyc_output/
|
||||
/bower_components/
|
||||
/dist/
|
||||
|
||||
npm-debug.log
|
||||
npm-debug.log.*
|
||||
|
||||
!node_modules/*
|
||||
node_modules/*/
|
5
packages/xo-remote-parser/.mocha.js
Normal file
5
packages/xo-remote-parser/.mocha.js
Normal file
@ -0,0 +1,5 @@
|
||||
Error.stackTraceLimit = 100
|
||||
|
||||
try { require('trace') } catch (_) {}
|
||||
try { require('clarify') } catch (_) {}
|
||||
try { require('source-map-support/register') } catch (_) {}
|
1
packages/xo-remote-parser/.mocha.opts
Normal file
1
packages/xo-remote-parser/.mocha.opts
Normal file
@ -0,0 +1 @@
|
||||
--require ./.mocha.js
|
10
packages/xo-remote-parser/.npmignore
Normal file
10
packages/xo-remote-parser/.npmignore
Normal file
@ -0,0 +1,10 @@
|
||||
/examples/
|
||||
example.js
|
||||
example.js.map
|
||||
*.example.js
|
||||
*.example.js.map
|
||||
|
||||
/test/
|
||||
/tests/
|
||||
*.spec.js
|
||||
*.spec.js.map
|
9
packages/xo-remote-parser/.travis.yml
Normal file
9
packages/xo-remote-parser/.travis.yml
Normal file
@ -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
|
52
packages/xo-remote-parser/README.md
Normal file
52
packages/xo-remote-parser/README.md
Normal file
@ -0,0 +1,52 @@
|
||||
# ${pkg.name} [](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})
|
64
packages/xo-remote-parser/package.json
Normal file
64
packages/xo-remote-parser/package.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
50
packages/xo-remote-parser/src/index.js
Normal file
50
packages/xo-remote-parser/src/index.js
Normal file
@ -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
|
||||
}
|
13
packages/xo-remote-parser/src/index.spec.js
Normal file
13
packages/xo-remote-parser/src/index.spec.js
Normal file
@ -0,0 +1,13 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
import expect from 'must'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
import myLib from './'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
describe('myLib', () => {
|
||||
// TODO
|
||||
})
|
Loading…
Reference in New Issue
Block a user