
Introduction to GuPM
GuPM is a package manager written with the goal to unify the package management scene. Unifying doesn’t mean centralising: the point of GuPM is also ensuring a community-driven development scene by working with decentralised repositories, and a powerful scripting/plugin system for customising the behaviours of the tools.
This guide assumes you are familiar with NPM or equivalent (gem, yarn, maven, etc…).In order to follow this article, you will need to have both GuPM and the NPM provider installed in your machine.
# Install GUPM curl -fsSL https://azukaar.github.io/GuPM/install.sh | bash# Install the NPM Provider g plugin install https://azukaar.github.io/GuPM-official/repo:provider-npm
What can it do
- Dependency management (npm make / npm install) using more than one source (for exemple, instead of using NVM, simply set node to be a dependency of your project)
- Scripts (g myscript.gs will execute your scripts in a cross-platform way, useful for build/publishing)
- Cross platform environment variables
- Smart Git hooks (only executing commands on changed files)
- Execute your tests / linting in parallel
Getting started
Let’s start a cli in your project and type:
g b -p npm
# short-hand for g bootstrap --provider npm
It will ask you if you want to use gupm.json or package.json. If your project already exists, GuPM has the ability to import it into a gupm.json (see next paragraph for the benefit of the gupm.json). If you plan on publishing a lib to NPM for people to install it with NPM, then you will have no choice than skipping the import, and keep using the same package.json (Don’t worry, GuPM can also use the package.json!). If you choose that second path, GuPM will still create a gupm.json in your project allowing you to benefit from GuPM’s features.
Once done, GuPM will have generated a Readme containing basic instructions.
g make # Install your project's dependenciesg i webpack # shorthand for g install webpack
You might wonder: Tell me, if GuPM is a generic package manager, how does it know to install those dependencies from NPM? Let’s dive a bit deeper in the project to find out what it the scaffolding does!
Understanding GuPM
So what did we generate here? Most importantly, we generated a
gupm.json
.{
"author": "",
"description": "",
"licence": "ISC",
"name": "test",
"binaries": {},
"cli": {
"aliases": {}
},
"dependencies": {
"default": {},
"defaultProvider": "npm"
},
"publish": {
"destination": "docs/repo",
"source": []
}
}
If you generated the project to use your package.json, you should see this instead :
{
"author": "",
"cli": {
"defaultProviders": {
"install": "npm",
"make": "npm"
}
},
"licence": "ISC",
"name": "test"
}
If you are familiar with the package.json, there’s already a few things here that should be able to pick up. First of all, name/author/description/license are pretty self explainatory.
the
cli
option allow you to customise how different cli commands will work inside your project. We can for example set aliases (think of it as ‘scripts’ in your package.json)."cli": {
"aliases": {
"start": "node index.js"
}
},
You can also here tell GuPM to use specific providers when using specific commands using the defaultProvider. That’s how we get GuPM to use npm for make and install.
In the first example, you can notice that we haven’t set a defaultProvider in the cli options, but yet, we can still install webpack directly. That’s because in the dependencies we have another option to set a defaultProvider. The difference with that one, is that this is set to be the default provider at
resolution
stage. To understand better, let’s imagine we have set no config:# First, let's try to install webpack # this will not use NPM # because no defaultProvider is set in gupm.jsong i webpack# We can tell GuPM to use NPM to INSTALL a dependency # If you do this, NPM will take over the whole install process # Meaning it will save the dependency to package.json # This is what happens when you set cli.defaultProvidersg -p npm i webpack# A better way to do this, is to still use GuPM's default INSTALL # But tell it to resolve the dependency from NPM # Here, only the RESOLVE stage gets overwritten by NPM # This is what happens when you set dependencies.defaultProviderg i npm://webpack
Next up, we have publish, which is easy to understand, if you decide to publish to a decentralised repo, it contains the source files and the destination of the repo to publish to.
The binaries is the strict equivalant to bin in a package.json.
One last file we need to look at, is
make.gs
. If you decided to keep a package.json, it will be generated alongside your gupm.json. This file is automatically executed by GuPM afteryou executed g make
(you can also create install.gs, etc…). What it does, is tell GuPM “Once you are done installing GuPM’s dependencies, install the NPM ones”.exec('g', ['make', '-p', 'npm']);
Conclusion
GuPM has been built with seamlessness in mind, for maximum flexibility and customisation around your projects. This article gave you a quick overview of how you can easily use it with NPM, but of course, feel free to check our github (and ⭐ it!) for the rest of the documentation on how to make you a GuPM ninja!
Comments
Post a Comment