-
-
Notifications
You must be signed in to change notification settings - Fork 387
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (51 loc) · 1.51 KB
/
index.js
File metadata and controls
62 lines (51 loc) · 1.51 KB
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
'use strict'
const { resolve } = require('path')
const { writeFile, readFile } = require('fs').promises
const layout = require('../utils/layout')
const config = require('../utils/config')
const customTracker = require('../utils/customTracker')
const signale = require('../utils/signale')
const index = () => {
return layout('<div id="main"></div>', 'favicon.ico', [ 'index.css' ], [ 'index.js' ], {
isDemoMode: config.isDemoMode,
isAnonymousMode: config.isAnonymousMode,
customTracker,
})
}
const styles = () => {
const sass = require('rosid-handler-sass')
const filePath = resolve(__dirname, './styles/index.scss')
return sass(filePath, { optimize: config.isDevelopmentMode === false })
}
const scripts = () => {
const js = require('rosid-handler-js-next')
const filePath = resolve(__dirname, './scripts/index.js')
return js(filePath, {
optimize: config.isDevelopmentMode === false,
nodeGlobals: config.isDevelopmentMode === true,
replace: { 'process.env.NODE_ENV': JSON.stringify(config.isDevelopmentMode === true ? 'development' : 'production') },
babel: false,
})
}
const tracker = () => {
const filePath = require.resolve('ackee-tracker')
return readFile(filePath, 'utf8')
}
const build = async (path, fn) => {
try {
signale.await(`Building and writing '${ path }'`)
const data = await fn()
await writeFile(path, data)
signale.success(`Finished building '${ path }'`)
} catch (error) {
signale.fatal(error)
process.exit(1)
}
}
module.exports = {
index,
styles,
scripts,
tracker,
build,
}