Skip to content

Commit

Permalink
feat(scripts/create-cohort-project): Agrega soporte para variantes de…
Browse files Browse the repository at this point in the history
… proyectos en script para coaches
  • Loading branch information
lupomontero committed Jun 11, 2024
1 parent 0aceb04 commit 7586cd3
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 67 deletions.
86 changes: 51 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"devDependencies": {
"@laboratoria/curriculum-parser": "^6.0.0-alpha.0",
"@laboratoria/mdlint": "^1.2.3",
"@laboratoria/sdk-js": "8.0.0-beta.0",
"@octokit/rest": "^20.0.2",
"@sentry/vite-plugin": "^2.16.0",
"@testing-library/jest-dom": "^6.1.5",
Expand Down
15 changes: 15 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,25 @@ Argumentos:
Opciones:

* `--locale`: Puede ser `es` o `pt`. Por defecto es `es`.
* `--variant`: Variente de implementación (si el proyecto tiene variantes).
* `--noop`: Si esta opción está presente el script nos dirá que es lo que haríá
paso a paso pero sin realmente hacer nada. Es útil para familiarizarse con el
script.

:warning: Para pasar opciones al script cuando invocamos a través de
`npm-scripts` (`npm run create-cohort-project`) hay que separar las opciones con
` -- ` para que `npm` las pase al script.

```sh
npm run create-cohort-project projects/05-fleet-management-api /tmp XXX999 -- --variant java
```

Si invocamos directamente no es necesario. Por ejemplo:

```sh
./scripts/create-cohort-project.mjs projects/05-fleet-management-api /tmp XXX999 --variant java
```

***

## Testing y linters
Expand Down
40 changes: 28 additions & 12 deletions scripts/create-cohort-project.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import {
transformLearningObjectives,
loadYaml,
} from '@laboratoria/curriculum-parser/lib/project.js';
import { getFilesWithLocales,
import { parseProject } from '@laboratoria/sdk-js';
import {
getFilesWithLocales,
defaultLocale,
supportedLocales,
getLearningObjectivesHeadings,
getLearningObjectivesHierarchy,
createLearningObjectivesMarkdown } from './script-utils.mjs';
createLearningObjectivesMarkdown
} from './script-utils.mjs';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const uiUrl = 'https://curriculum.laboratoria.la';
Expand Down Expand Up @@ -87,7 +90,7 @@ const copy = async (src, repoDir, opts) => {

// rename / replace default files with localized content
if (opts.locale && opts.locale !== defaultLocale) {
const files = getFilesWithLocales(repoDir, [ opts.locale ]);
const files = getFilesWithLocales(repoDir, [opts.locale]);
await Promise.all(files.map(filepath => rename(`${filepath}`, `${filepath.replace(`.${opts.locale}`, '')}`)));
}

Expand Down Expand Up @@ -125,15 +128,21 @@ const addExplainDevConfigFile = async ({ project, cohort, track, repoDir }) => {
};

const addLocalizedLearningObjectives = async (repoDir, opts, meta) => {

const learningObjectives = await transformLearningObjectives(repoDir, {
const { learningObjectives, variants } = await transformLearningObjectives(repoDir, {
lo: path.join(__dirname, '../learning-objectives'),
}, meta);

// Note: learningObjectives returns list of specific oa's
// example: so for js/modules -> js/modules/esm, js/modules/common
if (variants?.length && !opts.variant) {
throw new Error('Project has variants, please specify one with --variant');
}

const parsedProject = parseProject({ ...meta, learningObjectives, variants });
const combinedLearningObjectives = parsedProject.getCombinedLearningObjectives(opts.variant);

if (!learningObjectives) {
// Note: combinedLearningObjectives returns list of objects, each with a
// property `id` containing a string like: js/modules, s/modules/esm, etc

if (!combinedLearningObjectives?.length) {
return;
}

Expand All @@ -142,9 +151,14 @@ const addLocalizedLearningObjectives = async (repoDir, opts, meta) => {
path.join(__dirname, '../learning-objectives', 'intl', `${lang}.yml`),
);

const categoryTree = getLearningObjectivesHierarchy(learningObjectives);
const categoryTree = getLearningObjectivesHierarchy(combinedLearningObjectives);
const sectionTree = getLearningObjectivesHeadings(categoryTree, intl);
const text = createLearningObjectivesMarkdown(learningObjectives, sectionTree, intl, lang);
const text = createLearningObjectivesMarkdown(
combinedLearningObjectives,
sectionTree,
intl,
lang,
);
const readmePath = path.join(repoDir, 'README.md');
const contents = (await readFile(readmePath, 'utf8')).split('\n');
const startIndex = contents.findIndex(
Expand Down Expand Up @@ -226,14 +240,13 @@ const main = async (args, opts) => {
ensureSrc(src);

const slug = path.basename(src).slice(3);
const repoName = prefix ? `${prefix}-${slug}` : slug;
const repoName = `${prefix ? `${prefix}-` : ''}${slug}${opts.variant ? `-${opts.variant}` : ''}`;
const repoDir = dest ? `${dest}/${repoName}` : repoName;

await ensureRepoDir(repoDir, opts);
await copy(src, repoDir, opts);
await addBootcampInfo(repoDir);
const meta = await loadYaml(path.join(src, 'project.yml'));
// console.log('learning Objectives son', learningObjectives);
await addExplainDevConfigFile({
project: slug,
cohort: prefix,
Expand Down Expand Up @@ -299,6 +312,9 @@ Este es un mensaje de ayuda para que puedas usarlo.
# crea el proyecto Markdown Links en la ruta actual para DEV999
npm run create-cohort-project projects/04-md-links ./ DEV999
# crea proyecto Fleet Management API en su variante de Java
npm run create-cohort-project projects/05-fleet-management-api / XXX999 -- --variant java
Acá puedes encontrar la documentación completa:
https://github.com/Laboratoria/curriculum/tree/main/scripts#create-cohort-project
`);
Expand Down
Loading

0 comments on commit 7586cd3

Please sign in to comment.