1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee
holiday/build/generate.js

46 lines
2.4 KiB
JavaScript

const fs = require('fs');
const path = require('path');
let order = fs.readFileSync(path.join(__dirname, '../data/order.json'), 'utf8');
order = JSON.parse(order);
let simplifyField = fs.readFileSync(path.join(__dirname, '../data/simplify_field.json'), 'utf8');
simplifyField = JSON.parse(simplifyField);
let ChineseEngilshMapper = {};
let holidayList = [], simplifyHolidayList = [], solarTermsList = [], simplifySolarTermsList = [];
for (let holidayId of order) {
let holiday = fs.readFileSync(path.join(__dirname, `../data/holiday/${holidayId}.json`), 'utf8');
holiday = JSON.parse(holiday);
holidayList.push(holiday);
let simplifyHoliday = {};
simplifyField.forEach(field => simplifyHoliday[field] = holiday[field]);
simplifyHolidayList.push(simplifyHoliday);
if (holiday.solarTerms) {
solarTermsList.push(holiday);
simplifySolarTermsList.push(simplifyHoliday);
}
ChineseEngilshMapper[holiday.name] = holiday.englishName;
}
fs.writeFileSync(path.join(__dirname, `../dist/holiday.json`), JSON.stringify(holidayList, null, 4));
fs.writeFileSync(path.join(__dirname, `../dist/holiday.min.json`), JSON.stringify(holidayList));
fs.writeFileSync(path.join(__dirname, `../dist/holiday.simplify.json`), JSON.stringify(simplifyHolidayList, null, 4));
fs.writeFileSync(path.join(__dirname, `../dist/holiday.simplify.min.json`), JSON.stringify(simplifyHolidayList));
fs.writeFileSync(path.join(__dirname, `../dist/holiday.solarTerms.json`), JSON.stringify(solarTermsList, null, 4));
fs.writeFileSync(path.join(__dirname, `../dist/holiday.solarTerms.min.json`), JSON.stringify(solarTermsList));
fs.writeFileSync(path.join(__dirname, `../dist/holiday.solarTerms.simplify.json`), JSON.stringify(simplifySolarTermsList, null, 4));
fs.writeFileSync(path.join(__dirname, `../dist/holiday.solarTerms.simplify.min.json`), JSON.stringify(simplifySolarTermsList));
fs.writeFileSync(path.join(__dirname, `../dist/chinese_english_mapper.json`), JSON.stringify(ChineseEngilshMapper, null, 4));
fs.writeFileSync(path.join(__dirname, `../dist/chinese_english_mapper.min.json`), JSON.stringify(ChineseEngilshMapper));
fs.copyFileSync(path.join(__dirname, `../dist/holiday.min.json`), path.join(__dirname, `../html/data/holiday.min.json`))
fs.copyFileSync(path.join(__dirname, `../dist/holiday.simplify.min.json`), path.join(__dirname, `../html/data/holiday.simplify.min.json`))