UNPKG

lasso

Version:

Lasso.js is a build tool and runtime library for building and bundling all of the resources needed by a web application

54 lines (45 loc) 1.96 kB
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } const promisify = require('pify'); const fs = require('fs'); const writeFileAsync = promisify(fs.writeFile); /** * We may want to store the prebuild in the same directory as the page * file instead of the current working directory. There will often be * an npm script that is running at the base of the project. In the * AWS Lambda case, we want the prebuild file to live alongside of the * page itself. We need to preprocess all of the builds and then write * them individually after because there may be multiple pages that live * in the same directory as well as multiple builds for the same page * with different flags. */ class LassoPrebuildResult { constructor() { this._buildsByPath = {}; } addBuild(path, build) { if (this._buildsByPath[path]) { this._buildsByPath[path].push(build); } else { this._buildsByPath[path] = [build]; } } write() { var _this = this; return _asyncToGenerator(function* () { for (const buildPath in _this._buildsByPath) { yield writeFileAsync(buildPath, _this.serializeBuild(buildPath), 'utf8'); } })(); } serializeBuild(path) { const build = this._buildsByPath[path]; return JSON.stringify(build, null, 2); } getBuildByPath(path) { return this._buildsByPath[path]; } getBuildsByPath() { return this._buildsByPath; } } module.exports = LassoPrebuildResult;