-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
170 lines (158 loc) · 5.39 KB
/
index.html
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<!-- Generated by litjs - https://github.com/apres/lit.js
Part of the Apres suite - http://apres.github.com/ -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>main.js</title>
<link href='http://apres.github.com/lit.js/css/lit-columns.css' rel='stylesheet' type='text/css'>
<link href='http://apres.github.com/lit.js/css/apres.css' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="lit">
<section>
<div class="lit-comment">
<h1>main.js</h1>
<p>Loader for Strider extension modules.</p>
</div>
<code class="lit-code">
<span class="keyword">var</span> fs = require(<span class="string">'fs'</span>),
path = require(<span class="string">'path'</span>),
Step = require(<span class="string">'step'</span>);
</code>
</section>
<section>
<div class="lit-comment">
<h3>Locate Strider Extensions</h3>
<p>Under a specified path <strong>dir</strong> [by default, process.cwd()/node_modules] look<br />for directories containing file 'strider.json'. These are considered<br />Strider modules.</p>
<p><strong>cb</strong> is a function of signature cb(err, extensions) where extensions is an<br />array of filesystems path on success and err is an error on failure.</p>
</div>
<code class="lit-code">
<span class="function"><span class="keyword">function</span> <span class="title">findExtensions</span><span class="params">(dir, cb)</span> {</span>
</code>
</section>
<section>
<div class="lit-comment">
<p>XXX May not be sane default when installed globally</p>
</div>
<code class="lit-code">
<span class="keyword">var</span> dir = dir || path.join(process.cwd(), <span class="string">"node_modules"</span>);
<span class="keyword">var</span> filename = <span class="string">"strider.json"</span>;
<span class="keyword">var</span> extensions = [];
Step(
<span class="keyword">function</span>() {
</code>
</section>
<section>
<div class="lit-comment">
<p>find top-level module dirs</p>
</div>
<code class="lit-code">
fs.readdir(dir, <span class="keyword">this</span>);
},
<span class="keyword">function</span>(err, entries) {
<span class="keyword">if</span> (err) {
<span class="keyword">throw</span> err;
}
</code>
</section>
<section>
<div class="lit-comment">
<p>Stat extension files in parallel</p>
</div>
<code class="lit-code">
<span class="keyword">var</span> group = <span class="keyword">this</span>.group();
entries.forEach(<span class="keyword">function</span>(module) {
<span class="keyword">var</span> p = path.join(dir, module, filename);
<span class="keyword">var</span> cb = group();
fs.stat(p, <span class="keyword">function</span>(err, stat) {
cb(err,
{stat:stat, path:p});
});
});
},
<span class="keyword">function</span>(err, results) {
results.forEach(<span class="keyword">function</span>(r) {
<span class="keyword">if</span> (!r.stat) {
<span class="keyword">return</span>;
}
</code>
</section>
<section>
<div class="lit-comment">
<p>Ensure they are of type file not something else</p>
</div>
<code class="lit-code">
<span class="keyword">if</span> (r.stat.isFile()) {
extensions.push(r.path);
}
});
cb(err, extensions);
}
);
}
</code>
</section>
<section>
<div class="lit-comment">
<h3>Load a Strider extension</h3>
<p><strong>filename</strong> is a filesystem location to a strider.json file. Extension is<br />assumed to be contained in same directory as strider.json.</p>
<p><strong>cb</strong> is a function of signature function(err, extension) where extension<br />is an extension object on success and err is an error on failure.</p>
<p>Note that this function does not initialize the extension.</p>
</div>
<code class="lit-code">
<span class="function"><span class="keyword">function</span> <span class="title">loadExtension</span><span class="params">(filename, cb)</span> {</span>
Step(
<span class="keyword">function</span>() {
fs.readFile(filename, <span class="keyword">this</span>);
},
<span class="keyword">function</span>(err, data) {
<span class="keyword">if</span> (err) {
<span class="keyword">return</span> cb(err, <span class="literal">null</span>);
}
</code>
</section>
<section>
<div class="lit-comment">
<p>Parse extension JSON</p>
</div>
<code class="lit-code">
<span class="keyword">try</span> {
<span class="keyword">var</span> extensionConfig = JSON.parse(data);
} <span class="keyword">catch</span>(e) {
<span class="keyword">return</span> cb(e, <span class="literal">null</span>);
}
</code>
</section>
<section>
<div class="lit-comment">
<p>Build require'able path to extension sources</p>
</div>
<code class="lit-code">
<span class="keyword">var</span> extension = {
webapp: require(filename.replace(<span class="string">'strider.json'</span>,
extensionConfig.webapp)),
worker: require(filename.replace(<span class="string">'strider.json'</span>,
extensionConfig.worker)),
};
cb(<span class="literal">null</span>, extension);
}
);
}
</code>
</section>
<section>
<div class="lit-comment">
<p>Exported functions</p>
</div>
<code class="lit-code">
module.exports = {
findExtensions: findExtensions,
loadExtension: loadExtension
};
</code>
</section>
</div>
</body>
</html>