diff --git a/presentation-rules-editor-react/CHANGELOG.md b/presentation-rules-editor-react/CHANGELOG.md index ab83e5e..52d0294 100644 --- a/presentation-rules-editor-react/CHANGELOG.md +++ b/presentation-rules-editor-react/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/iTwin/presentation-rules-editor/tree/HEAD) +## [0.1.0](https://github.com/iTwin/presentation-rules-editor/tree/v0.1.0) - 2022-04-04 + ### Added - `EditableRuleset`: Represents a ruleset with dynamic content. It acts as the main communication channel between different components in this package. diff --git a/presentation-rules-editor-react/package.json b/presentation-rules-editor-react/package.json index 6812600..1f66e6b 100644 --- a/presentation-rules-editor-react/package.json +++ b/presentation-rules-editor-react/package.json @@ -1,7 +1,7 @@ { "name": "@itwin/presentation-rules-editor-react", "description": "iTwin.js Presentation Rules Editor React components", - "version": "0.0.1", + "version": "0.1.0", "scripts": { "build": "run-p build:* copy:*", "build:cjs": "tsc --project tsconfig.build.json --outDir ./lib/cjs --module CommonJS", @@ -12,7 +12,8 @@ "test:cover": "nyc npm test", "lint": "eslint **/*.{ts,tsx}", "typecheck": "tsc --noEmit", - "typecheck:watch": "tsc --noEmit --watch" + "typecheck:watch": "tsc --noEmit --watch", + "release": "ts-node --transpile-only ../scripts/src/finalizeRelease.ts" }, "license": "MIT", "private": true, diff --git a/presentation-rules-editor-react/publish.yaml b/presentation-rules-editor-react/publish.yaml index 7c60f26..ca38ebf 100644 --- a/presentation-rules-editor-react/publish.yaml +++ b/presentation-rules-editor-react/publish.yaml @@ -75,5 +75,3 @@ stages: parameters: path: $(tarballName) artifactName: published-package - dryrun: true - releaseTag: pre-release diff --git a/scripts/src/finalizeRelease.ts b/scripts/src/finalizeRelease.ts new file mode 100644 index 0000000..0bffe5a --- /dev/null +++ b/scripts/src/finalizeRelease.ts @@ -0,0 +1,73 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Bentley Systems, Incorporated. All rights reserved. +* See LICENSE.md in the project root for license terms and full copyright notice. +*--------------------------------------------------------------------------------------------*/ +import { execSync } from "child_process"; +import * as fs from "fs"; +import * as path from "path"; + +const packageJsonFilePath = path.join(process.cwd(), "package.json"); +if (!fs.existsSync(packageJsonFilePath)) { + console.error(`File "${packageJsonFilePath}" does not exist.`); + process.exit(1); +} + +const packageJson = JSON.parse(String(fs.readFileSync(packageJsonFilePath))); +const packageName: string = packageJson.name; +if (!packageName) { + console.error("Could not obtain package name."); + process.exit(1); +} + +const packageVersion: string = packageJson.version; +if (!packageVersion) { + console.error("Could not obtain package version."); + process.exit(1); +} + +const changelogFilePath = path.join(process.cwd(), "CHANGELOG.md"); +if (!fs.existsSync(changelogFilePath)) { + console.error(`File "${changelogFilePath}" does not exist.`); + process.exit(1); +} + +const changelogContent = String(fs.readFileSync(changelogFilePath)); +const unreleasedHeaderStartPosition = changelogContent.indexOf("## [Unreleased]"); +if (unreleasedHeaderStartPosition === -1) { + console.error("Could not find Unreleased section."); + process.exit(1); +} + +const unreleasedHeaderEndPosition = changelogContent.indexOf("\n", unreleasedHeaderStartPosition); +if (unreleasedHeaderEndPosition === -1) { + console.error("Changelog file cannot end with Unreleased section without listed changes."); + process.exit(1); +} + +const unreleasedHeader = changelogContent.substring(unreleasedHeaderStartPosition, unreleasedHeaderEndPosition); +const releaseHeader = unreleasedHeader + .replace("Unreleased", packageVersion) + .replace("HEAD", `v${packageVersion}`) + .concat(` - ${formatDate(new Date())}`); + +const updatedChangelogContent = changelogContent + .slice(0, unreleasedHeaderEndPosition) + .concat("\n\n", releaseHeader, changelogContent.slice(unreleasedHeaderEndPosition)); + +fs.writeFileSync(changelogFilePath, updatedChangelogContent); + +try { + execSync(`git add ${packageJsonFilePath} ${changelogFilePath}`); + execSync(`git commit -e -m \"Release ${packageName}@${packageVersion}\"`); +} catch (error) { + console.error(error instanceof Error ? `${error.name}: ${error.message}` : "Could not commit file changes."); + process.exit(1); +} + +function formatDate(date: Date): string { + return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`; + + function pad(component: number): string { + return String(component).padStart(2, "0"); + } +}