|
1 | 1 | import fs from 'fs';
|
2 | 2 | import { splitCodeToSolutions } from './format.js';
|
3 | 3 |
|
4 | | -const makeAPI = () => |
5 | | - [1, 2, 3, 4, 5].flatMap(level => |
6 | | - fs |
7 | | - .readdirSync(`level-${level}`) |
8 | | - .filter(name => name !== '00-해답-예시.js') |
9 | | - .map(file => { |
10 | | - const [name, id, extension] = file.split('&'); |
11 | | - const code = splitCodeToSolutions(fs.readFileSync(`level-${level}/${file}`, 'utf-8')); |
12 | | - return { id, name: name.replace('-', ' '), level, code: code[0] + code[1] }; |
13 | | - }) |
14 | | - ); |
15 | | - |
16 | | -fs.writeFileSync('api.json', JSON.stringify(makeAPI())); |
| 4 | +export const getSolutions = () => { |
| 5 | + try { |
| 6 | + const api = [1, 2, 3, 4, 5].flatMap(level => |
| 7 | + fs |
| 8 | + .readdirSync(`level-${level}`) |
| 9 | + .filter(name => name !== '00-해답-예시.js') |
| 10 | + .map(file => { |
| 11 | + const [name, id, extension] = file.split('&'); |
| 12 | + const code = splitCodeToSolutions(fs.readFileSync(`level-${level}/${file}`, 'utf-8')); |
| 13 | + return { id, name: name.replaceAll('-', ' '), level, code: code[0] + code[1] }; |
| 14 | + }) |
| 15 | + ); |
| 16 | + fs.writeFileSync('api.json', JSON.stringify(api)); |
| 17 | + return api; |
| 18 | + } catch (e) { |
| 19 | + console.log('Making API ERROR: ' + e); |
| 20 | + return []; |
| 21 | + } |
| 22 | +}; |
0 commit comments