changelord.js/src/command/init.js

51 lines
1.3 KiB
JavaScript

import fs from 'fs-extra';
import { consola } from 'consola';
import { stringify } from 'yaml';
const change_types = [
{ title: 'Features' , level: 'minor', keywords: [ 'feat' ] } ,
{ title : 'Bug fixes' , level : 'patch', keywords : [ 'fix' ] },
{ title : 'Package maintenance' , level : 'patch', keywords : [ 'chore', 'maint', 'refactor' ] },
{ title : 'Statistics' , level : 'patch', keywords : [ 'stats' ] },
];
const base_changelog = {
project: {
name: null,
homepage: null,
with_stats: true,
ticket_url: null,
},
releases: [
{ version: 'NEXT', changes: [] }
],
change_types,
};
const handler = async (config) => {
if( await fs.pathExists(config.source) ) {
consola.error(`${config.source} already exist, aborting.`);
process.exit();
}
consola.start(`creating ${config.source}...`);
await fs.writeFile( config.source, stringify(base_changelog) );
consola.success('done!');
};
export default {
command: 'init',
desc : 'initialize new changelog source file',
builder: (yargs) => {
yargs.boolean('json')
.boolean('next')
.default('json',false)
.default('next',true);
},
handler,
}