Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ jobs:
deploy:
uses: Geode-solutions/actions/.github/workflows/py-deploy.yml@master
with:
npm: false
npm: true
secrets: inherit

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
test:
uses: Geode-solutions/actions/.github/workflows/py-test.yml@master
with:
npm: false
npm: true
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ jobs:
test:
uses: Geode-solutions/actions/.github/workflows/py-test-pr.yml@master
with:
npm: false
npm: true
secrets: inherit
122 changes: 122 additions & 0 deletions generate_schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const process = require("process");

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.name != "tests" &&
folder.name != "__pycache__" &&
folder.name.includes(folderName)
)
.map((folder) => ({
name: folder.name,
path: path.join(pathToCheck, folder.name),
}));
console.log("folders", folders);
const routesDirectory = path.join(folders[0].path);
return routesDirectory;
};

const directoryPath = findDirectoryPath(projectName, folderName);

const outputFile = path.join(process.cwd(), `${projectName}_schemas.json`);

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() && folder.name != "__pycache__")
.map((folder) => ({
name: folder.name,
path: path.join(directoryPath, folder.name),
}));
var folders_schemas = {};
folders.forEach((folder) => {
if (folder.name == "schemas") {
const jsonFiles = glob.sync(path.join(folder.path, "**/*.json"));
var schemas = {};
jsonFiles.forEach((filePath) => {
try {
const fileContent = fs.readFileSync(filePath, "utf8");
var jsonData = JSON.parse(fileContent);
var filename = filePath
.replace(/^.*[\\/]/, "")
.replace(/\.[^/.]+$/, "");
var route = jsonData[key];
console.log("FOLDER PATH", projectName);
var values = [projectName, folder_path, route];
console.log("values", values);
values = values.map(function (x) {
console.log("x", x);
return x.replace("/", "").replace(".", "");
}); // first replace first . / by empty string
values = values.map(function (x) {
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;
})
.join(separator);
schemas[filename] = jsonData;
} catch (error) {
console.error(
`Erreur lors de la lecture du fichier ${filePath}:`,
error
);
}
});
folders_schemas = Object.keys(schemas).reduce((acc, key) => {
const currentSchema = schemas[key];
const modifiedSchema = {
$id: path.join(folder_path, currentSchema["$id"]),
...currentSchema,
};
acc[key] = modifiedSchema;
return acc;
}, folders_schemas);
} else {
var new_folder_path = folder_path + "/" + folder.name;
var test = return_json_schema(folder.path, new_folder_path, projectName);
folders_schemas[folder.name] = test;
}
});
return folders_schemas;
}

if (fs.existsSync(outputFile)) {
fs.unlinkSync(outputFile);
}

const finalJson = {};
finalJson[projectName] = return_json_schema(directoryPath, "", projectName);

fs.writeFileSync(outputFile, JSON.stringify(finalJson, null, 2));
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@geode/opengeodeweb-microservice",
"version": "0.0.0",
"description": "Shared utilities and schema generator for OpenGeodeWeb ecosystem",
"main": "generate_schemas.js",
"bin": {
"ogw-generate-schemas": "./generate_schemas.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 0",
"build": "echo \"Error: no test specified\" && exit 0"
},
"dependencies": {
"glob": "^11.0.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Geode-solutions/OpenGeodeWeb-Microservice.git"
},
"author": {
"name": "Geode-solutions",
"email": "contact@geode-solutions.com",
"url": "https://geode-solutions.com/"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice/issues"
},
"homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Microservice",
"publishConfig": {
"access": "public"
},
"files": [
"generate_schemas.js"
]
}
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
SQLAlchemy==2.0.43
Flask-SQLAlchemy==3.1.1
Flask-SQLAlchemy==3.1.1
fastjsonschema==2.21.1
Loading