vikejs / bati

Next-gen scaffolder. Get started with fully-functional apps, and choose any tool you want.
https://batijs.dev
MIT License
282 stars 14 forks source link

feat: package.json transformer #398

Closed magne4000 closed 2 months ago

magne4000 commented 2 months ago

Example

// boilerplates/abc/files/$package.json.ts

import { loadPackageJson, type TransformerProps } from "@batijs/core";

export default async function getPackageJson(props: TransformerProps) {
  const packageJson = await loadPackageJson(props, await import("../package.json").then((x) => x.default));

  return packageJson
    // set scripts
    .setScript("test", {
      value: "vitest",
      precedence: 0,
    })
    // add dependencies
    .addDependencies(["aws-cdk-lib", "constructs", "source-map-support"])
    // add devDependencies with conditions on scripts, meaning that if all
    // given scripts are moved or replaced, the dependency will also be removed
    .addDevDependencies(["npm-run-all2"], ["deploy:aws", "cdk:app"])
    // Only add `eslint-aws` if --eslint is provided
    .addDevDependencies(["eslint-aws"], props.meta.BATI.has("eslint"));
}