Skip to content

Commit e9164d8

Browse files
committed
Updates for default folder
1 parent 6544497 commit e9164d8

15 files changed

+169
-30
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.git/
22
Dockerfile
3-
.vscode/
3+
.vscode/
4+
dist/

.gitignore

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ server/music/*
77
#except for the readme
88
!server/music/readme.txt
99
#and the sample songs
10-
!server/music/Catch the Sun.mp3
11-
!server/music/Crisp day.mp3
12-
!server/music/Rolling Clouds.mp3
13-
!server/music/Strong Breeze.mp3
10+
!server/music/default
11+
12+
#dist folder
13+
dist/*
14+
!dist/readme.txt

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ As time allows I will be working on the following enhancements.
9898

9999
* Better error reporting when api.weather.gov is down (happens more often than you would think)
100100

101+
## Serving static files
102+
The app can be served as a static set of files on any web server. Run the provided gulp task to create a set of static distribution files:
103+
```
104+
npm run buildDist
105+
```
106+
The resulting files will be in the /dist folder in the root of the project. These can then be uploaded to a web server for hosting, no server-side scripting is required.
107+
101108
## Community Notes
102109

103110
Thanks to the WeatherStar community for providing these discussions to further extend your retro forecasts!

dist/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder is a placeholder for static files generated by the gulp task buildDist

gulp/publish-frontend.mjs

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import s3Upload from 'gulp-s3-upload';
1212
import webpack from 'webpack-stream';
1313
import TerserPlugin from 'terser-webpack-plugin';
1414
import { readFile } from 'fs/promises';
15+
import reader from '../src/playlist-reader.mjs';
16+
import file from "gulp-file";
1517

1618
// get cloudfront
1719
import { CloudFrontClient, CreateInvalidationCommand } from '@aws-sdk/client-cloudfront';
1820

19-
const clean = () => deleteAsync(['./dist**']);
21+
const clean = () => deleteAsync(['./dist/**/*', '!./dist/readme.txt']);
2022

2123
const cloudfront = new CloudFrontClient({ region: 'us-east-1' });
2224

@@ -122,8 +124,9 @@ const compressHtml = async () => {
122124
const otherFiles = [
123125
'server/robots.txt',
124126
'server/manifest.json',
127+
'server/music/**/*.mp3'
125128
];
126-
const copyOtherFiles = () => src(otherFiles, { base: 'server/' })
129+
const copyOtherFiles = () => src(otherFiles, { base: 'server/', encoding: false })
127130
.pipe(dest('./dist'));
128131

129132
const s3 = s3Upload({
@@ -170,10 +173,20 @@ const invalidate = () => cloudfront.send(new CreateInvalidationCommand({
170173
},
171174
}));
172175

173-
const buildDist = series(clean, parallel(buildJs, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles));
176+
const buildPlaylist = async () => {
177+
const availableFiles = await reader();
178+
const playlist = { availableFiles };
179+
return file('playlist.json', JSON.stringify(playlist)).pipe(dest('./dist'))
180+
}
181+
182+
const buildDist = series(clean, parallel(buildJs, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles, buildPlaylist));
174183

175184
// upload_images could be in parallel with upload, but _images logs a lot and has little changes
176185
// by running upload last the majority of the changes will be at the bottom of the log for easy viewing
177186
const publishFrontend = series(buildDist, uploadImages, upload, invalidate);
178187

179188
export default publishFrontend;
189+
190+
export {
191+
buildDist,
192+
}

gulpfile.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import updateVendor from './gulp/update-vendor.mjs';
2-
import publishFrontend from './gulp/publish-frontend.mjs';
2+
import publishFrontend, { buildDist } from './gulp/publish-frontend.mjs'
33

44
export {
55
updateVendor,
66
publishFrontend,
7+
buildDist,
78
};

package-lock.json

+97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",
99
"build:css": "sass --style=compressed ./server/styles/scss/main.scss ./server/styles/main.css",
10+
"build": "gulp buildDist",
1011
"lint": "eslint ./server/scripts/**/*.mjs",
1112
"lint:fix": "eslint --fix ./server/scripts/**/*.mjs"
1213
},
@@ -21,32 +22,33 @@
2122
},
2223
"homepage": "https://github.com/netbymatt/ws4kp#readme",
2324
"devDependencies": {
24-
"del": "^8.0.0",
25-
"jquery": "^3.6.0",
26-
"jquery-touchswipe": "^1.6.19",
27-
"luxon": "^3.0.0",
28-
"nosleep.js": "^0.12.0",
29-
"suncalc": "^1.8.0",
30-
"swiped-events": "^1.1.4",
3125
"@aws-sdk/client-cloudfront": "^3.609.0",
32-
"gulp-awspublish": "^8.0.0",
33-
"gulp-s3-upload": "^1.7.3",
26+
"del": "^8.0.0",
3427
"eslint": "^8.2.0",
3528
"eslint-config-airbnb-base": "^15.0.0",
3629
"eslint-plugin-import": "^2.10.0",
3730
"gulp": "^5.0.0",
31+
"gulp-awspublish": "^8.0.0",
3832
"gulp-concat": "^2.6.1",
3933
"gulp-ejs": "^5.1.0",
34+
"gulp-file": "^0.4.0",
4035
"gulp-htmlmin": "^5.0.1",
4136
"gulp-rename": "^2.0.0",
37+
"gulp-s3-upload": "^1.7.3",
4238
"gulp-sass": "^6.0.0",
4339
"gulp-terser": "^2.0.0",
40+
"jquery": "^3.6.0",
41+
"jquery-touchswipe": "^1.6.19",
42+
"luxon": "^3.0.0",
43+
"nosleep.js": "^0.12.0",
44+
"sass": "^1.54.0",
45+
"suncalc": "^1.8.0",
46+
"swiped-events": "^1.1.4",
4447
"terser-webpack-plugin": "^5.3.6",
45-
"webpack-stream": "^7.0.0",
46-
"sass": "^1.54.0"
48+
"webpack-stream": "^7.0.0"
4749
},
4850
"dependencies": {
49-
"express": "^4.17.1",
50-
"ejs": "^3.1.5"
51+
"ejs": "^3.1.5",
52+
"express": "^4.17.1"
5153
}
5254
}
2.22 MB
Binary file not shown.

server/music/default/Crisp day.mp3

2.49 MB
Binary file not shown.
2.38 MB
Binary file not shown.
5.09 MB
Binary file not shown.

server/music/readme.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.mp3 files placed in this folder will be available via the un-mute button in the application.
2-
No subdirectories will be scanned, and music will be played in a random order.
2+
No subdirectories will be scanned, and music will be played in a random order.
3+
The default folder will be used only if no .mp3 files are found in this /server/music folder

server/scripts/modules/media.mjs

+10-4
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@ const toggleMedia = (forcedState) => {
6363
stateChanged();
6464
};
6565

66-
const startMedia = () => {
66+
const startMedia = async () => {
6767
// if there's not media player yet, enable it
6868
if (!player) {
6969
initializePlayer();
7070
} else {
71-
player.play();
71+
try {
72+
await player.play();
73+
} catch (e) {
74+
console.error('Couldn\'t play music');
75+
console.error(e);
76+
}
7277
}
7378
};
7479

@@ -128,11 +133,12 @@ const initializePlayer = () => {
128133
console.log('player initialized');
129134
};
130135

131-
const playerCanPlay = () => {
136+
const playerCanPlay = async () => {
132137
// check to make sure they user still wants music (protect against slow loading music)
133138
if (!mediaPlaying.value) return;
134139
// start playing
135-
player.play();
140+
startMedia();
141+
136142
};
137143

138144
const playerEnded = () => {

src/playlist-reader.mjs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import fs from 'fs/promises';
22

3+
const mp3Filter = (file) => file.match(/\.mp3$/);
4+
35
const reader = async () => {
46
// get the listing of files in the folder
57
const rawFiles = await fs.readdir('./server/music');
68
// filter for mp3 files
7-
const files = rawFiles.filter((file) => file.match(/\.mp3$/));
8-
console.log(files);
9-
return files;
9+
const files = rawFiles.filter(mp3Filter);
10+
// if files were found return them
11+
if (files.length > 0) {
12+
return files;
13+
}
14+
15+
// fall back to the default folder
16+
const defaultFiles = await fs.readdir('./server/music/default');
17+
return defaultFiles.map(file => `default/${file}`).filter(mp3Filter);
18+
1019
};
1120

1221
export default reader;

0 commit comments

Comments
 (0)