JPeer264 / node-rename-css-selectors

šŸ“ Rename css classes and id's in files
MIT License
66 stars 9 forks source link

`process()` doesn't work if `src` parameter only contains HTML #19

Closed Stephen-X closed 6 years ago

Stephen-X commented 6 years ago

It's part of a series of issues I found, so I'm going to reuse the base test case and open separate issues for each of them šŸ˜„ I'm developing on Windows btw; not sure if these are all platform specific bugs.

Issue Description:

If you only send HTML file to the process function, then it'll only output a new CSS file.

Steps to reproduce this issue:

  1. Create a simple project with the following code:

index.html:

<html>
    <head>
        <meta name="description" content="Fire in the hole!">
        <link rel="stylesheet" href="style.css">
    </head>
    <body div class="in wf-active">
        <p>Fire in the hole!</p>
    </body>
</html>

style.css:

.wf-active {
    color: red;
}

.in {
    font-weight: bold;
}

selector_obfs.js:

const rcs = require('rename-css-selectors')

rcs.loadMapping('./temp/renaming_map.json')

rcs.processCss('style.css', {newPath: 'temp'}, err => {
    rcs.process(['index.html'], {newPath: 'temp'}, err => {
        rcs.generateMapping('./temp', { overwrite: true }, err => {
            // the mapping file is now saved
        })
    })
})
  1. Run RCS by node selector_obfs.js. Notice that there's no new HTML files in the temp directory; only the CSS file gets renamed.
JPeer264 commented 6 years ago

@Stephen-X this should be fixed in v3.0.0

You can now also write it a bit different, as I refactored it a bit for an easier usage:


const rcs = require('rename-css-selectors')

rcs.loadMapping('./temp/renaming_map.json')

rcs.process.auto(['style.css', 'index.html'], {newPath: 'temp'}, err => {
    rcs.generateMapping('./temp', { overwrite: true }, err => {
        // the mapping file is now saved
    })
})