diff --git a/apps/showcase/.gitignore b/apps/showcase/.gitignore index 61534a6926..4f4e5da2c3 100644 --- a/apps/showcase/.gitignore +++ b/apps/showcase/.gitignore @@ -6,3 +6,5 @@ dist-e2e-playwright playwright-reports test-results training-assets +src/assets/trainings/*-training/**/exercise.json +src/assets/trainings/*-training/**/solution.json diff --git a/apps/showcase/package.json b/apps/showcase/package.json index a6db3a37f5..a6ac690e65 100644 --- a/apps/showcase/package.json +++ b/apps/showcase/package.json @@ -14,6 +14,7 @@ "start:no-translation": "ng serve", "generate:translations:dev": "ng run showcase:generate-translations", "generate:translations": "ng run showcase:generate-translations:production", + "prepare-training": "node scripts/prepare-training-exercises/index.cjs", "cms-adapters:localizations": "ng run showcase:extract-translations", "cms-adapters:metadata": "yarn run cms-adapters:localizations", "update:otter": "ng update @o3r/core", diff --git a/apps/showcase/project.json b/apps/showcase/project.json index 27f42baa34..ea2c437d73 100644 --- a/apps/showcase/project.json +++ b/apps/showcase/project.json @@ -55,7 +55,7 @@ "{projectRoot}/dev-resources", "{projectRoot}/training-assets", "{projectRoot}/*.metadata.json", - "packages/@o3r/training-sdk/dist/*-structure.json" + "{workspaceRoot}/packages/@o3r/training-sdk/dist/*-structure.json" ], "options": { "outputPath": "apps/showcase/dist", @@ -145,7 +145,8 @@ "generate-theme", "generate-dark-theme", "generate-horizon-theme", - "copy-training-assets" + "copy-training-assets", + "prepare-training" ] }, "serve": { @@ -380,6 +381,23 @@ }, "dependsOn": ["^build-builders"] }, + "prepare-training": { + "executor": "nx:run-script", + "inputs": [ + "global", + "{projectRoot}/package.json", + "{projectRoot}/src/assets/**/exercise/**", + "{projectRoot}/src/assets/**/solution/**", + "{projectRoot}/scripts/prepare-training-exercises/*.cjs" + ], + "outputs": [ + "{projectRoot}/src/assets/**/solution.json", + "{projectRoot}/src/assets/**/exercise.json" + ], + "options": { + "script": "prepare-training" + } + }, "copy-training-assets": { "executor": "nx:run-script", "inputs": [ diff --git a/apps/showcase/scripts/prepare-training-exercises/index.cjs b/apps/showcase/scripts/prepare-training-exercises/index.cjs new file mode 100644 index 0000000000..8c03316ffe --- /dev/null +++ b/apps/showcase/scripts/prepare-training-exercises/index.cjs @@ -0,0 +1,26 @@ +const {readdir, readFile, writeFile} = require('node:fs/promises'); +const {getFilesTree} = require('@o3r/training-tools'); +const {dirname, join, resolve} = require('node:path'); +const glob = require('globby'); + +/** + * The purpose of this script is to generate the exercise and solution files for the code editor + */ + +void (async () => { + const root = resolve(__dirname, '..', '..'); + const files = await glob('src/assets/trainings/*-training/**/(exercise|solution)/**', {cwd: root}); + const paths = files.reduce((exercisePaths, file) => { + const exerciseDirectory = dirname(file).match('(.*/(?:exercise|solution))')[0]; + exercisePaths.add(`${exerciseDirectory}`); + return exercisePaths; + }, new Set()); + for (const folder of paths) { + const filePath = join(root, folder); + 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); + await writeFile(targetPath, content); + } +})(); diff --git a/apps/showcase/src/app/app-routing.module.ts b/apps/showcase/src/app/app-routing.module.ts index 5fe834d86b..78d1df3bb2 100644 --- a/apps/showcase/src/app/app-routing.module.ts +++ b/apps/showcase/src/app/app-routing.module.ts @@ -13,6 +13,7 @@ const appRoutes: Routes = [ {path: 'run-app-locally', loadComponent: () => import('./run-app-locally/index').then((m) => m.RunAppLocallyComponent), title: 'Otter Showcase - Run App Locally'}, {path: 'sdk', loadComponent: () => import('./sdk/index').then((m) => m.SdkComponent), title: 'Otter Showcase - SDK'}, {path: 'placeholder', loadComponent: () => import('./placeholder/index').then((m) => m.PlaceholderComponent), title: 'Otter Showcase - Placeholder'}, + {path: 'sdk-training', loadComponent: () => import('./sdk-training/index').then((m) => m.SdkTrainingComponent), title: 'Otter Showcase - SDK Training'}, {path: '**', redirectTo: '/home', pathMatch: 'full'} ]; diff --git a/apps/showcase/src/app/app.component.html b/apps/showcase/src/app/app.component.html index fb9c8bab04..a309bb1e05 100644 --- a/apps/showcase/src/app/app.component.html +++ b/apps/showcase/src/app/app.component.html @@ -1,28 +1,31 @@ - -
-
-
- + +
+
+
+ -
-
- + > +
+
+ +
-