From 172b23e2574c1ebcffc0d4abe8f8f97975c59c69 Mon Sep 17 00:00:00 2001 From: Aamir khan Date: Sat, 4 Dec 2021 18:48:05 +0530 Subject: [PATCH] refactor: modularize assets --- assets/index.js | 31 +++++++++++++++++++++++++++++++ index.js | 36 +++++++++++------------------------- 2 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 assets/index.js diff --git a/assets/index.js b/assets/index.js new file mode 100644 index 0000000..5eb3ef0 --- /dev/null +++ b/assets/index.js @@ -0,0 +1,31 @@ +const assets = [ + { + path: 'bootstrap', + modulePath: 'bootstrap/dist', + }, + { + path: 'jquery', + modulePath: 'jquery/dist', + }, + { + path: 'octicons', + modulePath: '@primer/octicons/build', + }, + { + path: 'filesize', + modulePath: 'filesize/lib', + }, { + path: 'xterm', + modulePath: 'xterm', + }, { + path: 'xterm-addon-attach', + modulePath: 'xterm-addon-attach', + }, { + path: 'xterm-addon-fit', + modulePath: 'xterm-addon-fit', + } +]; + + +module.exports = assets; + diff --git a/index.js b/index.js index 0806dac..6ccb286 100755 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ const session = require("express-session"); const busboy = require("connect-busboy"); const flash = require("connect-flash"); const querystring = require("querystring"); - +const assets = require("./assets"); const archiver = require("archiver"); const notp = require("notp"); @@ -72,30 +72,16 @@ app.engine( app.set("view engine", "handlebars"); app.use("/@assets", express.static(path.join(__dirname, "assets"))); -app.use( - "/@assets/bootstrap", - express.static(path.join(__dirname, "node_modules/bootstrap/dist")) -); -app.use( - "/@assets/octicons", - express.static(path.join(__dirname, "node_modules/@primer/octicons/build")) -); -app.use( - "/@assets/jquery", - express.static(path.join(__dirname, "node_modules/jquery/dist")) -); -app.use( - "/@assets/filesize", - express.static(path.join(__dirname, "node_modules/filesize/lib")) -); -app.use( - "/@assets/xterm", - express.static(path.join(__dirname, "node_modules/xterm")) -); -app.use( - "/@assets/xterm-addon-attach", - express.static(path.join(__dirname, "node_modules/xterm-addon-attach")) -); +// init assets +assets.forEach(asset => { + const { path: url, modulePath } = asset; + app.use( + `/@assets/${url}`, + express.static(path.join(__dirname, `node_modules/${modulePath}`)) + ); +}) + + app.use( "/@assets/xterm-addon-fit", express.static(path.join(__dirname, "node_modules/xterm-addon-fit"))