Skip to content

Commit

Permalink
feat(training): create json schema to validate filesystemtree (#2485)
Browse files Browse the repository at this point in the history
## Proposed change

<!--
Please include a summary of the changes and the related issue.
Please also include relevant motivation and context.
-->

## Related issues

<!--
Please make sure to follow the [contribution
guidelines](https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md)
-->

*- No issue associated -*

<!-- * 🐛 Fix #issue -->
<!-- * 🐛 Fix resolves #issue -->
<!-- * 🚀 Feature #issue -->
<!-- * 🚀 Feature resolves #issue -->
<!-- * :octocat: Pull Request #issue -->
  • Loading branch information
fpaul-1A authored Nov 19, 2024
2 parents 96522c5 + 9124168 commit 6cb7e63
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 381 deletions.
2 changes: 2 additions & 0 deletions apps/showcase/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"defaultConfiguration": "production",
"dependsOn": [
"^build",
"^extract-folder-structure",
"generate-translations",
"generate-theme",
"generate-dark-theme",
Expand All @@ -176,6 +177,7 @@
"dependsOn": [
"^build-builders",
"^build",
"^extract-folder-structure",
"copy-training-assets",
"prepare-training"
]
Expand Down
68 changes: 68 additions & 0 deletions apps/showcase/schemas/webcontainer-file-system-tree.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "WebContainerFileSystemTreeSchema",
"description": "Schema of a webcontainer api file system tree",
"required": ["fileSystemTree"],
"properties": {
"fileSystemTree": {
"$ref": "#/definitions/FileSystemTree"
}
},
"definitions": {
"FileSystemTree": {
"type": "object",
"additionalProperties": {
"oneOf": [
{"$ref": "#/definitions/DirectoryNode"},
{"$ref": "#/definitions/FileNode"},
{"$ref": "#/definitions/SymlinkNode"}
]
}
},
"DirectoryNode": {
"type": "object",
"required": ["directory"],
"properties": {
"directory": {
"$ref": "#/definitions/FileSystemTree"
}
}
},
"FileNode": {
"type": "object",
"required": [
"file"
],
"properties": {
"file": {
"type": "object",
"description": "Metadata type",
"required": ["contents"],
"properties": {
"contents": {
"type": "string"
}
}
}
}
},
"SymlinkNode": {
"type": "object",
"required": [
"file"
],
"properties": {
"file": {
"type": "object",
"description": "Metadata type",
"required": ["symlink"],
"properties": {
"symlink": {
"type": "string"
}
}
}
}
}
}
}
4 changes: 3 additions & 1 deletion apps/showcase/scripts/prepare-training-exercises/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ void (async () => {
const exerciseStructure = await getFilesTree([{isDir: true, path: `${filePath}`}], {readdir, readFile});
const [_, commonPath, folderName] = folder.match('(.*)/(exercise|solution)');
const targetPath = join(commonPath, `${folderName}.json`);
const content = JSON.stringify(exerciseStructure);
const content = JSON.stringify({
fileSystemTree: exerciseStructure
});
await writeFile(targetPath, content);
}
})();
748 changes: 371 additions & 377 deletions apps/showcase/src/assets/trainings/sdk/shared/monorepo-template.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function getFilesContent(resources: Resource[]) {
return (resources.reduce((fileSystemTree: FileSystemTree, resource) => {
const sanitizedPath = `./${resource.path.replace(new RegExp('^[.]/?'), '')}`;
const parsedPath = sanitizedPath.split('/').filter((pathEl) => !!pathEl);
overrideFileSystemTree(fileSystemTree, JSON.parse(resource.content) as FileSystemTree, parsedPath);
overrideFileSystemTree(fileSystemTree, JSON.parse(resource.content).fileSystemTree as FileSystemTree, parsedPath);
return fileSystemTree;
}, {} as FileSystemTree)['.'] as DirectoryNode).directory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ void (async () => {
readdir: readdir,
readFile: readFile
} as FileSystem);
const content = JSON.stringify(folderStructure);
const content = JSON.stringify({
fileSystemTree: folderStructure
});

const targetPath = options.output.replace(/\\/g, "/");
const targetPath = options.output.replace(/\\/g, '/');
const parsedPath = parse(options.output);
if (parsedPath.dir) {
await mkdir(parsedPath.dir, {recursive: true});
Expand Down

0 comments on commit 6cb7e63

Please sign in to comment.