зеркало из https://github.com/github/docs.git
Script to create webhook payload files for a new version (#16393)
* new script to create webhook payload files for new version * version does not have to be a GHES version * remove newline
This commit is contained in:
Родитель
a6f976cc69
Коммит
cf82c63698
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
const mkdirp = require('mkdirp').sync
|
||||
const path = require('path')
|
||||
const program = require('commander')
|
||||
const allVersions = require('../lib/all-versions')
|
||||
|
||||
// [start-readme]
|
||||
//
|
||||
// This script creates new static webhook payload files for a new version.
|
||||
//
|
||||
// [end-readme]
|
||||
|
||||
program
|
||||
.description('Create new payload files in lib/webhooks/static/<new_version> based on an existing version.')
|
||||
.option('-n, --newVersion <version>', 'The version to copy the payloads to. Must be in <plan@release> format.')
|
||||
.option('-o, --oldVersion <version>', 'The version to copy the payloads from. Must be in <plan@release> format.')
|
||||
.parse(process.argv)
|
||||
|
||||
if (!(program.newVersion && program.oldVersion)) {
|
||||
console.log('Error! You must provide --newVersion and --oldVersion.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!(Object.keys(allVersions).includes(program.newVersion) && Object.keys(allVersions).includes(program.oldVersion))) {
|
||||
console.log('Error! You must provide the full name of a supported version, e.g., enterprise-server@2.22.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const newVersionDirName = allVersions[program.newVersion].miscVersionName
|
||||
const oldVersionDirName = allVersions[program.oldVersion].miscVersionName
|
||||
|
||||
const payloadsDir = 'lib/webhooks/static'
|
||||
const srcDir = path.join(payloadsDir, oldVersionDirName)
|
||||
const destDir = path.join(payloadsDir, newVersionDirName)
|
||||
|
||||
// create the new directory
|
||||
mkdirp(destDir)
|
||||
|
||||
// copy the files
|
||||
fs.readdirSync(srcDir).forEach(file => {
|
||||
const srcFile = path.join(srcDir, file)
|
||||
const destFile = path.join(destDir, file)
|
||||
fs.copyFileSync(srcFile, destFile)
|
||||
})
|
||||
|
||||
// check that it worked
|
||||
if (!fs.existsSync(destDir)) {
|
||||
console.log(`Error! A new directory was not successfully created at ${destDir}.`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!fs.readdirSync(destDir).length) {
|
||||
console.log(`Error! The directory created at ${destDir} is empty.`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// print success message
|
||||
console.log(`Done! Copied ${srcDir} to ${destDir}.`)
|
Загрузка…
Ссылка в новой задаче