-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.ts
More file actions
30 lines (26 loc) · 833 Bytes
/
gulpfile.ts
File metadata and controls
30 lines (26 loc) · 833 Bytes
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
import gulp, { watch } from 'gulp';
import { echo, exec, exit } from 'shelljs';
const IMPORT_FILE_PATH = './excels/go-tips.csv';
const EXPORT_FILE_PATH = './out/tips.json';
const importCmd = `mongoimport -d go -c tips --type csv --file ${IMPORT_FILE_PATH} --columnsHaveTypes --headerline --drop --maintainInsertionOrder`;
const exportCmd = `mongoexport -d go -c tips -o ${EXPORT_FILE_PATH} --jsonArray`;
function importCSV(cb: (param?: any) => void) {
if (exec(importCmd).code !== 0) {
echo('Error: 引入表格错误');
exit(1);
}
cb();
}
function exportJson(cb: (param?: any) => void) {
if (exec(exportCmd).code !== 0) {
echo('Error: 导出表格错误');
exit(1);
}
cb();
}
function watchCSV() {
watch('./excels/go-tips.csv', gulp.series([importCSV, exportJson]));
}
export default function () {
watchCSV();
}