# Milkee

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Vitest](https://github.com/otnc/coffeescript-milkee/actions/workflows/test.yml/badge.svg)](https://github.com/otnc/coffeescript-milkee/actions)
[![npm version](https://img.shields.io/npm/v/milkee.svg)](https://www.npmjs.com/package/milkee)
[![Downloads](https://img.shields.io/npm/dw/milkee.svg)](https://www.npmjs.com/package/milkee)
[![License](https://img.shields.io/npm/l/milkee.svg)](./LICENSE)

**English** | [日本語](./README-ja.md)  

[![Milkee logo](./img/Milkee-logo.png)](https://milkee.org)  

A simple CoffeeScript build tool with [coffee.config.cjs](./temp/setup/coffee.config.cjs) ☕  

Official site: https://milkee.org  

## How to get started

### Install

Install Milkee:  

```bash
# npm
npm i -g milkee
# pnpm
pnpm add -g milkee
# yarn
yarn global add milkee
# bun
bun add -g milkee

# or local installation
npm i -D milkee
pnpm add -D milkee
```

CoffeeScript & @babel/core are required.  

> [!TIP]
> `@babel/core` is required if `options.transpile` is `true` .

```bash
# global installation
npm i -g coffeescript @babel/core

# or local installation
npm i -D coffeescript @babel/core
```

### Setup

Run `-s` (`--setup`) command, generate [coffee.config.cjs](./temp/setup/coffee.config.cjs)!  

```bash
# global
milkee -s

# or local
npx milkee -s
```

#### coffee.config.cjs

```js
/** @type {import('@milkee/d').Config} */

module.exports = {
  // The entry point for compilation.
  // This can be a single file or a directory (e.g., 'src/' or 'src/app.coffee').
  entry: 'src',
  // The output for the compiled JavaScript files.
  // If 'options.join' is true, this should be a single file path (e.g., 'dist/app.js').
  // If 'options.join' is false, this should be a directory (e.g., 'dist').
  output: 'dist',
  // (Optional) Additional options for the CoffeeScript compiler.
  // See `coffee --help` for all available options.
  // Web: https://coffeescript.org/annotated-source/command.html
  options: {
    // The following options are supported:
    // bare: false,
    // join: false,
    // map: false,
    // inlineMap: false,
    // noHeader: false,
    // transpile: false,
    // literate: false,
    // watch: false,
  },
  // (Optional) Additional options/plugins for the Milkee builder.
  milkee: {
    // Package manager used in this project. Auto-detected from lock files and package.json.
    // Supported: 'npm' | 'pnpm' | 'yarn' | 'bun' | 'aube' | 'nub' | 'vlt' | 'bower'
    // packageManager: 'npm',
    options: {
      // Ignore update notifications.
      // ignoreUpdate: false,
      // Before compiling, reset the directory.
      // refresh: false,
      // Before compiling, confirm "Do you want to Continue?"
      // confirm: false,
      // After compiling, copy non-coffee files from entry to output directory. (Only works when options.join is false)
      // copy: false,
    },
    plugins: []
  },
};
```

##### `options` (CoffeeScript Compiler Options)

These options are passed directly to the `coffee` compiler.  

| Option | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `bare` | `boolean` | `false` | compile without a top-level function wrapper |
| `join` | `boolean` | `false` | concatenate the source CoffeeScript before compiling |
| `map` | `boolean` | `false` | generate source map and save as `.js.map` files |
| `inlineMap` | `boolean` | `false` | generate source map and include it directly in output |
| `noHeader` | `boolean` | `false` | suppress the "Generated by" header |
| `transpile` | `boolean` | `false` | pipe generated JavaScript through Babel |
| `literate` | `boolean` | `false` | treat stdio as literate style coffeescript |
| `watch` | `boolean` | `false` | watch scripts for changes and rerun commands |

[CoffeeScript - command.coffee](https://coffeescript.org/annotated-source/command.html)  

##### `milkee.packageManager` (Package Manager)

Milkee auto-detects the package manager from lock files and the `packageManager` field in `package.json`. You can override it explicitly.  

| Detection source | Priority |
| :--- | :--- |
| `milkee.packageManager` in `coffee.config.cjs` | 1st (highest) |
| `packageManager` field in `package.json` | 2nd |
| Lock file (`pnpm-lock.yaml`, `yarn.lock`, `bun.lockb`, `vlt-lock.json`, `bower.json`) | 3rd |
| Default | `npm` |

Supported values: `'npm'` `'pnpm'` `'yarn'` `'bun'` `'aube'` `'nub'` `'vlt'` `'bower'`

##### `milkee.options` (Milkee Specific Options)

These options control Milkee's behavior.  

| Option | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `ignoreUpdate` | `boolean` | `false` | Ignore update notifications. |
| `refresh` | `boolean` | `false` | Before compiling, reset the output directory. |
| `confirm` | `boolean` | `false` | Before compiling, prompt "Do you want to Continue?". |
| `copy` | `boolean` | `false` | After compiling, copy non-coffee files from entry to output directory. (Only works when `options.join` is `false`) |

##### `milkee.plugins` (Milkee Specific Plugins)

You can extend Milkee's functionality by using plugins. Plugins are simple functions that run after each successful compilation, giving you access to the compiled files and configuration.  

Example:

```js
const myPlugin = require('./plugins/my-plugin.js');

module.exports = {
  // ...
  milkee: {
    plugins: [
      // This call returns the PluginExecutor
      myPlugin({ option: 'value' }),
      // ...
    ]
  }
}
```

### Compile

Milkee will automatically read [coffee.config.cjs](./temp/setup/coffee.config.cjs), assemble the command from your `options`, and start compilation!  

```bash
# global
milkee

# or local
npx milkee
```

## Creating a Plugin

Want to create your own Milkee plugin? Check out the plugin documentation:  

- [English](./docs/PLUGIN.md)
- [日本語](./docs/PLUGIN-ja.md)

## Donate

<a href="https://www.buymeacoffee.com/devuloper" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

<a href='https://ko-fi.com/E1E41LY2C9' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi6.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
