2016-11-16 15:27:30 +03:00
|
|
|
/* eslint-disable */
|
2017-03-14 19:04:46 +03:00
|
|
|
'use strict';
|
|
|
|
|
2015-06-03 09:25:56 +03:00
|
|
|
module.exports = {
|
|
|
|
name: 'asset-delivery',
|
2017-03-14 19:04:46 +03:00
|
|
|
|
2022-08-02 15:43:28 +03:00
|
|
|
env: null,
|
|
|
|
|
2017-03-14 19:04:46 +03:00
|
|
|
isDevelopingAddon() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2022-08-02 15:43:28 +03:00
|
|
|
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;
|
2017-03-14 19:04:46 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-03 09:25:56 +03:00
|
|
|
postBuild: function (results) {
|
2022-08-02 15:43:28 +03:00
|
|
|
const fs = this.project.require('fs-extra');
|
|
|
|
const walkSync = this.project.require('walk-sync');
|
2015-02-14 07:03:16 +03:00
|
|
|
|
2022-08-03 16:59:51 +03:00
|
|
|
const assetsOut = `../core/core/built/admin/${this.env}`;
|
2015-06-03 09:25:56 +03:00
|
|
|
fs.ensureDirSync(assetsOut);
|
|
|
|
|
2022-08-02 15:43:28 +03:00
|
|
|
// 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');
|
2015-08-21 19:17:39 +03:00
|
|
|
|
|
|
|
assets.forEach(function (relativePath) {
|
|
|
|
if (relativePath.slice(-1) === '/') { return; }
|
|
|
|
|
2022-08-02 15:43:28 +03:00
|
|
|
fs.copySync(`${results.directory}/assets/${relativePath}`, `${assetsOut}/assets/${relativePath}`, {overwrite: true, dereference: true});
|
2015-08-21 19:17:39 +03:00
|
|
|
});
|
2015-06-03 09:25:56 +03:00
|
|
|
}
|
|
|
|
};
|