-
-
Save KayLeung/b6455829db44d51f31aff27f6408b891 to your computer and use it in GitHub Desktop.
List jQuery UI Dependencies for Drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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