-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·56 lines (47 loc) · 1.37 KB
/
index.js
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
'use strict'
const {resolve} = require('path')
const chalk = require('chalk')
const pkg = require('./package.json')
const debug = require('debug')(`${pkg.name}:boot`)
const nameError =
`*******************************************************************
You need to give your app a proper name.
The package name
${pkg.name}
isn't valid. If you don't change it, things won't work right.
Please change it in ${__dirname}/package.json
~ xoxo, bones
********************************************************************`
const reasonableName = /^[a-z0-9\-_]+$/
if (!reasonableName.test(pkg.name)) {
console.error(chalk.red(nameError))
}
// This will load a secrets file from
//
// ~/.your_app_name.env.js
// or ~/.your_app_name.env.json
//
// and add it to the environment.
const env = Object.create(process.env)
, secretsFile = resolve(env.HOME, `.${pkg.name}.env`)
try {
Object.assign(env, require(secretsFile))
} catch (error) {
debug('%s: %s', secretsFile, error.message)
debug('%s: env file not found or invalid, moving on', secretsFile)
}
module.exports = {
get name() { return pkg.name },
get isTesting() { return !!global.it },
get isProduction() {
return process.env.NODE_ENV === 'production'
},
get baseUrl() {
return env.BASE_URL || `http://localhost:${PORT}`
},
get port() {
return env.PORT || 1337
},
package: pkg,
env,
}