(contest_id: string, template: Template | undefined, options: { force?: boolean, contestDirnameFormat?: string })
| 145 | * @param options |
| 146 | */ |
| 147 | export async function init(contest_id: string, template: Template | undefined, options: { force?: boolean, contestDirnameFormat?: string }): Promise<ContestProject> { |
| 148 | const atcoder = await getAtCoder(); |
| 149 | if (!await atcoder.checkSession()) await atcoder.login(); |
| 150 | const [contest, tasks] = await Promise.all([atcoder.contest(contest_id), atcoder.tasks(contest_id)]).catch(() => { |
| 151 | throw new Error("failed to get contest information."); |
| 152 | }); |
| 153 | const format = options.contestDirnameFormat !== undefined ? options.contestDirnameFormat : (await getConfig()).get("default-contest-dirname-format"); |
| 154 | const dirname = formatContestDirname(format, contest); |
| 155 | try { |
| 156 | await promisify(mkdir)(dirname); |
| 157 | } |
| 158 | catch { |
| 159 | // forceオプションがtrueでない場合のみエラーで停止する |
| 160 | if (options.force !== true) { |
| 161 | throw new Error(`${dirname} file/directory already exists.`) |
| 162 | } |
| 163 | } |
| 164 | process.chdir(dirname); |
| 165 | // プロジェクトディレクトリのpathを保持 |
| 166 | const contest_path = process.cwd(); |
| 167 | const data = {contest, tasks}; |
| 168 | await saveProjectJSON(data, process.cwd()); |
| 169 | console.log(`${dirname}/${PROJECT_JSON_FILE_NAME} created.`); |
| 170 | |
| 171 | // テンプレートの展開を行う |
| 172 | if (template !== undefined) { |
| 173 | await installContestTemplate(contest, template, contest_path, true); |
| 174 | } |
| 175 | return data; |
| 176 | } |
| 177 | |
| 178 | export async function installTask(detailed_task: DetailedTask, dirname: string, project_path: string, options?: { tests?: boolean }): Promise<Task> { |
| 179 | const {task, index, contest, template} = detailed_task; |
no test coverage detected