-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathadd.js
executable file
·47 lines (37 loc) · 1.06 KB
/
add.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
#!/usr/bin/env node
var readline = require('readline');
var fs = require('fs');
var path = require('path');
var keyArry = ['name', 'description', 'url', 'tags'];
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var i = 0;
var rst = {};
var DATAPATH = './data/sites/';
var info = JSON.parse(fs.readFileSync('./data/info.json', 'utf-8'));
function init() {
rl.question("the site " + keyArry[i] + ' is:', function(answer) {
rst[keyArry[i]] = answer;
i++;
if (i == keyArry.length) {
fs.writeFile(path.join(DATAPATH, (++info.totalCount) + '.json'), JSON.stringify({
name : rst.name,
id : info.totalCount++,
description: rst.description,
tags: rst.tags,
url: rst.url,
createAt: +new Date()
}), function(err) {
if (err) {
throw err;
}
});
i = 0;
rst = {};
}
init();
});
}
init();