-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.js
46 lines (38 loc) · 1 KB
/
build.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
// start
import {execSync} from 'child_process';
import {readdir, statSync, existsSync} from 'fs';
import {extname} from 'path';
import {getConfigs} from './configs';
import {error} from './utils/logger';
import release from './utils/release';
const isFile = (f) => {
const stats = statSync(f);
return !stats.isDirectory();
};
const isTplFile = (f) => {
return extname(f) === '.pug';
};
const build = () => {
const conf = getConfigs();
const {srcDir, distDir, staticDir} = conf;
if (existsSync(distDir)) {
execSync(`rm -rf ${distDir}`);
execSync(`mkdir ${distDir}`);
}
execSync(`cp -r ${staticDir}/. ${distDir}`);
execSync(`mkdir -p ${distDir}/css`);
execSync(`mkdir -p ${distDir}/js`);
const pageDir = `${srcDir}/pages`;
readdir(pageDir, 'utf8', (err, files) => {
if (err) {
error(err);
}
files.forEach((file) => {
const f = `${pageDir}/${file}`;
if (isFile(f) && isTplFile(f)) {
return release(f, srcDir, distDir);
}
});
});
};
build();