Skip to content

Commit 5d1f318

Browse files
Created a builder for the application. Also separated SCSS variables to another file.
1 parent 06354e9 commit 5d1f318

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+204
-666
lines changed

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

build.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const pug = require('pug');
5+
const sass = require('sass');
6+
7+
const constants = require('./constants');
8+
9+
function deleteCompiled() {
10+
console.log('Deleting build directory...');
11+
12+
// Delete the compiled files
13+
if (fs.existsSync(constants.STATIC_PATH)) {
14+
fs.rmSync(constants.STATIC_PATH, {
15+
recursive: true,
16+
force: true,
17+
});
18+
}
19+
20+
console.log('Build directory deleted!');
21+
}
22+
23+
function createDirectory() {
24+
console.log('Creating new build directory...');
25+
26+
fs.mkdirSync(constants.STATIC_PATH);
27+
fs.mkdirSync(constants.CSS_PATH);
28+
29+
console.log('Build directory created!');
30+
}
31+
32+
function buildHTML() {
33+
console.log('Building Pug file...');
34+
35+
const compiledFunction = pug.compileFile(path.join(constants.SRC_PATH, 'index.pug'));
36+
37+
fs.writeFileSync(path.join(constants.STATIC_PATH, 'index.html'), compiledFunction());
38+
39+
console.log('Build successful!');
40+
}
41+
42+
function buildCSS() {
43+
console.log('Building SCSS file...');
44+
45+
const normalize = sass.compile(path.join(__dirname, 'node_modules/normalize.css/normalize.css'), {
46+
style: 'compressed',
47+
});
48+
49+
const style = sass.compile(path.join(constants.SRC_PATH, 'style.scss'), {
50+
style: 'compressed',
51+
});
52+
53+
fs.writeFileSync(path.join(constants.CSS_PATH, 'style.css'), normalize.css + style.css);
54+
55+
console.log('Build successful!');
56+
}
57+
58+
function copyAssets() {
59+
console.log('Copying assets...');
60+
61+
// fs.copyFileSync(, constants.STATIC_PATH);
62+
const assets = fs.readdirSync(constants.ASSETS_PATH);
63+
64+
for (const asset of assets) {
65+
fs.cpSync(path.join(constants.ASSETS_PATH, asset), path.join(constants.STATIC_PATH, asset), {
66+
recursive: true,
67+
});
68+
}
69+
70+
console.log('Assets copied!');
71+
}
72+
73+
(async function main() {
74+
// Delete compiled files
75+
deleteCompiled();
76+
77+
// Create directory for compiled files
78+
createDirectory();
79+
80+
// Build Pug file
81+
buildHTML();
82+
83+
// Build SCSS file
84+
buildCSS();
85+
86+
// Copy the assets
87+
copyAssets();
88+
})();
89+
90+
module.exports = {
91+
buildHTML,
92+
buildCSS,
93+
}

constants.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require('path');
2+
3+
const SRC_PATH = path.join(__dirname, 'src');
4+
const STATIC_PATH = path.join(__dirname, '/static');
5+
const ASSETS_PATH = path.join(SRC_PATH, 'assets');
6+
const CSS_PATH = path.join(STATIC_PATH, 'css');
7+
8+
module.exports = {
9+
SRC_PATH,
10+
STATIC_PATH,
11+
CSS_PATH,
12+
ASSETS_PATH,
13+
};

develop.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require('path');
2+
3+
const express = require('express');
4+
const pug = require('pug');
5+
6+
const constants = require('./constants');
7+
const build = require('./build');
8+
9+
const app = express();
10+
const port = 3000;
11+
12+
app.get('/', (_, res) => {
13+
app.use('/', express.static(constants.STATIC_PATH));
14+
15+
build.buildCSS();
16+
build.buildHTML();
17+
18+
res.send(pug.renderFile(path.join(constants.STATIC_PATH, 'index.html')));
19+
});
20+
21+
app.listen(port, () => {
22+
console.log(`Example app listening on port ${port}`);
23+
});

index.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "css-room-escape",
33
"private": true,
4-
"version": "2.1.0",
4+
"version": "2.2.0",
55
"repository": "https://github.com/takaneichinose/profile.git",
66
"author": "Takane Ichinose <[email protected]>",
77
"license": "MIT",
88
"dependencies": {
99
"express": "^4.18.2",
10+
"normalize.css": "^8.0.1",
1011
"pug": "^3.0.2"
1112
},
1213
"devDependencies": {

server.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const express = require('express');
5+
const pug = require('pug');
6+
const sass = require('sass');
7+
8+
const constants = require('./constants');
9+
10+
const app = express();
11+
const port = 3000;
12+
13+
app.use('/', express.static(constants.STATIC_PATH))
14+
15+
app.get('/', (_, res) => {
16+
res.send(pug.renderFile(path.join(constants.STATIC_PATH, 'index.html')));
17+
});
18+
19+
app.listen(port, () => {
20+
console.log(`Example app listening on port ${port}`);
21+
});
545 Bytes
3.4 KB
284 Bytes

0 commit comments

Comments
 (0)