Introduction
Asset assistant is a tool for coordinating non-js files across multiple
projects. The intended use for copying .css and media files from a project
in the 'node_modules' directory into the projects public html directory.
Versions
The 0.0.* versions are for building up the repository and may have changes in
the command specification.
Prerequisites
These programs are intended to be used with the npm package manager. As such
they make use of the package.json file and the node_modules directory.
All file selections use the Glob package.
Programs
assets
Copy all asset files from source directories and source packages to a specified
build directory.
- The term assets refers to the assets parameter in package.json.
- The term dependencies refers to the dependencies parameter in package.json.
- Require: target project, default root project.
- Retrieve assets parameter, if not found, terminate.
- If this is a top level project it will continue normally without attempting
to copy any local files. This is put in place so that dependencies with
assets can easily be installed without defining assets in the root.
- Copy all files from assets.src into assets.build.
- assets.src is an array of strings which are interpreted
as globs.
- assets.build is a string which is the root destination of the copy. The
copy will preserve the directory structure.
- For each project p in dependencies, perform task with target = p.
inline
Add <script>
and <link>
tags to an html file based upon directory
contents.
Quick Start
- Install asset assistant into a project with
npm i asset-assistant
. - Run the assets intializeer with ' node_modules/.bin/assets --init'.
- The follwing can now be found in the package.json 'assets' field.
- The
src
parameter dictates the files to copy to destination. This refers
to local files and remote. Default is 'src/assets/**/*'. - The
local-src
parameter dictates the sources to copy only if this project
is the target. - The
dest
parameter dictates the target directory, defaults to build/
.
This is where other projects assets will be copied to. defaults to 'public_html'. - The
flat
parameter when true copies files without the directory structure,
defaults to false. - The
up
parameter defines how many src directories to omit on copy.
Defaults to 1
which is the project name directory. This Typically is not
modified. - The 'assets' script is added to the 'scripts' field.
The asset command accepts the following flags
- -v : Verbose, print out packages looked at and files copied.
- -d : Debug, print out more information.
- --fileset=parameter : only copy the local files specified in this parameter (
in the assets parameter).
example 1
In the package.json file (unrequired fields omitted).
"dependencies": {
"Collection": "file:../Collection",
"Context": "file:../Context",
"asset-assistant": "file:D:/project-local/assets",
"jquery": "^3.3.1",
"nidget": "file:../Nidget"
},
"scripts": {
"build-assets": "assets",
"build-remote": "assets --fileset=local-src",
"inject-header": "inject src/* src/css/* index.html"
},
"assets": {
"src": [
"src/assets/**/*",
"src/css/dialog.css"
],
"local-src": [
"src/*.html"
]
}
The script 'build-assets' will recursively copy all files in the src/assets
directory into the build/src/assets directory. It will also copy 'dialog.css'
into the build/css directory. It will then look for the "assets" parameter
in the package.json of all dependencies (Collection, Context, etc), if found
it will copy files specified by their 'src' parameters and recursively look in
their dependencies for more assets. If not found then the recursive search will
not follow that branch.
The script 'build-remote' will copy all html files from src/html to build/html,
and will not recursive search.
The script 'inject-header' will add a <script>
or <link>
element into
'index.html' for each .js and .css file found. The paths will be relative to
the location of 'index.html'.
Development
Development is setup as a NetBeans project. These are reminders to how the
project is setup and is not needed to run it.
- Clone repository:
git clone git@git.sharcnet.ca:edward/asset-assistant.git
. - Install dependencies with
npm install
in the project root directory. - Publish with
npm publish
.
Files
The package.json bin
parameter specifies where to find command line tools.
- src/assets.js main entry for asset command line tool as setup in the
package.json bin paramater.
- src/inject.js main entry for css injection command line tool as setup in the
package.json bin paramater.
- src/AbstractAssets Collectes common flags for the CleanAssets and
LoadAssets classes.