Repository: freeCodeCamp/freeCodeCamp
File: tools/challenge-helper-scripts/create-project.ts (TypeScript)

Code before:
    '../../curriculum/superblock-structure/full-stack.json',
    { encoding: 'utf-8' }
  );
  const fullStackData = JSON.parse(fullStackText) as FullStackData;

  const chapterExists =
    fullStackData['chapters'].findIndex(
      (chapter: FullStackChapter) => chapter.dashedName === chapterName
    ) !== -1;
  if (!chapterExists) {
    // Inserts the chapter, module and block if the chapter is missing
    const newChapter = {
      dashedName: chapterName,
      modules: [{ dashedName: moduleName, blocks: [{ dashedName: block }] }]
    };
    fullStackData['chapters'].push(newChapter);
  } else {
    // Chapter is present; is module present
    // Get the index of the correct chapter
    const chapterIndex = fullStackData['chapters'].findIndex(
      (chapter: FullStackChapter) => chapter.dashedName === chapterName
    );
    const moduleExists =
      fullStackData['chapters'][chapterIndex]['modules'].findIndex(
        (module: FullStackModule) => module.dashedName === moduleName
      ) !== -1;

    if (!moduleExists) {
      // Insert the new module and block
      fullStackData['chapters'][chapterIndex]['modules'].push({
        dashedName: moduleName,
        blocks: [{ dashedName: block }]
      });
    } else {
      const moduleIndex = fullStackData['chapters'][chapterIndex][
        'modules'
      ].findIndex(
        (module: FullStackModule) => module.dashedName === moduleName
      );
      fullStackData['chapters'][chapterIndex]['modules'][moduleIndex][
        'blocks'
      ].splice(position - 1, 0, { dashedName: block });
      // Insert the new block into the already present module
    }
    // Write the new changes to the file
    const newData = JSON.stringify(fullStackData, null, 2);
    await fs.writeFile(
      '../../curriculum/superblock-structure/full-stack.json',
      newData
    );
  }

Review comment (suggestion):
```suggestion
    const moduleExists = fullStackData['chapters'][chapterIndex][
      'modules'
    ].some((module: FullStackModule) => module.dashedName === moduleName);
```

Code after:
      projectArgs.block,
      projectArgs.title,
      projectArgs.helpCategory,
      challengeId,
      projectArgs.order,
      projectArgs.blockType,
      projectArgs.blockLayout
    );
    // TODO: remove once we stop relying on markdown in the client.
  }

  if (
    (projectArgs.superBlock === SuperBlocks.FullStackDeveloper &&
      projectArgs.blockType) == null
  ) {
    throw new Error('Missing argument: blockType when updating intro markdown');
  }

  void createIntroMD(
    projectArgs.superBlock,
    projectArgs.block,
    projectArgs.title
  );
}

async function updateIntroJson(
  superBlock: SuperBlocks,
  block: string,
  title: string
) {
  const introJsonPath = path.resolve(
    __dirname,
    '../../client/i18n/locales/english/intro.json'
  );
  const newIntro = await parseJson<IntroJson>(introJsonPath);
  newIntro[superBlock].blocks[block] = {
    title,
    intro: [title, '']
  };
  void withTrace(
    fs.writeFile,
    introJsonPath,
    await format(JSON.stringify(newIntro), { parser: 'json' })
  );
}

async function createMetaJson(
  superBlock: SuperBlocks,
  block: string,
  title: string,
  helpCategory: string,