cdnjs is a substitute for bower/npm in a node free environment. It depends on bash, jq and curl.
It is mainly a client for cdnjs/cdnjs API but it can handle any GET
'able, publicly-available resources; gists in particular .
To print the script's usage:
$ cdnjs --help
Which gives the following output:
$ cdnjs --help
Usage: cdnjs [OPTIONS] [ARGS]:
Options:
--init, init initialize a config file
--conf [CONFIG FILE] use a custom config file
--list, list [/to/exclude] prints a list of link and script tags
--index, index [/to/exclude] same as "--list"
--html, html [/to/exclude] same as "--list"
--nodev, nodev excludes non '.min.*' files; a flag for \"--list\"
--dev, dev excludes '.min.*' files; a flag for \"--list\"
-f, --find, find [ARGS] perform query on api.cdnjs.com
--search, search [ARGS] same as "--search [ARGS]"
-c, --clean, clean [ARGS] clean configured relative-location
-s, --sync, sync [ARGS] asynchronously download configured resources
--update, update [ARGS] same as "--sync [ARGS]"
-a, + [LIB[+VERSION]] [GROUP] add library with optional version to optional
--add, add group
-i, --install, install [LIB] same as "add" plus "sync"
-d, --delete, delete [LIB] removes library from configuration
--remove, remove [LIB] same as "delete"
-v, --verbose, verbose print debug/verbose output
--debug, debug same as "--verbose"
--nocolor, nocolor don't echo in color, useful for logging stdout/stderr
-h, -?, --help, help print usage
To initialize a cdnjs configuration file at the default location $(pwd)/.cdnjs
:
$ cdnjs init
To specify another location to initialize:
$ cdnjs --conf .another-cdnjs.conf init
To initialize a non-default configuration file in another directory:
$ cdnjs --conf ~/dir/to/create/.cdnjs init
NB. if the path
of the file doesn't exist the script will attempt to create it.
Requires a parameter "search string"
.
To search for libraries containing jquery
:
$ cdnjs search jquery
This command requires a parameter library
with an optional suffix +version
.
To add the latest version of jquery
to your configuration:
$ cdnjs add jquery
To add a specific version of jquery
to your configuration use the syntax library[+version]
$ cdnjs add jquery+1.9.0
To clean all the paths indicated by the configuration's relative-location
:
$ cdnjs clean
To download the resources indicated by the current configuration:
$ cdnjs sync
NB. the resources will be downloaded to a tmp directory and then moved to the configuration's relative-location
's.
Performs the --add
and --sync
commands:
$ cdnjs install jquery
#
# same as
#
$ cdnjs sync add jquery
Removes the indicated library from the configuration and filesystem:
$ cdnjs remove jquery
#
# or
#
$ cdnjs --delete jquery
There are a few flags for modifying output or functionality.
Some are general and can be used with any command, such as --conf
, --debug
or --nocolor
.
Others can be used only with specific commands, such as the list
command's --dev
and --nodev
flags.
Any command that requires the use of a configuration file can use the flag --conf
to indicate an alternate file.
The commands which require a configuration file are --init
, --add
, --clean
and --sync
.
The default configuration file, if --conf
is not specified, is .cdnjs
in the current working directory.
To initialize a non-default configuration file in the current working directory:
$ cdnjs --conf .another-cdnjs.conf init
To add jquery
version 2.1.4
to a non-default configuration:
$ cdnjs --conf .another-cdnjs.conf --add jquery+2.1.4
To output debug
messages add the -v
flag to any command:
$ cdnjs sync -v
# or
$ cdnjs clean --verbose
# or
$ cdnjs clean --debug
# or
$ cdnjs clean verbose
# or
$ cdnjs clean debug
To not output color escape codes add the nocolor
flag. This is helpful when you want to log stdout/stderr
to file.
$cdnjs sync nocolor
A flag for the --list
command, it excludes any min.js
or min.css
from its output.
$ cdnjs list --dev
A flag for the --list
command, it excludes any library not ending in min.js
or min.css
from its output.
$ cdnjs list --nodev
# or
$ cdnjs list nodev
An example configuration file is found in this repository at example/.cdnjs.
A file .cdnjs
in the pwd
or passed to the program through the --conf [conf-file]
option.
cdnjs
depends on bash
, jq
, curl
and mktemp
. If those dependencies are met and and cdnjs
is on your $PATH
everything should be fine.
Since cdnjs
is a bash
script it will work in a bash environment such as Git for Windows, however it requires jq
and mktemp
( not found in Git for Windows
pre version 1.9.5
).
Download the jq
binary and rename it to jq.exe
. Place it in a folder known to be on your $PATH
, eg. if you are using Git for Windows
version 2.6.1
you will have %PROGRAMFILES%\Git\usr\bin
in which you can place the jq.exe
binary.
Download the latest version of cdnjs. Save it to a folder on you $PATH
and make it executable.
- Edit
.bashrc
:
...
if [ -d "~/bin" ]; then
export PATH=$PATH:~/bin
fi
...
- Then perform the following commands:
if [ ! -d "~/bin" ]; then mkdir "~/bin"; fi
cd ~/bin
wget https://raw.githubusercontent.com/matthewbednarski/cdnjs/master/cdnjs
chmod +x cdnjs
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-win64.exe
mv jq-win64.exe jq.exe
chmod +x jq.exe
ls -al
- allow partial
clean
's andsync
's by section key (iecdnjs
orgists
)