Cdnjs Client
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 .
Commands
Usage
To print the script's usage:
$ cdnjs --helpWhich 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
Init
To initialize a cdnjs configuration file at the default location $(pwd)/.cdnjs:
$ cdnjs initTo specify another location to initialize:
$ cdnjs --conf .another-cdnjs.conf initTo initialize a non-default configuration file in another directory:
$ cdnjs --conf ~/dir/to/create/.cdnjs initNB. if the path of the file doesn't exist the script will attempt to create it.
Search/Find
Requires a parameter "search string".
To search for libraries containing jquery:
$ cdnjs search jqueryAdd
This command requires a parameter library with an optional suffix +version.
To add the latest version of jquery to your configuration:
$ cdnjs add jqueryTo add a specific version of jquery to your configuration use the syntax library[+version]
$ cdnjs add jquery+1.9.0Clean
To clean all the paths indicated by the configuration's relative-location:
$ cdnjs cleanSync/Update
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.
Install
Performs the --add and --sync commands:
$ cdnjs install jquery
#
# same as
#
$ cdnjs sync add jqueryDelete/Remove
Removes the indicated library from the configuration and filesystem:
$ cdnjs remove jquery
#
# or
#
$ cdnjs --delete jqueryFlags
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.
Conf
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 initTo add jquery version 2.1.4 to a non-default configuration:
$ cdnjs --conf .another-cdnjs.conf --add jquery+2.1.4Debug/Verbose
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 debugNo Color
To not output color escape codes add the nocolor flag. This is helpful when you want to log stdout/stderr to file.
$cdnjs sync nocolorDev
A flag for the --list command, it excludes any min.js or min.css from its output.
$ cdnjs list --devNo-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 nodevConfiguration example:
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.
Setup
cdnjs depends on bash, jq, curl and mktemp. If those dependencies are met and and cdnjs is on your $PATH everything should be fine.
Windows Setup
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 Jq
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 cdnjs
Download the latest version of cdnjs. Save it to a folder on you $PATH and make it executable.
Windows Setup Example Steps:
- 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 -alTodo
- allow partial
clean's andsync's by section key (iecdnjsorgists)