Skip to content

Commit f471a23

Browse files
authored
Merge pull request #1648 from SciCatProject/fix-unix-sdk-generation
adapted sdk generation to unix environment
2 parents ef06cc8 + 0271c1c commit f471a23

File tree

2 files changed

+109
-32
lines changed

2 files changed

+109
-32
lines changed

scripts/generate-nestjs-sdk.bash

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
#
3+
#
4+
5+
USER=`who am i | cut -d\ -f1`
6+
echo -e "\nUser running the script: ${USER}"
7+
8+
echo -e "\nCleanup old files..."
9+
rm -rf node_modules/@scicatproject/scicat-sdk-ts
10+
rm -rf @scicatproject/scicat-sdk-ts
11+
12+
echo -e "\nGenerating the new sdk..."
13+
docker run \
14+
--rm \
15+
--add-host host.docker.internal:host-gateway \
16+
-v "`pwd`:/local" \
17+
openapitools/openapi-generator-cli:v7.9.0 generate \
18+
-i http://host.docker.internal:3000/explorer-json \
19+
-g typescript-angular \
20+
-o local/@scicatproject/scicat-sdk-ts \
21+
--additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true
22+
23+
REMOVE_NPM_LINK=0
24+
if ! command -v npm 2>&1 1>/dev/null
25+
then
26+
if [ "--`env | grep NVM_BIN`--" != "----" ]
27+
then
28+
echo -e "\nCreating links to npm and node versions"
29+
ln -s "$NVM_BIN/npm" "/usr/local/bin/npm"
30+
whereis npm
31+
ln -s "$NVM_BIN/node" "/usr/local/bin/node"
32+
whereis node
33+
REMOVE_NPM_LINK=1
34+
else
35+
echo -e "\nNo npm found!!!"
36+
exit 1
37+
fi
38+
fi
39+
40+
echo -e "\nInstalling dependencies and building the sdk..."
41+
cd @scicatproject/scicat-sdk-ts
42+
npm install
43+
npm run build
44+
45+
echo -e "\nCopying the build files in node_modules..."
46+
cd ../..
47+
cp -rv @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts
48+
49+
echo -e "\nAdjusting ownership to user ${USER}"
50+
chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts
51+
52+
echo -e "\nFinal cleanup..."
53+
echo -e "Removing sdk folder"
54+
rm -rfv @scicatproject
55+
56+
if [ $REMOVE_NPM_LINK -eq 1 ];
57+
then
58+
echo -e "\nRemoving links to npm and node"
59+
rm -fv "/usr/local/bin/npm"
60+
rm -fv "/usr/local/bin/node"
61+
fi
62+

scripts/generate-nestjs-sdk.js

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,50 @@ function getCurrentDirectory() {
1919
return "$(pwd)";
2020
}
2121

22-
// NOTE: First do some cleanup before starting the generation
23-
console.log("Cleanup old files...");
24-
execSync(
25-
"rm -rf node_modules/@scicatproject/scicat-sdk-ts && rm -rf @scicatproject/scicat-sdk-ts",
26-
{ encoding: "utf-8" },
27-
);
28-
29-
console.log("Generating the new sdk...");
30-
const generationOutput = execSync(
31-
`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`,
32-
{ encoding: "utf-8" },
33-
);
34-
console.log(generationOutput);
35-
36-
console.log("Installing dependencies and building the sdk...");
37-
const installBuildOutput = execSync(
38-
"cd @scicatproject/scicat-sdk-ts && npm install && npm run build",
39-
{ encoding: "utf-8" },
40-
);
41-
console.log(installBuildOutput);
42-
43-
console.log("Copying the build files in node_modules...");
44-
const copyToNodeModulesOutput = execSync(
45-
"cp -r @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts",
46-
{ encoding: "utf-8" },
47-
);
48-
console.log(copyToNodeModulesOutput);
49-
50-
console.log("Final cleanup...");
51-
execSync("rm -rf @scicatproject", {
52-
encoding: "utf-8",
53-
});
22+
if (isWindows()) {
23+
24+
// NOTE: First do some cleanup before starting the generation
25+
console.log("Cleanup old files...");
26+
execSync(
27+
"rm -rf node_modules/@scicatproject/scicat-sdk-ts && rm -rf @scicatproject/scicat-sdk-ts",
28+
{ encoding: "utf-8" },
29+
);
30+
31+
console.log("Generating the new sdk...");
32+
const generationOutput = execSync(
33+
`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`,
34+
{ encoding: "utf-8" },
35+
);
36+
console.log(generationOutput);
37+
38+
console.log("Installing dependencies and building the sdk...");
39+
const installBuildOutput = execSync(
40+
"cd @scicatproject/scicat-sdk-ts && npm install && npm run build",
41+
{ encoding: "utf-8" },
42+
);
43+
console.log(installBuildOutput);
44+
45+
console.log("Copying the build files in node_modules...");
46+
const copyToNodeModulesOutput = execSync(
47+
"cp -r @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts",
48+
{ encoding: "utf-8" },
49+
);
50+
console.log(copyToNodeModulesOutput);
51+
52+
console.log("Final cleanup...");
53+
execSync("rm -rf @scicatproject", {
54+
encoding: "utf-8",
55+
});
56+
57+
console.log("Local SDK generation completed");
58+
59+
} else {
60+
console.log("Your environment is a linux/unix");
61+
console.log("Please run the following command on your terminal:");
62+
console.log("> sudo -E ./scripts/generate-nestjs-sdk.bash");
63+
console.log("");
64+
console.log("IMPORTANT: the script runs under sudo. You will be asked your password.");
65+
console.log("");
66+
67+
}
68+

0 commit comments

Comments
 (0)