|
| 1 | +const path = require('path') |
| 2 | +const fs = require('fs-extra') |
| 3 | +const crypto = require('crypto') |
| 4 | + |
| 5 | +const pkg = require('../package.json') |
| 6 | +const plugAppcast = require('../appcast.json') |
| 7 | +const githubRelease = `https://github.com/geekdada/bob-plugin-deepl-translate/releases/download` |
| 8 | + |
| 9 | +function main() { |
| 10 | + const pkgName = 'bob-plugin-deepl-translate' |
| 11 | + const pkgPath = path.join( |
| 12 | + __dirname, |
| 13 | + `../release/${pkgName}-v${pkg.version}.bobplugin`, |
| 14 | + ) |
| 15 | + const appcastPath = path.join(__dirname, '../appcast.json') |
| 16 | + |
| 17 | + const fileBuffer = fs.readFileSync(pkgPath) |
| 18 | + const sum = crypto.createHash('sha256') |
| 19 | + sum.update(fileBuffer) |
| 20 | + const hex = sum.digest('hex') |
| 21 | + |
| 22 | + const version = { |
| 23 | + version: pkg.version, |
| 24 | + desc: |
| 25 | + 'https://github.com/geekdada/bob-plugin-deepl-translate/blob/master/CHANGELOG.md', |
| 26 | + sha256: hex, |
| 27 | + url: `${githubRelease}/v${pkg.version}/${pkgName}-v${pkg.version}.bobplugin`, |
| 28 | + minBobVersion: '0.5.0', |
| 29 | + } |
| 30 | + |
| 31 | + let versions = (plugAppcast && plugAppcast.versions) || [] |
| 32 | + |
| 33 | + if (!Array.isArray(versions)) versions = [] |
| 34 | + |
| 35 | + const index = versions.findIndex((v) => v.version === pkg.version) |
| 36 | + |
| 37 | + if (index === -1) { |
| 38 | + versions.splice(0, 0, version) |
| 39 | + } else { |
| 40 | + versions.splice(index, 1, version) |
| 41 | + } |
| 42 | + |
| 43 | + const appcastData = { |
| 44 | + identifier: 'dev.royli.bob-plugin-deepl-translate', |
| 45 | + versions, |
| 46 | + } |
| 47 | + |
| 48 | + fs.outputJSONSync(appcastPath, appcastData, { spaces: 2 }) |
| 49 | +} |
| 50 | + |
| 51 | +main() |
0 commit comments