-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
73 lines (64 loc) · 2.36 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const columnCheck = require("./module/columnCheck");
const deleteNotionData = require("./module/deleteNotionData");
const addNotionPage = require("./module/addNotionPage");
const fs = require('fs');
const { apiDocFilePath, apiBlank } = require("./config/setting");
const ora = require('ora');
const path = require("path");
const jsonRefCheck = require("./module/checkRefJson");
require('dotenv').config();
const main = async () => {
const spinner = ora('').start();
try {
// 노션 데이터베이스 컬럼 정보 확인
spinner.text = 'Loading Database Column Check';
await columnCheck();
// 데이터베이스 페이지 모두 삭제
spinner.text = 'Loading Delete All Database pages\n';
await deleteNotionData();
spinner.text = 'Loading Read API JS\n';
const docFilePath = path.resolve(__dirname, '..', '..', apiDocFilePath);
let fileArray;
try {
fileArray = fs.readdirSync(docFilePath);
} catch (err) {
spinner.stop();
return console.log(`${docFilePath} 디렉토리가 존재하지 않습니다.`);
}
const apiDocArray = [];
for (const fileName of fileArray) {
if (fileName.split('.')[1] === 'json') {
const apiArray = jsonRefCheck(require(path.join(docFilePath, fileName)), path.join(docFilePath, 'components'));
if (Array.isArray(apiArray)) {
apiDocArray.push(...apiArray);
// 공백 추가
if (apiBlank) {
apiDocArray.push({});
}
}
}
}
if (apiBlank) { // 마지막 공백 제거
apiDocArray.pop(0, -1);
}
// 데이터베이스 페이지 추가
try {
for (const i in apiDocArray) {
spinner.text = `Insert Notion Page ${parseInt(i) + 1}/${apiDocArray.length}`;
const apiDoc = apiDocArray[i];
await addNotionPage(apiDoc);
}
spinner.stop();
console.log('All Success');
} catch (err) {
spinner.stop();
console.log(err);
}
} catch (err) {
if (err.code === 'object_not_found') {
return console.log(err.message);
}
console.log(err);
}
}
main();