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

Changing build to possible use parser output for learningObjectives #1681

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 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 @@ -23,6 +23,7 @@
"test:scripts": "mocha './scripts/test/*.spec.mjs' --verbose",
"pretest": "npm run mdlint && npm run eslint && npm run validate && npm run test:topics",
"validate": "node ./scripts/build.mjs --validate",
"validate:objectives": "curriculum-parser learning-objectives ./learning-objectives/ --validate --strict",
"build:content": "node ./scripts/build.mjs",
"changelog": "git log $(git describe --tags --abbrev=0)..HEAD --oneline --format=\"* %h %s (%an)\"",
"create-cohort-project": "node ./scripts/create-cohort-project.mjs",
Expand Down
82 changes: 56 additions & 26 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const parse = (dir, validate) => new Promise((resolve) => {
});

//
// Create projects.json and topics.json with indeces of all projects and topics.
// Create projects.json and topics.json with indices of all projects and topics.
//
const createIndexes = async (results) => {
const resultsWithJson = await Promise.all(results.map(async result => ({
Expand All @@ -122,30 +122,59 @@ const createIndexes = async (results) => {
)));
};

const addLearningObjectives = async () => {
const dir = path.join(__dirname, '../learning-objectives')
const [tree, es, pt] = await Promise.all([
loadYaml(path.join(dir, 'data.yml')),
loadYaml(path.join(dir, 'intl', 'es.yml')),
loadYaml(path.join(dir, 'intl', 'pt.yml')),
]);

const flat = flattenLearningObjectives(tree);
const json = {
tree,
flat,
intl: { es, pt },
table: flat.map(key => ({
key,
es: es[key]?.title || es[key],
pt: pt[key]?.title || pt[key],
})),
};

await writeFile(
path.join(buildDir, 'learning-objectives.json'),
JSON.stringify(json, null, 2),
);
const addLearningObjectives = async (validate) => {

const parseObjectives = (validate) => new Promise((resolve) => {
const dir = path.join(__dirname, '../learning-objectives');
const dest = path.join(buildDir, 'learning-objectives.json')
const fd = openSync(validate ? '/dev/null' : dest, 'w');

const args = [
'curriculum-parser',
'learning-objectives',
dir,
// '--repo', repository,
// '--version', version,
Comment on lines +136 to +137
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repo y version seran necesarios?

];
unjust marked this conversation as resolved.
Show resolved Hide resolved

if (validate) {
args.push('--validate'); // TODO: put strict here?
}

console.log(args);
const child = spawn(
'npx',
args,
{ stdio: [null, fd, 'pipe'] },
);

const stderrChunks = [];
child.stderr.on('data', chunk => stderrChunks.push(chunk));

child.on('close', (code) => {
if (code > 0) {
const err = Object.assign(new Error(`Error parsing learning objectives`), {
stderr: stderrChunks.join(''),
});
console.error(err.stderr);
return resolve(err);
}

console.log(`<= OK parsing objectives`);
return resolve({ dest });
});
});

const { dest } = await parseObjectives(validate);
console.log(buildDir, dest);
if (!validate) {
const json = await JSON.parse(await readFile(dest));
await writeFile(
path.join(buildDir, 'learning-objectives.json'),
JSON.stringify(json, null, 2),
);
Comment on lines +171 to +175
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this step may be unnecessary since fd is the same (we are just reading and writing the same file)

}

};

const main = async (args, opts) => {
Expand All @@ -172,8 +201,9 @@ const main = async (args, opts) => {

if (!validate) {
await createIndexes(results);
await addLearningObjectives();
}

await addLearningObjectives(validate);
};

const { _: args, ...opts } = minimist(process.argv.slice(2));
Expand Down
Loading