Skip to content

Commit

Permalink
WIP node scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
schickling committed Sep 22, 2023
1 parent 84d8687 commit 5ae57f2
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .envrc
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
.direnv
22 changes: 22 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/master";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{

devShell = with pkgs; pkgs.mkShell {
buildInputs = [
nodejs_20
(yarn.override { nodejs = nodejs_20; })
];
};

});
}
1 change: 1 addition & 0 deletions node-scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output
7 changes: 7 additions & 0 deletions node-scripts/README.md
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
```
13 changes: 12 additions & 1 deletion node-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"name": "node-scripts",
"private": true
"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"
}
}
14 changes: 14 additions & 0 deletions node-scripts/src/fs-write-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as FS from '@effect/platform/FileSystem'
import * as Node from '@effect/platform-node/Runtime'
import * as NodeContext from '@effect/platform-node/NodeContext'
import { Effect } from 'effect'

const main = Effect.gen(function* ($) {
const fs = yield* $(FS.FileSystem)

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)))
158 changes: 157 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ae57f2

Please sign in to comment.