1 | const tasksConf = require('config').get('tasks')
|
2 | const Copy = require('copy')
|
3 | const pathConfig = require('config').get('path')
|
4 | const { printRoute } = require('./router.js')
|
5 |
|
6 | const _move_ = (from, to) => {
|
7 | return new Promise((resolve, reject) => {
|
8 | Copy(from, to, (err, files) => {
|
9 | if (err) reject(err)
|
10 | else resolve(files)
|
11 | })
|
12 | })
|
13 | }
|
14 |
|
15 | async function move() {
|
16 | const patterns = [
|
17 | {
|
18 | from: `${pathConfig.dist}/css/*.css`,
|
19 | to: pathConfig.static + '/css'
|
20 | },
|
21 | {
|
22 | from: `${pathConfig.dist}/js/*.js`,
|
23 | to: pathConfig.static + '/js'
|
24 | },
|
25 | {
|
26 | from: `${pathConfig.dist}/js/*.js.map`,
|
27 | to: pathConfig.static + '/js'
|
28 | },
|
29 | {
|
30 | from: `${pathConfig.dist}/image/*.*`,
|
31 | to: pathConfig.static + '/image'
|
32 | },
|
33 | {
|
34 | from: `${pathConfig.dll}/css/*.css`,
|
35 | to: pathConfig.static + '/css'
|
36 | },
|
37 | {
|
38 | from: `${pathConfig.dll}/js/*.js`,
|
39 | to: pathConfig.static + '/js'
|
40 | },
|
41 | {
|
42 | from: `${pathConfig.dll}/image/*.*`,
|
43 | to: pathConfig.static + '/image'
|
44 | },
|
45 | {
|
46 | from: pathConfig.favicon,
|
47 | to: pathConfig.static
|
48 | }
|
49 | ]
|
50 |
|
51 | try {
|
52 | for (const { from, to } of patterns) {
|
53 | await _move_(from, to)
|
54 | }
|
55 |
|
56 | await printRoute()
|
57 | } catch (err) {
|
58 | console.error(err)
|
59 | }
|
60 | }
|
61 |
|
62 | const afterHook = async function() {
|
63 | let { afterHook } = tasksConf
|
64 |
|
65 | let hooks = afterHook.filter(v => {
|
66 | return typeof v === 'function'
|
67 | })
|
68 |
|
69 | for (const index in hooks) {
|
70 | if (hooks.hasOwnProperty(index)) {
|
71 | const fn = hooks[index]
|
72 |
|
73 | await fn.call()
|
74 | }
|
75 | }
|
76 | }
|
77 |
|
78 | async function hook() {
|
79 | await move()
|
80 |
|
81 | await afterHook()
|
82 | }
|
83 |
|
84 | module.exports = hook
|