forked from substance/texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.js
152 lines (131 loc) · 3.67 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
IMPORTANT: Don't use ES6 here, as some people are still on Node 4.
*/
var b = require('substance-bundler')
var fs = require('fs')
var path = require('path')
var DIST = 'dist/'
var NPM = '.npm/'
var NPMDIST = NPM+'dist/'
var TEST ='.test/'
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.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' },
]
})
})
b.task('test:browser', function() {
b.js('./test/index.js', {
// buble necessary here, as travis has old browser versions
buble: true,
ignore: ['substance-cheerio'],
external: ['substance-test', 'substance'],
commonjs: { include: ['node_modules/lodash/**'] },
targets: [
{ dest: TEST+'tests.js', format: 'umd', moduleName: 'tests' }
]
})
})
b.task('test', ['test:browser', 'test:server'])
/* Development bundle */
b.task('dev', function() {
b.rm(DIST)
_buildDist(DIST, true)
})
/* Prepare NPM bundle */
b.task('npm', function() {
// Cleanup
b.rm(NPM)
_buildDist(NPMDIST, true)
// Copy source
b.copy('index.es.js', NPM)
b.copy('lib/**/*.js', NPM)
// Copy stuff
;[
'package.json',
'LICENSE.md',
'README.md',
'CHANGELOG.md',
'make.js'
].forEach(function(f) {
b.copy(f, NPM)
})
})
b.task('default', ['dev'])
function _buildDist(DIST, transpileToES5) {
// Bundle Substance and Texture JS
_substanceJS(DIST+'substance', transpileToES5)
_textureJS(DIST, transpileToES5)
// Bundle CSS
b.css('texture.css', DIST+'texture.css', {variables: transpileToES5})
b.css('./node_modules/substance/dist/substance-pagestyle.css', DIST+'texture-pagestyle.css', {variables: transpileToES5})
b.css('./node_modules/substance/dist/substance-reset.css', DIST+'texture-reset.css', {variables: transpileToES5})
// Copy assets
_distCopyAssets(DIST)
}
function _substanceJS(DEST, transpileToES5) {
if (transpileToES5) {
b.make('substance', 'clean', 'browser')
} else {
b.make('substance', 'clean', 'browser:pure')
}
b.copy('node_modules/substance/dist', DEST)
}
function _textureJS(DEST, transpileToES5) {
b.js('./index.es.js', {
buble: transpileToES5,
external: ['substance'],
commonjs: { include: ['node_modules/lodash/**'] },
targets: [{
useStrict: !transpileToES5,
dest: DEST+'texture.js',
format: 'umd', moduleName: 'texture', sourceMapRoot: __dirname, sourceMapPrefix: 'texture'
}]
})
}
function _distCopyAssets(DIST) {
b.copy('./node_modules/font-awesome', DIST+'font-awesome')
// Landing page
b.copy('./index.html', DIST+'index.html')
// Examples
b.copy('./examples', DIST+'examples')
// Convert XML files to data.js
b.custom('Bundle XML files as data.js', {
src: ['data/*.xml'],
dest: DIST+'examples/data.js',
execute: function(files) {
var xmls = {}
files.forEach(function(f) {
var xml = fs.readFileSync(f, 'utf8')
var docId = path.basename(f, '.xml')
xmls[docId] = xml
})
var out = [
"window.XMLFILES = ",
JSON.stringify(xmls)
].join('')
fs.writeFileSync(DIST+'examples/data.js', out)
}
})
}
// starts a server when CLI argument '-s' is set
b.setServerPort(5555)
b.serve({
static: true, route: '/', folder: 'dist'
})