mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
Minify: Move getTar()
to static.js
`static.js` is the only file that uses it.
This commit is contained in:
parent
996dc81825
commit
7f4a7156e2
2 changed files with 24 additions and 21 deletions
|
@ -1,10 +1,33 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const minify = require('../../utils/Minify');
|
const minify = require('../../utils/Minify');
|
||||||
|
const path = require('path');
|
||||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||||
|
const settings = require('../../utils/Settings');
|
||||||
const CachingMiddleware = require('../../utils/caching_middleware');
|
const CachingMiddleware = require('../../utils/caching_middleware');
|
||||||
const Yajsml = require('etherpad-yajsml');
|
const Yajsml = require('etherpad-yajsml');
|
||||||
|
|
||||||
|
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
||||||
|
const getTar = () => {
|
||||||
|
const prefixLocalLibraryPath = (path) => {
|
||||||
|
if (path.charAt(0) === '$') {
|
||||||
|
return path.slice(1);
|
||||||
|
} else {
|
||||||
|
return `ep_etherpad-lite/static/js/${path}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const tarJson = fs.readFileSync(path.join(settings.root, 'src/node/utils/tar.json'), 'utf8');
|
||||||
|
const tar = {};
|
||||||
|
for (const [key, relativeFiles] of Object.entries(JSON.parse(tarJson))) {
|
||||||
|
const files = relativeFiles.map(prefixLocalLibraryPath);
|
||||||
|
tar[prefixLocalLibraryPath(key)] = files
|
||||||
|
.concat(files.map((p) => p.replace(/\.js$/, '')))
|
||||||
|
.concat(files.map((p) => `${p.replace(/\.js$/, '')}/index.js`));
|
||||||
|
}
|
||||||
|
return tar;
|
||||||
|
};
|
||||||
|
|
||||||
exports.expressCreateServer = (hookName, args, cb) => {
|
exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
// Cache both minified and static.
|
// Cache both minified and static.
|
||||||
const assetCache = new CachingMiddleware();
|
const assetCache = new CachingMiddleware();
|
||||||
|
@ -26,7 +49,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const StaticAssociator = Yajsml.associators.StaticAssociator;
|
const StaticAssociator = Yajsml.associators.StaticAssociator;
|
||||||
const associations = Yajsml.associators.associationsForSimpleMapping(minify.getTar());
|
const associations = Yajsml.associators.associationsForSimpleMapping(getTar());
|
||||||
const associator = new StaticAssociator(associations);
|
const associator = new StaticAssociator(associations);
|
||||||
jsServer.setAssociator(associator);
|
jsServer.setAssociator(associator);
|
||||||
|
|
||||||
|
|
|
@ -48,26 +48,6 @@ const LIBRARY_WHITELIST = [
|
||||||
'unorm',
|
'unorm',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
|
||||||
exports.getTar = () => {
|
|
||||||
const prefixLocalLibraryPath = (path) => {
|
|
||||||
if (path.charAt(0) === '$') {
|
|
||||||
return path.slice(1);
|
|
||||||
} else {
|
|
||||||
return `ep_etherpad-lite/static/js/${path}`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const tarJson = fs.readFileSync(path.join(__dirname, 'tar.json'), 'utf8');
|
|
||||||
const tar = {};
|
|
||||||
for (const [key, relativeFiles] of Object.entries(JSON.parse(tarJson))) {
|
|
||||||
const files = relativeFiles.map(prefixLocalLibraryPath);
|
|
||||||
tar[prefixLocalLibraryPath(key)] = files
|
|
||||||
.concat(files.map((p) => p.replace(/\.js$/, '')))
|
|
||||||
.concat(files.map((p) => `${p.replace(/\.js$/, '')}/index.js`));
|
|
||||||
}
|
|
||||||
return tar;
|
|
||||||
};
|
|
||||||
|
|
||||||
// What follows is a terrible hack to avoid loop-back within the server.
|
// What follows is a terrible hack to avoid loop-back within the server.
|
||||||
// TODO: Serve files from another service, or directly from the file system.
|
// TODO: Serve files from another service, or directly from the file system.
|
||||||
const requestURI = (url, method, headers, callback) => {
|
const requestURI = (url, method, headers, callback) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue