he wei
2022-11-17 cd327dcbaca3476df44b064e56b950dc054cbb87
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
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}.`))
})