forked from bitovi/documentjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetscripts.js
More file actions
96 lines (92 loc) · 2.41 KB
/
Copy pathgetscripts.js
File metadata and controls
96 lines (92 loc) · 2.41 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
steal('documentjs/types/script.js', 'steal/build', 'steal/rhino/json.js',
function(Script) {
var helpers = {
files : function(path, cb){
var getJSFiles = function(dir){
var file = new steal.URI(dir);
if(file.isFile()) {
cb(dir.replace('\\', '/'), dir);
} else {
file.contents(function(f, type){
if(type == 'directory' && !/node_modules/.test(f)) {
getJSFiles(dir+"/"+f)
}else {
cb((dir+"/"+f).replace('\\', '/'), f);
}
});
}
};
getJSFiles(path);
},
getScripts : function(file){
var collection = [], scriptUrl;
if (/\.html?$/.test(file)) { // load all the page's scripts
steal.build.open(file, function(scripts){
var paths = steal.config().paths;
scripts.each(function(script, text){
if(script.id && text){
scriptUrl = paths[script.id] || script.id;
collection.push({
src: scriptUrl,
text: script.text
})
}
});
});
}
else if (/\.js$/.test(file)) { // load just this file
collection.push( {
src: file,
text: readFile(file)
} )
}
else { // assume its a directory
this.files(file, function(path, f){
if(/\.(js|md|markdown)$/.test(f)){
collection.push( {
src: path,
text: readFile(path)
} )
}
})
}
return collection;
}
};
return function(scripts, options){
var scriptsToProcess = [];
// an array of folders
if(options.markdown){
for(var i =0 ; i < options.markdown.length; i++){
helpers.files(options.markdown[i], function(path, f){
if(/\.(md|markdown)$/.test(f) && !/node_modules/.test(path)){
scriptsToProcess.push( {
src: path,
text: readFile(path)
} )
}
})
}
}
if(typeof scripts == 'string'){
if(!options.out){
if(/\.html?$|\.js$/.test(scripts)){
options.out = scripts.replace(/[^\/]*$/, 'docs')
}else{ //folder
options.out = scripts+"/docs";
}
}
new steal.URI(options.out).mkdir();
scriptsToProcess.push.apply(scriptsToProcess, helpers.getScripts(scripts))
} else if(scripts instanceof Array){
new steal.URI(options.out).mkdir();
trueScriptsArr = [];
for(idx in scripts) {
files = helpers.getScripts(scripts[idx]);
trueScriptsArr = trueScriptsArr.concat(files);
}
scriptsToProcess.push.apply(scriptsToProcess, trueScriptsArr);
}
return scriptsToProcess;
}
})