(detailed_task: DetailedTask, dirname: string, project_path: string, options?: { tests?: boolean })
| 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; |
| 180 | const task_template = template !== undefined ? template.task : undefined; |
| 181 | const pwd = process.cwd(); |
| 182 | await promisify(mkdirp)(project_path); |
| 183 | process.chdir(project_path); |
| 184 | await promisify(mkdirp)(dirname); |
| 185 | process.chdir(dirname); |
| 186 | |
| 187 | const flg_tests = options !== undefined && options.tests === true; |
| 188 | let testdir = null; |
| 189 | |
| 190 | // サンプルケースのダウンロードを行う |
| 191 | if (flg_tests) { |
| 192 | testdir = formatTaskDirname(task_template !== undefined && task_template.testdir !== undefined ? task_template.testdir : (await getConfig()).get("default-test-dirname-format"), task, index, contest); |
| 193 | if (OnlineJudge.checkAvailable()) { |
| 194 | await OnlineJudge.call(["dl", task.url, "-d", testdir]); |
| 195 | } else { |
| 196 | console.error("online-judge-tools is not available. downloading of sample cases skipped."); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // テンプレートの展開を行う |
| 201 | if (task_template !== undefined) { |
| 202 | await installTaskTemplate(detailed_task, {contest: project_path, task: process.cwd()}, true); |
| 203 | } |
| 204 | |
| 205 | // もとのディレクトリに戻る |
| 206 | process.chdir(pwd); |
| 207 | // 新しく情報を付与したTaskオブジェクトを返す |
| 208 | const s: any = {directory: {path: dirname}}; |
| 209 | if (flg_tests) s.directory.testdir = testdir; |
| 210 | if (task_template !== undefined && task_template.submit !== undefined) s.directory.submit = formatTaskDirname(task_template.submit, task, index, contest); |
| 211 | return Object.assign(task, s); |
| 212 | } |
| 213 | |
| 214 | export function formatContestDirname(format: string, contest: Contest): string { |
| 215 | const convert = (pattern: string): string => { |
no test coverage detected