Skip to content

Commit bf4274f

Browse files
authored
Merge pull request #63 from Geode-solutions/feat/schemas
Feat/schemas
2 parents da2b977 + 51189d6 commit bf4274f

File tree

6 files changed

+582
-9
lines changed

6 files changed

+582
-9
lines changed

.github/workflows/CD.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,25 @@ jobs:
2222
run: |
2323
python3 -m pip install --upgrade build
2424
python3 -m build
25-
- name: Upload
25+
- name: Upload PYPI
2626
if: steps.semantic-release.outputs.released == 'true'
2727
run: |
2828
python3 -m pip install twine
2929
python3 -m twine upload --repository pypi dist/* -u __token__ -p ${{ secrets.PYPI_TOKEN }}
30+
- name: Setup NODE
31+
uses: actions/setup-node@v3
32+
with:
33+
node-version: "20.x"
34+
- name: Upload NPM
35+
if: steps.semantic-release.outputs.released == 'true'
36+
run: |
37+
npm ci
38+
rm -f -- schemas.json
39+
npm run json
40+
jq -c '.version = "steps.semantic-release.outputs.version"' package.json > tmp.$$.json && mv tmp.$$.json package.json
41+
npm publish
42+
env:
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3044
- name: Merge master -> next
3145
if: github.ref == 'refs/heads/master'
3246
uses: devmasx/merge-branch@master

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ venv
44
output
55
__pycache__
66
.vscode
7-
uploads
7+
uploads
8+
node_modules
9+
schemas.json

generate_schemas.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const glob = require("glob");
4+
const process = require("process");
5+
6+
const findDirectoryPath = (targetDirectoryName) => {
7+
const pathToCheck = path.join(process.cwd(), targetDirectoryName);
8+
const folders = fs
9+
.readdirSync(pathToCheck, { withFileTypes: true })
10+
.filter((folder) => folder.isDirectory())
11+
.map((folder) => ({
12+
name: folder.name,
13+
path: path.join(pathToCheck, folder.name),
14+
}));
15+
const routesDirectory = path.join(folders[0].path, "routes");
16+
return [routesDirectory, folders[0].name];
17+
};
18+
19+
const [directoryPath, project_name] = findDirectoryPath("src/");
20+
21+
const outputFile = path.join(process.cwd(), "schemas.json");
22+
23+
function return_json_schema(directoryPath, folder_path, project_name) {
24+
const folders = fs
25+
.readdirSync(directoryPath, { withFileTypes: true })
26+
.filter((folder) => folder.isDirectory())
27+
.map((folder) => ({
28+
name: folder.name,
29+
path: path.join(directoryPath, folder.name),
30+
}));
31+
var folders_schemas = {};
32+
folders.forEach((folder) => {
33+
if (folder.name == "schemas") {
34+
const jsonFiles = glob.sync(path.join(folder.path, "**/*.json"));
35+
var schemas = {};
36+
jsonFiles.forEach((filePath) => {
37+
try {
38+
const fileContent = fs.readFileSync(filePath, "utf8");
39+
var jsonData = JSON.parse(fileContent);
40+
var filename = filePath
41+
.replace(/^.*[\\/]/, "")
42+
.replace(/\.[^/.]+$/, "");
43+
var route = jsonData["route"];
44+
jsonData["$id"] = project_name + folder_path + route;
45+
schemas[filename] = jsonData;
46+
} catch (error) {
47+
console.error(
48+
`Erreur lors de la lecture du fichier ${filePath}:`,
49+
error
50+
);
51+
}
52+
});
53+
folders_schemas = Object.keys(schemas).reduce((acc, key) => {
54+
const currentSchema = schemas[key];
55+
const modifiedSchema = {
56+
$id: path.join(folder_path, currentSchema["$id"]),
57+
...currentSchema,
58+
};
59+
acc[key] = modifiedSchema;
60+
return acc;
61+
}, folders_schemas);
62+
} else {
63+
var new_folder_path = folder_path + "/" + folder.name;
64+
var test = return_json_schema(folder.path, new_folder_path, project_name);
65+
folders_schemas[folder.name] = test;
66+
}
67+
});
68+
return folders_schemas;
69+
}
70+
71+
if (fs.existsSync(outputFile)) {
72+
fs.unlinkSync(outputFile);
73+
}
74+
75+
const finalJson = {};
76+
finalJson[project_name] = return_json_schema(directoryPath, "", project_name);
77+
78+
fs.writeFileSync(outputFile, JSON.stringify(finalJson, null, 2));
79+
80+
console.log("Fichier JSON créé avec succès :", outputFile);

0 commit comments

Comments
 (0)