-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
58 lines (52 loc) · 1.41 KB
/
build.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
57
58
const Bundler = require('parcel-bundler')
const Filesystem = require('fs')
const Path = require('path')
function generateEnvModule () {
const envRegex = /(^NODE_ENV$)|(^ELM_*.*)/
const envVars = Object.entries(process.env)
.filter(([k]) => k.match(envRegex))
.map(([k, v]) => [k.toLocaleLowerCase(), v])
const header = [
`module Env exposing (${envVars.map(([k]) => k).join(', ')})`,
'',
'-- This file was generated automatically at build time. Do not edit it and',
'-- do not check it into git.',
''
].join('\n')
const module = envVars.reduce(
(m, [k, v]) => {
return [
m,
'',
`${k} : String`,
`${k} =`,
` "${v}"`
].join('\n')
},
header
)
return Filesystem.promises.writeFile(
Path.join(__dirname, 'src', 'elm', 'Env.elm'),
module
)
}
const entry = Path.join(__dirname, 'src', 'elm-package-prefixer.js')
const options = {
outDir: './bin',
outFile: process.env.NODE_ENV === 'production' ? 'elm-package-prefixer.js' : 'elm-package-prefixer.dev.js',
watch: false,
cache: true,
cacheDir: '.cache',
contentHash: false,
minify: process.env.NODE_ENV === 'production',
scopeHoist: false,
target: 'node',
logLevel: 3,
hmr: false,
sourceMaps: false,
detailedReport: process.env.NODE_ENV === 'production',
autoInstall: true
}
generateEnvModule().then(() => {
new Bundler(entry, options).bundle()
})