-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.js
112 lines (100 loc) · 3.64 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
109
110
111
112
var b = require('substance-bundler')
var fs = require('fs')
var config = require('config')
var TEST ='.test/'
b.task('clean', function() {
b.rm('./dist')
})
// copy assets
b.task('assets', function() {
b.copy('node_modules/font-awesome', './dist/font-awesome')
})
// this optional task makes it easier to work on Substance core
b.task('substance', function() {
b.make('substance', 'clean', 'browser', 'server')
b.copy('node_modules/substance/dist', './dist/substance')
})
function buildMainApp(app) {
return function() {
b.copy('client/' + app + '/index.html', './dist/')
b.copy('client/' + app + '/assets', './dist/assets/')
b.css('./client/' + app + '/app.css', 'dist/mpro.css', {variables: true})
b.css('./node_modules/substance/dist/substance-pagestyle.css', 'dist/mpro-pagestyle.css', {variables: true})
b.css('./node_modules/substance/dist/substance-reset.css', 'dist/mpro-reset.css', {variables: true})
b.js('client/' + app + '/app.js', {
// need buble if we want to minify later
buble: true,
external: ['substance'],
commonjs: { include: ['node_modules/lodash/**', 'node_modules/moment/moment.js'] },
dest: './dist/app.js',
format: 'umd',
moduleName: app
})
b.custom('injecting config', {
src: './dist/app.js',
dest: './dist/mpro.js',
execute: function(file) {
const code = fs.readFileSync(file[0], 'utf8')
const result = code.replace(/MPROCONFIG/g, JSON.stringify(config.get('app')))
fs.writeFileSync(this.outputs[0], result, 'utf8')
}
})
b.copy('./dist/app.js.map', './dist/mpro.js.map')
b.rm('./dist/app.js')
b.rm('./dist/app.js.map')
}
}
function buildApp(app) {
return function() {
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.css('./node_modules/substance/dist/substance-pagestyle.css', 'dist/mpro-pagestyle.css', {variables: true})
// b.css('./node_modules/substance/dist/substance-reset.css', 'dist/mpro-reset.css', {variables: true})
b.js('client/' + app + '/' + app + '.js', {
// need buble if we want to minify later
buble: true,
external: ['substance'],
commonjs: { include: ['node_modules/lodash/**', 'node_modules/moment/moment.js'] },
dest: './dist/' + app + '/' + app + '.js',
format: 'umd',
moduleName: app
})
b.rm('./dist/' + app + '/app.js')
b.rm('./dist/' + app + '/app.js.map')
}
}
b.task('client', ['clean', 'substance', 'assets'], buildMainApp('mpro'))
b.task('digest', buildApp('digest'))
b.task('embed', buildApp('embed'))
// build all
b.task('default', ['client', 'embed'])
b.task('test:server', function() {
// Cleanup
b.rm(TEST)
b.make('substance')
// TODO: it would be nice to treat such glob patterns
// differently, so that we do not need to specify glob root
b.copy('./node_modules/substance-test/dist/*', TEST, { root: './node_modules/substance-test/dist' })
b.copy('./test/**/*', TEST, { root: './test' })
b.js('./test/index.js', {
// buble necessary here, for nodejs
buble: true,
external: ['substance-test', 'substance'],
commonjs: {
include: [
'/**/lodash/**',
'/**/substance-cheerio/**'
]
},
targets: [
{ dest: TEST+'tests.cjs.js', format: 'cjs', sourceMapRoot: __dirname, sourceMapPrefix: 'test' }
]
})
})
b.task('test', ['test:server'])
// starts a server when CLI argument '-s' is set
b.setServerPort(5001)
b.serve({
static: true, route: '/', folder: 'dist'
})