@@ -4,21 +4,26 @@ set -euo pipefail
4
4
# Get the path to the current directory (works in both bash and zsh)
5
5
# https://stackoverflow.com/a/54755784
6
6
PATH_CURRENT=" $( dirname ${BASH_SOURCE[0]:- ${(% ):-% x} } ) "
7
+ cd $PATH_CURRENT
7
8
8
- TEST_SPEC_PATH=" ${PATH_CURRENT} /../fixtures/fixture1_spec.ts" ;
9
- TEST_API_PATH=" ${PATH_CURRENT} /../fixtures/fixture1_api.json" ;
10
- TEST_OUTPUT_PATH=" ${PATH_CURRENT} /../project_simulation/generated/fixture1" ;
11
- mkdir -p " ${TEST_OUTPUT_PATH} "
12
- npm run generate -- " --spec=${TEST_SPEC_PATH} " " ${TEST_API_PATH} " " ${TEST_OUTPUT_PATH} " ;
9
+ # Note: do not use `npm run` here, because `npm run` always changes the working directory to that of the project root
10
+ generate () {
11
+ node --import=tsx -- " ../../src/openapiToEffect.ts" gen " $@ "
12
+ }
13
13
14
+ TEST_SPEC_PATH=" ../fixtures/fixture1_spec.ts" ;
15
+ TEST_API_PATH=" ../fixtures/fixture1_api.json" ;
16
+ TEST_OUTPUT_PATH=" ../project_simulation/generated/fixture1" ;
17
+ mkdir -p " ${TEST_OUTPUT_PATH} "
18
+ generate --spec=" ${TEST_SPEC_PATH} " " ${TEST_API_PATH} " " ${TEST_OUTPUT_PATH} "
14
19
15
20
echo
16
21
echo ' Generating sample file...'
17
- cat << "EOT " | npm run --silent node | prettier --parser=babel-ts --single-quote > "${TEST_OUTPUT_PATH}/fixture1_sample.ts"
22
+ cat << "EOT " | node --import=tsx | npx --silent prettier --parser=babel-ts --single-quote > "${TEST_OUTPUT_PATH}/fixture1_sample.ts"
18
23
(async () => {
19
24
const { dedent } = await import('ts-dedent');
20
25
const S = await import('@effect/schema');
21
- const Fx = await import('./tests /project_simulation/generated/fixture1/fixture1.ts');
26
+ const Fx = await import('.. /project_simulation/generated/fixture1/fixture1.ts');
22
27
23
28
console.log(dedent`
24
29
import { pipe } from 'effect';
@@ -53,10 +58,10 @@ cat <<"EOT" | npm run --silent node | prettier --parser=babel-ts --single-quote
53
58
EOT
54
59
echo ' Done!'
55
60
56
- npm run node " ${TEST_OUTPUT_PATH} /fixture1_sample.ts"
61
+ node --import=tsx " ${TEST_OUTPUT_PATH} /fixture1_sample.ts"
57
62
58
63
59
64
# Type check the output
60
65
# Note: no way to call `tsc` with a `tsconfig.json` while overriding the input file path dynamically, need to use
61
66
# a specialized `tsconfig.json` file that extends the base config.
62
- tsc --project " ${PATH_CURRENT} / tsconfig.json"
67
+ npx --silent tsc --project tsconfig.json
0 commit comments