Logo

dev-resources.site

for different kinds of informations.

App::cpx

Published at
9/5/2024
Categories
perl
cpan
npx
Author
thibaultduponchelle
Categories
3 categories in total
perl
open
cpan
open
npx
open
Author
19 person written this
thibaultduponchelle
open
App::cpx

(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.
=======================================
Enter fullscreen mode Exit fullscreen mode

(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
Enter fullscreen mode Exit fullscreen mode

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 this cpm 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
Enter fullscreen mode Exit fullscreen mode

Your companion for Continuous Integration

$ curl -sL https://git.io/cpm | sudo perl - install -g App::cpx
$ cpx hr -s 40
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

And see the result:
GitHub Action cpx

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
npx Article's
30 articles in total
Favicon
Improving Port Management Speed: Why I Created `port-client` to Replace `npx kill-port`
Favicon
How to install react
Favicon
npm vs npx: Choosing the Right Tool for the Job
Favicon
npm vs npx - What's the difference?
Favicon
npmใจnpxใฎ้•ใ„
Favicon
Package Manager Fight: npm vs pnpm vs npx vs yarn vs bun
Favicon
App::cpx
Favicon
NPM vs NPX: What's the Difference?
Favicon
npm vs npx โ€” What are the Basic Difference?
Favicon
Create an NPX professional card
Favicon
Diferenรงa entre NPM INIT eย NPX
Favicon
Demystifying NPM and NPX: A Dive into Package Management
Favicon
npm vs npx: Friends or Enemy?
Favicon
Understanding npm vs npx: A Developer's Guide ๐Ÿ“ฆ๐Ÿš€
Favicon
Understanding NPM and NPX in frontend Development
Favicon
A NodeJS newbie's guide to understanding NPM and NPX
Favicon
Errors when creating strapi app using the command npx create-strapi-app@latest --quickstart
Favicon
Npx, c'est quoi ?
Favicon
You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0)
Favicon
What is NPX?
Favicon
Use this NPM script to create your EditorConfig files
Favicon
Creating an npx Command
Favicon
Automatically Remove Unused Node Modules with Python
Favicon
Animated CLI Profile Card
Favicon
Useful Npx Packages for the Developer's Everyday Life
Favicon
Short Video example in 20 Seconds. Get a Github directory quickly by a simple command without installation.
Favicon
My personal business card - What's next?
Favicon
Creating my personal business card
Favicon
When to Use Global NPM Installs? Rarely
Favicon
Useful NPX

Featured ones: