Skip to content

Commit e1a5d2f

Browse files
committed
chore: update-tools
made a package within tools and refactored cli
1 parent 85bccfb commit e1a5d2f

8 files changed

Lines changed: 102 additions & 77 deletions

File tree

.changeset/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@forgerock/device-client",
1818
"@forgerock/davinci-app",
1919
"@forgerock/davinci-suites",
20-
"@forgerock/mock-api-v2"
20+
"@forgerock/mock-api-v2",
21+
"@forgerock/local-release-tool"
2122
]
2223
}

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"docs": "nx affected --target=typedoc",
1919
"format": "pnpm nx format:write",
2020
"lint": "nx affected --target=lint",
21+
"local-release": "pnpm ts-node tools/release/release.ts",
2122
"nx": "nx",
2223
"preinstall": "npx only-allow pnpm",
2324
"prepare": "node .husky/install.mjs",
@@ -52,6 +53,7 @@
5253
"@commitlint/cli": "^19.1.0",
5354
"@commitlint/config-conventional": "^19.1.0",
5455
"@commitlint/prompt": "^19.1.0",
56+
"@effect/cli": "0.59.9",
5557
"@effect/language-service": "^0.2.0",
5658
"@effect/platform": "^0.58.27",
5759
"@effect/platform-node": "^0.53.26",
@@ -127,8 +129,5 @@
127129
},
128130
"nx": {
129131
"includedScripts": []
130-
},
131-
"dependencies": {
132-
"@effect/cli": "0.59.9"
133132
}
134133
}

pnpm-lock.yaml

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/release/commands/commands.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Effect, Stream, Console } from 'effect';
2+
import { Command } from '@effect/platform';
3+
// Effect to check git status for staged files
4+
export const checkGitStatus = Command.make('git', 'status', '--porcelain').pipe(
5+
Command.string,
6+
Effect.flatMap((output) => {
7+
// Check if the output contains lines indicating staged changes (e.g., starting with M, A, D, R, C, U followed by a space)
8+
const stagedChanges = output.split('\n').some((line) => /^[MADRCU] /.test(line.trim()));
9+
if (stagedChanges) {
10+
return Effect.fail(
11+
'Git repository has staged changes. Please commit or stash them before releasing.',
12+
);
13+
}
14+
return Effect.void; // No staged changes
15+
}),
16+
// If the command fails (e.g., not a git repo), treat it as an error too.
17+
Effect.catchAll((error) => Effect.fail(`Git status check command failed: ${error}`)),
18+
Effect.tapError((error) => Console.error(error)), // Log the specific error message
19+
Effect.asVoid, // Don't need the output on success
20+
);
21+
22+
// Effect to run changesets snapshot
23+
export const runChangesetsSnapshot = Command.make(
24+
'pnpm',
25+
'changesets',
26+
'version',
27+
'--snapshot',
28+
'beta',
29+
).pipe(
30+
Command.lines, // Get output line by line
31+
Effect.tap((line) => Console.log(`Changesets: ${line}`)), // Log output
32+
Stream.runDrain, // Consume the stream and wait for completion
33+
Effect.tapBoth({
34+
onFailure: (error) => Console.error(`Changesets snapshot command failed: ${error}`),
35+
onSuccess: () => Console.log('Changesets snapshot completed successfully.'),
36+
}),
37+
Effect.asVoid, // Don't need the final result
38+
);
39+
40+
// Effect to start local registry (run in background)
41+
export const startLocalRegistry = Command.make('pnpm', 'nx', 'local-registry').pipe(
42+
Command.start, // Starts the process and returns immediately
43+
Effect.tap(() =>
44+
Console.log('Attempting to start local registry (Verdaccio) in the background...'),
45+
),
46+
Effect.tapError((error) => Console.error(`Failed to start local registry: ${error}`)),
47+
Effect.asVoid, // We don't need the Process handle for this script's logic
48+
);
49+
50+
export const restoreGitFiles = Command.make('git', 'restore', '.').pipe(Command.start);
51+
52+
export const publishPackages = Command.make(
53+
'pnpm',
54+
'publish',
55+
'-r',
56+
'--tag',
57+
'beta',
58+
'--registry=http://localhost:4873',
59+
).pipe(
60+
Command.lines, // Stream output line by line
61+
Effect.tap((line) => Console.log(`Publish: ${line}`)),
62+
Stream.runDrain,
63+
Effect.tapBoth({
64+
onFailure: (error) => Effect.fail(() => Console.error(`Publishing failed: ${error}`)),
65+
onSuccess: () => Console.log('Packages were published successfully to the local registry.'),
66+
}),
67+
Effect.asVoid,
68+
);

tools/release/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@forgerock/local-release-tool",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC"
13+
}

tools/release/release.ts

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,13 @@
1-
import { Effect, Console, Stream } from 'effect';
2-
import { Command } from '@effect/platform';
1+
import { Effect, Console } from 'effect';
32
import { NodeContext, NodeRuntime } from '@effect/platform-node';
43
import { FileSystem, Path } from '@effect/platform';
5-
6-
// Effect to check git status for staged files
7-
const checkGitStatus = Command.make('git', 'status', '--porcelain').pipe(
8-
Command.string,
9-
Effect.flatMap((output) => {
10-
// Check if the output contains lines indicating staged changes (e.g., starting with M, A, D, R, C, U followed by a space)
11-
const stagedChanges = output.split('\n').some((line) => /^[MADRCU] /.test(line.trim()));
12-
if (stagedChanges) {
13-
return Effect.fail(
14-
'Git repository has staged changes. Please commit or stash them before releasing.',
15-
);
16-
}
17-
return Effect.void; // No staged changes
18-
}),
19-
// If the command fails (e.g., not a git repo), treat it as an error too.
20-
Effect.catchAll((error) => Effect.fail(`Git status check command failed: ${error}`)),
21-
Effect.tapError((error) => Console.error(error)), // Log the specific error message
22-
Effect.asVoid, // Don't need the output on success
23-
);
24-
25-
// Effect to run changesets snapshot
26-
const runChangesetsSnapshot = Command.make(
27-
'pnpm',
28-
'changesets',
29-
'version',
30-
'--snapshot',
31-
'beta',
32-
).pipe(
33-
Command.lines, // Get output line by line
34-
Effect.tap((line) => Console.log(`Changesets: ${line}`)), // Log output
35-
Stream.runDrain, // Consume the stream and wait for completion
36-
Effect.tapBoth({
37-
onFailure: (error) => Console.error(`Changesets snapshot command failed: ${error}`),
38-
onSuccess: () => Console.log('Changesets snapshot completed successfully.'),
39-
}),
40-
Effect.asVoid, // Don't need the final result
41-
);
42-
43-
// Effect to start local registry (run in background)
44-
const startLocalRegistry = Command.make('pnpm', 'nx', 'local-registry').pipe(
45-
Command.start, // Starts the process and returns immediately
46-
Effect.tap(() =>
47-
Console.log('Attempting to start local registry (Verdaccio) in the background...'),
48-
),
49-
Effect.tapError((error) => Console.error(`Failed to start local registry: ${error}`)),
50-
Effect.asVoid, // We don't need the Process handle for this script's logic
51-
);
52-
53-
const restoreGitFiles = Command.make('git', 'restore', '.').pipe(Command.start);
54-
const publishPackages = Command.make(
55-
'pnpm',
56-
'publish',
57-
'-r',
58-
'--tag',
59-
'beta',
60-
'--registry=http://localhost:4873',
61-
).pipe(
62-
Command.lines, // Stream output line by line
63-
Effect.tap((line) => Console.log(`Publish: ${line}`)),
64-
Stream.runDrain,
65-
Effect.tapBoth({
66-
onFailure: (error) => Effect.fail(() => Console.error(`Publishing failed: ${error}`)),
67-
onSuccess: () => Console.log('Packages were published successfully to the local registry.'),
68-
}),
69-
Effect.asVoid,
70-
);
4+
import {
5+
checkGitStatus,
6+
startLocalRegistry,
7+
runChangesetsSnapshot,
8+
restoreGitFiles,
9+
publishPackages,
10+
} from './commands/commands.js';
7111

7212
// Effect to check for the presence of changeset files
7313
const checkForChangesets = Effect.gen(function* () {

tools/release/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"files": [],
4-
"include": ["./release.ts"],
4+
"include": ["**/*.ts"],
55
"compilerOptions": {
66
"moduleResolution": "NodeNext",
77
"module": "NodeNext",

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
},
1919
{
2020
"path": "./packages/davinci-client"
21+
},
22+
{
23+
"path": "./tools/release"
2124
}
2225
]
2326
}

0 commit comments

Comments
 (0)