Skip to content

Instantly share code, notes, and snippets.

@KayLeung
Created November 25, 2017 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KayLeung/b6455829db44d51f31aff27f6408b891 to your computer and use it in GitHub Desktop.
Save KayLeung/b6455829db44d51f31aff27f6408b891 to your computer and use it in GitHub Desktop.
List jQuery UI Dependencies for Drupal
const glob = require('glob');
const yaml = require('js-yaml');
const fs = require('fs');
const path = require("path");
function trim(string) {
return string.trim();
}
function getDependencies(data) {
var match = data.match(/define\(\ ?\[([^\]]*?)\]/);
if (match === null) {
return [];
}
return match[1].replace(/\/\/.+/g, "").replace(/"/g, "").split(",").map(trim);
}
const fileMatch = './assets/vendor/jquery.ui/ui/widgets/*.js';
const doc = yaml.safeLoad(fs.readFileSync('core.libraries.yml', 'utf8'));
const processFiles = (error, filePaths) => {
if (error) {
process.exitCode = 1;
}
filePaths.forEach((filePath) => {
fs.readFile(filePath, function read(err, data) {
if (err) {
throw err;
}
const lists = getDependencies(data.toString()).map(function (dependency) {
return `core/jquery.ui.${dependency.replace('../', '').replace('./', '')}`;
});
const widgetName = 'jquery.ui.' + path.basename(filePath).replace('-min.js', '');
doc[widgetName].dependencies = lists;
fs.writeFileSync('core.libraries.yml', yaml.safeDump(doc))
});
});
};
glob(fileMatch, null, processFiles);
process.exitCode = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment