-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
93 lines (66 loc) · 1.99 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const fs = require('fs');
const path = require('path');
const pug = require('pug');
const sass = require('sass');
const constants = require('./constants');
function deleteCompiled() {
console.log('Deleting build directory...');
// Delete the compiled files
if (fs.existsSync(constants.STATIC_PATH)) {
fs.rmSync(constants.STATIC_PATH, {
recursive: true,
force: true,
});
}
console.log('Build directory deleted!');
}
function createDirectory() {
console.log('Creating new build directory...');
fs.mkdirSync(constants.STATIC_PATH);
fs.mkdirSync(constants.CSS_PATH);
console.log('Build directory created!');
}
function buildHTML() {
console.log('Building Pug file...');
const compiledFunction = pug.compileFile(path.join(constants.SRC_PATH, 'index.pug'));
fs.writeFileSync(path.join(constants.STATIC_PATH, 'index.html'), compiledFunction());
console.log('Build successful!');
}
function buildCSS() {
console.log('Building SCSS file...');
const normalize = sass.compile(path.join(__dirname, 'node_modules/normalize.css/normalize.css'), {
style: 'compressed',
});
const style = sass.compile(path.join(constants.SRC_PATH, 'style.scss'), {
style: 'compressed',
});
fs.writeFileSync(path.join(constants.CSS_PATH, 'style.css'), normalize.css + style.css);
console.log('Build successful!');
}
function copyAssets() {
console.log('Copying assets...');
// fs.copyFileSync(, constants.STATIC_PATH);
const assets = fs.readdirSync(constants.ASSETS_PATH);
for (const asset of assets) {
fs.cpSync(path.join(constants.ASSETS_PATH, asset), path.join(constants.STATIC_PATH, asset), {
recursive: true,
});
}
console.log('Assets copied!');
}
(async function main() {
// Delete compiled files
deleteCompiled();
// Create directory for compiled files
createDirectory();
// Build Pug file
buildHTML();
// Build SCSS file
buildCSS();
// Copy the assets
copyAssets();
})();
module.exports = {
buildHTML,
buildCSS,
}