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
| yaml = require("js-yaml"); fs = require("fs");
try { var doc = yaml.safeLoad(fs.readFileSync('config.yml', 'utf8')); } catch (e) { console.log('沒法正常解析yaml'); console.error(e); process.exit(1); }
try { let default_path = doc.templates.default.transmission.path; let olddownload_path = doc.templates.olddownload.transmission.path; let autoPass_path = doc.templates.autoPass.transmission.path; let default_month = default_path.substr(32, 2); let olddownload_month = olddownload_path.substr(32, 2); let autoPass_month = autoPass_path.substr(32, 2);
let now_month = new Date().getMonth();
let month_maping = { '0' : '01', '1' : '01', '2' : '01', '3' : '04', '4' : '04', '5' : '04', '6' : '07', '7' : '07', '8' : '07', '09' : '10', '10' : '10', '11' : '10', };
if (month_maping[now_month] != default_month) throw "config.yml裡default_path沒設定正確(" + month_maping[now_month] +")月份名稱"; if (month_maping[now_month-3] != olddownload_month) throw "config.yml裡olddownload_month沒設定正確(" + month_maping[now_month] + ")月份名稱"; if (month_maping[now_month-3] != autoPass_month) throw "config.yml裡autoPass_month沒設定正確(" + month_maping[now_month] + ")月份名稱";
} catch (error) { console.error(error); process.exit(1); }
console.log('測試正常');
|