1 | let fs = require('fs-extra')
|
2 | let Path = require('path')
|
3 | let jsCompile = require('./compiler/compile-js')
|
4 | let cssCompile = require('./compiler/compile-css')
|
5 | let utils = require('../utils/utils')
|
6 | let log = utils.log
|
7 | let projectConfig = utils.getProjectConfig()
|
8 |
|
9 | function ignoreMatch(target) {
|
10 | let result = false
|
11 | utils.getProjectConfig().ignore.find((v)=>{
|
12 | if(v===Path.parse(target).base){
|
13 | result = true
|
14 | }
|
15 | })
|
16 | return result
|
17 | }
|
18 |
|
19 | async function walk(target) {
|
20 |
|
21 | if(ignoreMatch(target)){
|
22 | return
|
23 | }
|
24 | if (fs.lstatSync(target).isFile()) {
|
25 | if (Path.extname(target) === (projectConfig.css.ext||'.css')) {
|
26 | let a = await Promise.resolve(cssCompile(target))
|
27 | }
|
28 | else if(Path.extname(target) === (projectConfig.js.ext||'.js')) {
|
29 | jsCompile.compiler(target)
|
30 | }
|
31 | else {
|
32 |
|
33 | let destPath = utils.getOutputFile(target)
|
34 | fs.copySync(target,destPath)
|
35 | log.tag('复制文件',`${destPath}`)
|
36 | }
|
37 | return
|
38 | }
|
39 | if (fs.lstatSync(target).isDirectory()) {
|
40 | let dirs = fs.readdirSync(target)
|
41 | for(let value of dirs){
|
42 | await walk(Path.join(target, value))
|
43 | }
|
44 | }
|
45 | }
|
46 |
|
47 | module.exports = async function(callback){
|
48 | if (!utils.getProjectConfig()) {
|
49 | log.error('未检测到配置文件,无法编译')
|
50 | return
|
51 | }
|
52 | await walk(utils.getSrcPath())
|
53 | if(callback) callback()
|
54 | }
|
55 |
|