Skip to content

Commit 044dbbf

Browse files
authored
Merge pull request #229 from RTUITLab/fix-app
Fix app
2 parents 8e856b1 + fab868f commit 044dbbf

8 files changed

Lines changed: 6919 additions & 20494 deletions

File tree

.github/workflows/buildFront.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [16.x]
16+
node-version: [22.x]
1717
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1818

1919
steps:
@@ -48,7 +48,6 @@ jobs:
4848
uses: actions/setup-node@v2
4949
with:
5050
node-version: ${{ matrix.node-version }}
51-
cache: 'npm'
5251

5352
- run: git submodule update --init --recursive -j 8
5453
- run: npm ci

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $ npm install
2828
$ npm start
2929
```
3030

31-
And then look main page in [http://localhost:3000/index.html](http://localhost:3000/index.html)
31+
And then look main page in [http://localhost:3000/](http://localhost:3000/)
3232

3333
## Production
3434

data

Submodule data updated from 6529e5e to 0b87408

package-lock.json

Lines changed: 6740 additions & 20486 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
9-
"start": "parcel ./src/index.pug ./src/achievements/*.pug ./src/projects/*.pug --open -p 3000 --out-dir build --no-cache",
9+
"start": "node scripts/dev.js",
1010
"predeploy": "npm ci && jake && exit 0",
1111
"deploy": "gh-pages -d build -b gh-pages-pr"
1212
},
@@ -28,7 +28,6 @@
2828
"jake": "^10.8.2",
2929
"lodash.escaperegexp": "^4.1.2",
3030
"node-fetch": "^3.2.10",
31-
"npm": "^8.11.0",
3231
"parcel-bundler": "^1.12.5",
3332
"parcel-plugin-clean-easy": "^1.0.2",
3433
"postcss": "^8.4.7",

scripts/dev.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
const { spawn } = require('child_process');
2+
const http = require('http');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const ROOT = path.resolve(__dirname, '..');
7+
const BUILD = path.join(ROOT, 'build');
8+
const PORT = Number(process.env.PORT) || 3000;
9+
10+
const MIME = {
11+
'.html': 'text/html; charset=utf-8',
12+
'.js': 'application/javascript; charset=utf-8',
13+
'.css': 'text/css; charset=utf-8',
14+
'.json': 'application/json; charset=utf-8',
15+
'.png': 'image/png',
16+
'.jpg': 'image/jpeg',
17+
'.jpeg': 'image/jpeg',
18+
'.gif': 'image/gif',
19+
'.webp': 'image/webp',
20+
'.svg': 'image/svg+xml',
21+
'.ico': 'image/x-icon',
22+
'.woff': 'font/woff',
23+
'.woff2': 'font/woff2',
24+
'.wasm': 'application/wasm',
25+
'.map': 'application/json',
26+
};
27+
28+
function tryResolveFile(filePath) {
29+
if (!filePath.startsWith(BUILD)) {
30+
return null;
31+
}
32+
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
33+
return filePath;
34+
}
35+
return null;
36+
}
37+
38+
function resolveRequest(urlPath) {
39+
const decoded = decodeURIComponent(urlPath.split('?')[0]);
40+
const normalized =
41+
decoded === '/' || decoded === ''
42+
? '/index.html'
43+
: decoded.endsWith('/')
44+
? decoded + 'index.html'
45+
: decoded;
46+
47+
let filePath = path.normalize(path.join(BUILD, normalized));
48+
49+
let found = tryResolveFile(filePath);
50+
if (found) {
51+
return found;
52+
}
53+
54+
if (path.extname(filePath) === '') {
55+
found = tryResolveFile(filePath + '.html');
56+
if (found) {
57+
return found;
58+
}
59+
}
60+
61+
found = tryResolveFile(path.join(BUILD, path.basename(filePath)));
62+
if (found) {
63+
return found;
64+
}
65+
66+
if (normalized.startsWith('/dist/')) {
67+
found = tryResolveFile(path.join(BUILD, 'dist', path.basename(filePath)));
68+
if (found) {
69+
return found;
70+
}
71+
}
72+
73+
return null;
74+
}
75+
76+
let serverStarted = false;
77+
78+
function startServer() {
79+
if (serverStarted) {
80+
return;
81+
}
82+
serverStarted = true;
83+
84+
const server = http.createServer((req, res) => {
85+
const filePath = resolveRequest(req.url || '/');
86+
87+
if (!filePath) {
88+
res.writeHead(404);
89+
res.end();
90+
return;
91+
}
92+
93+
const ext = path.extname(filePath);
94+
res.writeHead(200, {
95+
'Content-Type': MIME[ext] || 'application/octet-stream',
96+
'Access-Control-Allow-Origin': '*',
97+
});
98+
fs.createReadStream(filePath).pipe(res);
99+
});
100+
101+
server.on('error', (err) => {
102+
if (err.code === 'EADDRINUSE') {
103+
console.error(
104+
`Port ${PORT} is already in use. Stop the other process or set PORT to another value.`
105+
);
106+
} else {
107+
console.error(err);
108+
}
109+
parcel.kill('SIGINT');
110+
process.exit(1);
111+
});
112+
113+
server.listen(PORT, () => {
114+
const url = `http://localhost:${PORT}/`;
115+
console.log(`Dev server: ${url}`);
116+
openBrowser(url);
117+
});
118+
}
119+
120+
function openBrowser(url) {
121+
const cmd =
122+
process.platform === 'win32'
123+
? `start "" "${url}"`
124+
: process.platform === 'darwin'
125+
? `open "${url}"`
126+
: `xdg-open "${url}"`;
127+
spawn(cmd, { shell: true, stdio: 'ignore' });
128+
}
129+
130+
const parcelBin = path.join(
131+
ROOT,
132+
'node_modules',
133+
'.bin',
134+
process.platform === 'win32' ? 'parcel.cmd' : 'parcel'
135+
);
136+
137+
const parcelArgs = [
138+
'watch',
139+
'./src/index.pug',
140+
'./src/achievements/*.pug',
141+
'./src/projects/*.pug',
142+
'--out-dir',
143+
'build',
144+
'--public-url',
145+
'/',
146+
'--no-cache',
147+
];
148+
149+
const parcel = spawn(parcelBin, parcelArgs, {
150+
cwd: ROOT,
151+
stdio: ['inherit', 'pipe', 'pipe'],
152+
shell: process.platform === 'win32',
153+
});
154+
155+
parcel.stdout.on('data', (chunk) => {
156+
process.stdout.write(chunk);
157+
if (!serverStarted && /Built in/.test(chunk.toString())) {
158+
startServer();
159+
}
160+
});
161+
162+
parcel.stderr.on('data', (chunk) => {
163+
process.stderr.write(chunk);
164+
});
165+
166+
parcel.on('exit', (code) => {
167+
process.exit(code ?? 1);
168+
});
169+
170+
process.on('SIGINT', () => {
171+
parcel.kill('SIGINT');
172+
process.exit(0);
173+
});

src/js/projects/projects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function onMouseUp(e) {
3535
function updateProjectsInfo() {
3636
if (displayedProjects.length === 0) return;
3737
currentProjectTitle.innerText = displayedProjects[currentActiveTab].title;
38-
currentProjectLink.href = 'projects/' + displayedProjects[currentActiveTab].link;
38+
currentProjectLink.href = 'projects/' + displayedProjects[currentActiveTab].link + '.html';
3939
currentProjectLink.style.display = 'block';
4040
}
4141

src/layout/achievements/achievements.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ article#achievements.achievements__achievementsParent
2222
// Здесь не тег <a/>, так как swiper баганулся и при клике на этот тег свайпает на следующий слайд
2323
// поэтому здесь реализовано с помощью div и onclick
2424
25-
div(href="/achievements/" + obj.link onclick=`window.location='${"achievements/" + obj.link}'`).achievementCard__parent
25+
div(href="/achievements/" + obj.link + ".html" onclick=`window.location='${"achievements/" + obj.link + ".html"}'`).achievementCard__parent
2626
h1
2727
=obj.title.replaceAll("\\n", "")
2828
.linkButton Подробнее

0 commit comments

Comments
 (0)