Skip to content

Commit

Permalink
repo sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Octomerger authored Nov 6, 2020
2 parents 3e78db7 + 930875c commit 991c005
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions script/create-webhooks-for-new-version.js
Original file line number Diff line number Diff line change
@@ -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., [email protected].')
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}.`)

0 comments on commit 991c005

Please sign in to comment.