-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.js
executable file
·108 lines (99 loc) · 3.08 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
107
108
const b = require('substance-bundler')
const fs = require('fs')
const config = require('config')
b.task('clean', function() {
b.rm('./dist')
})
// copy assets
b.task('assets', function() {
b.copy('node_modules/font-awesome', './dist/libs/font-awesome')
})
// 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))
// build apps
b.task('client', ['publisher', 'scholar'])
b.task('client-min', ['scholar-min', 'publisher-min'])
// build libraries
b.task('deps', () => {
_buildDeps()
})
b.task('deps-min', () => {
_buildDeps(true)
})
// build server js
b.task('server', () => {
buildServerJS()
})
// build all
b.task('default', ['dev'])
b.task('dev', ['clean', 'assets', 'deps', 'server', 'client'])
b.task('production', ['clean', 'assets', 'deps-min', 'server', 'client-min'])
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')
b.js('client/' + app + '/app.js', {
targets: [{
dest: './dist/' + app + '/app.js',
format: 'umd', moduleName: 'app'
}],
commonjs: {
include: [
'node_modules/moment/moment.js',
'node_modules/plyr/src/js/plyr.js',
'node_modules/dropzone/dist/dropzone.js'
]
},
external: ['substance', 'archivist'],
globals: {
'substance': 'substance',
'archivist-js': 'archivist-js'
}
})
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')
}
})
if(production) {
b.minify('./dist/' + app + '/' + app + '.js', './dist/' + app + '/' + app + '.min.js')
} else {
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 buildServerJS() {
b.js('./index.es.js', {
external: ['substance', 'archivist-js'],
globals: {
'substance': 'substance',
'archivist-js': 'archivist-js'
},
targets: [{
dest: 'dist/sgn.cjs.js',
format: 'cjs'
}]
})
}
/* HELPERS */
function _buildDeps(min) {
b.copy('node_modules/substance/dist', './dist/libs/substance')
if(min) b.minify('./dist/libs/substance/substance.js', './dist/libs/substance/substance.min.js')
b.copy('node_modules/archivist-js/dist', './dist/libs/archivist')
if(min) b.minify('./dist/libs/archivist/archivist.js', './dist/libs/archivist/archivist.min.js')
}