1.1.1 • Published 4 years ago

tfux-deploy-replace v1.1.1

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
4 years ago

tfux-deploy-replace

tufx-deploy-replace

INSTALL

npm install [-g] tfux-deploy-replace

USE

fis.match('**', {
    deploy: [
        fis.plugin('replace', {
            from: 'from/string',
            to: 'to/string',
            type: 'type/string' // 'string | file',optional,default to 'string'
        }),
        fis.plugin('local-deliver') //must add a deliver, such as http-push, local-deliver
    ]
});

EXAMPLE

多字符串替换

fis.match('**', {
    deploy: [
        fis.plugin('replace', {
            from: /(img|cdn)\.baidu\.com/,
            to: function ($0, $1) {
                switch ($1) {
                    case 'img':
                        return '127.0.0.1:8080';
                    case 'cdn':
                        return '127.0.0.1:8081';
                }
                return $0;
            }
        }),
        fis.plugin('local-deliver')
    ]
});

或者

function replacer(opt) {
    if (!Array.isArray(opt)) {
        opt = [opt];
    }
    var r = [];
    opt.forEach(function (raw) {
        r.push(fis.plugin('replace', raw));
    });
    return r;
};

fis.match('*', {
    deploy: replacer([
        {
            from: 'a',
            to: 'b',
        },
        {
            from: 'a0',
            to: 'b0'
        }
    ]).concat(fis.plugin('local-deliver'));
});

文件替换

fis.match('**', {
    deploy: [
        fis.plugin('replace', {
            from: '__zhTranslate()',
            to: 'i18n/zh_CN.json',
            type: 'file'
        }),
        fis.plugin('local-deliver')
    ]
});