From 1b4b76e41a048a9fab3967c3a34608920c44fff6 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 14 Jan 2025 09:30:29 +0100 Subject: [PATCH 1/2] fix(schemas_script): parametric & reusable sript --- generate_schemas.js | 63 ++++++++++++++++++++++++++++++++++++--------- package.json | 6 ++--- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/generate_schemas.js b/generate_schemas.js index 608bb884..fe7d6cdb 100644 --- a/generate_schemas.js +++ b/generate_schemas.js @@ -3,29 +3,55 @@ const path = require("path"); const glob = require("glob"); const process = require("process"); -const findDirectoryPath = (targetDirectoryName) => { - const pathToCheck = path.join(process.cwd(), targetDirectoryName); +console.log("process.argv", process.argv); + +var projectName = process.argv[2]; +console.log("projectName", projectName); +var folderName = process.argv[3]; +console.log("folderName", folderName); +var key = process.argv[4]; +console.log("key", key); +var separator = process.argv[5]; +console.log("separator", separator); + +const findDirectoryPath = (targetDirectoryName, folderName) => { + const pathToCheck = path.join( + process.cwd(), + "/src", + "/", + targetDirectoryName + ); + console.log("pathToCheck", pathToCheck); + const folders = fs .readdirSync(pathToCheck, { withFileTypes: true }) .filter( - (folder) => folder.isDirectory() && !folder.name.endsWith(".egg-info") + (folder) => + folder.isDirectory() && + !folder.name.endsWith(".egg-info") && + folder.name != "tests" && + folder.name != "__pycache__" && + folder.name.includes(folderName) ) .map((folder) => ({ name: folder.name, path: path.join(pathToCheck, folder.name), })); - const routesDirectory = path.join(folders[0].path, "routes"); - return [routesDirectory, folders[0].name]; + console.log("folders", folders); + const routesDirectory = path.join(folders[0].path); + return routesDirectory; }; -const [directoryPath, project_name] = findDirectoryPath("src/"); +const directoryPath = findDirectoryPath(projectName, folderName); const outputFile = path.join(process.cwd(), "schemas.json"); -function return_json_schema(directoryPath, folder_path, project_name) { +function return_json_schema(directoryPath, folder_path, projectName) { + console.log("return_json_schema", directoryPath, folder_path, projectName); + const folders = fs .readdirSync(path.normalize(directoryPath), { withFileTypes: true }) - .filter((folder) => folder.isDirectory()) + .filter((folder) => folder.isDirectory() && folder.name != "__pycache__") .map((folder) => ({ name: folder.name, path: path.join(directoryPath, folder.name), @@ -42,8 +68,21 @@ function return_json_schema(directoryPath, folder_path, project_name) { var filename = filePath .replace(/^.*[\\/]/, "") .replace(/\.[^/.]+$/, ""); - var route = jsonData["route"]; - jsonData["$id"] = project_name + folder_path + route; + var route = jsonData[key]; + console.log("FOLDER PATH", projectName); + var values = [projectName, folder_path, route]; + console.log("values", values); + values = values.map(function (x) { + return x.replace("/", ""); + }); + values = values.map(function (x) { + return x.replace(".", ""); + }); + jsonData["$id"] = values + .filter(function (val) { + return val; + }) + .join(separator); schemas[filename] = jsonData; } catch (error) { console.error( @@ -63,7 +102,7 @@ function return_json_schema(directoryPath, folder_path, project_name) { }, folders_schemas); } else { var new_folder_path = folder_path + "/" + folder.name; - var test = return_json_schema(folder.path, new_folder_path, project_name); + var test = return_json_schema(folder.path, new_folder_path, projectName); folders_schemas[folder.name] = test; } }); @@ -75,6 +114,6 @@ if (fs.existsSync(outputFile)) { } const finalJson = {}; -finalJson[project_name] = return_json_schema(directoryPath, "", project_name); +finalJson[projectName] = return_json_schema(directoryPath, "", projectName); fs.writeFileSync(outputFile, JSON.stringify(finalJson, null, 2)); diff --git a/package.json b/package.json index a5ae2a96..8c17bb92 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,9 @@ { "name": "@geode/opengeodeweb-back", + "version": "0.0.0-semantically-released", + "description": "", "scripts": { - "json": "node generate_schemas.js" + "json": "node generate_schemas.js opengeodeweb_back routes route /" }, "dependencies": { "glob": "^10.3.10" @@ -12,8 +14,6 @@ "require": "./schemas.json" } }, - "version": "0.0.0-semantically-released", - "description": "", "main": "generate_schemas.js", "repository": { "type": "git", From a8f7923573483cc6e4eae89f8fd0b45633abd80d Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Tue, 14 Jan 2025 10:25:49 +0100 Subject: [PATCH 2/2] replace separators in folders --- generate_schemas.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/generate_schemas.js b/generate_schemas.js index fe7d6cdb..b5264f99 100644 --- a/generate_schemas.js +++ b/generate_schemas.js @@ -73,11 +73,14 @@ function return_json_schema(directoryPath, folder_path, projectName) { var values = [projectName, folder_path, route]; console.log("values", values); values = values.map(function (x) { - return x.replace("/", ""); - }); + console.log("x", x); + return x.replace("/", "").replace(".", ""); + }); // first replace first . / by empty string values = values.map(function (x) { - return x.replace(".", ""); - }); + console.log("x", x); + return x.replaceAll("/", separator).replaceAll(".", separator); + }); // then replace all . / by separator + console.log("values", values); jsonData["$id"] = values .filter(function (val) { return val;