mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-08-02 04:33:09 +00:00
feature(config) improve speed: decrease config loading count
This commit is contained in:
parent
2769ac2ef5
commit
bbb8ca15c6
16 changed files with 290 additions and 358 deletions
|
|
@ -1,8 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const test = require('tape');
|
||||
const readjson = require('readjson');
|
||||
|
||||
const root = '../../';
|
||||
const config = require(root + 'server/config');
|
||||
const dir = root + 'server/';
|
||||
const config = require(dir + 'config');
|
||||
|
||||
const pathConfig = path.join(os.homedir(), '.cloudcmd.json');
|
||||
const localConfig = path.join(__dirname, '..', '..', 'json', 'config.json');
|
||||
|
||||
const clean = (name) => {
|
||||
delete require.cache[require.resolve(name)];
|
||||
};
|
||||
|
||||
function readConfig() {
|
||||
return readjson.sync.try(pathConfig) || require(localConfig);
|
||||
}
|
||||
|
||||
const before = require('../before');
|
||||
|
||||
|
|
@ -35,3 +52,13 @@ test('config: manage: get', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('config: manage: get: *', (t) => {
|
||||
clean(dir + 'config');
|
||||
|
||||
const config = require(dir + 'config');
|
||||
const data = config('*');
|
||||
|
||||
t.deepEqual(data, readConfig(), 'should return config data');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue