aem-clientlib-generator
A node plugin that creates ClientLib configuration files (repository nodes) for
AEM ClientLibs,
creates Client Library Folders and synchronizes all assets.
Installation
npm install aem-clientlib-generator
Usage
Command Line Interface
The CLI clientlib
is located in ./bin/clientlib-cli.js
.
The command can be used without parameters, it loads the default configuration file clientlib.config.js
.
More options are described in help menu:
Options:
--help, -h Show help [boolean]
--version, -v Show version number [boolean]
--dry 'Dry run' without write operations. [boolean]
--verbose Prints more details [boolean]
clientlib.config.js
A clientlib configuration file is a simple exported module:
module.exports = {
context: __dirname,
clientLibRoot: "path/to/clientlib-root",
libs: [
{
name: "test.base.apps.mainapp",
assets: {
js: [
"src/frontend/js/app.js"
],
css: [
"src/frontend/css/styling.css"
]
}
},
...
],
libs: {
name: "test.base.apps.mainapp",
assets: {
js: [
"src/frontend/js/app.js"
],
css: [
"src/frontend/css/styling.css"
]
}
}
}
npm scripts
The CLI can be used in a project as local module via npm scripts (defined in package.json
).
"scripts": {
"test": "mocha",
"build": "clientlib --verbose"
}
In this case npm run build
tries to load the default clientlib configuration file
clientlib.config.js
(same directory like package.json) and generates all clientslib
as defined.
Module: clientlib(arrProps | props, [options], callback)
Import the module into a JavaScript file and run the module as a function:
var clientlib = require("aem-clientlib-generator");
clientlib(arrProps, { verbose: true }, function() {
console.log("generator has finished");
});
Important: Due to many write operations, the clientlib
function is asynchronously!
-
arrProps
{Array<Object>}
Array of Clientlib configuration properties (see below)
-
props
{Object}
Clientlib configuration properties
path
{String}
Clientlib root path (optional if options.clientLibRoot
is set)name
{String}
Clientlib name (required)embed
{Array<String>}
other Clientlib names that should be embedded (optional)dependencies
{Array<String>}
other Clientlib names that should be included (optional)cssProcessor
{Array<String>}
configuration for the clientlib CSS processor, requires AEM 6.2 (optional)jsProcessor
{Array<String>}
configuration for the clientlib JS processor, requires AEM 6.2 (optional)assets
{Object}
content that should be copied to the clientlib folder, more details below (required)allowProxy
{Boolean}
allow for Clientlib creation under /apps/myapp/clientLibs
but enable proxy to /etc.clientlibs/myapp/clientlibs/mylib
See AEM 6.3 DocumentationlongCacheKey
{String}
optional string with placeholders to use with URL Fingerprinting, eq. "${project.version}-${buildNumber}"
-
options
{Object}
global options to be used for all clientlib definitions (optional)
clientLibRoot
{String} Clientlib root pathcontext
{String} changes the current working directory (via process.chdir()
)cwd
{String} alias for context
verbose
{Boolean} prints detailed information during generationdry
{Boolean} dry run without file write operations (sets automatically verbose to true)
-
callback
{Function}
to be called if clientlib() has finished
The assets
Object
The assets
object determine the content that should be pushed into the clientlib folder. The key stands for
the content type, js
for JavaScript files, css
for styles and resources
for other content such as
fonts or images.
{
js: {
},
css: {
},
resources: {
}
}
Each property can be an object of deeper configuration options (assetConfig
) or an array of files (simple way, see example below).
The following can be configured:
assetConfig
{Object}
Configuration object for an asset type
base
{String}
path within the clientlib folder where the data should be copied to (optional), default: asset key, e.g. for "js" is the base "js"
- Hint: Using "." copies the files into the clientlib folder instead of the subfolder
files
{Array<String|Object>}
array of file paths (sources) or a src-dest key value map (required)
- Important: The order of JS or CSS files in this property defines the merging/bundling order in AEM clientlib.
- file object contains:
src
{String} - source file relative to the current working directory or the global cwd
option, if setdest
{String} - destination relative to the clientlib folder including base
cwd
{String} - change working directory (relative to the context / global cwd
option); only available with glob patternflatten
{Boolean} - using file's basename instead of folder hierarchy; default true; only available with glob pattern
For an glob example see example section below.
js: [
"pth/to/file.js",
{src:"pth/to/lib/file.js", dest: "lib/file.js"}
]
js: {
base: "js"
files: [
{src:"pth/to/file.js", dest: "file.js"},
{src:"pth/to/lib/file.js", dest: "lib/file.js"}
]
}
Example
var clientlib = require("aem-clientlib-generator");
clientlib([
{
name: "test.base.apps.mainapp",
cssProcessor: ["default:none", "min:none"],
jsProcessor: ["default:none", "min:gcc"],
allowProxy: true,
longCacheKey: "${project.version}-${buildNumber}",
assets: {
js: [
{src: "src/frontend/js/app.js", dest: "app.js"},
{src: "src/frontend/js/libs/mylib.min.js", dest: "libs/mylib.min.js"},
{src: "src/frontend/js/libs/mylib.min.js.map", dest: "libs/mylib.min.js.map"}
],
css: [
"src/frontend/css/styling.css",
"src/frontend/css/lib.css"
]
}
},
{
name: "test.base.apps.secondapp",
embed: [
"test.base.apps.thirdapp"
],
dependencies: [
"test.base.apps.mainapp"
],
assets: {
js: {
base: "js",
files: [
{src: "src/frontend/secondapp/js/lib.js", dest: "secondapp-lib.js"}
]
},
css: {
base: "style",
files: [
"src/frontend/secondapp/main.css"
]
},
resources: [
"src/frontend/resources/template.html"
]
}
},
{
name: "test.base.apps.thirdapp",
assets: {
resources: {
base: ".",
files: [
"src/frontend/resources/notice.txt"
]
}
}
},
{
name: "test.base.apps.fourth",
assets: {
js: {
flatten: false,
cwd: "src/frontend/js/",
files: [
"**/*.js",
"**/*.js.map"
]
},
css: [
{src: "src/frontend/css/*.css", dest: "style/"},
{src: "src/frontend/secondapp/*.css", dest: "vendor/"}
]
}
}
],
{
cwd: __dirname,
clientLibRoot: path.join(__dirname, "path/to/clientlibs-root")
},
function() {
console.log("clientlibs created");
});