-
Notifications
You must be signed in to change notification settings - Fork 33
adapted sdk generation to unix environment #1648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/bin/bash | ||
| # | ||
| # | ||
|
|
||
| USER=`who am i | cut -d\ -f1` | ||
| echo -e "\nUser running the script: ${USER}" | ||
|
|
||
| echo -e "\nCleanup old files..." | ||
| rm -rf node_modules/@scicatproject/scicat-sdk-ts | ||
| rm -rf @scicatproject/scicat-sdk-ts | ||
|
|
||
| echo -e "\nGenerating the new sdk..." | ||
| docker run \ | ||
| --rm \ | ||
| --add-host host.docker.internal:host-gateway \ | ||
| -v "`pwd`:/local" \ | ||
| openapitools/openapi-generator-cli:v7.9.0 generate \ | ||
| -i http://host.docker.internal:3000/explorer-json \ | ||
| -g typescript-angular \ | ||
| -o local/@scicatproject/scicat-sdk-ts \ | ||
| --additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true | ||
|
|
||
| REMOVE_NPM_LINK=0 | ||
| if ! command -v npm 2>&1 1>/dev/null | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider using direct binary path variables instead of creating symlinks in system directories The current approach of creating/removing symlinks in # At the start of the script
if ! command -v npm >/dev/null 2>&1; then
if [[ -n "${NVM_BIN}" ]]; then
NPM_CMD="${NVM_BIN}/npm"
NODE_CMD="${NVM_BIN}/node"
if [[ ! -x "$NPM_CMD" ]] || [[ ! -x "$NODE_CMD" ]]; then
echo "Required binaries not found or not executable in NVM_BIN" >&2
exit 1
fi
else
echo "No npm found and NVM_BIN not set" >&2
exit 1
fi
else
NPM_CMD="npm"
NODE_CMD="node"
fi
# Then use these variables instead of global npm/node commands
"$NPM_CMD" install
"$NPM_CMD" run buildThis approach:
|
||
| then | ||
| if [ "--`env | grep NVM_BIN`--" != "----" ] | ||
| then | ||
| echo -e "\nCreating links to npm and node versions" | ||
| ln -s "$NVM_BIN/npm" "/usr/local/bin/npm" | ||
| whereis npm | ||
| ln -s "$NVM_BIN/node" "/usr/local/bin/node" | ||
| whereis node | ||
| REMOVE_NPM_LINK=1 | ||
| else | ||
| echo -e "\nNo npm found!!!" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo -e "\nInstalling dependencies and building the sdk..." | ||
| cd @scicatproject/scicat-sdk-ts | ||
| npm install | ||
| npm run build | ||
|
|
||
| echo -e "\nCopying the build files in node_modules..." | ||
| cd ../.. | ||
| cp -rv @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts | ||
|
|
||
| echo -e "\nAdjusting ownership to user ${USER}" | ||
| chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts | ||
|
|
||
| echo -e "\nFinal cleanup..." | ||
| echo -e "Removing sdk folder" | ||
| rm -rfv @scicatproject | ||
|
|
||
| if [ $REMOVE_NPM_LINK -eq 1 ]; | ||
| then | ||
| echo -e "\nRemoving links to npm and node" | ||
| rm -fv "/usr/local/bin/npm" | ||
| rm -fv "/usr/local/bin/node" | ||
| fi | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,35 +19,50 @@ function getCurrentDirectory() { | |
| return "$(pwd)"; | ||
| } | ||
|
|
||
| // NOTE: First do some cleanup before starting the generation | ||
| console.log("Cleanup old files..."); | ||
| execSync( | ||
| "rm -rf node_modules/@scicatproject/scicat-sdk-ts && rm -rf @scicatproject/scicat-sdk-ts", | ||
| { encoding: "utf-8" }, | ||
| ); | ||
|
|
||
| console.log("Generating the new sdk..."); | ||
| const generationOutput = execSync( | ||
| `docker run --rm --add-host host.docker.internal:host-gateway -v "${getCurrentDirectory()}:/local" openapitools/openapi-generator-cli:v7.9.0 generate -i http://host.docker.internal:3000/explorer-json -g typescript-angular -o local/@scicatproject/scicat-sdk-ts --additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true`, | ||
| { encoding: "utf-8" }, | ||
| ); | ||
| console.log(generationOutput); | ||
|
|
||
| console.log("Installing dependencies and building the sdk..."); | ||
| const installBuildOutput = execSync( | ||
| "cd @scicatproject/scicat-sdk-ts && npm install && npm run build", | ||
| { encoding: "utf-8" }, | ||
| ); | ||
| console.log(installBuildOutput); | ||
|
|
||
| console.log("Copying the build files in node_modules..."); | ||
| const copyToNodeModulesOutput = execSync( | ||
| "cp -r @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts", | ||
| { encoding: "utf-8" }, | ||
| ); | ||
| console.log(copyToNodeModulesOutput); | ||
|
|
||
| console.log("Final cleanup..."); | ||
| execSync("rm -rf @scicatproject", { | ||
| encoding: "utf-8", | ||
| }); | ||
| if (isWindows()) { | ||
|
|
||
| // NOTE: First do some cleanup before starting the generation | ||
| console.log("Cleanup old files..."); | ||
| execSync( | ||
| "rm -rf node_modules/@scicatproject/scicat-sdk-ts && rm -rf @scicatproject/scicat-sdk-ts", | ||
| { encoding: "utf-8" }, | ||
| ); | ||
|
|
||
| console.log("Generating the new sdk..."); | ||
| const generationOutput = execSync( | ||
| `docker run --rm --add-host host.docker.internal:host-gateway -v "${getCurrentDirectory()}:/local" openapitools/openapi-generator-cli:v7.9.0 generate -i http://host.docker.internal:3000/explorer-json -g typescript-angular -o local/@scicatproject/scicat-sdk-ts --additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true`, | ||
| { encoding: "utf-8" }, | ||
| ); | ||
| console.log(generationOutput); | ||
|
|
||
| console.log("Installing dependencies and building the sdk..."); | ||
| const installBuildOutput = execSync( | ||
| "cd @scicatproject/scicat-sdk-ts && npm install && npm run build", | ||
| { encoding: "utf-8" }, | ||
| ); | ||
| console.log(installBuildOutput); | ||
|
|
||
| console.log("Copying the build files in node_modules..."); | ||
| const copyToNodeModulesOutput = execSync( | ||
| "cp -r @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts", | ||
| { encoding: "utf-8" }, | ||
| ); | ||
| console.log(copyToNodeModulesOutput); | ||
|
|
||
| console.log("Final cleanup..."); | ||
| execSync("rm -rf @scicatproject", { | ||
| encoding: "utf-8", | ||
| }); | ||
|
|
||
| console.log("Local SDK generation completed"); | ||
|
|
||
| } else { | ||
| console.log("Your environment is a linux/unix"); | ||
| console.log("Please run the following command on your terminal:"); | ||
| console.log("> sudo -E ./scripts/generate-nestjs-sdk.bash"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nitrosx I am thinking instead of asking people to run the command, can't we just run the command from here directly. Something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately it does not work in the current form of the bash script. |
||
| console.log(""); | ||
| console.log("IMPORTANT: the script runs under sudo. You will be asked your password."); | ||
| console.log(""); | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Add error handling for Docker operations
Add checks to verify Docker is running and host.docker.internal is accessible before attempting operations. Handle potential errors explicitly.