-
Notifications
You must be signed in to change notification settings - Fork 93
/
config.html
133 lines (115 loc) · 25.3 KB
/
config.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
<!DOCTYPE html> <html> <head> <title>config.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To … <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//jitsu/api/apps.html"> jitsu/api/apps.html </a> <a class="source" href="..//jitsu/api/client.html"> jitsu/api/client.html </a> <a class="source" href="..//jitsu/api/snapshots.html"> jitsu/api/snapshots.html </a> <a class="source" href="..//jitsu/api/users.html"> jitsu/api/users.html </a> <a class="source" href="..//jitsu/commands/apps.html"> jitsu/commands/apps.html </a> <a class="source" href="..//jitsu/commands/config.html"> jitsu/commands/config.html </a> <a class="source" href="..//jitsu/commands/help.html"> jitsu/commands/help.html </a> <a class="source" href="..//jitsu/commands/package.html"> jitsu/commands/package.html </a> <a class="source" href="..//jitsu/commands/snapshots.html"> jitsu/commands/snapshots.html </a> <a class="source" href="..//jitsu/commands/users.html"> jitsu/commands/users.html </a> <a class="source" href="..//jitsu/commands.html"> jitsu/commands.html </a> <a class="source" href="..//jitsu/config.html"> jitsu/config.html </a> <a class="source" href="..//jitsu/package.html"> jitsu/package.html </a> <a class="source" href="..//jitsu/properties.html"> jitsu/properties.html </a> <a class="source" href="..//jitsu/utils/base64.html"> jitsu/utils/base64.html </a> <a class="source" href="..//jitsu/utils/index.html"> jitsu/utils/index.html </a> <a class="source" href="..//jitsu.html"> jitsu.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> config.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * config.js: Configuration for the jitsu CLI.</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2010, Nodejitsu Inc.</span>
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">nconf</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'nconf'</span><span class="p">),</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'path'</span><span class="p">),</span>
<span class="nx">winston</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'winston'</span><span class="p">),</span>
<span class="nx">optimist</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'optimist'</span><span class="p">),</span>
<span class="nx">argv</span> <span class="o">=</span> <span class="nx">optimist</span><span class="p">.</span><span class="nx">argv</span><span class="p">,</span>
<span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'fs'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <p>Set up our default config</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">dir</span> <span class="o">=</span> <span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">(),</span>
<span class="nx">configPath</span> <span class="o">=</span> <span class="nx">argv</span><span class="p">.</span><span class="nx">jitsuconf</span> <span class="o">||</span> <span class="nx">argv</span><span class="p">.</span><span class="nx">j</span><span class="p">,</span>
<span class="nx">looking</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">defaults</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">'root'</span><span class="o">:</span> <span class="nx">process</span><span class="p">.</span><span class="nx">env</span><span class="p">.</span><span class="nx">HOME</span><span class="p">,</span>
<span class="s1">'protocol'</span><span class="o">:</span> <span class="s1">'http'</span><span class="p">,</span>
<span class="s1">'remoteHost'</span><span class="o">:</span> <span class="s1">'api.nodejitsu.com'</span><span class="p">,</span>
<span class="s1">'userconfig'</span><span class="o">:</span> <span class="s1">'.jitsuconf'</span><span class="p">,</span>
<span class="s1">'loglevel'</span><span class="o">:</span> <span class="s1">'info'</span><span class="p">,</span>
<span class="s1">'tmproot'</span><span class="o">:</span> <span class="s1">'/tmp'</span><span class="p">,</span>
<span class="s1">'tar'</span><span class="o">:</span> <span class="s1">'tar'</span><span class="p">,</span>
<span class="s1">'gzipbin'</span><span class="o">:</span> <span class="s1">'gzip'</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p>Make sure the file exists if it was set explicitly</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">config</span><span class="p">.</span><span class="nx">findJitsuconf</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">filename</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>Use pre-existing config file if already found</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">looking</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">filename</span> <span class="o">=</span> <span class="nx">filename</span> <span class="o">||</span> <span class="s1">'.jitsuconf'</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">configPath</span><span class="p">)</span> <span class="p">{</span>
<span class="k">try</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">stat</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">statSync</span><span class="p">(</span><span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span><span class="p">(</span><span class="nx">configPath</span><span class="p">));</span>
<span class="nx">looking</span> <span class="o">=</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">isDirectory</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">catch</span> <span class="p">(</span><span class="nx">ex</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">while</span> <span class="p">(</span><span class="nx">looking</span><span class="p">)</span> <span class="p">{</span>
<span class="k">try</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">stat</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">statSync</span><span class="p">(</span><span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span><span class="p">(</span><span class="nx">configPath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">dir</span><span class="p">,</span> <span class="nx">filename</span><span class="p">)));</span>
<span class="nx">looking</span> <span class="o">=</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">isDirectory</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">olddir</span> <span class="o">=</span> <span class="nx">dir</span><span class="p">;</span>
<span class="nx">dir</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span><span class="p">(</span><span class="nx">dir</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">olddir</span> <span class="o">===</span> <span class="nx">dir</span><span class="p">)</span> <span class="p">{</span>
<span class="k">try</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">stat</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">statSync</span><span class="p">(</span><span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span><span class="p">(</span><span class="nx">configPath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">process</span><span class="p">.</span><span class="nx">env</span><span class="p">.</span><span class="nx">HOME</span><span class="p">,</span> <span class="nx">filename</span><span class="p">)));</span>
<span class="k">if</span><span class="p">(</span><span class="nx">stat</span><span class="p">.</span><span class="nx">isDirectory</span><span class="p">())</span> <span class="p">{</span>
<span class="nx">configPath</span> <span class="o">=</span> <span class="kc">undefined</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Ignore errors</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">configPath</span> <span class="o">=</span> <span class="kc">undefined</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">looking</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">configPath</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">writeFileSync</span><span class="p">(</span><span class="nx">configPath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">process</span><span class="p">.</span><span class="nx">env</span><span class="p">.</span><span class="nx">HOME</span><span class="p">,</span> <span class="nx">filename</span><span class="p">),</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">defaults</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="mi">2</span><span class="p">));</span>
<span class="p">}</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">silly</span><span class="p">(</span><span class="s1">'Using config file '</span> <span class="o">+</span> <span class="nx">configPath</span><span class="p">.</span><span class="nx">magenta</span><span class="p">);</span>
<span class="nx">config</span><span class="p">.</span><span class="nx">use</span><span class="p">(</span><span class="s1">'file'</span><span class="p">,</span> <span class="p">{</span> <span class="nx">file</span><span class="o">:</span> <span class="nx">configPath</span> <span class="p">});</span>
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">};</span>
<span class="kd">var</span> <span class="nx">_get</span> <span class="o">=</span> <span class="nx">config</span><span class="p">.</span><span class="nx">get</span><span class="p">,</span>
<span class="nx">_load</span> <span class="o">=</span> <span class="nx">config</span><span class="p">.</span><span class="nx">load</span><span class="p">;</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">defaults</span><span class="p">,</span> <span class="s1">'remoteUri'</span><span class="p">,</span> <span class="p">{</span>
<span class="nx">get</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">port</span> <span class="o">=</span> <span class="nx">optimist</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">port</span> <span class="o">||</span> <span class="nx">config</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">'port'</span><span class="p">)</span> <span class="o">||</span> <span class="k">this</span><span class="p">.</span><span class="nx">port</span> <span class="o">||</span> <span class="s1">''</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">port</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">port</span> <span class="o">=</span> <span class="s1">':'</span> <span class="o">+</span> <span class="nx">port</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">protocol</span><span class="p">,</span> <span class="s1">'://'</span><span class="p">,</span> <span class="p">(</span><span class="nx">optimist</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">remoteHost</span> <span class="o">||</span> <span class="nx">config</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">'remoteHost'</span><span class="p">)</span> <span class="o">||</span> <span class="nx">defaults</span><span class="p">.</span><span class="nx">remoteHost</span><span class="p">),</span> <span class="nx">port</span><span class="p">].</span><span class="nx">join</span><span class="p">(</span><span class="s1">''</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="nx">config</span><span class="p">.</span><span class="nx">load</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">filename</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="nx">filename</span><span class="p">;</span>
<span class="nx">filename</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p>Find the <code>.jitsuconf</code> file to be used for this
jitsu session.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">config</span><span class="p">.</span><span class="nx">findJitsuconf</span><span class="p">(</span><span class="nx">filename</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="nx">configPath</span><span class="p">.</span><span class="nx">magenta</span> <span class="o">+</span> <span class="s1">' does not exist'</span><span class="p">),</span> <span class="kc">true</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">_load</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">config</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">store</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="s1">'Error parsing '</span> <span class="o">+</span> <span class="nx">config</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">file</span><span class="p">.</span><span class="nx">magenta</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="nx">err</span><span class="p">.</span><span class="nx">message</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">warn</span><span class="p">(</span><span class="s1">''</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">warn</span><span class="p">(</span><span class="s1">'This is most likely not an error in jitsu.'</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">warn</span><span class="p">(</span><span class="s1">'Please check your jitsuconf and try again.'</span><span class="p">);</span>
<span class="nx">winston</span><span class="p">.</span><span class="nx">warn</span><span class="p">(</span><span class="s1">''</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">filename</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">'userconfig'</span><span class="p">,</span> <span class="nx">filename</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">store</span><span class="p">.</span><span class="nx">auth</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">auth</span> <span class="o">=</span> <span class="nx">store</span><span class="p">.</span><span class="nx">auth</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">':'</span><span class="p">);</span>
<span class="nx">config</span><span class="p">.</span><span class="nx">clear</span><span class="p">(</span><span class="s1">'auth'</span><span class="p">);</span>
<span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="nx">auth</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
<span class="nx">config</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">'password'</span><span class="p">,</span> <span class="nx">auth</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
<span class="k">return</span> <span class="nx">config</span><span class="p">.</span><span class="nx">save</span><span class="p">(</span><span class="nx">callback</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">store</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">};</span>
<span class="nx">config</span><span class="p">.</span><span class="nx">get</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">optimist</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">optimist</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="nx">_get</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">config</span><span class="p">,</span> <span class="nx">key</span><span class="p">);</span>
<span class="k">return</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">!==</span> <span class="s1">'undefined'</span> <span class="o">?</span> <span class="nx">value</span> <span class="o">:</span> <span class="nx">defaults</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
<span class="p">};</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>