Ghost/ghost/admin/lib/asset-delivery/index.js
Daniel Lockyer 7cf4f595f7 🐛 Fixed missing published Admin assets when running in development
refs https://forum.ghost.org/t/admin-template-issues-default-install/31750

- we recently switched to using different folders within `core/built`, to
  indicate the assets that are applicable for development/production
  environments
- unfortunately, this came with the side effect of the "development" assets
  missing in the published tarball, which meant Admin wouldn't load when
  running in development mode
- this was a regression from how it previously worked because we used to
  just copy the production HTML file to the development HTML name, and
  use the same assets
- after thinking about it, I think we can get rid of the split folders
  for assets, because I don't think the use-case is there for having
  them:
  - if you run Ghost from source, you're 99% only using the
    development-built assets
  - if you want production ones, you can run with a flag, but the
    development ones get wiped anyway
  - those running Ghost from a published package are using the same
    assets and HTML file
- therefore, I think we can make our lives simpler by removing the env
  folders and using a folder under `core/built/admin/...`
- this commit implements that across Ghost and Admin
2022-08-04 10:55:35 +02:00

45 lines
1.4 KiB
JavaScript

/* eslint-disable */
'use strict';
module.exports = {
name: 'asset-delivery',
env: null,
isDevelopingAddon() {
return true;
},
config(env) {
// only set this.env on the first call otherwise when `postBuild()` is
// called this.env will always be 'test' due to multiple `config()` calls
if (!this.env) {
this.env = env;
}
},
postBuild: function (results) {
const fs = this.project.require('fs-extra');
const walkSync = this.project.require('walk-sync');
const assetsOut = `../core/core/built/admin`;
fs.ensureDirSync(assetsOut);
// the dist folder contains more than just index.html and /assets, especially
// for development builds but for Ghost's purposes it only needs to serve
// index.html and /assets
// copy the index.html file
fs.copySync(`${results.directory}/index.html`, `${assetsOut}/index.html`, {overwrite: true, dereference: true});
// copy all the `/assets` files
const assets = walkSync(results.directory + '/assets');
assets.forEach(function (relativePath) {
if (relativePath.slice(-1) === '/') { return; }
fs.copySync(`${results.directory}/assets/${relativePath}`, `${assetsOut}/assets/${relativePath}`, {overwrite: true, dereference: true});
});
}
};