Skip to content

Commit 339cb00

Browse files
authored
add native toolchain support (#79)
1 parent 8580c93 commit 339cb00

File tree

11 files changed

+168
-3
lines changed

11 files changed

+168
-3
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Add native toolchain support [#79](https://github.com/hasura/ndc-open-api-lambda/pull/79)
6+
57
## [[1.3.0](https://github.com/hasura/ndc-open-api-lambda/releases/tag/v1.3.0)] 2025-01-22
68

79
- Extend `@save` annotation support for user defined type (types, interfaces, classes) ([#71](https://github.com/hasura/ndc-open-api-lambda/pull/71))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$minimumNodeVersion = 20
4+
5+
if (-not (Get-Command "node" -ErrorAction SilentlyContinue)) {
6+
Write-Host "node could not be found. Please install NodeJS v$minimumNodeVersion+."
7+
exit 1
8+
}
9+
10+
$nodeVersion = & node --version
11+
if ($nodeVersion -match "^v(\d+)\.") {
12+
$majorVersion = $Matches[1]
13+
if ($majorVersion -lt $minimumNodeVersion) {
14+
Write-Host "Detected Node.js version $nodeVersion on the PATH. The minimum required version is v$minimumNodeVersion."
15+
exit 1
16+
}
17+
}
18+
19+
Push-Location $env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
20+
try {
21+
if ((Test-Path "./node_modules") -eq $false) {
22+
Write-Host "node_modules not found, please ensure you have run 'npm install'."
23+
exit 1
24+
}
25+
} finally {
26+
Pop-Location
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
minimum_node_version="20"
5+
6+
if ! command -v node &> /dev/null
7+
then
8+
echo "node could not be found on the PATH. Please install Node.js v$minimum_node_version+."
9+
exit 1
10+
fi
11+
12+
node_version=$(node --version)
13+
if [[ "$node_version" =~ ^v([[:digit:]]+)\. ]]; then
14+
major_version="${BASH_REMATCH[1]}"
15+
if [[ $major_version -lt $minimum_node_version ]]; then
16+
echo "Detected Node.js version $node_version on the PATH. The minimum required version is v$minimum_node_version."
17+
exit 1
18+
fi
19+
else
20+
echo "no match"
21+
fi
22+
23+
cd $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
24+
25+
if [ ! -d "node_modules" ]
26+
then
27+
echo "node_modules directory not found, please ensure you have run 'npm install'."
28+
exit 1
29+
fi

connector-definition/.hasura-connector/connector-metadata.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,22 @@ dockerComposeWatch:
3232
target: /functions
3333
action: sync+restart
3434
exclude: swagger.json
35+
nativeToolchainDefinition:
36+
commands:
37+
start:
38+
type: ShellScript
39+
bash: ./start.sh
40+
powershell: ./start.ps1
41+
watch:
42+
type: ShellScript
43+
bash: ./watch.sh
44+
powershell: ./watch.ps1
45+
update:
46+
type: ShellScript
47+
bash: |
48+
#!/usr/bin/env bash
49+
set -eu -o pipefail
50+
HASURA_CONFIGURATION_DIRECTORY="$HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" "$HASURA_DDN_NATIVE_CONNECTOR_PLUGIN_DIR/ndc-oas-lambda" update
51+
powershell: |
52+
$ErrorActionPreference = "Stop"
53+
& "$env:HASURA_DDN_NATIVE_CONNECTOR_PLUGIN_DIR\ndc-oas-lambda.bat" update
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This script reads from the package.json file in the current working directory
2+
// and prints out the text in the "scripts.<name>" entry. This is used to bypass
3+
// npm, which does not handle signals correctly, and execute the command directly
4+
5+
const fs = require("node:fs");
6+
const process = require("node:process");
7+
const path = require("node:path");
8+
9+
const cwd = process.cwd();
10+
const packageJsonPath = path.join(cwd, "./package.json");
11+
12+
if (process.argv.length < 3) {
13+
console.error("Error: Pass the name of script command you want to read as the first command line arg.");
14+
console.error("Usage: node read-package-script.js <name>");
15+
process.exit(1);
16+
}
17+
const desiredScript = process.argv[2];
18+
19+
try {
20+
const packageJsonText = fs.readFileSync(packageJsonPath);
21+
const packageJson = JSON.parse(packageJsonText);
22+
const script = packageJson.scripts[desiredScript];
23+
if (script === undefined) {
24+
console.error(`Error: script ${desiredScript} not found in ${packageJsonPath}`)
25+
}
26+
console.log(script);
27+
} catch (e) {
28+
console.error(`Error reading ${packageJsonPath}: ${e}`);
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$scriptDir = Get-Location
4+
5+
& ./check-reqs.ps1
6+
7+
Push-Location $env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
8+
try {
9+
$startScript = & node "$PSScriptRoot\read-package-script.js" "start"
10+
if ($LASTEXITCODE -ne 0) {
11+
exit 1
12+
}
13+
$env:PATH = "$($env:PATH);$($env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH)\node_modules\.bin"
14+
Invoke-Expression "& $startScript"
15+
} finally {
16+
Pop-Location
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
script_dir=$(pwd)
5+
6+
./check-reqs.sh
7+
8+
cd $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
9+
start_script=$(node "$script_dir/read-package-script.js" "start")
10+
PATH="$PATH:$(pwd)/node_modules/.bin" exec $start_script
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$scriptDir = Get-Location
4+
5+
& ./check-reqs.ps1
6+
7+
Push-Location $env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
8+
try {
9+
$watchScript = & node "$PSScriptRoot\read-package-script.js" "watch"
10+
if ($LASTEXITCODE -ne 0) {
11+
exit 1
12+
}
13+
$env:PATH = "$($env:PATH);$($env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH)\node_modules\.bin"
14+
Invoke-Expression "& $watchScript"
15+
} finally {
16+
Pop-Location
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
script_dir=$(pwd)
5+
6+
./check-reqs.sh
7+
8+
cd $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH
9+
watch_script=$(node "$script_dir/read-package-script.js" "watch")
10+
PATH="$PATH:$(pwd)/node_modules/.bin" exec $watch_script

src/app/writer/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export async function writeToFileSystem(codeToWrite: types.GeneratedCode[]) {
2222
tsConfigWriter.writeToFileSystem();
2323

2424
logger.info("running npm install :: installing dependencies");
25-
execSync("npm install", { stdio: "inherit" });
25+
if (process.env.HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH) {
26+
execSync("npm install ", { stdio: "inherit", cwd: process.env.HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH });
27+
} else {
28+
execSync("npm install ", { stdio: "inherit" });
29+
}
30+
2631
logger.info("all dependencies installed");
2732
} catch (e) {
2833
if (e instanceof apiWriter.SimilarFileContentsError) {

0 commit comments

Comments
 (0)