Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 51 additions & 12 deletions generate_schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(
Expand All @@ -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;
}
});
Expand All @@ -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));
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,8 +14,6 @@
"require": "./schemas.json"
}
},
"version": "0.0.0-semantically-released",
"description": "",
"main": "generate_schemas.js",
"repository": {
"type": "git",
Expand Down
Loading