-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruby.js
42 lines (32 loc) · 1016 Bytes
/
ruby.js
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
40
41
42
const io = require("@actions/io")
const { readFile } = require("fs")
const { promisify } = require("util")
const { easyExec } = require('./utils')
const readFileAsync = promisify(readFile)
let gemVersion = null
async function getGemVersion() {
if (gemVersion) return gemVersion
await readFileAsync("Gemfile.lock").then((data) => {
const match = data.toString().match(/prettier \((?<version>[\d.]+)\)/)
if (match) {
gemVersion = match.groups.version
} else {
console.log("No prettier gem found in Gemfile.lock. Skipping..." )
}
}).catch((error) => {
console.error(error)
})
return gemVersion
}
exports.setup = async function setup() {
const version = await getGemVersion()
await io.mv("Gemfile", "Gemfile.bak")
if (version) {
await easyExec(["gem install prettier -v", version].join(" "))
}
}
exports.teardown = async function teardown() {
await io.mv("Gemfile.bak", "Gemfile")
}
exports.packageMatcher = /prettier\/plugin-ruby/
exports.name = "Ruby"