1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var dbg = require('debug')
|
15 | var debug = dbg('pub:generator');
|
16 | var asyncbuilder = require('asyncbuilder');
|
17 | var u = require('pub-util');
|
18 |
|
19 | var srcGitHub = require('pub-src-github');
|
20 |
|
21 | module.exports = function initOpts(cb) {
|
22 | cb = u.onceMaybe(cb);
|
23 | console.log(location.pathname)
|
24 | $.getJSON(pubRef.relPath + '/pub/_opts.json')
|
25 | .fail(function(jqXHR) { cb(new Error(jqXHR.responseText)); })
|
26 | .done(function(respData) {
|
27 |
|
28 |
|
29 |
|
30 | var opts = respData;
|
31 |
|
32 |
|
33 | dbg.enable(opts.dbg);
|
34 |
|
35 |
|
36 | opts.staticRoot = location.pathname.slice(0,location.pathname.length - pubRef.href.length);
|
37 | debug('opts.staticRoot: "' + opts.staticRoot + '"');
|
38 |
|
39 | var ab = asyncbuilder(function(err) { cb(err, opts); });
|
40 |
|
41 |
|
42 |
|
43 | opts.source$ = {};
|
44 |
|
45 | opts.sources.forEach(function(source) {
|
46 | opts.source$[source.name] = source;
|
47 |
|
48 |
|
49 | if (opts.staticHost && source.staticSrc) {
|
50 | if (source.gatekeeper) {
|
51 | var append = ab.asyncAppend();
|
52 | debug('authenticating ' + source.gatekeeper);
|
53 | $.getJSON(source.gatekeeper + '/status' + location.search)
|
54 | .fail(function(jqXHR) { append(new Error(jqXHR.responseText)); })
|
55 | .done(function(status) {
|
56 |
|
57 |
|
58 | if (!status || !status.access_token) {
|
59 | location.assign(source.gatekeeper +
|
60 | '?ref=' + encodeURIComponent(location.href));
|
61 | }
|
62 |
|
63 | else {
|
64 | source.auth = status;
|
65 | source.src = require(source.staticSrc)(source);
|
66 | }
|
67 | debug(status);
|
68 | append(status);
|
69 | });
|
70 | }
|
71 | }
|
72 | });
|
73 | ab.complete();
|
74 |
|
75 | });
|
76 | }
|