(projectArgs: CreateProjectArgs)
| 56 | } |
| 57 | |
| 58 | async function createProject(projectArgs: CreateProjectArgs) { |
| 59 | if (!projectArgs.title) { |
| 60 | projectArgs.title = projectArgs.block; |
| 61 | } |
| 62 | |
| 63 | const order = projectArgs.order; |
| 64 | const chapter = projectArgs.chapter; |
| 65 | const module = projectArgs.module; |
| 66 | const position = projectArgs.position; |
| 67 | |
| 68 | const superblockFilename = ( |
| 69 | superBlockToFilename as Record<SuperBlocks, string> |
| 70 | )[projectArgs.superBlock]; |
| 71 | |
| 72 | if (chapterBasedSuperBlocks.includes(projectArgs.superBlock)) { |
| 73 | if (!chapter || !module || typeof position == 'undefined') { |
| 74 | throw Error( |
| 75 | 'Missing one of the following arguments: chapter, module, position' |
| 76 | ); |
| 77 | } |
| 78 | void updateChapterModuleSuperblockStructure( |
| 79 | projectArgs.block, |
| 80 | // Convert human-friendly (1-based) position to 0-based index for insertion. |
| 81 | { order: position - 1, chapter, module }, |
| 82 | superblockFilename |
| 83 | ); |
| 84 | } else { |
| 85 | if (typeof order == 'undefined') { |
| 86 | throw Error('Missing argument: order'); |
| 87 | } |
| 88 | void updateSimpleSuperblockStructure( |
| 89 | projectArgs.block, |
| 90 | { order }, |
| 91 | superblockFilename |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | void updateIntroJson( |
| 96 | projectArgs.superBlock, |
| 97 | projectArgs.block, |
| 98 | projectArgs.title |
| 99 | ); |
| 100 | |
| 101 | const challengeId = new ObjectId(); |
| 102 | |
| 103 | if (projectArgs.blockLabel === BlockLabel.quiz) { |
| 104 | if (projectArgs.questionCount == null) { |
| 105 | throw new Error( |
| 106 | 'Property `questionCount` is null when creating new Quiz Challenge' |
| 107 | ); |
| 108 | } |
| 109 | await createMetaJson( |
| 110 | projectArgs.superBlock, |
| 111 | projectArgs.block, |
| 112 | projectArgs.title, |
| 113 | projectArgs.helpCategory, |
| 114 | challengeId |
| 115 | ); |
no test coverage detected