UNPKG

1.53 kBJavaScriptView Raw
1const cpr = require('cpr')
2const path = require('path')
3const tiresiasWebpack = require('tiresias-webpack')
4
5const serverTemplatePath = path.join(__dirname, '../tiresias-template')
6const distPath = path.join(__dirname, '../dist')
7
8const buildSourcePath = path.join(__dirname, '../test')
9const buildDistPath = path.join(__dirname, '../dist/src')
10
11const defaultConfig = {}
12defaultConfig.buildSourcePath = buildSourcePath
13defaultConfig.buildDistPath = buildDistPath
14
15function copyServerFiles (config, callback) {
16 console.log('copying server files...')
17 cpr(serverTemplatePath, config.distDir, {
18 deleteFirst: true, //Delete "to" before
19 overwrite: true, //If the file exists, overwrite it
20 confirm: true //After the copy, stat all the copied files to make sure they are there
21 }, (err, files) => {
22 if (typeof callback === 'function') {
23 callback(err, files)
24 }
25 })
26}
27
28function buildFiles (buildConfig) {
29 buildConfig.distDir = path.join(buildConfig.distDir, './src')
30 tiresiasWebpack(buildConfig)
31}
32
33function buildProd (buildConfig) {
34 var config = {}
35 config.rootDir = buildSourcePath
36 config.distDir = buildDistPath
37 config = Object.assign({}, config, buildConfig)
38
39 copyServerFiles(config, (err, files) => {
40 if (err) {
41 throw err
42 } else {
43 console.log(files.join(',\n'))
44 console.log('server files copied.')
45 console.log('building files...')
46 buildFiles(config)
47 console.log('build files end.')
48 }
49 })
50}
51
52module.exports = buildProd
53
54