-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
72 lines (65 loc) · 1.96 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var hooks = {};
module['exports'] = hooks;
hooks.services = {};
var fs = require('fs');
var dir = fs.readdirSync(__dirname);
// filter directories for any known non-service folders
dir = dir.filter(function(item){
if ([".git", "node_modules"].indexOf(item) === -1) {
return true;
}
});
dir.forEach(function (item) {
var stat = fs.statSync(__dirname + "/" + item);
// only consider folders possible services
if (stat.isDirectory()) {
// assume directory is a service,
// load all its subfiles as a strings
hooks.services[item] = {};
var files = fs.readdirSync(__dirname + "/" + item);
files.forEach(function(file){
var _language = item.split('-')[1] || "javascript";
/*
var pkg = {
file: file,
language: _language,
source: fs.readFileSync(__dirname + "/" + item + "/" + file).toString()
};
*/
if (file === "package.json") {
return;
}
var pkg = {
"name": "marak/" + item,
"version": "1.0.0",
"description": "",
"language": _language,
"source": fs.readFileSync(__dirname + "/" + item + "/" + file).toString(),
"main": file,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Marak",
"license": "MIT"
}
// auto-create package.json if missing
var oldPkg;
var exists = false;
try {
oldPkg = fs.readFileSync(__dirname + "/" + item + "/package.json").toString();
oldPkg = JSON.parse(oldPkg);
exists = true;
} catch (err) {
throw err;
//oldPkg = pkg;
}
if(!exists) {
//fs.writeFileSync(__dirname + "/" + item + "/package.json", JSON.stringify(pkg, true, 2));
} else {
pkg.description = oldPkg.description;
}
fs.writeFileSync(__dirname + "/" + item + "/package.json", JSON.stringify(pkg, true, 2));
hooks.services[item] = pkg;
});
}
});