mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
fix(cloudcmd) prefix: duplicate (#102)
This commit is contained in:
parent
1994b84810
commit
a13e8c4544
4 changed files with 45 additions and 11 deletions
|
|
@ -158,11 +158,12 @@ var Util, DOM, CloudFunc, join;
|
|||
return new F();
|
||||
}
|
||||
|
||||
/** Конструктор CloudClient, который
|
||||
/**
|
||||
* Конструктор CloudClient, который
|
||||
* выполняет весь функционал по
|
||||
* инициализации
|
||||
*/
|
||||
this.init = function(config) {
|
||||
this.init = function(prefix, config) {
|
||||
var func = function() {
|
||||
Util.exec.series([
|
||||
initModules,
|
||||
|
|
@ -185,8 +186,6 @@ var Util, DOM, CloudFunc, join;
|
|||
});
|
||||
};
|
||||
|
||||
var prefix = config.prefix;
|
||||
|
||||
CloudCmd.PREFIX = prefix;
|
||||
CloudCmd.PREFIX_URL = prefix + CloudFunc.apiURL;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ var CloudCmd;
|
|||
CloudCmd = load;
|
||||
|
||||
function load(config) {
|
||||
var prefix = config.prefix || '';
|
||||
|
||||
var prefix = getPrefix(config.prefix);
|
||||
var modules = '/modules/';
|
||||
var client = 'client/';
|
||||
var files = [
|
||||
|
|
@ -53,7 +52,7 @@ var CloudCmd;
|
|||
var urlFiles = getJoinURL(allFiles);
|
||||
|
||||
createScript(prefix + urlFiles, function() {
|
||||
CloudCmd.init(config);
|
||||
CloudCmd.init(prefix, config);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +69,16 @@ var CloudCmd;
|
|||
return name + '/dist/' + name + '.min';
|
||||
}
|
||||
|
||||
function getPrefix(prefix) {
|
||||
if (!prefix)
|
||||
return '';
|
||||
|
||||
if (!prefix.indexOf('/'))
|
||||
return prefix;
|
||||
|
||||
return '/' + prefix;
|
||||
}
|
||||
|
||||
function createScript(url, callback) {
|
||||
var script = document.createElement('script');
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
module.exports = (value) => {
|
||||
if (typeof value !== 'string')
|
||||
return value;
|
||||
|
||||
if (value && !~value.indexOf('/'))
|
||||
return '/' + value;
|
||||
return '';
|
||||
|
||||
if (value.length === 1)
|
||||
return '';
|
||||
|
||||
if (value && !~value.indexOf('/'))
|
||||
return '/' + value;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
|
|
|
|||
26
test/server/prefixer.js
Normal file
26
test/server/prefixer.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
|
||||
const dir = '../../server/';
|
||||
const prefixer = require(dir + 'prefixer');
|
||||
|
||||
test('prefixer: prefix without a slash', (t) => {
|
||||
t.equal(prefixer('hello'), '/hello', 'should add slash');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('prefixer: root', (t) => {
|
||||
t.equal(prefixer('/'), '', 'should add slash');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('prefixer: with slash', (t) => {
|
||||
t.equal(prefixer('/hello'), '/hello', 'should add slash');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('prefixer: not a string', (t) => {
|
||||
t.equal(prefixer(false), '', 'should add slash');
|
||||
t.end();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue