Merge branch 'command-init'

This commit is contained in:
Yanick Champoux 2023-05-10 10:29:06 -04:00
commit 7771f39676
5 changed files with 122 additions and 1 deletions

27
CHANGELOG.yml Normal file
View File

@ -0,0 +1,27 @@
project:
name: null
homepage: null
with_stats: true
ticket_url: null
releases:
- version: NEXT
changes: []
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

View File

@ -2,7 +2,11 @@
"name": "changelord",
"version": "0.0.1",
"description": "cli-based changelog manager",
"main": "dist/index.js",
"type": "module",
"main": "src/index.js",
"bin": {
"changelord": "./src/changelord.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@ -12,6 +16,12 @@
"author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca/)",
"license": "ISC",
"dependencies": {
"consola": "^3.1.0",
"fs-extra": "^11.1.1",
"yaml": "^2.2.2",
"yargs": "^17.7.2"
},
"devDependencies": {
"prettier": "^2.8.8"
}
}

18
src/changelord.js Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env node
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs';
import { join } from 'path';
import print from './command/print.js'
import init from './command/init.js'
yargs(hideBin(process.argv))
.default('source', join( process.cwd(), 'CHANGELOG.yml' ))
.describe('source', 'changelog source')
.command({
...print,
command: '$0',
})
.command(init)
.command(print).help().parse();

50
src/command/init.js Normal file
View File

@ -0,0 +1,50 @@
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,
}

16
src/command/print.js Normal file
View File

@ -0,0 +1,16 @@
const handler = (...args) => {
console.log('hi!',args);
};
export default {
command: 'print',
desc : 'render the changelog',
builder: (yargs) => {
yargs.boolean('json')
.boolean('next')
.default('json',false)
.default('next',true);
},
handler,
}