@fang/rename

Rename your input files, change their extension, add suffixes, ... using rename.

Usage no npm install needed!

<script type="module">
  import fangRename from 'https://cdn.skypack.dev/@fang/rename';
</script>

README

fang-rename

Rename your input files, change their extension, add suffixes, ... using rename.

Summary

About

I created this plugin for those who need a flexible way to rename their output file. As this is a common task, I wanted to created an "official" plugin, but feel free to check out others solution!

Requirements

Having @fang/core installed on version 0.*.

Features

  • Everything that rename can do, which means
    • changing the original directory name
    • changing the prefix
    • changing the base name
    • changing the suffix
    • replacing the file extension name

Installation

  • Using NPM: npm install --save-dev @fang/rename
  • Using Yarn: yarn add --dev @fang/rename

Examples

1. Replace the extension name of your file

// script.js
const { run } = require("@fang/core");
const save = require("@fang/save");
const rename = require("@fang/rename");

const ts = {
  name: "Typescript",
  input: "example/code.ts",
  tasks: [
    rename({
      extname: ".js",
    }),
    save({
      folder: "example/dist/js",
    }),
  ],
};

const main = async () => await run([ts]);

main();

Run node script.js, and you should see something like this in your console.

$ node script.js
fang: start
8 CPUs core(s)
1 tasks to run
Typescript: start
Typescript: 10.915ms
fang: 108.374ms

2. Replace the extension name of your file using a transform function

// script.js
const { run } = require("@fang/core");
const save = require("@fang/save");
const rename = require("@fang/rename");

const ts = {
  name: "Typescript",
  input: "example/code.ts",
  tasks: [
    rename(() => ({
      extname: ".js",
    })),
    save({
      folder: "example/dist/js",
    }),
  ],
};

const main = async () => await run([ts]);

main();

Run script.js, and you should see something like this in your console.

$ node script.js
fang: start
8 CPUs core(s)
1 tasks to run
Typescript: start
Typescript: 14.156ms
fang: 107.332ms