mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
* move remaining files frm /common/script/public to website/public * remove localstorage * add back noscript template and put all javascript in the footer * fixes client side tests * remove double quotes where possible * simplify jade code and add tests for buildManifest * loading page with logo and spinner * better loading screen in landscape mode * icon on top of text logo * wip: user.notifications * notifications: simpler and working code * finish implementing notifications * correct loading screen css and re-inline images * add tests for user notifications * split User model in multiple files * remove old comment about missing .catch() * correctly setup hooks and methods for User model. Cleanup localstorage * include UserNotificationsService in static page js and split loading-screen css in its own file * add cron notification and misc fixes * remove console.log * fix tests * fix multiple notifications
73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import nconf from 'nconf';
|
|
|
|
const MANIFEST_FILE_PATH = path.join(__dirname, '/../../../client/manifest.json');
|
|
const BUILD_FOLDER_PATH = path.join(__dirname, '/../../../build');
|
|
let manifestFiles = require(MANIFEST_FILE_PATH);
|
|
|
|
const IS_PROD = nconf.get('IS_PROD');
|
|
let buildFiles = [];
|
|
|
|
function _walk (folder) {
|
|
let files = fs.readdirSync(folder);
|
|
|
|
files.forEach((fileName) => {
|
|
let file = `${folder}/${fileName}`;
|
|
|
|
if (fs.statSync(file).isDirectory()) {
|
|
_walk(file);
|
|
} else {
|
|
let relFolder = path.relative(BUILD_FOLDER_PATH, folder);
|
|
let original = fileName.replace(/-.{8}(\.[\d\w]+)$/, '$1'); // Match the hash part of the filename
|
|
|
|
if (relFolder) {
|
|
original = `${relFolder}/${original}`;
|
|
fileName = `${relFolder}/${fileName}`;
|
|
}
|
|
|
|
buildFiles[original] = fileName;
|
|
}
|
|
});
|
|
}
|
|
|
|
// Walks through all the files in the build directory
|
|
// and creates a map of original files names and hashed files names
|
|
_walk(BUILD_FOLDER_PATH);
|
|
|
|
export function getBuildUrl (url) {
|
|
return `/${buildFiles[url] || url}`;
|
|
}
|
|
|
|
export function getManifestFiles (page, type) {
|
|
let files = manifestFiles[page];
|
|
|
|
if (!files) throw new Error(`Page "${page}" not found!`);
|
|
|
|
let htmlCode = '';
|
|
|
|
if (IS_PROD) {
|
|
if (type !== 'js') {
|
|
htmlCode += `<link rel="stylesheet" type="text/css" href="${getBuildUrl(page + '.css')}">`; // eslint-disable-line prefer-template
|
|
}
|
|
|
|
if (type !== 'css') {
|
|
htmlCode += `<script type="text/javascript" src="${getBuildUrl(page + '.js')}"></script>`; // eslint-disable-line prefer-template
|
|
}
|
|
} else {
|
|
if (type !== 'js') {
|
|
files.css.forEach((file) => {
|
|
htmlCode += `<link rel="stylesheet" type="text/css" href="${getBuildUrl(file)}">`;
|
|
});
|
|
}
|
|
|
|
if (type !== 'css') {
|
|
files.js.forEach((file) => {
|
|
htmlCode += `<script type="text/javascript" src="${getBuildUrl(file)}"></script>`;
|
|
});
|
|
}
|
|
}
|
|
|
|
return htmlCode;
|
|
}
|