Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(training): create json schema to validate filesystemtree #2485

Merged
merged 1 commit into from
Nov 19, 2024
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
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"
}
}
}
}
}
}
}
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