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

Function init

src/project.ts:147–176  ·  view source on GitHub ↗
(contest_id: string, template: Template | undefined, options: { force?: boolean, contestDirnameFormat?: string })

Source from the content-addressed store, hash-verified

145 * @param options
146 */
147export 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
178export async function installTask(detailed_task: DetailedTask, dirname: string, project_path: string, options?: { tests?: boolean }): Promise<Task> {
179 const {task, index, contest, template} = detailed_task;

Callers 1

setupFunction · 0.90

Calls 9

getAtCoderFunction · 0.90
installContestTemplateFunction · 0.90
formatContestDirnameFunction · 0.85
saveProjectJSONFunction · 0.85
checkSessionMethod · 0.80
loginMethod · 0.80
contestMethod · 0.80
tasksMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected