piral-cli
Version:
The standard CLI for creating and building a Piral instance or a Pilet.
28 lines (27 loc) • 1.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPiralStubIndexIfNotExists = createPiralStubIndexIfNotExists;
const io_1 = require("./io");
function fillTemplate(data) {
return `if (process.env.NODE_ENV === 'test') {
// behavior for the test environment, we'll try to make it work
if (typeof window !== 'undefined') {
require('./${data.outFile}');
const ctx = window['dbg:piral'];
const dependencies = (ctx && ctx.pilets && ctx.pilets.getDependencies({})) || {};
module.exports = dependencies['${data.name}'] || {};
} else {
console.error('Your test environment does not define "window". Please make sure to provide a proper environment.');
module.exports = {};
}
} else {
// under "normal" circumstances disallow such an import
throw new Error("This file should not be included anywhere. Usually, this means you've imported the Piral instance directly.");
}
`;
}
async function createPiralStubIndexIfNotExists(targetDir, fileName, forceOverwrite, data) {
const content = fillTemplate(data);
await (0, io_1.createFileIfNotExists)(targetDir, fileName, content, forceOverwrite);
}
//# sourceMappingURL=template.js.map