2022-09-10 21:55:53 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Command } from '@commander-js/extra-typings';
|
2023-04-27 22:16:19 +00:00
|
|
|
import { Logger } from '@woocommerce/monorepo-utils/src/core/logger';
|
2022-09-10 21:55:53 +00:00
|
|
|
import { writeFile } from 'fs/promises';
|
|
|
|
import { tmpdir } from 'os';
|
|
|
|
import { join } from 'path';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { generateContributors } from '../../lib/contributors';
|
|
|
|
import { renderTemplate } from '../../lib/render-template';
|
|
|
|
|
|
|
|
// Define the contributors command
|
|
|
|
const program = new Command()
|
|
|
|
.command( 'contributors' )
|
|
|
|
.description( 'CLI to automate generation of a release post.' )
|
|
|
|
.argument(
|
|
|
|
'<currentVersion>',
|
|
|
|
'The version of the plugin to generate a post for, please use the tag version from Github.'
|
|
|
|
)
|
|
|
|
.argument(
|
|
|
|
'--previousVersion <previousVersion>',
|
|
|
|
'If you would like to compare against a version other than last minor you can provide a tag version from Github.'
|
|
|
|
)
|
|
|
|
.action( async ( currentVersion, previousVersion ) => {
|
|
|
|
Logger.startTask( 'Generating contributors list...' );
|
|
|
|
|
|
|
|
const contributors = await generateContributors(
|
|
|
|
currentVersion,
|
|
|
|
previousVersion.toString()
|
|
|
|
);
|
|
|
|
|
|
|
|
Logger.endTask();
|
|
|
|
|
|
|
|
const html = await renderTemplate( 'contributors.ejs', {
|
|
|
|
contributors,
|
|
|
|
} );
|
|
|
|
|
|
|
|
const tmpFile = join(
|
|
|
|
tmpdir(),
|
2023-03-07 15:13:15 +00:00
|
|
|
`contributors-${ currentVersion.replace( '/', '-' ) }.html`
|
2022-09-10 21:55:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await writeFile( tmpFile, html );
|
|
|
|
|
|
|
|
Logger.notice( `Contributors HTML generated at ${ tmpFile }` );
|
|
|
|
} );
|
|
|
|
|
|
|
|
program.parse( process.argv );
|