Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #48 switch to esmodules and update dependencies #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ os:
notifications:
email: false
node_js:
- "10.19.0"
- "16.18.0"
cache:
npm: true,
directories:
Expand Down
34 changes: 20 additions & 14 deletions bin/clientlib-cli.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#!/usr/bin/env node

var DEFAULT_FILE = "clientlib.config.js";
var clientlib = require("../lib/clientlib");
import clientlib from "../lib/clientlib.js";

var path = require("path");
var fs = require("fs");
var yargs = require("yargs")
.usage("aem-clientlib-generator " + require("../package.json").version + "\n" +
import path from "node:path";
import fs from "fs";
import yargs from "yargs";
import url from 'node:url';

const y = yargs();

y
.usage("aem-clientlib-generator " + process.env.npm_package_version + "\n" +
"Usage with config file: clientlib [path] [options]" + "\n\n" +
"Default config path: " + DEFAULT_FILE);

yargs
y
.help("help")
.alias("help", "h")
.version()
Expand All @@ -26,7 +31,7 @@ yargs
}
}).strict();

var argv = yargs.argv;
var argv = y.argv;
var configPath = path.resolve(process.cwd(), DEFAULT_FILE);

if (argv._ && argv._.length > 0) {
Expand All @@ -41,11 +46,12 @@ if (!fs.existsSync(configPath)) {
process.exit(1);
}

var clientLibConf = require(configPath);
var libs = clientLibConf.libs;
delete clientLibConf.libs;

clientLibConf.dry = argv.dry;
clientLibConf.verbose = argv.verbose || argv.dry;
import(path.isAbsolute(configPath) ? url.pathToFileURL(configPath).toString() : configPath ).then(conf => {
var libs = [...conf.default.libs];
var clientLibConf = conf.default;
delete conf.default.libs;
clientLibConf.dry = argv.dry;
clientLibConf.verbose = argv.verbose || argv.dry;

clientlib(libs, clientLibConf);
clientlib(libs, clientLibConf);
}).catch(err => console.error(err));
72 changes: 38 additions & 34 deletions lib/clientlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

"use strict";

var async = require("async");
var path = require("path");
var _ = require("lodash");
var fs = require("fs");
var fse = require("fs-extra");
var glob = require("glob");
import async from "async";
import path from "path";
import _ from "lodash";
import fs from "fs";
import fse from "fs-extra";
import { glob } from "glob";

/**
* JSON serialization format
Expand Down Expand Up @@ -204,8 +204,8 @@ function writeClientLibJson(item, options) {
*/
function writeClientLibXml(item, options) {
var content = '<?xml version="1.0" encoding="UTF-8"?>' +
'\n<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"' +
'\n jcr:primaryType="cq:ClientLibraryFolder"';
'\n<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"' +
'\n jcr:primaryType="cq:ClientLibraryFolder"';

if (item.hasOwnProperty('categories')) {
var fieldValue = item.categories.join(',');
Expand Down Expand Up @@ -248,32 +248,32 @@ function writeClientLibXml(item, options) {
*/
function writeClientLibSlingXml(item, options) {
var content = '<?xml version="1.0" encoding="UTF-8"?>' +
'\n<node>' +
'\n <name>' + item.name + '</name>' +
'\n <primaryNodeType>cq:ClientLibraryFolder</primaryNodeType>' +
'\n <property>' +
'\n <name>categories</name>' +
'\n <values>';
'\n<node>' +
'\n <name>' + item.name + '</name>' +
'\n <primaryNodeType>cq:ClientLibraryFolder</primaryNodeType>' +
'\n <property>' +
'\n <name>categories</name>' +
'\n <values>';
if (item.hasOwnProperty('categories')) {
item.categories.forEach(category => {
content += '\n <value>' + category + '</value>';
});
} else {
content += '\n <value>' + item.name + '</value>';
}
content +=
'\n </values>' +
'\n <type>String</type>' +
'\n </property>';
content +=
'\n </values>' +
'\n <type>String</type>' +
'\n </property>';

clientLibDirectoryFields.forEach(function (fieldKey) {
if (item.hasOwnProperty(fieldKey)) {
content += '\n <property>\n <name>' + fieldKey + '</name>';
if (typeof item[fieldKey] === 'boolean') {
// Boolean value
content +=
'\n <value>' + item[fieldKey] + '</value>' +
'\n <type>Boolean</type>';
content +=
'\n <value>' + item[fieldKey] + '</value>' +
'\n <type>Boolean</type>';
} else if (Array.isArray(item[fieldKey])) {
// Array of strings
content += '\n <values>';
Expand All @@ -283,9 +283,9 @@ function writeClientLibSlingXml(item, options) {
content += '\n </values>\n <type>String</type>';
} else if (typeof item[fieldKey] === 'string') {
// String value
content +=
'\n <value>' + item[fieldKey] + '</value>' +
'\n <type>String</type>';
content +=
'\n <value>' + item[fieldKey] + '</value>' +
'\n <type>String</type>';
}
content += '\n </property>';
}
Expand Down Expand Up @@ -388,7 +388,7 @@ function normalizeAssets(clientLibPath, assets) {
var mapping = [];
var flatName = typeof asset.flatten !== "boolean" ? true : asset.flatten;
var assetPath = path.posix.join(clientLibPath, asset.base);
var globOptions = {};
var globOptions = { posix: true };
if (asset.cwd) {
globOptions.cwd = asset.cwd;
}
Expand Down Expand Up @@ -422,6 +422,7 @@ function normalizeAssets(clientLibPath, assets) {
// resolve magic pattern
else {
var files = glob.sync(fileItem.src, globOptions);
files.sort();
var hasCwd = !!globOptions.cwd;
var dest = fileItem.dest ? path.posix.join(assetPath, fileItem.dest) : assetPath;

Expand Down Expand Up @@ -494,14 +495,14 @@ function processItem(item, options, processDone) {
options.verbose && console.log("Write node configuration using serialization format: " + serializationFormat);

if (serializationFormat === SERIALIZATION_FORMAT_JSON) {
// write configuration JSON
writeClientLibJson(item, options);
// write configuration JSON
writeClientLibJson(item, options);
} else if (serializationFormat === SERIALIZATION_FORMAT_SLING_XML) {
// write Sling-Initial-Content configuration
writeClientLibSlingXml(item, options);
// write Sling-Initial-Content configuration
writeClientLibSlingXml(item, options);
} else {
// write FileVault XML configuration
writeClientLibXml(item, options);
// write FileVault XML configuration
writeClientLibXml(item, options);
}

var assetList = normalizeAssets(clientLibPath, item.assets);
Expand Down Expand Up @@ -538,6 +539,9 @@ function processItem(item, options, processDone) {
});
}

module.exports = start;
module.exports.removeClientLib = removeClientLib;
module.exports.fileExists = fileExists;
export default start;

export {
removeClientLib,
fileExists,
};
Loading