forked from GlimpseArchive/Glimpse.Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.js
80 lines (63 loc) · 2.8 KB
/
make.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
73
74
75
76
77
78
79
80
var fs = require('fs');
var path = require('path');
var regex = /\/\*\(import:\S*\)\*\//g;
var process = function (data, dir) {
return data.replace(regex, function (match) {
var matchIdentifier = match.substring(10, match.length - 3);
var matchFileName = matchIdentifier;
var tabIndex = 0;
if (matchFileName.indexOf('|') > -1) {
tabIndex = matchFileName.substring(matchFileName.indexOf('|') + 1, matchFileName.length - matchFileName.indexOf('|') - 1) * 1;
matchFileName = matchFileName.substring(0, matchFileName.indexOf('|'));
}
var tabs = '';
for (var i = 0; i < tabIndex; i++) {
tabs += ' ';
}
var matchContent = '';
matchContent = process(fs.readFileSync(path.join(dir, matchFileName), 'UTF-8'), dir);
if (/(.htm|.css)/g.test(matchFileName)) {
matchContent = matchContent.replace(/[\r|\n|\r\n|\t]/gi, '');
matchContent = matchContent.replace(/\s{2,}/gi, '');
}
if (tabIndex > 0)
matchContent = tabs + matchContent.replace(/\n/, '\n' + tabs);
return matchContent;
});
},
output = function(manifest, sourceDir, outputDir, outputFile) {
fs.readFile(manifest, 'UTF-8', function(err, data) {
if (err) {
throw err;
}
data = process(data, sourceDir);
fs.exists(outputDir, function(exists) {
if (!exists) {
fs.mkdirSync(outputDir);
}
fs.exists(outputFile, function(exists) {
if (exists) {
fs.unlinkSync(outputFile);
}
fs.writeFile(outputFile, data, function (err) {
if (err) {
throw err;
}
console.log('File has been generated at ' + outputFile);
});
});
});
});
};
var outputDir = path.join(__dirname, 'build');
var sourceDir = path.join(__dirname, 'source');
var coreManifest = path.join(sourceDir, '_build.js');
var coreOutputFile = path.join(outputDir, 'glimpse.js');
output(coreManifest, sourceDir, outputDir, coreOutputFile);
var insightManifest = path.join(sourceDir, '_buildInsight.js');
var insightOutputFile = path.join(outputDir, 'glimpseInsight.js');
output(insightManifest, sourceDir, outputDir, insightOutputFile);
var testSourceDir = path.join(__dirname, 'test', 'mock');
var testManifest = path.join(testSourceDir, 'test.glimpse.ajax.js');
var testOutputFile = path.join(outputDir, 'glimpseTest.js');
output(testManifest, testSourceDir, outputDir, testOutputFile);