From 4ac55ca676769a54a76c5881d40109b556f497b7 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Fri, 21 May 2021 09:45:36 -0700 Subject: [PATCH] fix(dev-infra): use template strings for release note templates (#42224) Use template strings for release note templates rather than loading `ejs` files at runtime. PR Close #42224 --- dev-infra/BUILD.bazel | 1 - dev-infra/ng-dev.js | 178 +++++++++++++++++- .../publish/release-notes/release-notes.ts | 13 +- .../release-notes/templates/BUILD.bazel | 6 - .../templates/{changelog.ejs => changelog.ts} | 10 + .../{github-release.ejs => github-release.ts} | 10 + dev-infra/release/publish/test/BUILD.bazel | 3 - 7 files changed, 202 insertions(+), 19 deletions(-) delete mode 100644 dev-infra/release/publish/release-notes/templates/BUILD.bazel rename dev-infra/release/publish/release-notes/templates/{changelog.ejs => changelog.ts} (85%) rename dev-infra/release/publish/release-notes/templates/{github-release.ejs => github-release.ts} (85%) diff --git a/dev-infra/BUILD.bazel b/dev-infra/BUILD.bazel index a45de570d1..b3ca536634 100644 --- a/dev-infra/BUILD.bazel +++ b/dev-infra/BUILD.bazel @@ -44,7 +44,6 @@ pkg_npm( "index.bzl", "//dev-infra/bazel:files", "//dev-infra/benchmark:files", - "//dev-infra/release/publish/release-notes/templates", ], substitutions = { # angular/angular should not consume it's own packages, so we use diff --git a/dev-infra/ng-dev.js b/dev-infra/ng-dev.js index 962be84f09..ad96619fc7 100755 --- a/dev-infra/ng-dev.js +++ b/dev-infra/ng-dev.js @@ -5857,6 +5857,180 @@ function buildDateStamp(date = new Date()) { return [year, month, day].join('-'); } +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +var changelogTemplate = ` + +# <%- version %><% if (title) { %> "<%- title %>"<% } %> (<%- dateStamp %>) + +<%_ +const commitsInChangelog = commits.filter(includeInReleaseNotes()); +for (const group of asCommitGroups(commitsInChangelog)) { +_%> + +### <%- group.title %> +| Commit | Description | +| -- | -- | +<%_ + for (const commit of group.commits) { +_%> +| <%- commit.shortHash %> | <%- commit.header %> | +<%_ + } +} +_%> + +<%_ +const breakingChanges = commits.filter(contains('breakingChanges')); +if (breakingChanges.length) { +_%> +## Breaking Changes + +<%_ + for (const group of asCommitGroups(breakingChanges)) { +_%> +### <%- group.title %> + +<%_ + for (const commit of group.commits) { +_%> +<%- commit.breakingChanges[0].text %> + +<%_ + } + } +} +_%> + +<%_ +const deprecations = commits.filter(contains('deprecations')); +if (deprecations.length) { +_%> +## Deprecations +<%_ + for (const group of asCommitGroups(deprecations)) { +_%> +### <%- group.title %> + +<%_ + for (const commit of group.commits) { +_%> +<%- commit.deprecations[0].text %> +<%_ + } + } +} +_%> + +<%_ +const authors = commits.filter(unique('author')).map(c => c.author).sort(); +if (authors.length === 1) { +_%> +## Special Thanks: +<%- authors[0]%> +<%_ +} +if (authors.length > 1) { +_%> +## Special Thanks: +<%- authors.slice(0, -1).join(', ') %> and <%- authors.slice(-1)[0] %> +<%_ +} +_%> +`; + +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ +var githubReleaseTemplate = ` + +# <%- version %><% if (title) { %> "<%- title %>"<% } %> (<%- dateStamp %>) + +<%_ +const commitsInChangelog = commits.filter(includeInReleaseNotes()); +for (const group of asCommitGroups(commitsInChangelog)) { +_%> + +### <%- group.title %> +| Commit | Description | +| -- | -- | +<%_ + for (const commit of group.commits) { +_%> +| <%- commit.shortHash %> | <%- commit.header %> | +<%_ + } +} +_%> + +<%_ +const breakingChanges = commits.filter(contains('breakingChanges')); +if (breakingChanges.length) { +_%> +## Breaking Changes + +<%_ + for (const group of asCommitGroups(breakingChanges)) { +_%> +### <%- group.title %> + +<%_ + for (const commit of group.commits) { +_%> +<%- commit.breakingChanges[0].text %> + +<%_ + } + } +} +_%> + +<%_ +const deprecations = commits.filter(contains('deprecations')); +if (deprecations.length) { +_%> +## Deprecations +<%_ + for (const group of asCommitGroups(deprecations)) { +_%> +### <%- group.title %> + +<%_ + for (const commit of group.commits) { +_%> +<%- commit.deprecations[0].text %> +<%_ + } + } +} +_%> + +<%_ +const authors = commits.filter(unique('author')).map(c => c.author).sort(); +if (authors.length === 1) { +_%> +## Special Thanks: +<%- authors[0]%> +<%_ +} +if (authors.length > 1) { +_%> +## Special Thanks: +<%- authors.slice(0, -1).join(', ') %> and <%- authors.slice(-1)[0] %> +<%_ +} +_%> +`; + /** Gets the path for the changelog file in a given project. */ function getLocalChangelogFilePath(projectDir) { return path.join(projectDir, changelogPath); @@ -5882,13 +6056,13 @@ class ReleaseNotes { /** Retrieve the release note generated for a Github Release. */ getGithubReleaseEntry() { return tslib.__awaiter(this, void 0, void 0, function* () { - return ejs.renderFile(path.join(__dirname, 'templates/github-release.ejs'), yield this.generateRenderContext(), { rmWhitespace: true }); + return ejs.render(githubReleaseTemplate, yield this.generateRenderContext(), { rmWhitespace: true }); }); } /** Retrieve the release note generated for a CHANGELOG entry. */ getChangelogEntry() { return tslib.__awaiter(this, void 0, void 0, function* () { - return ejs.renderFile(path.join(__dirname, 'templates/changelog.ejs'), yield this.generateRenderContext(), { rmWhitespace: true }); + return ejs.render(changelogTemplate, yield this.generateRenderContext(), { rmWhitespace: true }); }); } /** diff --git a/dev-infra/release/publish/release-notes/release-notes.ts b/dev-infra/release/publish/release-notes/release-notes.ts index 5b2e6aff55..0d756df255 100644 --- a/dev-infra/release/publish/release-notes/release-notes.ts +++ b/dev-infra/release/publish/release-notes/release-notes.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {renderFile} from 'ejs'; +import {render} from 'ejs'; import {join} from 'path'; import * as semver from 'semver'; import {CommitFromGitLog} from '../../../commit-message/parse'; @@ -17,6 +17,9 @@ import {DevInfraReleaseConfig, getReleaseConfig, ReleaseNotesConfig} from '../.. import {changelogPath} from '../constants'; import {RenderContext} from './context'; +import changelogTemplate from './templates/changelog'; +import githubReleaseTemplate from './templates/github-release'; + /** Gets the path for the changelog file in a given project. */ export function getLocalChangelogFilePath(projectDir: string): string { return join(projectDir, changelogPath); @@ -45,16 +48,12 @@ export class ReleaseNotes { /** Retrieve the release note generated for a Github Release. */ async getGithubReleaseEntry(): Promise { - return renderFile( - join(__dirname, 'templates/github-release.ejs'), await this.generateRenderContext(), - {rmWhitespace: true}); + return render(githubReleaseTemplate, await this.generateRenderContext(), {rmWhitespace: true}); } /** Retrieve the release note generated for a CHANGELOG entry. */ async getChangelogEntry() { - return renderFile( - join(__dirname, 'templates/changelog.ejs'), await this.generateRenderContext(), - {rmWhitespace: true}); + return render(changelogTemplate, await this.generateRenderContext(), {rmWhitespace: true}); } /** diff --git a/dev-infra/release/publish/release-notes/templates/BUILD.bazel b/dev-infra/release/publish/release-notes/templates/BUILD.bazel deleted file mode 100644 index af8c1453dd..0000000000 --- a/dev-infra/release/publish/release-notes/templates/BUILD.bazel +++ /dev/null @@ -1,6 +0,0 @@ -package(default_visibility = ["//dev-infra:__subpackages__"]) - -filegroup( - name = "templates", - srcs = glob(["*.ejs"]), -) diff --git a/dev-infra/release/publish/release-notes/templates/changelog.ejs b/dev-infra/release/publish/release-notes/templates/changelog.ts similarity index 85% rename from dev-infra/release/publish/release-notes/templates/changelog.ejs rename to dev-infra/release/publish/release-notes/templates/changelog.ts index df335f515d..8b96d62531 100644 --- a/dev-infra/release/publish/release-notes/templates/changelog.ejs +++ b/dev-infra/release/publish/release-notes/templates/changelog.ts @@ -1,3 +1,12 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export default ` # <%- version %><% if (title) { %> "<%- title %>"<% } %> (<%- dateStamp %>) @@ -75,3 +84,4 @@ _%> <%_ } _%> +`; diff --git a/dev-infra/release/publish/release-notes/templates/github-release.ejs b/dev-infra/release/publish/release-notes/templates/github-release.ts similarity index 85% rename from dev-infra/release/publish/release-notes/templates/github-release.ejs rename to dev-infra/release/publish/release-notes/templates/github-release.ts index df335f515d..8b96d62531 100644 --- a/dev-infra/release/publish/release-notes/templates/github-release.ejs +++ b/dev-infra/release/publish/release-notes/templates/github-release.ts @@ -1,3 +1,12 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export default ` # <%- version %><% if (title) { %> "<%- title %>"<% } %> (<%- dateStamp %>) @@ -75,3 +84,4 @@ _%> <%_ } _%> +`; diff --git a/dev-infra/release/publish/test/BUILD.bazel b/dev-infra/release/publish/test/BUILD.bazel index 3bb2a41242..b958bdb9c2 100644 --- a/dev-infra/release/publish/test/BUILD.bazel +++ b/dev-infra/release/publish/test/BUILD.bazel @@ -33,8 +33,5 @@ jasmine_node_test( # enabled in NodeJS. TODO: Remove this with rules_nodejs 3.x where patching is optional. # https://github.com/bazelbuild/rules_nodejs/commit/7d070ffadf9c3b41711382a4737b995f987c14fa. args = ["--nobazel_patch_module_resolver"], - data = [ - "//dev-infra/release/publish/release-notes/templates", - ], deps = [":test_lib"], )