-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sebastian Lorenz <[email protected]>
- Loading branch information
1 parent
970697c
commit e17b2f5
Showing
14 changed files
with
409 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if test -f ./.envrc.local; then | ||
source_env ./.envrc.local | ||
fi | ||
|
||
if command -v nix-shell &> /dev/null | ||
then | ||
use_flake | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
node_modules/ | ||
.direnv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"Effect Gen Function": { | ||
"prefix": "egen", | ||
"body": ["Effect.gen(function* ($) {\n\t$0\n})"], | ||
"description": "Effect generator FUnction with $ input" | ||
}, | ||
"Gen Function": { | ||
"prefix": "gen", | ||
"body": ["function* ($) {}"], | ||
"description": "Generator FUnction with $ input" | ||
}, | ||
"Gen Yield * tmp": { | ||
"prefix": "yy", | ||
"body": ["yield* $($0)"], | ||
"description": "Yield generator calling $()" | ||
}, | ||
"Gen Yield *": { | ||
"prefix": "!", | ||
"body": ["yield* $($0)"], | ||
"description": "Yield generator calling $()" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "cli", | ||
"private": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
corepack = pkgs.runCommand "corepack-enable" {} '' | ||
mkdir -p $out/bin | ||
${pkgs.nodejs_20}/bin/corepack enable --install-directory $out/bin | ||
''; | ||
in | ||
{ | ||
devShell = with pkgs; pkgs.mkShell { | ||
buildInputs = [ | ||
act | ||
nodejs_20 | ||
corepack | ||
]; | ||
}; | ||
|
||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# node-scripts | ||
|
||
## Example | ||
|
||
```bash | ||
pnpm dev src/fs-write-file.ts | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "node-scripts", | ||
"private": true, | ||
"scripts": { | ||
"dev": "tsx --watch" | ||
}, | ||
"dependencies": { | ||
"effect": "2.0.0-next.34", | ||
"@effect/platform-node": "^0.17.0", | ||
"@effect/platform": "^0.16.1" | ||
}, | ||
"devDependencies": { | ||
"tsx": "^3.12.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as Node from '@effect/platform-node/Runtime' | ||
import { Cause, Duration, Effect } from 'effect' | ||
import { TaggedClass } from 'effect/Data' | ||
|
||
// --- HELPERS --- | ||
|
||
const getMagicNumber = async () => { | ||
await sleep(200) | ||
|
||
return 42 | ||
} | ||
|
||
const throwSomeError = async () => { | ||
throw new Error('some error') | ||
} | ||
|
||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
class MyCustomError extends TaggedClass('MyCustomError')<{ readonly cause: unknown }> {} | ||
|
||
const someEffect = Effect.succeed(69).pipe(Effect.delay(Duration.seconds(0.5))) | ||
|
||
const someAsyncFnRunningAnEffect = async () => { | ||
const result = await Effect.runPromise(someEffect) | ||
|
||
return result | ||
} | ||
|
||
// --- MAIN --- | ||
|
||
const main = Effect.gen(function* ($) { | ||
// calling a async function/promise from Effect | ||
const result1 = yield* $(Effect.promise(() => getMagicNumber())) | ||
|
||
console.log('Got result 1:', result1) | ||
|
||
// calling a async function/promise from Effect (with error handling) | ||
const result2 = yield* $( | ||
Effect.tryPromise({ try: () => throwSomeError(), catch: (cause) => new MyCustomError({ cause }) }), | ||
Effect.catchTag('MyCustomError', (error) => Effect.succeed(`Got error: ${error.cause}`)), | ||
) | ||
|
||
console.log('Got result 2:', result2) | ||
|
||
// calling an Effect from an async function/promise | ||
const result3 = yield* $(Effect.promise(() => someAsyncFnRunningAnEffect())) | ||
|
||
console.log('Got result 3:', result3) | ||
}) | ||
|
||
Node.runMain(main.pipe(Effect.tapErrorCause((_) => Effect.log(Cause.pretty(_))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as FS from '@effect/platform/FileSystem' | ||
import * as Node from '@effect/platform-node/Runtime' | ||
import * as NodeContext from '@effect/platform-node/NodeContext' | ||
import { Cause, Effect } from 'effect' | ||
|
||
const main = Effect.gen(function* ($) { | ||
const fs = yield* $(FS.FileSystem) | ||
|
||
yield* $(fs.makeDirectory('output')) | ||
yield* $(fs.writeFileString('output/fs-write-file.txt', 'Hello World!')) | ||
|
||
console.log('Wrote file (output/fs-write-file.txt)') | ||
}) | ||
|
||
Node.runMain( | ||
main.pipe( | ||
Effect.provideSomeLayer(NodeContext.layer), | ||
Effect.tapErrorCause((_) => Effect.log(Cause.pretty(_))), | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"module": "Node16", | ||
"moduleResolution": "Node16", | ||
"strict": true, | ||
"plugins": [{ "name": "@effect/language-service" }], | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
Oops, something went wrong.