chore(cli): add changelog template files

This commit is contained in:
陈嘉涵 2019-12-28 22:11:39 +08:00
parent 4377a1f3aa
commit 2299879dff
7 changed files with 39 additions and 38 deletions

View File

@ -19,10 +19,10 @@
"test": "vant-cli test", "test": "vant-cli test",
"build": "vant-cli build", "build": "vant-cli build",
"release": "vant-cli release", "release": "vant-cli release",
"changelog": "vant-cli changelog",
"test:watch": "vant-cli test --watch", "test:watch": "vant-cli test --watch",
"release:site": "sh docs/site/release.sh", "release:site": "sh docs/site/release.sh",
"test:coverage": "open test/coverage/index.html", "test:coverage": "open test/coverage/index.html"
"changelog": "vant-cli changelog ./changelog.generated.md --tag 2.3.0"
}, },
"husky": { "husky": {
"hooks": { "hooks": {

View File

@ -17,6 +17,7 @@
"files": [ "files": [
"lib", "lib",
"site", "site",
"template",
"preset.js" "preset.js"
], ],
"author": "chenjiahan", "author": "chenjiahan",

View File

@ -1,41 +1,18 @@
import { join } from 'path'; import { join } from 'path';
import { ROOT } from '../common/constant'; import { ROOT } from '../common/constant';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { createWriteStream } from 'fs-extra'; import { createWriteStream, readFileSync } from 'fs-extra';
// @ts-ignore // @ts-ignore
import conventionalChangelog from 'conventional-changelog'; import conventionalChangelog from 'conventional-changelog';
const file = join(ROOT, './changelog.generated.md'); const DIST_FILE = join(ROOT, './changelog.generated.md');
const MAIN_TEMPLATE = join(__dirname, '../../template/changelog-main.hbs');
const HEADER_TEMPALTE = join(__dirname, '../../template/changelog-header.hbs');
const COMMIT_TEMPALTE = join(__dirname, '../../template/changelog-commit.hbs');
const mainTemplate = `{{> header}} const mainTemplate = readFileSync(MAIN_TEMPLATE, 'utf-8');
const headerPartial = readFileSync(HEADER_TEMPALTE, 'utf-8');
{{#each commitGroups}} const commitPartial = readFileSync(COMMIT_TEMPALTE, 'utf-8');
{{#if title}}
**{{title}}**
{{/if}}
{{#each commits}}
{{> commit root=@root}}
{{/each}}
{{/each}}
{{> footer}}`;
const headerPartial = `### [v{{version}}]({{~@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}})
\`{{date}}\``;
const commitPartial = `*{{#if scope}} {{scope}}:
{{~/if}} {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}
{{#if references~}}
{{~#each references}} [{{~this.repository}}#{{this.issue}}]({{~@root.repoUrl}}/{{~@root.issue}}/{{this.issue}}){{/each}}
{{~else}} [{{shortHash}}]({{~@root.repoUrl}}/{{~@root.commit}}/{{hash}})
{{~/if}}
`;
function formatType(type: string) { function formatType(type: string) {
const MAP: Record<string, string> = { const MAP: Record<string, string> = {
@ -87,8 +64,8 @@ export function changelog() {
transform transform
} }
) )
.pipe(createWriteStream(file)) .pipe(createWriteStream(DIST_FILE))
.on('close', () => { .on('close', () => {
logger.success(`Generated changelog at ${file}`); logger.success(`Generated changelog at ${DIST_FILE}`);
}); });
} }

View File

@ -23,9 +23,7 @@ command('build')
command('release').action(release); command('release').action(release);
command('changelog <dir>') command('changelog').action(changelog);
.option('--tag [tag]', 'Since tag')
.action(changelog);
command('build-site').action(buildSite); command('build-site').action(buildSite);

View File

@ -0,0 +1,11 @@
*{{#if scope}} {{scope}}:
{{~/if}} {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}
{{#if references~}}
{{~#each references}} [{{~this.repository}}#{{this.issue}}]({{~@root.repoUrl}}/{{~@root.issue}}/{{this.issue}}){{/each}}
{{~else}} [{{shortHash}}]({{~@root.repoUrl}}/{{~@root.commit}}/{{hash}})
{{~/if}}

View File

@ -0,0 +1,2 @@
### [v{{version}}]({{~@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}})
`{{date}}`

View File

@ -0,0 +1,12 @@
{{> header}}
{{#each commitGroups}}
{{#if title}}
**{{title}}**
{{/if}}
{{#each commits}}
{{> commit root=@root}}
{{/each}}
{{/each}}
{{> footer}}