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AEpB,IAAK,EAAU,YACX,MAAM,IAAI,MAAM,mCAEpB,IAAK,EAAU,gBACX,MAAM,IAAI,MAAM,uCAEpB,IAAK,EAAU,OACX,MAAM,IAAI,MAAM,8BAEf,EAAU,UACX,EAAU,QAAU,IAGhC,CACA,MAAO,CACH,MAAO,MAAM,KAAK,KAAM,GAEhC","file":"/npm/webpack-nexus-upload-plugin@1.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/webpack-nexus-upload-plugin@1.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * Created by oyhanyu on 2017/9/14.\n * webpack plugin for detail the files of webpack compiled with your own way, such as OSS, S3 etc.\n */\n\nvar fs = require('fs');\nvar uploadArr = []\nfunction uploadFiles (options, filename, source, callback) {\n    var result;\n    try {\n        if (options.upload && typeof options.upload === 'function') {\n            options.upload.call(null, filename, source)\n        } else {\n            // ali oss default\n            var OSS = require('ali-oss');\n            var client = new OSS.Wrapper(options.aliOSS);\n            result = client.put(options.aliOSS.fileDir + filename, source)\n                .then(function (val) {\n                    console.log(filename + ' upload success, url=%j', val.url);\n                    return true;\n                })\n                .catch (function (err) {\n                    console.log(filename + ' upload failed: error=%j', err.toString());\n                    callback(new Error('webpack build failed, reason: file' + filename + ' upload failed!'))\n                    return false;\n                });\n            uploadArr.push(result);\n        }\n    } catch (e) {\n      callback(new Error('remote upload failed!'))\n    }\n}\nfunction apply(options, compiler) {\n    //\n    compiler.plugin(\"after-emit\", function(compilation, callback) {\n        console.log(\"The compilation is going to handle files...\");\n        var basePath = options.path;\n        for (var filename in compilation.assets) {\n            var stream = fs.createReadStream(basePath + '/' + filename);\n            uploadFiles(options, filename, stream, callback)\n        }\n        Promise.all(uploadArr).then((result) => {\n            if (result.length && !result.includes(false)) {\n              console.log('build success')\n              callback();\n            } else {\n              callback(new Error('webpack build failed, reason: some files upload failed!'))\n            }\n        });\n    });\n}\nmodule.exports = function(options) {\n    // validate the options\n    if (!options.path || options.path === '') {\n        throw new Error('publish path is required!')\n    } else if (!options.upload || typeof options.upload !== 'function') {\n        if (!options.aliOSS) {\n            throw new Error('Must contain one of upload function and aliOSS !')\n        } else {\n            var aliOssOpt = options.aliOSS;\n            if (!aliOssOpt.region) {\n                throw new Error('aliOSS region is required!')\n            }\n            if (!aliOssOpt.accessKeyId) {\n                throw new Error('aliOSS accessKeyId is required!')\n            }\n            if (!aliOssOpt.accessKeySecret) {\n                throw new Error('aliOSS accessKeySecret is required!')\n            }\n            if (!aliOssOpt.bucket) {\n                throw new Error('aliOSS bucket is required!')\n            }\n            if (!aliOssOpt.fileDir) {\n                aliOssOpt.fileDir = '/';\n            }\n        }\n    }\n    return {\n        apply: apply.bind(this, options)\n    };\n};"]}