-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkVersionNumber.js
70 lines (61 loc) · 2.11 KB
/
checkVersionNumber.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const fs = require('fs')
const path = require('path')
const identifyPluginFile = (file) => {
const pluginFile = fs.readFileSync(file, 'utf8')
const fileByLine = pluginFile.split(/\r?\n/)
let pluginIdentified = false
fileByLine.forEach(line => {
if(line.includes("use base qw(Koha::Plugins::Base)")){
pluginIdentified = true
}
})
return pluginIdentified
}
const collectPluginFiles = (fullPath) => {
let files = []
fs.readdirSync(fullPath).forEach(file => {
const absolutePath = path.join(fullPath, file)
if (fs.statSync(absolutePath).isDirectory()) {
const filesFromNestedFolder = collectPluginFiles(absolutePath)
filesFromNestedFolder && filesFromNestedFolder.forEach(file => {
files.push(file)
})
} else {
return files.push(absolutePath)
}
})
return files
}
const pluginFiles = collectPluginFiles('./Koha')
let pluginFilePath
pluginFiles.forEach(file => {
const pluginFile = identifyPluginFile(file)
if(pluginFile) {
pluginFilePath = file
}
})
if(!pluginFilePath) return console.log('No plugin file found')
const cliInput = process.argv.slice(2)[0]
if(cliInput === 'filename') {
const filename = pluginFilePath.replace(/^.*[\\\/]/, '').toLowerCase()
const removeFileExtension = path.parse(filename).name
const kpzFileName = `koha-plugin-${removeFileExtension}.kpz`
console.log(kpzFileName)
}
if(cliInput === 'version') {
const pluginFile = fs.readFileSync(pluginFilePath, 'utf8')
const fileByLine = pluginFile.split(/\r?\n/)
let versionNumberIdentified
fileByLine.forEach((line, index)=> {
if(line.includes("our $VERSION")){
versionNumberIdentified = index
}
})
if(!versionNumberIdentified) return console.log('No version found')
if(versionNumberIdentified) {
const regex = /"(.*?)"/
const findVersionNumber = regex.exec(fileByLine[versionNumberIdentified])
const pluginVersion = findVersionNumber[1]
console.log(`v${pluginVersion}`)
}
}