From 5ae57f2ab02712b05cc3572e5d4da1a769b87bc6 Mon Sep 17 00:00:00 2001 From: Johannes Schickling Date: Fri, 22 Sep 2023 15:31:16 +0200 Subject: [PATCH] WIP node scripts --- .envrc | 8 ++ .gitignore | 3 +- flake.nix | 22 +++++ node-scripts/.gitignore | 1 + node-scripts/README.md | 7 ++ node-scripts/package.json | 13 ++- node-scripts/src/fs-write-file.ts | 14 +++ pnpm-lock.yaml | 158 +++++++++++++++++++++++++++++- 8 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 .envrc create mode 100644 flake.nix create mode 100644 node-scripts/.gitignore create mode 100644 node-scripts/README.md create mode 100644 node-scripts/src/fs-write-file.ts diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..d859d83 --- /dev/null +++ b/.envrc @@ -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 diff --git a/.gitignore b/.gitignore index 40b878d..d75e450 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +.direnv \ No newline at end of file diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..acb0c20 --- /dev/null +++ b/flake.nix @@ -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; }) + ]; + }; + + }); +} diff --git a/node-scripts/.gitignore b/node-scripts/.gitignore new file mode 100644 index 0000000..6caf68a --- /dev/null +++ b/node-scripts/.gitignore @@ -0,0 +1 @@ +output \ No newline at end of file diff --git a/node-scripts/README.md b/node-scripts/README.md new file mode 100644 index 0000000..b1f9332 --- /dev/null +++ b/node-scripts/README.md @@ -0,0 +1,7 @@ +# node-scripts + +## Example + +```bash +pnpm dev src/fs-write-file.ts +``` diff --git a/node-scripts/package.json b/node-scripts/package.json index 5cfb865..d026b7a 100644 --- a/node-scripts/package.json +++ b/node-scripts/package.json @@ -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" + } } diff --git a/node-scripts/src/fs-write-file.ts b/node-scripts/src/fs-write-file.ts new file mode 100644 index 0000000..e50be3b --- /dev/null +++ b/node-scripts/src/fs-write-file.ts @@ -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))) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b08fc9e..e34de36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,24 @@ importers: specifier: ^5.2.2 version: 5.2.2 + cli: {} + + node-scripts: + dependencies: + '@effect/platform': + specifier: ^0.16.1 + version: 0.16.1(@effect/data@0.18.6)(@effect/io@0.40.3)(@effect/schema@0.36.5)(@effect/stream@0.36.1) + '@effect/platform-node': + specifier: ^0.17.0 + version: 0.17.0(@effect/data@0.18.6)(@effect/io@0.40.3)(@effect/schema@0.36.5)(@effect/stream@0.36.1) + effect: + specifier: 2.0.0-next.34 + version: 2.0.0-next.34(@effect/data@0.18.6)(@effect/io@0.40.3)(@effect/match@0.35.2)(@effect/stm@0.24.0)(@effect/stream@0.36.1) + devDependencies: + tsx: + specifier: ^3.12.10 + version: 3.12.10 + react-heavy-work: dependencies: autoprefixer: @@ -1684,6 +1702,50 @@ packages: dependencies: '@effect/data': 0.18.6 + /@effect/platform-node@0.17.0(@effect/data@0.18.6)(@effect/io@0.40.3)(@effect/schema@0.36.5)(@effect/stream@0.36.1): + resolution: {integrity: sha512-2lnzzEN6avKPyZLzKp07Avsa62TuHSuQlO09NKkkhcgIJerlafXqFFbvTB3oq5X0RNFh8COROKR5M2r6icNucQ==} + peerDependencies: + '@effect/data': ^0.18.5 + '@effect/io': ^0.40.1 + '@effect/stream': ^0.36.0 + dependencies: + '@effect/data': 0.18.6 + '@effect/io': 0.40.3(@effect/data@0.18.6) + '@effect/platform': 0.16.1(@effect/data@0.18.6)(@effect/io@0.40.3)(@effect/schema@0.36.5)(@effect/stream@0.36.1) + '@effect/stream': 0.36.1(@effect/data@0.18.6)(@effect/io@0.40.3) + busboy: 1.6.0 + mime: 3.0.0 + transitivePeerDependencies: + - '@effect/schema' + dev: false + + /@effect/platform@0.16.1(@effect/data@0.18.6)(@effect/io@0.40.3)(@effect/schema@0.36.5)(@effect/stream@0.36.1): + resolution: {integrity: sha512-zbtHiWGA2IbxU6WzoMM1bAKSeLyfHrnPZO/d0DC1bPodutt60tgh1oUJUaTi4fPsksplxomuzNnIIfAwWfiqPA==} + peerDependencies: + '@effect/data': ^0.18.5 + '@effect/io': ^0.40.1 + '@effect/schema': ^0.36.1 + '@effect/stream': ^0.36.0 + dependencies: + '@effect/data': 0.18.6 + '@effect/io': 0.40.3(@effect/data@0.18.6) + '@effect/schema': 0.36.5(@effect/data@0.18.6)(@effect/io@0.40.3) + '@effect/stream': 0.36.1(@effect/data@0.18.6)(@effect/io@0.40.3) + find-my-way: 7.6.2 + path-browserify: 1.0.1 + dev: false + + /@effect/schema@0.36.5(@effect/data@0.18.6)(@effect/io@0.40.3): + resolution: {integrity: sha512-E8KZ17DqZJl7E/eEVTkxb2NEv6vYhab79HugHi10krd2Gm3vOJvWs+nRgtPhI+0dvkXVxzCcY8bLfkND2F0rBg==} + peerDependencies: + '@effect/data': ^0.18.5 + '@effect/io': ^0.40.1 + dependencies: + '@effect/data': 0.18.6 + '@effect/io': 0.40.3(@effect/data@0.18.6) + fast-check: 3.13.0 + dev: false + /@effect/stm@0.24.0(@effect/data@0.18.6)(@effect/io@0.40.3): resolution: {integrity: sha512-6L4zhy2lvkxn3jMG7dvZ4lKOmxSvaNBpkIT/ZOS6mad+B5/r8G3bKFe0C70aHwpQkxORd9LVmFr/f5MXLKZtfQ==} peerDependencies: @@ -1723,6 +1785,27 @@ packages: - '@effect/stream' dev: true + /@esbuild-kit/cjs-loader@2.4.4: + resolution: {integrity: sha512-NfsJX4PdzhwSkfJukczyUiZGc7zNNWZcEAyqeISpDnn0PTfzMJR1aR8xAIPskBejIxBJbIgCCMzbaYa9SXepIg==} + dependencies: + '@esbuild-kit/core-utils': 3.3.2 + get-tsconfig: 4.7.2 + dev: true + + /@esbuild-kit/core-utils@3.3.2: + resolution: {integrity: sha512-sPRAnw9CdSsRmEtnsl2WXWdyquogVpB3yZ3dgwJfe8zrOzTsV7cJvmwrKVa+0ma5BoiGJ+BoqkMvawbayKUsqQ==} + dependencies: + esbuild: 0.18.20 + source-map-support: 0.5.21 + dev: true + + /@esbuild-kit/esm-loader@2.6.5: + resolution: {integrity: sha512-FxEMIkJKnodyA1OaCUoEvbYRkoZlLZ4d/eXFu9Fh8CbBBgP5EmZxrfTRyN0qpXZ4vOvqnE5YdRdcrmUUXuU+dA==} + dependencies: + '@esbuild-kit/core-utils': 3.3.2 + get-tsconfig: 4.7.2 + dev: true + /@esbuild-plugins/node-modules-polyfill@0.1.4(esbuild@0.15.12): resolution: {integrity: sha512-uZbcXi0zbmKC/050p3gJnne5Qdzw8vkXIv+c2BW0Lsc1ji1SkrxbKPUy5Efr0blbTu1SL8w4eyfpnSdPg3G0Qg==} peerDependencies: @@ -3181,6 +3264,13 @@ packages: ieee754: 1.2.1 dev: true + /busboy@1.6.0: + resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==} + engines: {node: '>=10.16.0'} + dependencies: + streamsearch: 1.1.0 + dev: false + /bytes@3.0.0: resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==} engines: {node: '>= 0.8'} @@ -4999,9 +5089,19 @@ packages: - supports-color dev: true + /fast-check@3.13.0: + resolution: {integrity: sha512-m6+3gZ/yTiCWTuV/1e/UuPPjyyyHdQ5gu0pMd84C6705VTDjAgAE6nqFT5jhgegFllCJ95yOzBpqvJSs2DZAxQ==} + engines: {node: '>=8.0.0'} + dependencies: + pure-rand: 6.0.3 + dev: false + + /fast-decode-uri-component@1.0.1: + resolution: {integrity: sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==} + dev: false + /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} - dev: true /fast-glob@3.2.11: resolution: {integrity: sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==} @@ -5032,6 +5132,12 @@ packages: resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} dev: true + /fast-querystring@1.1.2: + resolution: {integrity: sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg==} + dependencies: + fast-decode-uri-component: 1.0.1 + dev: false + /fastq@1.15.0: resolution: {integrity: sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==} dependencies: @@ -5106,6 +5212,15 @@ packages: pkg-dir: 3.0.0 dev: true + /find-my-way@7.6.2: + resolution: {integrity: sha512-0OjHn1b1nCX3eVbm9ByeEHiscPYiHLfhei1wOUU9qffQkk98wE0Lo8VrVYfSGMgnSnDh86DxedduAnBf4nwUEw==} + engines: {node: '>=14'} + dependencies: + fast-deep-equal: 3.1.3 + fast-querystring: 1.1.2 + safe-regex2: 2.0.0 + dev: false + /find-up@3.0.0: resolution: {integrity: sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==} engines: {node: '>=6'} @@ -6838,6 +6953,12 @@ packages: engines: {node: '>=4'} hasBin: true + /mime@3.0.0: + resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==} + engines: {node: '>=10.0.0'} + hasBin: true + dev: false + /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} @@ -7404,6 +7525,10 @@ packages: engines: {node: '>=0.10.0'} dev: true + /path-browserify@1.0.1: + resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==} + dev: false + /path-exists@3.0.0: resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==} engines: {node: '>=4'} @@ -7694,6 +7819,10 @@ packages: engines: {node: '>=6'} dev: true + /pure-rand@6.0.3: + resolution: {integrity: sha512-KddyFewCsO0j3+np81IQ+SweXLDnDQTs5s67BOnrYmYe/yNmUhttQyGsYzy8yUnoljGAQ9sl38YB4vH8ur7Y+w==} + dev: false + /qs@6.11.0: resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==} engines: {node: '>=0.6'} @@ -8038,6 +8167,11 @@ packages: engines: {node: '>=0.12'} dev: true + /ret@0.2.2: + resolution: {integrity: sha512-M0b3YWQs7R3Z917WRQy1HHA7Ba7D8hvZg6UE5mLykJxQVE2ju0IXbGlaHPPlkY+WN7wFP+wUMXmBFA0aV6vYGQ==} + engines: {node: '>=4'} + dev: false + /reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} @@ -8140,6 +8274,12 @@ packages: is-regex: 1.1.4 dev: true + /safe-regex2@2.0.0: + resolution: {integrity: sha512-PaUSFsUaNNuKwkBijoAPHAK6/eM6VirvyPWlZ7BAQy4D+hCvh4B6lIG+nPdhbFfIbP+gTGBcrdsOaUs0F+ZBOQ==} + dependencies: + ret: 0.2.2 + dev: false + /safe-regex@1.1.0: resolution: {integrity: sha512-aJXcif4xnaNUzvUuC5gcb46oTS7zvg4jpMTnuqtrEPlR3vFr4pxtdTwaF1Qs3Enjn9HK+ZlwQui+a7z0SywIzg==} dependencies: @@ -8472,6 +8612,11 @@ packages: resolution: {integrity: sha512-QzQxpoacatkreL6jsxnVb7X5R/pGw9OUv2qWTYWnmLpg4NdN31snPy/f3TdQE1ZUXaThRvj1Zw4/OGg0ZkaLMA==} dev: false + /streamsearch@1.1.0: + resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} + engines: {node: '>=10.0.0'} + dev: false + /string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} @@ -8852,6 +8997,17 @@ packages: typescript: 4.8.4 dev: true + /tsx@3.12.10: + resolution: {integrity: sha512-2+46h4xvUt1aLDNvk5YBT8Uzw+b7BolGbn7iSMucYqCXZiDc+1IMghLVdw8kKjING32JFOeO+Am9posvjkeclA==} + hasBin: true + dependencies: + '@esbuild-kit/cjs-loader': 2.4.4 + '@esbuild-kit/core-utils': 3.3.2 + '@esbuild-kit/esm-loader': 2.6.5 + optionalDependencies: + fsevents: 2.3.3 + dev: true + /type-check@0.3.2: resolution: {integrity: sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg==} engines: {node: '>= 0.8.0'}