@@ -140,28 +140,25 @@ export async function validateProjectJSON(data: ContestProject): Promise<[true,
140
140
export async function init ( contest_id : string , options : { force ?: boolean , contestDirnameFormat ?: string } ) : Promise < ContestProject > {
141
141
const atcoder = new AtCoder ( ) ;
142
142
if ( ! await atcoder . checkSession ( ) ) await atcoder . login ( ) ;
143
+ const [ contest , tasks ] = await Promise . all ( [ atcoder . contest ( contest_id ) , atcoder . tasks ( contest_id ) ] ) . catch ( ( ) => {
144
+ throw new Error ( "failed to get contest information." ) ;
145
+ } ) ;
146
+ const format = options . contestDirnameFormat !== undefined ? options . contestDirnameFormat : ( await getConfig ( ) ) . get ( "default-contest-dirname-format" ) ;
147
+ const dirname = formatContestDirname ( format , contest ) ;
143
148
try {
144
- const [ contest , tasks ] = await Promise . all ( [ atcoder . contest ( contest_id ) , atcoder . tasks ( contest_id ) ] ) ;
145
- const format = options . contestDirnameFormat !== undefined ? options . contestDirnameFormat : ( await getConfig ( ) ) . get ( "default-contest-dirname-format" ) ;
146
- const dirname = formatContestDirname ( format , contest ) ;
147
- try {
148
- await promisify ( mkdir ) ( dirname ) ;
149
- }
150
- catch {
151
- // forceオプションがtrueでない場合のみエラーで停止する
152
- if ( options . force !== true ) {
153
- throw new Error ( `${ dirname } file/directory already exists.` )
154
- }
155
- }
156
- process . chdir ( dirname ) ;
157
- const data = { contest, tasks} ;
158
- await saveProjectJSON ( data , process . cwd ( ) ) ;
159
- console . log ( `${ dirname } /${ PROJECT_JSON_FILE_NAME } created.` ) ;
160
- return data ;
149
+ await promisify ( mkdir ) ( dirname ) ;
161
150
}
162
151
catch {
163
- throw new Error ( "failed to get contest information." ) ;
152
+ // forceオプションがtrueでない場合のみエラーで停止する
153
+ if ( options . force !== true ) {
154
+ throw new Error ( `${ dirname } file/directory already exists.` )
155
+ }
164
156
}
157
+ process . chdir ( dirname ) ;
158
+ const data = { contest, tasks} ;
159
+ await saveProjectJSON ( data , process . cwd ( ) ) ;
160
+ console . log ( `${ dirname } /${ PROJECT_JSON_FILE_NAME } created.` ) ;
161
+ return data ;
165
162
}
166
163
167
164
interface DetailedTask {
0 commit comments