(path?: string)
| 81 | * @param path 省略するとカレントディレクトリを使用 |
| 82 | */ |
| 83 | export async function detectTaskByPath(path?: string): Promise<{ contest: Contest | null, task: Task | null }> { |
| 84 | if (path === undefined) path = process.cwd(); |
| 85 | try { |
| 86 | const {path: project_path, data: {contest, tasks}} = await findProjectJSON(); |
| 87 | if (path === project_path) { |
| 88 | // ブロジェクトディレクトリとカレントディレクトリが一致 |
| 89 | return {contest, task: null}; |
| 90 | } |
| 91 | // projectディレクトリの一つ下の階層のディレクトリ名を取得 |
| 92 | const dirname = path.split(sep)[project_path.split(sep).length]; |
| 93 | let task = null; |
| 94 | for (const t of tasks) { |
| 95 | if (t.directory !== undefined) { |
| 96 | if (resolve(project_path, t.directory.path) === resolve(project_path, dirname)) { |
| 97 | task = t; |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | return {contest, task}; |
| 103 | } catch { |
| 104 | return {contest: null, task: null}; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * プロジェクトJSONファイルを保存する |
no test coverage detected