fabrique
v1.1.4
Published
CLI to build a library
Readme
Fabrique
fabrique is a cli to create and build libraries,
letting the user focus on the functionalities of its library, instead of the build process.
With fabrique you'll be able to:
- create rapidly a library with all the tools and scripts to:
- build and publish your library
- write tests for it
- format your code
- and debug it
- upgrade any Fabrique project to get the last functionalities in one command line.
fabrique is not intended to provide ci scripts and pipelines to automate the processes.
Instead, it gives a uniform and simple entry point for everyone, to publish rapidly our own libraries,
on which we may add automation, scripts, and complexity.
fabriqueis the French word for "made/factory"
Motivation
When we develop javascript/typescript libraries, we frequently create new repositories,
and maintains the scripts to build, test, and debug them.
This tends to become rapidly cumbersome, especially when their number grows.
We may choose to opt in for a monorepo, and I'll tell you: yes, in many cases, this is the optimal solution.
However, in many other cases, one library per-repo makes sense, and this is where fabrique comes in.
Another goal is to focus on simplicity: for new incomers in javascript,
learning all the tools and build processes is complicated.
You want to write your library, but you have to learn vite, jest, how to build and publish a lib,
install prettier, etc. With fabrique all comes in pre-configured.
📝 Documentation
Requirements
The library requires Node.js 24+ and yarn 4+.
Installation
We recommend to use npx:
npx fabrique [cmd]But, you may prefer to install globally fabrique:
npm install -g fabriqueAnd run a command with:
fabrique [cmd]List of commands
[cmd]: create
npx fabrique create [type] [name][type]: lib
example
npx fabrique create lib @my-company/my-libraryaction
This command creates a new library with the name [name] inside the folder ./[name] (in our example: ./@my-company/my-library).
You'll be prompted for a description, author and git url.
INFO: run the command where you want to create your project.
options
[name]: the library name
NOTE: currently only the
libtype is supported. More architectures may be developed in the future.
[cmd]: upgrade
# from the root of a "fabrique" project
npx fabrique upgradeaction
This command updates an existing fabrique project: it updates the build files, the scripts, etc.
It tries to be non-destructive.
INFO: run the command inside the
fabriqueproject.
options
--force: forces an upgrade even if the lib is not afabriqueproject or if the version is identical. Use with caution.
[cmd]: refactor
# from the directory we want to refactor
npx fabrique refactor [from] [to]example
npx fabrique refactor my-component my-new-componentRefactors all files and directories having
my-componentas name intomy-new-component(recursively). AND all text-based files (ex: html, js, ts, css, etc...) containingmy-component(or derived cases) intomy-new-component(keeping the same case).
If we run this command with the following files structure:
- some-component
- my-component
- my-component.ts
- my-component-abc
- my-component-abc.ts
We get:
- some-component
- my-new-component
- my-new-component.ts
- my-new-component-abc
- my-new-component-abc.ts
If my-component.ts has this content:
class MyComponent {}
// my-component
const MY_COMPONENT = null;
function my_component(myComponent: MyComponent) {}We get:
class MyNewComponent {}
// my-new-component
const MY_NEW_COMPONENT = null;
function my_new_component(myNewComponent: MyNewComponent) {}action
This command refactors files and directories recursively from the cwd (by default, the current directory in which the script is executed).
It preserves the case of the names (ex: dash-case, or cameCase).
INFO: run the command inside the folder that you want to refactor.
options
[from]: the "source" text to refactor. Must bedash-case.[to]: the "destination" text to refactor. Must bedash-case.--dry(default: false): runs without modifying the files. This is useful to check if your refactoring is safe or not.--cwd(default: current folder): specifies the directory to start from.
[cmd]: verdaccio
npx fabrique verdaccioInstalls and launches verdaccio. This is useful to debug interdependent libraries.
Let's say we have:
- a library
my-lib-a - another library
my-lib-bwithmy-lib-aasdependency
When working on my-lib-a, if we want to test if our changes works properly on my-lib-b, we'll publish a dev version of my-lib-a on a local verdaccio,
then, we'll consume this dev version on my-lib-b.
We choose verdaccio instead of
npm linkbecause versions and dev packages are unique with a package registry.Thus, we may have
my-lib-bconsumingmy-lib-a-dev.0andmy-lib-cconsumingmy-lib-a-dev.1, which is not possible withnpm link.
--version
npx fabrique --version
# or
npx fabrique -vReturns the current fabrique version.
--help
npx fabrique --help
# or
npx fabrique -hYou may get help on individual commands:
npx fabrique create -h