|
1 | | -import { Effect, Console, Stream } from 'effect'; |
2 | | -import { Command } from '@effect/platform'; |
| 1 | +import { Effect, Console } from 'effect'; |
3 | 2 | import { NodeContext, NodeRuntime } from '@effect/platform-node'; |
4 | 3 | 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'; |
71 | 11 |
|
72 | 12 | // Effect to check for the presence of changeset files |
73 | 13 | const checkForChangesets = Effect.gen(function* () { |
|
0 commit comments