Makage Build Helper
Makage is a lightweight, cross-platform build helper specifically designed for managing common tasks within monorepo environments. Currently at version 0.3.0, it provides essential utilities for file operations such as copying files, cleaning directories, and general asset management. Its primary focus is on simplifying build processes across different operating systems, offering a more streamlined alternative to platform-specific scripts or heavier build tools. Given its pre-1.0 version, the release cadence is likely irregular, with features and API potentially evolving rapidly. Key differentiators include its 'tiny' footprint and explicit support for monorepo structures, aiming to minimize configuration overhead for common build-related file manipulations. It ships with TypeScript types, facilitating its integration into modern TypeScript-based projects.
Common errors
-
Error: Command 'makage' not found
cause The `makage` CLI tool is not installed globally or is not in the system's PATH.fixInstall Makage globally using `npm install -g makage` or run it locally via `npx makage` or `yarn makage` if installed as a dev dependency. -
Error: ENOENT: no such file or directory, stat '/path/to/nonexistent/source'
cause A `copy` or `clean` operation was attempted on a source file/directory that does not exist.fixVerify that the source paths provided to Makage's functions or CLI commands are correct and that the files/directories exist before the operation is executed. Add path validation if necessary. -
TypeError: Cannot read properties of undefined (reading 'copy')
cause Attempting to `require()` Makage functions in a CommonJS module when the package's main entry point is ESM-first, or using incorrect named imports.fixFor CommonJS, ensure `type: 'module'` is not set in `package.json` or switch to dynamic `import()` if the package is truly ESM-only. For ESM, use `import { copy } from 'makage';`. Always confirm the package's module type and export patterns.
Warnings
- breaking As a pre-1.0 package (v0.3.0), Makage does not strictly adhere to semantic versioning. Minor or patch releases may introduce breaking API changes without prior deprecation warnings.
- gotcha Cross-platform file path nuances (e.g., backslashes vs. forward slashes) can cause issues. While Makage aims for cross-platform compatibility, always test build scripts on all target operating systems.
- gotcha File operation permissions can lead to `EACCES` or `EPERM` errors, especially when writing to protected directories or attempting to clean files opened by another process.
Install
-
npm install makage -
yarn add makage -
pnpm add makage
Imports
- copy
const { copy } = require('makage');import { copy } from 'makage'; - clean
import clean from 'makage/clean';
import { clean } from 'makage'; - runCLI
import { MakageCLI } from 'makage';import { runCLI } from 'makage/cli';
Quickstart
import { copy, clean } from 'makage';
import * as path from 'path';
const projectRoot = process.cwd();
const distDir = path.join(projectRoot, 'dist');
const assetsSrc = path.join(projectRoot, 'src', 'assets');
const assetsDest = path.join(distDir, 'assets');
async function buildPackage() {
console.log('Starting build...');
try {
// Clean the distribution directory
console.log(`Cleaning ${distDir}...`);
await clean(distDir);
console.log('Clean complete.');
// Copy assets
console.log(`Copying assets from ${assetsSrc} to ${assetsDest}...`);
await copy(assetsSrc, assetsDest, { overwrite: true, recursive: true });
console.log('Asset copy complete.');
// Simulate other build steps (e.g., transpilation)
console.log('Running other build steps (e.g., TypeScript compilation)...');
await new Promise(resolve => setTimeout(resolve, 500)); // Placeholder for actual build logic
console.log('Build successful!');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
buildPackage();