Allow saving github token to a file

This commit is contained in:
Pavel Djundik 2019-08-05 15:33:31 +03:00
parent 9ad785c44e
commit 3c9ba130a0
2 changed files with 14 additions and 4 deletions

1
scripts/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
github_token.txt

View file

@ -48,25 +48,34 @@ node scripts/changelog <version>
const _ = require("lodash");
const colors = require("chalk");
const fs = require("fs");
const path = require("path");
const GraphQLClient = require("graphql-request").GraphQLClient;
const moment = require("moment");
const semver = require("semver");
const util = require("util");
const log = require("../src/log");
const packageJson = require("../package.json");
const token = process.env.CHANGELOG_TOKEN;
let token = process.env.CHANGELOG_TOKEN;
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const changelogPath = "./CHANGELOG.md";
const changelogPath = path.resolve(__dirname, "..", "CHANGELOG.md");
// CLI argument validations
if (token === undefined) {
try {
token = fs
.readFileSync(path.resolve(__dirname, "./github_token.txt"))
.toString()
.trim();
} catch (e) {
log.error(`Environment variable ${colors.bold("CHANGELOG_TOKEN")} must be set.`);
log.error(`Alternative create ${colors.bold("scripts/github_token.txt")} file.`);
process.exit(1);
}
}
if (process.argv[2] === undefined) {
log.error(`Argument ${colors.bold("version")} is missing`);