All files / switchman-core/src $.js

88.23% Statements 30/34
61.53% Branches 8/13
27.27% Functions 3/11
90.32% Lines 28/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 901x 1x 1x   1x 1x 1x   1x         4x 4x       4x     1x                                                 4x   4x 4x 4x 49x 1x     49x   49x   49x   49x           2x     2x 2x 2x   2x                       1x   1x  
const jsonCore = require('./json-core/core');
const repo = require('./repo');
const config = require('./config');
// const build = require('./build-node');
const loadFile = require('./file-tool/read-file');
const writeFile = require('./file-tool/write-file');
const pkg = require('../package.json');
 
const langCoreMap = {
    'jsonpatch': jsonCore
};
 
function getCore(parseOptions = {}) {
    let core = jsonCore;
    Iif (parseOptions.language && langCoreMap[parseOptions.language]) {
        core = langCoreMap[parseOptions.language];
    }
 
    return core;
}
 
const main = {
    //添加环境
    addRepo(options) {
        repo.add(options)
    },
    getRepo() {
        return repo.get()
    },
    getRepoList() {
    },
    removeRepo() {
    },
    //添加配置
    addConfig() {
    },
    getConfig() {
    },
    getConfigList() {
    },
    removeConfig() {
 
    },
 
    //执行patch脚本
    patch(options) {
        Iif (!options) throw new Error('options is null or undefined');
 
        const core = getCore(options.method);
        let patchFile = options.defaultPatchFile;
        for (let i = 0; i < options.mappings.length; i++) {
            if (options.mappings[i].patchFile) {
                patchFile = options.mappings[i].patchFile;
            }
 
            const patchContent = loadFile(patchFile).toString();
 
            const targetContent = loadFile(options.mappings[i].targetFile).toString();
 
            const content = core.patch(patchContent, targetContent, options.format);
 
            writeFile(content, options.mappings[i].targetFile);
        }
    },
 
    ///切换环境信息
    switch(projectAlias, configAlias) {
        if (!configAlias) configAlias = 'default'
 
        // 加载切换环境信息
        const repoConfig = repo.get(projectAlias)
        Eif (repoConfig) {
            const pathInfo = config.get(repoConfig.location, configAlias)
 
            this.patch(pathInfo)
        }
    },
};
 
// main.loadFile = (filePath, { parseOptions } = {}) => {
//     const content = loadFile(filePath).toString();
//     return main(content, { parseOptions })
// };
//
// main.writeFile = writeFile;
 
main.version = pkg.version;
 
module.exports = main;