Git Product home page Git Product logo

bun-banner-plugin's Introduction

bun-banner-plugin

A small plugin to insert an arbitrary string at the beginning of generated content. Inspired by esbuild banner option.

Installation

bun add -D bun-banner-plugin

Usage

build.ts:

import { bannerPlugin } from "bun-banner-plugin";

await Bun.build({
  entrypoints: ["src/index.ts"],
  outdir: "dist",
  target: "node",
  minify: true,
  plugins: [
    bannerPlugin({
      // Add banners to json files
      jsonc: ["// This is a jsonc file", "// Hello, jsonc!"],

      // Add a shebang to the top of `.ts`, `.tsx`, `.js`, `.jsx` files
      "ts|tsx|js|jsx": "#!/usr/bin/env node",
    }),
  ],
});

Example

Suppose you have the following src/index.ts.

console.log("Hello, world!");

Now, using the build.ts I wrote in Usage, run bun run build.ts, the following will be output:

#!/usr/bin/env node
console.log("Hello, world!");

Options

  • The key is a regular expression that matches the file extension.
    • The given key is interpreted as a regular expression, so you need to escape special characters.
    • For example:
      • If the key is json, it will interpreted as /.(json)$/. It will match .json files.
      • If the key is ts|tsx|js|jsx, it will iterpreted as /.(ts|tsx|js|jsx)$/. It will match .ts, .tsx, .js, .jsx files.
  • The value is the string to be inserted at the beginning of the file.
    • If the value is an array, the strings in the array will be joined with a newline character.

    • If the value is a string, it will be inserted as is.

    • For example, If the value is ["// This is a jsonc file", "// Hello, jsonc!"], it will be inserted as follows:

      // This is a jsonc file
      // Hello, jsonc!
      {
        "foo": "bar",
      }

Development

Commands

Command Description
bun install Install dependencies
bun run build Build the project
bun run test Run tests with watch mode
bun run check Lint and format
npm publish --dry-run Check locally for products to be published to npm
npm publish --access public Publish to npm

Publish

  1. Update version in package.json
  2. commit with tag vX.X.X
  3. push to GitHub

bun-banner-plugin's People

Contributors

r4ai avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.