Skip to content

Commit 53186ae

Browse files
authored
Merge pull request #1637 from SciCatProject/SWAP-4278-new-sdk-frotnend-code-refactor-part-3
feat: add new sdk generation script for local development
2 parents 04f5ac1 + ecd92bb commit 53186ae

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"lint:fix": "ng lint --fix",
1313
"betterer": "betterer",
1414
"cypress:open": "cypress open",
15-
"cypress:run": "cypress run"
15+
"cypress:run": "cypress run",
16+
"generate:sdk:local": "node scripts/generate-nestjs-sdk"
1617
},
1718
"private": true,
1819
"dependencies": {

scripts/generate-nestjs-sdk.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* NOTE: This file contains commands that generate new typescript-angular sdk against the running scicat backend
3+
* which overwrites the node_modules/@scicatproject/scicat-sdk-ts for development purpose
4+
* It should NOT be used in production because the real (@scicatproject/scicat-sdk-ts) npm package will be installed and used.
5+
*/
6+
7+
const execSync = require("child_process").execSync;
8+
9+
// NOTE: First do some cleanup before starting the generation
10+
console.log("Cleanup old files...");
11+
execSync(
12+
"rm -rf node_modules/@scicatproject/scicat-sdk-ts && rm -rf @scicatproject/scicat-sdk-ts",
13+
{ encoding: "utf-8" },
14+
);
15+
16+
console.log("Generating the new sdk...");
17+
const generationOutput = execSync(
18+
'docker run --rm -v "%cd%:/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',
19+
{ encoding: "utf-8" },
20+
);
21+
console.log(generationOutput);
22+
23+
console.log("Installing dependencies and building the sdk...");
24+
const installBuildOutput = execSync(
25+
"cd @scicatproject/scicat-sdk-ts && npm install && npm run build",
26+
{ encoding: "utf-8" },
27+
);
28+
console.log(installBuildOutput);
29+
30+
console.log("Copying the build files in node_modules...");
31+
const copyToNodeModulesOutput = execSync(
32+
"cp -r @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts",
33+
{ encoding: "utf-8" },
34+
);
35+
console.log(copyToNodeModulesOutput);
36+
37+
console.log("Final cleanup...");
38+
execSync("rm -rf @scicatproject", {
39+
encoding: "utf-8",
40+
});

0 commit comments

Comments
 (0)