feat: update challenge helpers to handle id filenames (#44769)
* refactor: light tweaks for readability * refactor: simplify metadata functions * fix: most tests * test: fix utils tests * test: simplify mocks * WIP: update get-last-step-file-content * feat: finish create-next-step * fix: type error * test: provide mock meta.json for test * refactor: get meta path from project path * refactor: get project name from path * refactor: simplify getProjectMetaPath further Also removes some excessive mocking * refactor: remove more mocks, always clear .env * feat: update create-next-step * feat: update create-empty steps Also refactors slightly, so it's easier to insert steps into the meta * docs: update challenge-helper-script docs * feat: create-step-between * refactor: allow metadata parse errors to propagate * fix: convert reorderSteps to renameSteps * refactor: create-step-between -> insert-step * feat: update delete-step * refactor: consolidate commands into commands.ts * refactor: clean up and consolidation * refactor: more cleanup * fix: make cli args consistent Everything accepts a single integer and nothing else * refactor: renameSteps -> updateStepTitles * docs: update with the names and args * feat: add step validating meta + files are synced
This commit is contained in:
committed by
GitHub
parent
16e7cdedb1
commit
339c6713d2
46
tools/challenge-helper-scripts/helpers/project-metadata.ts
Normal file
46
tools/challenge-helper-scripts/helpers/project-metadata.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import glob from 'glob';
|
||||
import { Meta } from '../create-project';
|
||||
import { getProjectName, getProjectPath } from './get-project-info';
|
||||
|
||||
function getMetaData(): Meta {
|
||||
const metaData = fs.readFileSync(getProjectMetaPath(), 'utf8');
|
||||
return JSON.parse(metaData) as Meta;
|
||||
}
|
||||
|
||||
function updateMetaData(newMetaData: Record<string, unknown>): void {
|
||||
fs.writeFileSync(getProjectMetaPath(), JSON.stringify(newMetaData, null, 2));
|
||||
}
|
||||
|
||||
function getProjectMetaPath(): string {
|
||||
return path.join(
|
||||
getProjectPath(),
|
||||
'../../..',
|
||||
'_meta',
|
||||
getProjectName(),
|
||||
'meta.json'
|
||||
);
|
||||
}
|
||||
|
||||
// This (and everything else) should be async, but it's fast enough
|
||||
// for the moment.
|
||||
function validateMetaData(): void {
|
||||
const { challengeOrder } = getMetaData();
|
||||
|
||||
// each step in the challengeOrder should correspond to a file
|
||||
challengeOrder.forEach(([id]) => {
|
||||
fs.accessSync(`${getProjectPath()}${id}.md`);
|
||||
});
|
||||
|
||||
// each file should have a corresponding step in the challengeOrder
|
||||
glob.sync(`${getProjectPath()}/*.md`).forEach(file => {
|
||||
const id = path.basename(file, '.md');
|
||||
if (!challengeOrder.find(([stepId]) => stepId === id))
|
||||
throw new Error(
|
||||
`File ${file} should be in the meta.json's challengeOrder`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export { getMetaData, updateMetaData, getProjectMetaPath, validateMetaData };
|
Reference in New Issue
Block a user