Skip to content

Commit

Permalink
Remove minified versions of patched Prism files (#35)
Browse files Browse the repository at this point in the history
* Remove minified versions of patched Prism files

* Add to changelog
  • Loading branch information
MattIPv4 authored Nov 15, 2022
1 parent 0364ad3 commit 48a0bfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Each list item should be prefixed with `(patch)` or `(minor)` or `(major)`.
See `PUBLISH.md` for instructions on how to publish a new version.
-->

- (patch) Remove minified versions of patched Prism files


## v1.3.2 - a395a43

Expand Down
18 changes: 8 additions & 10 deletions script/prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,18 @@ fs.writeFileSync(
*/
const template = source => `const component = Prism => {\n\t${source.replace(/\n/g, '\n\t')}\n};\n\nif (typeof module !== 'undefined' && module.exports) {\n\tmodule.exports = component;\n} else {\n\tcomponent(Prism);\n}\n`;

/**
* Template to wrap a minified Prism component to export when in a module context.
*
* @param {string} source Source code of the component.
* @returns {string}
* @private
*/
const templateMin = source => `const component=Prism=>{${source}};typeof module!='undefined'&&module.exports?module.exports=component:component(Prism);\n`;

// Patch all the components (except autoloader) + plugins to export functions
const components = getFilesInDir(path.join(base, 'components')).filter(f => f !== autoloader && f.endsWith('.js'));
const plugins = getFilesInDir(path.join(base, 'plugins')).filter(f => f.endsWith('.js'));
for (const file of components.concat(plugins)) {
fs.writeFileSync(file, (file.endsWith('.min.js') ? templateMin : template)(fs.readFileSync(file, 'utf8').trim()));
// Remove minified versions
if (file.endsWith('.min.js')) {
fs.unlinkSync(file);
continue;
}

// Patch the unminified version
fs.writeFileSync(file, template(fs.readFileSync(file, 'utf8').trim()));
}

console.info('Prism patched successfully!');

0 comments on commit 48a0bfd

Please sign in to comment.