const Minio = require('minio')
|
const shell = require('shelljs')
|
const fs = require('fs')
|
import chalk from 'chalk'
|
const json = require('./package.json');
|
const { version } = json;
|
|
const minioClient = new Minio.Client({
|
endPoint: '192.168.10.79',
|
port: 9000,
|
useSSL: false,
|
accessKey: 'hhh',
|
secretKey: 'EXAMPLEKEY'
|
})
|
|
const TAG = '[script/build.ts]'
|
const extraFile = './script/publish-extra-info.yml'
|
const latestFile = `./release/${version}/s3/latest.yml`
|
|
function isExists(filepath: string) {
|
if (!fs.existsSync(filepath)) {
|
console.log(TAG, `File ${filepath} not exists.`)
|
}
|
return true
|
}
|
|
// TODO: 该脚本被执行多次时,会累加内容到latest.yml,可能会引起自动升级功能失效。因此,不能被执行多次
|
if (!isExists(extraFile) || !isExists(latestFile) || shell.exec(`cat ${extraFile} >> ${latestFile}`).code !== 0) {
|
console.log(TAG, chalk.green(`Append failed from ${extraFile} to ${latestFile}.`))
|
shell.exit(1)
|
}
|
console.log(TAG, chalk.green(`Append successed from ${extraFile} to ${latestFile}.`))
|
|
minioClient.fPutObject('public', 'im/artifact/lastest/win/latest.yml', latestFile, (err: any, objInfo: string) => {
|
if (err) {
|
return console.log(TAG, err)
|
}
|
console.log(TAG, chalk.green(`Upload to MinIO successed, object id: ${objInfo}.`))
|
})
|