appril-cli 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/base/bootstrap/api/request-methods.js +7 -0
- data/app/base/bootstrap/api/rtcp.js +28 -0
- data/app/base/bootstrap/api/validate-arguments.js +29 -0
- data/app/base/bootstrap/api/xhr.js +88 -0
- data/app/base/bootstrap/components.js +5 -4
- data/app/base/bootstrap/router.js +42 -12
- data/app/base/bootstrap/rtcp.js +2 -2
- data/app/package.json +3 -2
- data/app/webpack/entry.js +1 -1
- data/lib/appril-cli/version.rb +1 -1
- metadata +8 -4
- /data/app/base/bootstrap/{api_callbacks.js → api/callbacks.js} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d28e060372bfb237fc2f55ce5f175d22638b826
|
4
|
+
data.tar.gz: 3c8ff729036829a42d8325e03beb31c133327db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 670bdd5a1c68d0455a57bb1780fececf8a3051664767481a06a0a2899c20d4753f7191fe5943cce7395b1f0f92422f84923dae4fe19c4b0aa35ef718c4fff7ab
|
7
|
+
data.tar.gz: 70cad4caf1e501927fcb530e2a956891c9c4a39f37344d5189a08c74f5687a0c193298158a9fc17129eab97fef595a3c1c165c04e5003f461c204ed557076623
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import {reduce} from 'lodash'
|
2
|
+
import validate_arguments from './validate-arguments'
|
3
|
+
import REQUEST_METHODS from './request-methods'
|
4
|
+
|
5
|
+
export default function(component, rtcp) {
|
6
|
+
|
7
|
+
return reduce(component.api || [], function(component_api, method) {
|
8
|
+
component_api[method] = function(...args) {
|
9
|
+
|
10
|
+
validate_arguments(args)
|
11
|
+
|
12
|
+
return reduce(REQUEST_METHODS, function(method_api, request_method) {
|
13
|
+
method_api[request_method.toLowerCase()] = function(callbacks) {
|
14
|
+
|
15
|
+
rtcp.call_server_method(
|
16
|
+
component.controller_name,
|
17
|
+
method,
|
18
|
+
args,
|
19
|
+
request_method,
|
20
|
+
callbacks
|
21
|
+
)
|
22
|
+
}
|
23
|
+
return method_api
|
24
|
+
}, {})
|
25
|
+
}
|
26
|
+
return component_api
|
27
|
+
}, {})
|
28
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import {forEach} from 'lodash'
|
2
|
+
|
3
|
+
const STRING = '[object String]'
|
4
|
+
const NUMBER = '[object Number]'
|
5
|
+
const OBJECT = '[object Object]'
|
6
|
+
|
7
|
+
function get_type(arg) {
|
8
|
+
const type = Object.prototype.toString.call(arg)
|
9
|
+
return {
|
10
|
+
is_string: type === STRING,
|
11
|
+
is_number: type === NUMBER,
|
12
|
+
is_object: type === OBJECT,
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
export default function(args) {
|
17
|
+
forEach(args, function(arg,i) {
|
18
|
+
|
19
|
+
const {is_string, is_number, is_object} = get_type(arg)
|
20
|
+
|
21
|
+
if (!is_string && !is_number && !is_object) {
|
22
|
+
throw `Api methods accepts only Strings, Numbers and Objects as arguments. Argument #${i} is a ${type} instead.`
|
23
|
+
}
|
24
|
+
|
25
|
+
if (is_object && i + 1 !== args.length) {
|
26
|
+
throw `Only last argument can be a Object`
|
27
|
+
}
|
28
|
+
})
|
29
|
+
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import {reduce, isObject, isArray, isFunction, last} from 'lodash'
|
2
|
+
import {url_builder} from 'appril-utils'
|
3
|
+
import validate_arguments from './validate-arguments'
|
4
|
+
import REQUEST_METHODS from './request-methods'
|
5
|
+
|
6
|
+
export default function(component, {on_request, on_response, on_error} = {}) {
|
7
|
+
|
8
|
+
return reduce(component.api || [], function(component_api, method) {
|
9
|
+
|
10
|
+
component_api[method] = function(...args) {
|
11
|
+
|
12
|
+
validate_arguments(args)
|
13
|
+
|
14
|
+
return reduce(REQUEST_METHODS, function(method_api, request_method) {
|
15
|
+
|
16
|
+
const is_post = request_method === 'POST'
|
17
|
+
|
18
|
+
method_api[request_method.toLowerCase()] = function(callbacks = {}) {
|
19
|
+
|
20
|
+
const error_reporter = function(error_message) {
|
21
|
+
if (callbacks.error)
|
22
|
+
return callbacks.error(error_message)
|
23
|
+
if (on_error)
|
24
|
+
return on_error(error_message)
|
25
|
+
throw error_message
|
26
|
+
}
|
27
|
+
|
28
|
+
const xhr = new XMLHttpRequest()
|
29
|
+
|
30
|
+
let params = last(args)
|
31
|
+
|
32
|
+
if (isObject(params)) {
|
33
|
+
if (is_post) {
|
34
|
+
args.pop()
|
35
|
+
}
|
36
|
+
} else {
|
37
|
+
params = {}
|
38
|
+
}
|
39
|
+
|
40
|
+
on_request && on_request(params)
|
41
|
+
|
42
|
+
xhr.onreadystatechange = function() {
|
43
|
+
if (xhr.readyState !== XMLHttpRequest.DONE)
|
44
|
+
return
|
45
|
+
|
46
|
+
callbacks.done && callbacks.done()
|
47
|
+
|
48
|
+
if (parseInt(xhr.status / 100) !== 2)
|
49
|
+
return error_reporter(xhr.responseText)
|
50
|
+
|
51
|
+
if (!callbacks.success)
|
52
|
+
return
|
53
|
+
|
54
|
+
let response = JSON.parse(xhr.responseText)
|
55
|
+
|
56
|
+
on_response && on_response(response)
|
57
|
+
|
58
|
+
callbacks.success(response)
|
59
|
+
}
|
60
|
+
|
61
|
+
xhr.onerror = function(error_message = 'Network error occurred') {
|
62
|
+
callbacks.done && callbacks.done()
|
63
|
+
error_reporter(error_message)
|
64
|
+
}
|
65
|
+
|
66
|
+
xhr.open(request_method, url_builder(component.url, method, ...args))
|
67
|
+
|
68
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
69
|
+
xhr.setRequestHeader('Accept', 'application/json')
|
70
|
+
|
71
|
+
if (is_post) {
|
72
|
+
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
|
73
|
+
xhr.send(JSON.stringify(params))
|
74
|
+
} else {
|
75
|
+
xhr.send()
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
return method_api
|
80
|
+
}, {})
|
81
|
+
|
82
|
+
}
|
83
|
+
|
84
|
+
return component_api
|
85
|
+
|
86
|
+
}, {})
|
87
|
+
|
88
|
+
}
|
@@ -1,14 +1,15 @@
|
|
1
1
|
import {reduce} from 'lodash'
|
2
2
|
import {urlify} from 'appril-utils'
|
3
|
-
import
|
4
|
-
import
|
3
|
+
import xhr_api_builder from './api/xhr'
|
4
|
+
import rtcp_api_builder from './api/rtcp'
|
5
|
+
import * as callbacks from './api/callbacks'
|
5
6
|
import rtcp from './rtcp'
|
6
7
|
import {components, default_api} from 'app/appril.json'
|
7
8
|
|
8
9
|
export default reduce(components, function(map,component) {
|
9
10
|
component.url = urlify(component.url)
|
10
|
-
component.xhr =
|
11
|
-
component.rtcp =
|
11
|
+
component.xhr = xhr_api_builder(component, callbacks)
|
12
|
+
component.rtcp = rtcp_api_builder(component, rtcp)
|
12
13
|
Object.defineProperty(component, 'api', {get() {return component[default_api]}})
|
13
14
|
map[component.name] = component
|
14
15
|
return map
|
@@ -5,6 +5,7 @@ import VueRouter from 'vue-router'
|
|
5
5
|
import components from './components'
|
6
6
|
import store from './store'
|
7
7
|
import componentify from './component'
|
8
|
+
import {client_url} from 'app/appril.json'
|
8
9
|
|
9
10
|
Vue.use(VueRouter)
|
10
11
|
|
@@ -15,18 +16,47 @@ export default new VueRouter({
|
|
15
16
|
return {
|
16
17
|
name: component.name,
|
17
18
|
path: component.url_pattern,
|
18
|
-
component: (resolve) =>
|
19
|
-
if (component.api._env) {
|
20
|
-
component.api._env().get({
|
21
|
-
success(env) {
|
22
|
-
store.commit('__SET_ENV__', {component: component.name, env})
|
23
|
-
resolve(componentify(components, component, constructor.default))
|
24
|
-
}
|
25
|
-
})
|
26
|
-
} else {
|
27
|
-
resolve(componentify(components, component, constructor.default))
|
28
|
-
}
|
29
|
-
})
|
19
|
+
component: (resolve, reject) => load_component(component, resolve, reject)
|
30
20
|
}
|
31
21
|
})
|
32
22
|
})
|
23
|
+
|
24
|
+
function resolve_component(component, constructor, resolve) {
|
25
|
+
if (component.api._env) {
|
26
|
+
component.api._env().get({
|
27
|
+
success(env) {
|
28
|
+
store.commit('__SET_ENV__', {component: component.name, env})
|
29
|
+
resolve(componentify(components, component, constructor))
|
30
|
+
}
|
31
|
+
})
|
32
|
+
} else {
|
33
|
+
resolve(componentify(components, component, constructor))
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
function load_component(component, resolve, reject) {
|
38
|
+
const xhr = new XMLHttpRequest()
|
39
|
+
|
40
|
+
xhr.onreadystatechange = function() {
|
41
|
+
if (xhr.readyState !== XMLHttpRequest.DONE)
|
42
|
+
return
|
43
|
+
|
44
|
+
if (parseInt(xhr.status / 100) !== 2)
|
45
|
+
return reject(xhr.responseText)
|
46
|
+
|
47
|
+
resolve_component(component, _eval(xhr.responseText), resolve)
|
48
|
+
}
|
49
|
+
|
50
|
+
xhr.onerror = function() {
|
51
|
+
reject('Network error occurred')
|
52
|
+
}
|
53
|
+
|
54
|
+
xhr.open('GET', `${client_url}/${APP_ENV}/${component.entry_path}.js`)
|
55
|
+
xhr.send()
|
56
|
+
}
|
57
|
+
|
58
|
+
function _eval(text) {
|
59
|
+
window.module = {exports: null}
|
60
|
+
eval.call(window, text)
|
61
|
+
return window.module.exports.default
|
62
|
+
}
|
data/app/base/bootstrap/rtcp.js
CHANGED
data/app/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"version": "0.0.0",
|
4
4
|
"description": "...",
|
5
5
|
"devDependencies": {
|
6
|
-
"appril": "
|
6
|
+
"appril-rtcp": "0",
|
7
7
|
"appril-alert": ">= 0.0.5",
|
8
8
|
"appril-polyfills": ">= 0.0.2",
|
9
9
|
"appril-url": ">= 0.0.5",
|
@@ -23,7 +23,8 @@
|
|
23
23
|
"optimize-css-assets-webpack-plugin": "1",
|
24
24
|
"style-loader": "*",
|
25
25
|
"url-loader": "*",
|
26
|
-
"vue": "^2.0.0-
|
26
|
+
"vue": "^2.0.0-rc.2",
|
27
|
+
"vue-router": "^2.0.0-rc.3",
|
27
28
|
"vue-html-loader": "1",
|
28
29
|
"vuex": "^2.0.0-rc.3",
|
29
30
|
"webpack": "^2.1.0-beta.18"
|
data/app/webpack/entry.js
CHANGED
@@ -3,6 +3,6 @@ const filter = require('lodash/filter')
|
|
3
3
|
const config = require('../appril.json')
|
4
4
|
|
5
5
|
module.exports = reduce(filter(config.components, 'entry_path'), function(entries,component) {
|
6
|
-
entries[component.
|
6
|
+
entries[component.entry_path] = 'components/' + component.entry_path + '/index.js'
|
7
7
|
return entries
|
8
8
|
}, {app: 'base/app.js'})
|
data/lib/appril-cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appril-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Slee Woo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Appril CLI
|
14
14
|
email:
|
@@ -27,7 +27,11 @@ files:
|
|
27
27
|
- app/base/app.js
|
28
28
|
- app/base/assets/app.css
|
29
29
|
- app/base/boot.rb
|
30
|
-
- app/base/bootstrap/
|
30
|
+
- app/base/bootstrap/api/callbacks.js
|
31
|
+
- app/base/bootstrap/api/request-methods.js
|
32
|
+
- app/base/bootstrap/api/rtcp.js
|
33
|
+
- app/base/bootstrap/api/validate-arguments.js
|
34
|
+
- app/base/bootstrap/api/xhr.js
|
31
35
|
- app/base/bootstrap/component.js
|
32
36
|
- app/base/bootstrap/components.js
|
33
37
|
- app/base/bootstrap/router.js
|
@@ -121,5 +125,5 @@ rubyforge_project:
|
|
121
125
|
rubygems_version: 2.5.1
|
122
126
|
signing_key:
|
123
127
|
specification_version: 4
|
124
|
-
summary: '["appril-cli-0.2.
|
128
|
+
summary: '["appril-cli-0.2.9", "Appril CLI"]'
|
125
129
|
test_files: []
|
File without changes
|