Skip to content

Commit

Permalink
Release @itwin/presentation-rules-editor-react@0.1.0 (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
roluk authored Apr 4, 2022
1 parent d621beb commit 108ad06
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
2 changes: 2 additions & 0 deletions presentation-rules-editor-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions presentation-rules-editor-react/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions presentation-rules-editor-react/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ stages:
parameters:
path: $(tarballName)
artifactName: published-package
dryrun: true
releaseTag: pre-release
73 changes: 73 additions & 0 deletions scripts/src/finalizeRelease.ts
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit 108ad06

Please sign in to comment.