1 | var $, M, _;
|
2 |
|
3 | $ = {};
|
4 |
|
5 | $.remove_ = require('../dist/remove_');
|
6 |
|
7 | $.compile_ = require('../dist/compile_');
|
8 |
|
9 | $.copy_ = require('../dist/copy_');
|
10 |
|
11 | $.chain = require('../dist/chain');
|
12 |
|
13 | _ = {};
|
14 |
|
15 | _.merge = require('lodash/merge');
|
16 |
|
17 | _.clone = require('lodash/clone');
|
18 |
|
19 | _.get = require('lodash/get');
|
20 |
|
21 | M = class M {
|
22 | constructor(option) {
|
23 | var data;
|
24 | data = {
|
25 | compile: {
|
26 | extend: ['!**/include/**', '!**/*.min.*'],
|
27 | extname: [
|
28 | '.coffee',
|
29 | '.css',
|
30 | '.html',
|
31 | '.js',
|
32 | '.md',
|
33 | '.pug',
|
34 | '.styl',
|
35 |
|
36 | '.yaml'
|
37 | ]
|
38 | },
|
39 | copy: {
|
40 | extend: ['!**/include/**'],
|
41 | extname: ['.css', '.gif', '.html', '.jpg', '.js', '.json', '.png', '.ttf', '.txt', '.vue', '.xml']
|
42 | },
|
43 | option: {},
|
44 | path: {
|
45 | source: './source',
|
46 | target: './build'
|
47 | }
|
48 | };
|
49 | this.data = _.merge(data, option);
|
50 | this;
|
51 | }
|
52 |
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | async clean_() {
|
61 | await $.remove_(this.get('path.target'));
|
62 | return this;
|
63 | }
|
64 |
|
65 | async compile_() {
|
66 | var ext, listExt, listSource, option, pathSource, pathTarget;
|
67 | listExt = this.get('compile.extname');
|
68 | pathSource = this.get('path.source');
|
69 | pathTarget = this.get('path.target');
|
70 | listSource = [
|
71 | ...((function() {
|
72 | var i,
|
73 | len,
|
74 | results;
|
75 | results = [];
|
76 | for (i = 0, len = listExt.length; i < len; i++) {
|
77 | ext = listExt[i];
|
78 | results.push(`${pathSource}/**/*${ext}`);
|
79 | }
|
80 | return results;
|
81 | })()),
|
82 | ...(this.get('compile.extend'))
|
83 | ];
|
84 | option = _.clone(this.data.option);
|
85 | option.base = pathSource;
|
86 | await $.compile_(listSource, pathTarget, option);
|
87 | return this;
|
88 | }
|
89 |
|
90 | async copy_() {
|
91 | var ext, listExt, listSource, pathSource, pathTarget;
|
92 | listExt = this.get('copy.extname');
|
93 | pathSource = this.get('path.source');
|
94 | pathTarget = this.get('path.target');
|
95 | listSource = [
|
96 | ...((function() {
|
97 | var i,
|
98 | len,
|
99 | results;
|
100 | results = [];
|
101 | for (i = 0, len = listExt.length; i < len; i++) {
|
102 | ext = listExt[i];
|
103 | results.push(`${pathSource}/**/*${ext}`);
|
104 | }
|
105 | return results;
|
106 | })()),
|
107 | ...(this.get('copy.extend'))
|
108 | ];
|
109 | await $.copy_(listSource, pathTarget);
|
110 | return this;
|
111 | }
|
112 |
|
113 | async execute_() {
|
114 | await $.chain(this).clean_().copy_().compile_();
|
115 | return this;
|
116 | }
|
117 |
|
118 | get(key) {
|
119 | return _.get(this.data, key);
|
120 | }
|
121 |
|
122 | };
|
123 |
|
124 |
|
125 | module.exports = async function(option = {}) {
|
126 | var m;
|
127 | m = new M(option);
|
128 | await m.execute_();
|
129 | return this;
|
130 | };
|