build-scripts/newChange.ts (45 lines of code) (raw):

/*! * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: MIT */ import * as child_process from 'child_process' import * as fs from 'fs-extra' import { join } from 'path' import * as readlineSync from 'readline-sync' import { v4 as uuid } from 'uuid' const directory = '.changes/next-release' const changeTypes = ['Breaking Change', 'Feature', 'Bug Fix', 'Deprecation', 'Removal', 'Test'] interface NewChange { type: string description: string } function promptForType(): string { while (true) { const response = readlineSync.keyInSelect(changeTypes, 'Please enter the type of change') if (response === -1) { console.log('Cancelling change') process.exit(0) } if (response >= 0 && response < changeTypes.length) { return changeTypes[response] } console.log('Invalid change type, change type must be between 0 and 5') } } function promptForChange(): string { while (true) { const response = readlineSync.question('Change message: ').trim() if (response) { return response } } } fs.mkdirpSync(directory) const type = promptForType() const description = promptForChange() const contents: NewChange = { type: type, description: description } const fileName = `${type}-${uuid()}.json` const path = join(directory, fileName) fs.writeFileSync(path, JSON.stringify(contents, undefined, '\t')) console.log(`Change log written to ${path}`) child_process.execSync(`git add ${directory}`) console.log('Change log added to git working directory')