Files
freeCodeCamp/tools/challenge-helper-scripts/helpers/project-metadata.ts
Niraj Nandish 53164e71f1 fix: circular dependencies (#46638)
* fix: circular dependency in formHelpers

* fix: circular dependency in Flash

* fix: circular dependency in helpers

* fix: circular dependency in current-challenge-saga (1/2)

* fix: circular dependency in code-lock-epic

* feat: eslint rule for circular dependencies

* fix: circular dependency in tools

* fix: import error and more circular dependencies in formHelpers

* fix prettier error

* fix: circular dependency in danger-zone-saga

* fix: circular dependency in update-email-saga

* fix: circular dependency in settings-saga

* fix: circular dependency in accept-terms-saga

* fix: circular dependency in codeally-saga

TODO: make a separate file for selectors

* fix: ci lint error

* fix: ci lint:prettier error

* fix: circular dependency in current-challenge-saga

* fix: cricular dependency in Challenges/redux

* fix: circular dependency in redux/settings

* fix: circular dependency in root redux

* fix: lint errors

* chore: remove unecessary comment

* chore: remove unused export

* fix: clear out actions and selectors

* revert changes to package.json

* test ci with maxDepth of 1

* fix: fallback to empty object

* test action if it will run for maxDepth of 2
2022-10-05 18:08:40 +01:00

60 lines
1.6 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import glob from 'glob';
import { getProjectName, getProjectPath } from './get-project-info';
export type Meta = {
name: string;
isUpcomingChange: boolean;
dashedName: string;
order: number;
time: string;
template: string;
required: string[];
superBlock: string;
superOrder: number;
isBeta: boolean;
challengeOrder: string[][];
};
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 };