From 2299879dff607132fb83b996dd554c4f4b05c316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Sat, 28 Dec 2019 22:11:39 +0800 Subject: [PATCH] chore(cli): add changelog template files --- package.json | 4 +- packages/vant-cli/package.json | 1 + packages/vant-cli/src/commands/changelog.ts | 43 +++++-------------- packages/vant-cli/src/index.ts | 4 +- .../vant-cli/template/changelog-commit.hbs | 11 +++++ .../vant-cli/template/changelog-header.hbs | 2 + packages/vant-cli/template/changelog-main.hbs | 12 ++++++ 7 files changed, 39 insertions(+), 38 deletions(-) create mode 100644 packages/vant-cli/template/changelog-commit.hbs create mode 100644 packages/vant-cli/template/changelog-header.hbs create mode 100644 packages/vant-cli/template/changelog-main.hbs diff --git a/package.json b/package.json index f69b7f1ab..3984989c9 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,10 @@ "test": "vant-cli test", "build": "vant-cli build", "release": "vant-cli release", + "changelog": "vant-cli changelog", "test:watch": "vant-cli test --watch", "release:site": "sh docs/site/release.sh", - "test:coverage": "open test/coverage/index.html", - "changelog": "vant-cli changelog ./changelog.generated.md --tag 2.3.0" + "test:coverage": "open test/coverage/index.html" }, "husky": { "hooks": { diff --git a/packages/vant-cli/package.json b/packages/vant-cli/package.json index f8779350c..dbcba7c8c 100644 --- a/packages/vant-cli/package.json +++ b/packages/vant-cli/package.json @@ -17,6 +17,7 @@ "files": [ "lib", "site", + "template", "preset.js" ], "author": "chenjiahan", diff --git a/packages/vant-cli/src/commands/changelog.ts b/packages/vant-cli/src/commands/changelog.ts index eff1e6760..3f4f389f0 100644 --- a/packages/vant-cli/src/commands/changelog.ts +++ b/packages/vant-cli/src/commands/changelog.ts @@ -1,41 +1,18 @@ import { join } from 'path'; import { ROOT } from '../common/constant'; import { logger } from '../common/logger'; -import { createWriteStream } from 'fs-extra'; +import { createWriteStream, readFileSync } from 'fs-extra'; // @ts-ignore 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}} - -{{#each commitGroups}} - -{{#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}} - -`; +const mainTemplate = readFileSync(MAIN_TEMPLATE, 'utf-8'); +const headerPartial = readFileSync(HEADER_TEMPALTE, 'utf-8'); +const commitPartial = readFileSync(COMMIT_TEMPALTE, 'utf-8'); function formatType(type: string) { const MAP: Record = { @@ -87,8 +64,8 @@ export function changelog() { transform } ) - .pipe(createWriteStream(file)) + .pipe(createWriteStream(DIST_FILE)) .on('close', () => { - logger.success(`Generated changelog at ${file}`); + logger.success(`Generated changelog at ${DIST_FILE}`); }); } diff --git a/packages/vant-cli/src/index.ts b/packages/vant-cli/src/index.ts index c945ed59d..294ed4f7c 100755 --- a/packages/vant-cli/src/index.ts +++ b/packages/vant-cli/src/index.ts @@ -23,9 +23,7 @@ command('build') command('release').action(release); -command('changelog ') - .option('--tag [tag]', 'Since tag') - .action(changelog); +command('changelog').action(changelog); command('build-site').action(buildSite); diff --git a/packages/vant-cli/template/changelog-commit.hbs b/packages/vant-cli/template/changelog-commit.hbs new file mode 100644 index 000000000..6c885fe84 --- /dev/null +++ b/packages/vant-cli/template/changelog-commit.hbs @@ -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}} + diff --git a/packages/vant-cli/template/changelog-header.hbs b/packages/vant-cli/template/changelog-header.hbs new file mode 100644 index 000000000..335c7f541 --- /dev/null +++ b/packages/vant-cli/template/changelog-header.hbs @@ -0,0 +1,2 @@ +### [v{{version}}]({{~@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}}) +`{{date}}` diff --git a/packages/vant-cli/template/changelog-main.hbs b/packages/vant-cli/template/changelog-main.hbs new file mode 100644 index 000000000..708f5b8be --- /dev/null +++ b/packages/vant-cli/template/changelog-main.hbs @@ -0,0 +1,12 @@ +{{> header}} +{{#each commitGroups}} + +{{#if title}} +**{{title}}** + +{{/if}} +{{#each commits}} +{{> commit root=@root}} +{{/each}} +{{/each}} +{{> footer}}