UNPKG

1.22 kBJavaScriptView Raw
1// Copyright Jon Williams 2017-2018. See LICENSE file.
2
3/**
4 * # ^ Cater
5 *
6 * The cater module is the Command-line interface (cli) to Cater. It also
7 * provides wrappering around the cater-build and cater-runtime modules.
8 *
9 * The cater-runtime module is always included. It contains the minimum
10 * configuration to run cater; including in production. The cater-build
11 * module should be a development dependency. It's added to develop and
12 * build a Cater application.
13 *
14 * @module cater
15 * @see module:cater-build
16 * @see module:cater-runtime
17 */
18
19// Determine if we're using the runtime or build versions of cater. Returns
20// that module, depending on the setup.
21const mode = process.env.CATER_MODE || (process.env.NODE_ENV === 'production' ? 'runtime' : 'dev');
22const runtime = mode === 'runtime';
23const moduleName = runtime ? 'cater-runtime' : 'cater-build';
24
25try {
26 if (!runtime) require.resolve(moduleName);
27} catch (e) {
28 throw new Error(
29 "Running Cater in build mode, but the cater-build package isn't installed. Add to your project as a development dependency using npm or yarn."
30 );
31}
32
33// eslint-disable-next-line global-require, import/no-dynamic-require
34module.exports = require(moduleName);