0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

build comment-counts.js at build time

This commit is contained in:
Michael Barrett 2024-12-13 11:02:41 +00:00
parent b6e1c11505
commit cb8a176cdb
No known key found for this signature in database
8 changed files with 36 additions and 42 deletions

1
.gitignore vendored
View file

@ -122,6 +122,7 @@ test/functional/*.png
# Built asset files
/ghost/core/core/built
/ghost/core/core/frontend/public/ghost.min.css
/ghost/core/core/frontend/public/comment-counts.min.js
# Caddyfile - for local development with ssl + caddy
Caddyfile

View file

@ -16,7 +16,7 @@ const logging = require('@tryghost/logging');
const tpl = require('@tryghost/tpl');
const themeEngine = require('./frontend/services/theme-engine');
const appService = require('./frontend/services/apps');
const {adminAuthAssets, cardAssets,commentCountsAssets, memberAttributionAssets} = require('./frontend/services/assets-minification');
const {adminAuthAssets, cardAssets, memberAttributionAssets} = require('./frontend/services/assets-minification');
const routerManager = require('./frontend/services/routing').routerManager;
const settingsCache = require('./shared/settings-cache');
const urlService = require('./server/services/url');
@ -72,7 +72,6 @@ class Bridge {
// TODO: is this in the right place?
// rebuild asset files
commentCountsAssets.invalidate();
adminAuthAssets.invalidate();
memberAttributionAssets.invalidate();
} catch (err) {

View file

@ -1,33 +0,0 @@
const Minifier = require('@tryghost/minifier');
const path = require('path');
const config = require('../../../shared/config');
const AssetsMinificationBase = require('./AssetsMinificationBase');
module.exports = class CommentCountsAssets extends AssetsMinificationBase {
constructor(options = {}) {
super(options);
this.src = options.src || path.join(config.get('paths').assetSrc, 'comment-counts');
this.dest = options.dest || config.getContentPath('public');
this.minifier = new Minifier({src: this.src, dest: this.dest});
this.files = [];
}
/**
* @override
*/
generateGlobs() {
return {
'comment-counts.min.js': 'js/*.js'
};
}
/**
* @override
*/
async load() {
const globs = this.generateGlobs();
this.files = await this.minify(globs);
}
};

View file

@ -1,16 +1,13 @@
const AdminAuthAssets = require('./AdminAuthAssets');
const CardAssets = require('./CardAssets');
const CommentCountsAssets = require('./CommentCountsAssets');
const MemberAttributionAssets = require('./MemberAttributionAssets');
const adminAuthAssets = new AdminAuthAssets();
const cardAssets = new CardAssets();
const commentCountsAssets = new CommentCountsAssets();
const memberAttributionAssets = new MemberAttributionAssets();
module.exports = {
adminAuthAssets,
cardAssets,
commentCountsAssets,
memberAttributionAssets
};

View file

@ -16,7 +16,7 @@ const membersService = require('../../server/services/members');
const offersService = require('../../server/services/offers');
const customRedirects = require('../../server/services/custom-redirects');
const linkRedirects = require('../../server/services/link-redirection');
const {cardAssets, commentCountsAssets, memberAttributionAssets} = require('../services/assets-minification');
const {cardAssets, memberAttributionAssets} = require('../services/assets-minification');
const siteRoutes = require('./routes');
const shared = require('../../server/web/shared');
const errorHandler = require('@tryghost/mw-error-handler');
@ -77,7 +77,7 @@ module.exports = function setupSiteApp(routerConfig) {
siteApp.use(cardAssets.serveMiddleware(), mw.servePublicFile('built', 'public/cards.min.js', 'application/javascript', config.get('caching:publicAssets:maxAge')));
// Comment counts
siteApp.use(commentCountsAssets.serveMiddleware(), mw.servePublicFile('built', 'public/comment-counts.min.js', 'application/javascript', config.get('caching:publicAssets:maxAge')));
siteApp.use(mw.servePublicFile('static', 'public/comment-counts.min.js', 'application/javascript', config.get('caching:publicAssets:maxAge')));
// Member attribution
siteApp.use(memberAttributionAssets.serveMiddleware(), mw.servePublicFile('built', 'public/member-attribution.min.js', 'application/javascript', config.get('caching:publicAssets:maxAge')));

View file

@ -22,7 +22,9 @@
"scripts": {
"archive": "npm pack",
"dev": "node --watch index.js",
"build:assets": "postcss core/frontend/public/ghost.css --no-map --use cssnano -o core/frontend/public/ghost.min.css",
"build:assets:css": "postcss core/frontend/public/ghost.css --no-map --use cssnano -o core/frontend/public/ghost.min.css",
"build:assets:js": "../minifier/bin/minify core/frontend/public/comment-counts.js core/frontend/public/comment-counts.min.js",
"build:assets": "yarn build:assets:css && yarn build:assets:js",
"test": "yarn test:unit",
"test:base": "mocha --reporter dot --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js",
"test:single": "yarn test:base --timeout=60000",
@ -282,6 +284,7 @@
},
"dev": {
"dependsOn": [
"build:assets",
"^build:ts"
]
},

27
ghost/minifier/bin/minify Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env node
/**
* Script to minify a given file
*
* Usage: bin/minify <source> <destination>
*/
const path = require('path');
const Minifier = require('../index');
const src = path.parse(process.argv[2]);
const dest = path.parse(process.argv[3]);
const minifier = new Minifier({src: src.dir, dest: dest.dir});
(async () => {
try {
await minifier.minify({
[dest.base]: src.base
});
} catch (error) {
console.error(error);
process.exit(1);
}
})();