-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake.js
106 lines (94 loc) · 3.19 KB
/
make.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
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
var b = require('substance-bundler');
var fs = require('fs')
var config = require('config')
b.task('clean', function() {
b.rm('./dist')
})
// copy assets
b.task('assets', function() {
b.copy('node_modules/font-awesome', './dist/font-awesome')
b.copy('node_modules/leaflet.markercluster/dist', './dist/markercluster')
})
// this optional task makes it easier to work on Substance core
b.task('substance', function() {
b.make('substance', 'build')
b.copy('node_modules/substance/dist', './dist/substance')
b.minify('./dist/substance/substance.js', './dist/substance/substance.min.js')
})
b.task('archivist', function() {
b.make('archivist', 'build')
b.copy('node_modules/archivist/dist', './dist/archivist')
b.minify('./dist/archivist/archivist.js', './dist/archivist/archivist.min.js')
})
function buildApp(app, production) {
return function() {
if(production) {
b.copy('client/'+app+'/index.production.html', './dist/'+app+'/index.html')
} else {
b.copy('client/'+app+'/index.html', './dist/'+app+'/')
}
b.copy('client/'+app+'/assets', './dist/'+app+'/assets/')
b.css('./client/' + app + '/app.css', 'dist/' + app + '/' + app + '.css', {variables: true})
b.js('client/' + app + '/app.js', {
// need buble if we want to minify later
buble: true,
external: ['substance', 'archivist'],
commonjs: {
include: [
'node_modules/moment/moment.js',
'node_modules/plyr/src/js/plyr.js',
'node_modules/leaflet/dist/leaflet-src.js',
'node_modules/leaflet.markercluster/dist/leaflet.markercluster-src.js'
]
},
targets: [{
dest: './dist/' + app + '/app.js',
format: 'umd',
moduleName: app
}]
})
b.custom('injecting config', {
src: './dist/' + app + '/app.js',
dest: './dist/' + app + '/' + app + '.js',
execute: function(file) {
const code = fs.readFileSync(file[0], 'utf8')
const result = code.replace(/ARCHIVISTCONFIG/g, JSON.stringify(config.get('app')))
fs.writeFileSync(this.outputs[0], result, 'utf8')
}
})
b.minify('./dist/' + app + '/' + app + '.js', './dist/' + app + '/' + app + '.min.js')
b.copy('./dist/' + app + '/app.js.map', './dist/' + app + '/' + app + '.js.map')
b.rm('./dist/' + app + '/app.js')
b.rm('./dist/' + app + '/app.js.map')
}
}
function _ostJS() {
b.js('./index.es.js', {
buble: true,
external: ['substance', 'archivist'],
targets: [{
dest: 'dist/ost.cjs.js',
format: 'cjs',
sourceMapRoot: __dirname,
sourceMapPrefix: 'ost'
}]
})
}
b.task('deps', ['substance', 'assets', 'archivist'])
b.task('ost', _ostJS())
// dev
b.task('publisher', buildApp('publisher'))
b.task('scholar', buildApp('scholar'))
// production
b.task('publisher-min', buildApp('publisher', true))
b.task('scholar-min', buildApp('scholar', true))
b.task('client', ['publisher', 'scholar'])
b.task('client-min', ['scholar-min'])
// build all
b.task('default', ['deps', 'client', 'ost'])
b.task('production', ['deps', 'client-min', 'ost'])
// starts a server when CLI argument '-s' is set
b.setServerPort(5001)
b.serve({
static: true, route: '/', folder: 'dist'
});