(Picture from Erda Estremera)
Background
I'm sometimes doing Front End dev.
Or sometimes the best tool for the job is only installable via npm
.
It can be scripts to "uglify" or "beautify" css/js, optimize svg files (svgo
) or clients to SaaS platforms (wrangler
).
Actually, it's not that important if it's part of javascript ecosystem, what I want is just to execute them!
The usual process: I start testing it locally, quickly and in a "trash-able" way, then install in a continuous integration pipeline, then forget 😄
So far, do you feel some resemblance with some periodical process or yours?
For this purpose, I'm using frequently npx (now part of npm).
Do you see now where I'm going to? 🤔
App::cpx, a npx
-like for CPAN
I just uploaded App::cpx for this purpose.
Give cpx
a binary and it will find it in CPAN, install it for you then execute it.
$ cpx hr -s 40
🎯 Found [bin/hr]
📦 Release to install [https://cpan.metacpan.org/authors/id/W/WO/WOLDRICH/App-term-hr-0.11.tar.gz]
🔧 Will install into /home/tib/cpx-test/.cpx
DONE install Term-ExtendedColor-0.504
DONE install App-term-hr-0.11
2 distributions installed.
=======================================
(purpose of hr
is to draw horizontal lines)
Or another example with mlocate
:
$ cpx mlocate Redis Moo
🎯 Found [bin/mlocate]
📦 Release to install [https://cpan.metacpan.org/authors/id/C/CE/CELOGEEK/App-Module-Locate-0.7.tar.gz]
🔧 Will install into /home/tib/cpx-test/.cpx
DONE install Module-Locate-1.80
DONE install Module-Build-0.4234
DONE install App-Module-Locate-0.7
3 distributions installed.
/usr/local/share/perl/5.34.0/Redis.pm
/usr/local/share/perl/5.34.0/Moo.pm
mlocate
is a script that lives in App::Module::Locate. It's an utility to "find a module by its name".
cpx
saves you from some frustrating tries:
- Is it
cpm install App::mlocate
? - OK try capitalize
cpm install App::Mlocate
, I know some authors do that - Hmm maybe simply
locate
like thiscpm install App::locate
- Oh wait, capitalize
cpm install App::Locate
- Raaah! Stop it and open MetaCPAN and search
- OK it's
cpm install App::Module::Locate
but now it's installed locally, how do I set local::lib? Maybe I should install globally - Hmm I will install globally even if it can be a bit dirty for a one time use
And at start were you 100% sure mlocate
was something that exists in CPAN? 🤔
cpx
saves you from this pain and hides you the internals of installing the module, if missing.
When running cpx
again, it won't reinstall but reuse the already installed binary:
$ cpx mlocate Redis Moo
âš“ Found executable already installed
/usr/local/share/perl/5.34.0/Redis.pm
/usr/local/share/perl/5.34.0/Moo.pm
Your companion for Continuous Integration
$ curl -sL https://git.io/cpm | sudo perl - install -g App::cpx
$ cpx hr -s 40
In GitHub Actions, it would give something like this:
name : Test cpx
on: push
jobs:
cpx:
runs-on: ubuntu-latest
steps:
- name: Install cpx
run: curl -sL https://git.io/cpm | sudo perl - install -g App::cpx
- name: cpx hr
run: cpx hr -s 40
Conclusion
As of now, the code for this small utility is ridiculously simple (source), but sometimes good ideas (yes, all glory to myself 😀) are simple to implement.
Resources
-
I'm still lazy - Great module discussed here and I stole the idea of using
App::cpm::CLI
Top comments (0)