@softwareventures/maintain-project
Version:
Automatically create and maintain TypeScript projects with standard settings for Software Ventures Limited
79 lines • 3.09 kB
JavaScript
import * as escodegen from "escodegen";
import { textFile } from "../fs-stage/file.js";
import { insert } from "../fs-stage/fs-stage.js";
import { success } from "../result/result.js";
export function writeWebpackConfig(project) {
if (project.target !== "webapp") {
return async (fsStage) => success(fsStage);
}
const program = {
type: "Program",
sourceType: "module",
body: [
{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: "use strict"
}
},
{
type: "VariableDeclaration",
kind: "const",
declarations: [
{
type: "VariableDeclarator",
id: { type: "Identifier", name: "config" },
init: {
type: "CallExpression",
callee: { type: "Identifier", name: "require" },
arguments: [
{ type: "Literal", value: "@softwareventures/webpack-config" }
],
optional: false
}
}
]
},
{
type: "ExpressionStatement",
expression: {
type: "AssignmentExpression",
operator: "=",
left: {
type: "MemberExpression",
object: { type: "Identifier", name: "module" },
property: { type: "Identifier", name: "exports" },
computed: false,
optional: false
},
right: {
type: "CallExpression",
callee: { type: "Identifier", name: "config" },
arguments: [
{
type: "ObjectExpression",
properties: [
{
type: "Property",
method: false,
shorthand: false,
computed: false,
key: { type: "Identifier", name: "title" },
value: { type: "Literal", value: project.npmPackage.name },
kind: "init"
}
]
}
],
optional: false
}
}
}
]
};
const text = escodegen.generate(program);
const file = textFile(text);
return async (fsStage) => insert(fsStage, "webpack.config.cjs", file);
}
//# sourceMappingURL=write.js.map