2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-27 18:57:39 -08:00
|
|
|
const loadPublicFiles = require('./public');
|
2020-02-25 19:37:10 -08:00
|
|
|
const Cache = require('./cache');
|
2020-02-27 18:57:39 -08:00
|
|
|
const Promise = require('bluebird');
|
|
|
|
const fs = require('fs-extra');
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-27 18:57:39 -08:00
|
|
|
const primeTweets = require('./page-tweets');
|
|
|
|
const pageWriter = require('./page-writer');
|
2020-02-25 19:37:10 -08:00
|
|
|
const evaluate = require('./evaluate');
|
2020-02-27 18:57:39 -08:00
|
|
|
const { resolve } = require('./resolve');
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-25 19:37:10 -08:00
|
|
|
const favicon = require('./favicon');
|
2020-02-28 09:15:21 -08:00
|
|
|
const scss = require('./scss');
|
2020-02-27 18:57:39 -08:00
|
|
|
const svg = require('./svg');
|
2020-02-28 10:27:52 -08:00
|
|
|
const scripts = require('./scripts');
|
|
|
|
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-25 19:37:10 -08:00
|
|
|
exports.everything = function (prod = false) {
|
|
|
|
const fn = async () => {
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-27 18:57:39 -08:00
|
|
|
// load a directory scan of the public folder
|
|
|
|
const PublicFiles = await loadPublicFiles();
|
|
|
|
|
|
|
|
// load data for all the files in that folder
|
2020-02-27 21:02:47 -08:00
|
|
|
await Promise.map(PublicFiles.assets, (p) => p.load());
|
|
|
|
await Promise.map(PublicFiles.pages, (p) => p.load(PublicFiles));
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-27 18:57:39 -08:00
|
|
|
// prime tweet data for all pages
|
|
|
|
const pages = await primeTweets(PublicFiles.pages);
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-27 18:57:39 -08:00
|
|
|
// compile all tasks to be completed
|
2020-02-25 19:37:10 -08:00
|
|
|
const tasks = await Promise.all([
|
2020-02-27 18:57:39 -08:00
|
|
|
PublicFiles.tasks,
|
2020-02-28 09:15:21 -08:00
|
|
|
scss(prod),
|
2020-02-28 10:27:52 -08:00
|
|
|
scripts(prod),
|
2020-02-27 18:57:39 -08:00
|
|
|
svg(prod),
|
2020-02-25 19:37:10 -08:00
|
|
|
favicon(prod),
|
|
|
|
]);
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-28 10:27:52 -08:00
|
|
|
await fs.writeFile(resolve('pages.json'), JSON.stringify(pages.map((p) => p.toJson()), null, 2));
|
|
|
|
|
|
|
|
await fs.ensureDir(resolve('dist'));
|
|
|
|
const cache = new Cache({ prod });
|
|
|
|
await cache.load();
|
|
|
|
await evaluate(tasks.flat(), cache);
|
|
|
|
await cache.save();
|
|
|
|
|
|
|
|
await pageWriter(pages, prod);
|
2020-02-27 18:57:39 -08:00
|
|
|
};
|
2020-02-21 20:05:52 -08:00
|
|
|
|
2020-02-27 18:57:39 -08:00
|
|
|
const ret = () => fn().catch((err) => { console.log(err.trace || err); throw err; });
|
|
|
|
ret.displayName = prod ? 'generateEverythingForProd' : 'generateEverything';
|
2020-02-25 19:37:10 -08:00
|
|
|
return ret;
|
|
|
|
};
|