-
Notifications
You must be signed in to change notification settings - Fork 0
/
command-line.html
228 lines (204 loc) · 11.2 KB
/
command-line.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Sequential bootloader and context for node applications">
<meta name="author" content="Matt Insler">
<link rel="apple-touch-icon" sizes="57x57" href="/icons/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/icons/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/icons/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/icons/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/icons/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/icons/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/icons/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/icons/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/icons/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/icons/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png">
<link rel="manifest" href="/icons/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/icons/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<meta property="og:site_name" content="app-context"/>
<meta property="og:title" content="app-context"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="http://app-contextjs.com" />
<meta property="og:description" content="Sequential bootloader and context for node applications" />
<meta property="og:image" content="http://app-contextjs.com/images/logo.png" />
<meta property="og:image:secure_url" content="https://app-contextjs.com/images/logo.png" />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="640" />
<meta property="og:image:height" content="640" />
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="app-context">
<meta name="twitter:description" content="Sequential bootloader and context for node applications">
<meta name="twitter:image" content="http://app-contextjs.com/images/logo.png">
<title>app-context</title>
<!-- Bootstrap core CSS -->
<link href="/css/main.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-67080368-1', 'auto');
ga('send', 'pageview');
</script>
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/bower_components/components-bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<header class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/" class="navbar-brand" alt="app-context">
<img src="/images/logo-white.png">
</a>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse collapse" role="navigation">
<ul class="nav navbar-nav">
<li class="">
<a href="/guide">Guide</a>
</li>
<li class="active">
<a href="/command-line">Command Line</a>
</li>
<li class="">
<a href="/initializers">Initializers</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<p class="navbar-text" style="margin-bottom:10px;padding-left:15px;">
<iframe src="//ghbtns.com/github-btn.html?user=app-context&repo=app-context&type=star&count=true" frameborder="0" scrolling="0" width="84px" height="20px"></iframe>
</p>
</li>
</ul>
</nav>
</div>
</header>
<div class="jumbotron">
<div class="container">
<h1>Command Line</h1>
<p>Sequential bootloader and context for node applications</p>
</div>
</div>
<div class="body-wrapper">
<div class="container">
<div class="row">
<div class="col-md-12 docs">
<p><code>app-context</code> ships with a convenient command-line to work with your
application in a simple and standard way. Every command will load your application
context, boot to a certain run level, and then take an action.</p>
<h2>Starting an Application</h2><pre><code class="bash">$ app-context start
</code></pre>
<p>Loads to the <code>running</code> run level. When the last initializer finishes
(resolves it's promise or calls it's callback) the application will be
exited using <code>process.exit()</code>. <code>start</code> will also exit the application if <code>SIGINT</code>
is sent to the process.</p>
<p><code>start</code> is great to use with your web app or long-running process. To have your
process never exit, just don't close out the final initializer. For instance:</p>
<pre><code class="javascript"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">this</span>.runlevel(<span class="hljs-string">'running'</span>)
.use(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">context, done</span>) </span>{
<span class="hljs-comment">// kick off some long-running job</span>
<span class="hljs-comment">// don't call done</span>
});
};
</code></pre>
<p>This application can still be exited by sending it a <code>SIGINT</code> (pressing CTRL-C).</p>
<h2>Running a script</h2><pre><code class="bash">$ app-context run <script>
</code></pre>
<p>Loads to the <code>initialized</code> run level and then executes the script that you pass
in. When the script finishes (resolves it's promise or calls it's callback)
the application will be exited. This is very similar to <code>start</code>, but can be used
to execute any script in the same environment as your full application.</p>
<p>In order for <code>app-context</code> to know when your script has completed, you must export
a method or an object with a key named <code>execute</code> that is a method. Your method
will be passed the application context and can signal that it is finished by
returning a promise or taking a second parameter as a callback.</p>
<p>For example, this method will be called and the application will be exited
when it finishes.</p>
<pre><code class="javascript"><span class="hljs-comment">// context is the same as APP</span>
<span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">context</span>) </span>{
foo();
bar();
};
</code></pre>
<p>Here, the method will be called and the application will be exited when the
promise is resolved.</p>
<pre><code class="javascript"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">context</span>) </span>{
<span class="hljs-keyword">return</span> promisedFoo();
};
</code></pre>
<p>This time we use a callback.</p>
<pre><code class="javascript"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">context, done</span>) </span>{
foo(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
<span class="hljs-keyword">if</span> (err) { <span class="hljs-keyword">return</span> done(err); }
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'YAY'</span>);
done();
})
};
</code></pre>
<h2>Printing the Configuration</h2><pre><code class="bash">$ app-context config
</code></pre>
<p>Loads to the <code>configured</code> run level and then prints the contents of <code>APP.config</code>.</p>
<h2>Starting a REPL Console</h2><pre><code class="bash">$ app-context console
</code></pre>
<p>Loads to the <code>initialized</code> run level and then will create a node REPL that has
your application context already loaded and initialized. This is great for
debugging your app's environment (via <code>APP</code>).</p>
<p>The REPL also has built-in support for promises. If you run a method that returns
a promise, the REPL will print the result of the promise when it is resolved or
print the error if it is rejected. For callbacks, there is a helper method to
do the same thing through <code>$_</code>. So you can do <code>fs.readFileSync('./config.json', $_)</code>.</p>
<h2>Changing the Environment</h2><p><code>app-context</code> bases it's current environment on the value of <code>NODE_ENV</code>. So to
run any of the above commands in a specific environment, just change the value
of <code>NODE_ENV</code>.</p>
<p>For instance, to run your application in production mode, you could just run:</p>
<pre><code class="bash">$ NODE_ENV=production app-context start
</code></pre>
</div>
</div>
</div>
</div>
<footer>
<div class="container">
<div class="social">
<iframe src="//ghbtns.com/github-btn.html?user=app-context&repo=app-context&type=star&count=true" frameborder="0" scrolling="0" width="170px" height="20px"></iframe>
</div>
<p>app-context and documentation is maintained by <a href="https://github.com/mattinsler">Matt Insler</a>.</p>
<p>Source code and documentation released until the <a href="https://github.com/app-context/app-context/blob/master/LICENSE-MIT">MIT License</a>.</p>
</div>
</footer>
<script>
function slugify(str) {
return str.toLowerCase().replace(/ /g, '-');
}
$(function() {
$('code:contains("app-context")').filter(function() {
return $(this).text() === 'app-context';
}).addClass('lobster');
$('.docs h1,.docs h2,.docs h3,.docs h4').each(function() {
var $el = $(this);
$el.attr('id', slugify($el.text()));
});
});
</script>
</body>
</html>