1 | #!/usr/bin/env node
|
2 | const fs = require('fs-extra')
|
3 | const execa = require('execa')
|
4 | const path = require('path')
|
5 |
|
6 | const package = require(path.join(__dirname, '../package.json'))
|
7 | const wd = path.join(__dirname, '../standalone')
|
8 | const v = package.version
|
9 | const name = package.name
|
10 |
|
11 | const plats = ['macos', 'win.exe', 'linux']
|
12 | const repo = 'github.com/jondot/homebrew-tap'
|
13 |
|
14 | const main = async () => {
|
15 | for (const plat of plats) {
|
16 | console.log(`standalone: packing ${plat}`)
|
17 | const file = `${name}-${plat}`
|
18 |
|
19 | await fs.remove(`${wd}/tar-${file}`)
|
20 | await fs.mkdir(`${wd}/tar-${file}`)
|
21 |
|
22 | if(plat === 'win.exe'){
|
23 | await fs.move(`${wd}/${file}`, `${wd}/tar-${file}/hygen.exe`)
|
24 | await execa.shell(
|
25 | `cd ${wd}/tar-${file} && zip ../hygen.${plat}.v${v}.zip hygen.exe`
|
26 | )
|
27 | } else {
|
28 | await fs.move(`${wd}/${file}`, `${wd}/tar-${file}/hygen`)
|
29 | await execa.shell(
|
30 | `cd ${wd}/tar-${file} && tar -czvf ../hygen.${plat}.v${v}.tar.gz hygen`
|
31 | )
|
32 | }
|
33 | await fs.remove(`${wd}/tar-${file}`)
|
34 | }
|
35 |
|
36 | console.log('standalone: done.')
|
37 | console.log((await execa.shell(`ls ${wd}`)).stdout)
|
38 |
|
39 | console.log('standalone: publishing to homebrew tap...')
|
40 | const matches = (await execa.shell(
|
41 | `shasum -a 256 ${wd}/hygen.macos.v${v}.tar.gz`
|
42 | )).stdout.match(/([a-f0-9]+)\s+/)
|
43 | console.log(matches)
|
44 | if (matches && matches.length > 1) {
|
45 | const sha = matches[1]
|
46 | await fs.writeFile('/tmp/hygen.rb', brewFormula(sha, v))
|
47 | const cmd = [
|
48 | `cd /tmp`,
|
49 | `git clone git://${repo} brew-tap`,
|
50 | `cd brew-tap`,
|
51 | `mv /tmp/hygen.rb .`,
|
52 | `git config user.email jondotan@gmail.com`,
|
53 | `git config user.name 'Dotan Nahum'`,
|
54 | `git add .`,
|
55 | `git commit -m 'hygen: auto-release'`,
|
56 | `git push https://${process.env.GITHUB_TOKEN}@${repo}`
|
57 | ].join(' && ')
|
58 | console.log(await execa.shell(cmd).stdout)
|
59 |
|
60 | console.log('standalone: publish done.')
|
61 | }
|
62 | }
|
63 |
|
64 | const brewFormula = (sha, ver) => `
|
65 | VER = "${ver}"
|
66 | SHA = "${sha}"
|
67 |
|
68 | class Hygen < Formula
|
69 | desc "The scalable code generator that saves you time."
|
70 | homepage "http://www.hygen.io"
|
71 | url "https://github.com/jondot/hygen/releases/download/v#{VER}/hygen.macos.v#{VER}.tar.gz"
|
72 | version VER
|
73 | sha256 SHA
|
74 |
|
75 | def install
|
76 | bin.install "hygen"
|
77 | end
|
78 | end
|
79 | `
|
80 | main()
|