forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.`) |