forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.js
More file actions
executable file
·49 lines (33 loc) · 928 Bytes
/
import.js
File metadata and controls
executable file
·49 lines (33 loc) · 928 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
/**
* Import tutorial into DB
* @type {TutorialImporter|exports}
*/
var TutorialImporter = require('../tutorialImporter');
var co = require('co');
var fs = require('fs');
var path = require('path');
var log = require('log')();
module.exports = function(options) {
return function() {
var args = require('yargs')
.usage("Path to tutorial root is required.")
.demand(['root'])
.argv;
var root = fs.realpathSync(args.root);
var importer = new TutorialImporter({
root: root
});
return co(function* () {
yield* importer.destroyAll();
var subRoots = fs.readdirSync(root);
for (var i = 0; i < subRoots.length; i++) {
var subRoot = subRoots[i];
if (!parseInt(subRoot)) continue;
yield* importer.sync(path.join(root, subRoot));
}
yield* importer.generateCaches();
log.info("DONE");
});
};
};