MCPcopy Create free account
hub / github.com/Tatamo/atcoder-cli / detectTaskByPath

Function detectTaskByPath

src/project.ts:83–106  ·  view source on GitHub ↗
(path?: string)

Source from the content-addressed store, hash-verified

81 * @param path 省略するとカレントディレクトリを使用
82 */
83export 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ファイルを保存する

Callers 2

taskFunction · 0.90
submitFunction · 0.90

Calls 1

findProjectJSONFunction · 0.85

Tested by

no test coverage detected