* Commit updated Javascript packages * Bump preact from 10.5.4 to 10.5.5 in /build/javascript (#265) * Trying a new github workflow to install javascript packages * Bump tailwindcss from 1.9.2 to 1.9.4 in /build/javascript (#266) Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 1.9.2 to 1.9.4. - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v1.9.2...v1.9.4) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Commit updated Javascript packages * Bump preact from 10.5.4 to 10.5.5 in /build/javascript Bumps [preact](https://github.com/preactjs/preact) from 10.5.4 to 10.5.5. - [Release notes](https://github.com/preactjs/preact/releases) - [Commits](https://github.com/preactjs/preact/compare/10.5.4...10.5.5) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Owncast <owncast@owncast.online> * Bump @justinribeiro/lite-youtube in /build/javascript Bumps [@justinribeiro/lite-youtube](https://github.com/justinribeiro/lite-youtube) from 0.9.0 to 0.9.1. - [Release notes](https://github.com/justinribeiro/lite-youtube/releases) - [Commits](https://github.com/justinribeiro/lite-youtube/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Owncast <owncast@owncast.online> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com>
78 lines
2.5 KiB
JavaScript
Executable File
78 lines
2.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
const program = require('commander');
|
|
const fs = require('fs');
|
|
const { default: PurgeCSS, defaultOptions, setOptions } = require('../lib/purgecss')
|
|
|
|
function getList(list) {
|
|
return list.split(',')
|
|
}
|
|
|
|
async function writeCSSToFile(filePath, css) {
|
|
try {
|
|
await fs.promises.writeFile(filePath, css);
|
|
} catch(err) {
|
|
console.error(err.message);
|
|
}
|
|
}
|
|
|
|
program
|
|
.usage('--css <css> --content <content> [options]')
|
|
.option('-con, --content <files>', 'glob of content files (comma separated)', getList)
|
|
.option('-css, --css <files>', 'glob of css files (comma separated)', getList)
|
|
.option('-c, --config <path>', 'path to the configuration file')
|
|
.option('-o, --output <path>', 'file path directory to write purged css files to')
|
|
.option('-font, --font-face', 'option to remove unused font-faces')
|
|
.option('-keyframes, --keyframes', 'option to remove unused keyframes')
|
|
.option('-rejected, --rejected', 'option to output rejected selectors')
|
|
.option('-w, --whitelist <list>', 'list of classes that should not be removed (comma separated)', getList);
|
|
|
|
program.parse(process.argv);
|
|
|
|
// config file is not specified or the content and css are not,
|
|
// PurgeCSS will not run
|
|
if (!program.config && !(program.content && program.css)) {
|
|
program.help();
|
|
}
|
|
|
|
(async() => {
|
|
// if the config file is present, use it
|
|
// other options specified will override
|
|
let options = defaultOptions;
|
|
if (program.config) {
|
|
options = await setOptions(program.config);
|
|
}
|
|
if (program.content) options.content = program.content;
|
|
if (program.css) options.css = program.css;
|
|
if (program.fontFace) options.fontFace = program.fontFace;
|
|
if (program.keyframes) options.keyframes = program.keyframes;
|
|
if (program.rejected) options.rejected = program.rejected;
|
|
if (program.variables) options.variables = program.variables;
|
|
if (program.whitelist) options.whitelist = program.whitelist;
|
|
|
|
// if (!options.css) {
|
|
// options.css = [{
|
|
// raw: stdInCSS
|
|
// }]
|
|
// }
|
|
|
|
const purged = await new PurgeCSS().purge(options);
|
|
|
|
const output = options.output || program.output;
|
|
// output results in specified directory
|
|
if (output) {
|
|
if (purged.length === 1 && output.endsWith('.css')) {
|
|
await writeCSSToFile(output, purged[0].css)
|
|
return
|
|
}
|
|
|
|
for (const purgedResult of purged) {
|
|
const fileName = purgedResult.file.split("/").pop();
|
|
await writeCSSToFile(`${output}/${fileName}`, purgedResult.css);
|
|
}
|
|
} else {
|
|
console.log(JSON.stringify(purged));
|
|
}
|
|
|
|
})()
|
|
|