Removed use of Node Module ESLint, generated files for Express server.

This commit is contained in:
Harrison Deng 2022-03-20 19:57:48 -05:00
parent 792251dada
commit d53b54fc83
16 changed files with 198 additions and 1641 deletions

View File

@ -1,29 +0,0 @@
export default {
"env": {
"browser": true,
"es2021": true,
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
};

41
expressjs/app.js Normal file
View File

@ -0,0 +1,41 @@
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;

90
expressjs/bin/www Executable file
View File

@ -0,0 +1,90 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('expressjs:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}

16
expressjs/package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "expressjs",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"jade": "~1.11.0",
"morgan": "~1.9.1"
}
}

View File

@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}

View File

@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;

View File

@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;

View File

@ -0,0 +1,6 @@
extends layout
block content
h1= message
h2= error.status
pre #{error.stack}

View File

@ -0,0 +1,5 @@
extends layout
block content
h1= title
p Welcome to #{title}

View File

@ -0,0 +1,7 @@
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content

1585
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +0,0 @@
{
"name": "audioshowkit",
"version": "1.0.0",
"description": "A music based website styling toolkit.",
"main": "audioshowkit.js",
"devDependencies": {
"eslint": "^8.11.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://dev.sys.reslate.xyz/git/ydeng/AudioShowKit.git"
},
"author": "",
"license": "ISC"
}

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
export default function VisualizerCore(mediaSource, fftSize = 1024) { function VisualizerCore(mediaSource, fftSize = 1024) {
this._stream = mediaSource; this._stream = mediaSource;
this._analyzing = false; this._analyzing = false;
this._updateListeners = []; this._updateListeners = [];
@ -46,7 +46,6 @@ export default function VisualizerCore(mediaSource, fftSize = 1024) {
this._analyzing = false; this._analyzing = false;
}; };
this.addUpdateListener = function (listener) { this.addUpdateListener = function (listener) {
console.log("added listener.");
this._updateListeners.push(listener); this._updateListeners.push(listener);
}; };
this.getNumberOfBins = function () { this.getNumberOfBins = function () {

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
export default function bindHorizontalBar(canvasElement, visualizerCore) { function bindHorizontalBar(canvasElement, visualizerCore) {
let _width = canvasElement.width; let _width = canvasElement.width;
let _height = canvasElement.height; let _height = canvasElement.height;
let _canvasCtx = canvasElement.getContext("2d"); let _canvasCtx = canvasElement.getContext("2d");
@ -9,7 +9,6 @@ export default function bindHorizontalBar(canvasElement, visualizerCore) {
_canvasCtx.clearRect(0, 0, _width, _height); // clear canvas. _canvasCtx.clearRect(0, 0, _width, _height); // clear canvas.
let barWidth = Math.floor(_width / bins.length) - 1; // -1 for 1 pixel gap between bars. let barWidth = Math.floor(_width / bins.length) - 1; // -1 for 1 pixel gap between bars.
let barIndex = 0; let barIndex = 0;
console.log("updating visuals.." + barWidth);
bins.forEach(bin => { bins.forEach(bin => {
let normalBin = bin / 255.0; let normalBin = bin / 255.0;
_canvasCtx.fillStyle = "rgb(" + 0 + "," + bin + "," + bin + ")"; _canvasCtx.fillStyle = "rgb(" + 0 + "," + bin + "," + bin + ")";

View File

@ -7,7 +7,11 @@
<title>AudioShowKit visual test</title> <title>AudioShowKit visual test</title>
<meta name='viewport' content='width=device-width, initial-scale=1'> <meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'> <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script defer type="module" src='script.js'></script>
<script defer src="../src/VisualizerCore.js"></script>
<script defer src="../src/patterns/HorizontalBar.js"></script>
<script defer src='script.js'></script>
</head> </head>
<body> <body>

View File

@ -1,8 +1,5 @@
"use strict"; "use strict";
import bindHorizontalBar from "../src/patterns/HorizontalBar.js";
import VisualizerCore from "../src/VisualizerCore.js";
// We will see if the visualizers core and event systems are working correctly. // We will see if the visualizers core and event systems are working correctly.
let startBtn = document.getElementById("startbtn"); let startBtn = document.getElementById("startbtn");
startBtn.addEventListener("click", async (ev) => { startBtn.addEventListener("click", async (ev) => {
@ -13,7 +10,6 @@ startBtn.addEventListener("click", async (ev) => {
coreAndEventCanvas.width = 640; coreAndEventCanvas.width = 640;
coreAndEventCanvas.height = 200; coreAndEventCanvas.height = 200;
console.log("starting playthrough.");
mediaStream.play(); mediaStream.play();
visCore.analyze(); visCore.analyze();