Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Docs: update readme
  • Loading branch information
JPeer264 committed Aug 26, 2018
commit eeb42b56e71802eeceeeb7399dd0e174e9edfb82
43 changes: 18 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,17 @@ const rcs = require('rename-css-selectors')
// you can also specify the string although it does not exist yet.
rcs.loadMapping('./renaming_map.json')

// first you have to process the css files
// to get a list of variables you want to minify
// options is optional
rcs.processCss('**/*.css', options, err => {
rcs.process.auto(['**/*.js', '**/*.html', '**/*.css'], options, (err) => {
// all css files are now saved, renamed and stored in the selectorLibrary

// now it is time to process all other files
rcs.process([ '**/*.js', '**/*.html' ], options, err => {
// that's it

// maybe you want to add the new selectors to your previous generated mappings
// do not worry, your old settings are still here, in case you used `loadMapping`
rcs.generateMapping('./', { overwrite: true }, err => {
// the mapping file is now saved
})
})
})
// also other files are not renamed
// that's it

// maybe you want to add the new selectors to your previous generated mappings
// do not worry, your old settings are still here, in case you used `loadMapping`
rcs.generateMapping('./', { overwrite: true }, (err) => {
// the mapping file is now saved
});
});
```

With promises:
Expand All @@ -65,8 +59,7 @@ const rcs = require('rename-css-selectors');

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

rcs.processCss('**/*.css', options)
.then(() => rcs.process([ '**/*.js', '**/*.html' ], options))
rcs.process.auto(['**/*.js', '**/*.html', '**/*.css'], options)
.then(() => rcs.generateMapping('./', { overwrite: true }))
.catch(console.error);
```
Expand All @@ -80,8 +73,7 @@ rcs.loadMapping('./renaming_map.json');

(async () => {
try {
await rcs.processCss('**/*.css', options);
await rcs.process([ '**/*.js', '**/*.html' ], options);
await rcs.process.auto(['**/*.js', '**/*.html', '**/*.css'], options);
await rcs.generateMapping('./', { overwrite: true });
} catch (err) {
console.error(err);
Expand All @@ -98,8 +90,7 @@ const rcs = require('rename-css-selectors');
rcs.loadMapping('./renaming_map.json');

try {
rcs.processCssSync('**/*.css', options);
rcs.processSync([ '**/*.js', '**/*.html' ], options);
rcs.process.autoSync(['**/*.js', '**/*.html', '**/*.css'], options);
rcs.generateMappingSync('./', { overwrite: true });
} catch (err) {
console.error(err);
Expand All @@ -108,9 +99,11 @@ try {

## Methods

- [rcs.processCss](docs/api/processCss.md)
- [rcs.processJs](docs/api/processJs.md)
- [rcs.process](docs/api/process.md)
- [rcs.process.auto](docs/api/processAuto.md)
- [rcs.process.css](docs/api/processCss.md)
- [rcs.process.js](docs/api/processJs.md)
- [rcs.process.html](docs/api/processHtml.md)
- [rcs.process.any](docs/api/processAny.md)
- [rcs.generateMapping](docs/api/generateMapping.md)
- [rcs.loadMapping](docs/api/loadMapping.md)
- [rcs.includeConfig](docs/api/includeconfig.md)
Expand Down
19 changes: 8 additions & 11 deletions docs/api/process.md → docs/api/processAuto.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# process
# rcs.process.auto

**process(src[, options][, callback])**
**rcs.process.auto(src[, options][, callback])**

> **Important!** processCss should run first, otherwise there are no minified selectors
> *Note:* JavaScript, HTML and CSS files are detected automatically. If you want to make sure that JavaScript files or others are detected correctly, you can use `process.js` for JavaScript files or `process.html` for HTML files manually to ensure a correct renaming within files.

> *Note:* JavaScript, HTML and CSS files are detected automatically. If you want to make sure that JavaScript files or others are detected correctly. You can use `processJs` for JavaScript files manually to ensure a correct renaming within files.
Not supported files are renamed by [`replace.any`](replaceAny.md).

Not supported files matches all strings `" "` or `' '` and replaces all matching words which are the same as the stored CSS selectors.

Sync: `processSync`
Sync: `process.autoSync`

Parameters:
- src `<String | Array>`
Expand All @@ -20,15 +18,14 @@ Options:
- overwrite `<Boolean>`: ensures that it does not overwrite the same file accidently. Default is `false`
- cwd `<String>`: the working directory in which to serach. Default is `process.cwd()`
- newPath `<String>`: in which folder the new files should go. Default is `rcs`
- collectSelectors `<Boolean>`: Force the algorithm to collect just CSS selectors and not renaming files

Example:

```js
const rcs = require('rename-css-selectors');

// callback
rcs.process('**/*.js', options, (err) => {
rcs.process.auto('**/*.js', options, (err) => {
if (err) {
return console.error(err);
}
Expand All @@ -37,14 +34,14 @@ rcs.process('**/*.js', options, (err) => {
});

// promise
rcs.process('**/*.js', options)
rcs.process.auto('**/*.js', options)
.then(() => console.log('Successfully wrote new files'))
.catch(console.error);

// async/await
(async () => {
try {
await rcs.process('**/*.js', options);
await rcs.process.auto('**/*.js', options);

console.log('Successfully wrote new files');
} catch (err) {
Expand Down
12 changes: 6 additions & 6 deletions docs/api/processCss.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# processCss
# rcs.process.css

**processCss(src[, options][, callback])**
**rcs.process.css(src[, options][, callback])**

Store all matched selectors into the library and saves the new generated file with all renamed selectors.

Sync: `processCssSync`
Sync: `process.cssSync`

Parameters:
- src `<String | Array>`
Expand All @@ -22,7 +22,7 @@ Example:
const rcs = require('rename-css-selectors');

// callback
rcs.processCss('**/*.css', options, (err) => {
rcs.process.css('**/*.css', options, (err) => {
if (err) {
return console.error(err);
}
Expand All @@ -31,14 +31,14 @@ rcs.processCss('**/*.css', options, (err) => {
});

// promise
rcs.processCss('**/*.css', options)
rcs.process.css('**/*.css', options)
.then(() => console.log('Successfully wrote new files and stored values'));
.catch(console.error);

// async/await
(async () => {
try {
await rcs.processCss('**/*.css', options);
await rcs.process.css('**/*.css', options);

console.log('Successfully wrote new files and stored values')
} catch (err) {
Expand Down
48 changes: 48 additions & 0 deletions docs/api/processHtml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# process.html

**rcs.process.html(src[, options][, callback])**

> **Important!** process.css should run first, otherwise there are no minified selectors

Sync: `process.htmlSync`

Parameters:
- src `<String | Array>`
- options `<Object>` *optional*
- callback `<Function>` *optional*

Options:

- *all options of [rcs.process](process.md)*
- *plus options [rcsCore.replace.html](https://github.com/JPeer264/node-rcs-core/blob/master/docs/api/replace.md#html)*

Example:

```js
const rcs = require('rename-css-selectors');

// callback
rcs.process.html('**/*.html', options, (err) => {
if (err) {
return console.error(err);
}

console.log('Successfully wrote new HTML files');
});

// promise
rcs.process.html('**/*.html', options)
.then(() => console.log('Successfully wrote new HTML files'))
.catch(console.error);

// async/await
(async () => {
try {
await rcs.process.html('**/*.html', options);

console.log('Successfully wrote new HTML files');
} catch (err) {
console.error(err);
}
})();
```
20 changes: 10 additions & 10 deletions docs/api/processJs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# processJs
# rcs.process.js

**process(src[, options][, callback])**
**rcs.process.js(src[, options][, callback])**

> **Important!** processCss should run first, otherwise there are no minified selectors
> **Important!** process.css should run first, otherwise there are no minified selectors

Sync: `processJsSync`
Sync: `process.jsSync`

Parameters:
- src `<String | Array>`
Expand All @@ -22,25 +22,25 @@ Example:
const rcs = require('rename-css-selectors');

// callback
rcs.processJs('**/*.js', options, (err) => {
rcs.process.js('**/*.js', options, (err) => {
if (err) {
return console.error(err);
}

console.log('Successfully wrote new javascript files');
console.log('Successfully wrote new JavaScript files');
});

// promise
rcs.processJs('**/*.js', options)
.then(() => console.log('Successfully wrote new javascript files'))
rcs.process.js('**/*.js', options)
.then(() => console.log('Successfully wrote new JavaScript files'))
.catch(console.error);

// async/await
(async () => {
try {
await rcs.processJs('**/*.js', options);
await rcs.process.js('**/*.js', options);

console.log('Successfully wrote new javascript files');
console.log('Successfully wrote new JavaScript files');
} catch (err) {
console.error(err);
}
Expand Down
49 changes: 49 additions & 0 deletions docs/api/replaceAny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# rcs.process.any

**rcs.process.any(src[, options][, callback])**

> **Important!** process.any should run first, otherwise there are no minified selectors

Matches all strings (`" "` or `' '`) and replaces all matching words which are the same as the stored CSS selectors.

Sync: `process.anySync`

Parameters:
- src `<String | Array>`
- options `<Object>` *optional*
- callback `<Function>` *optional*

Options:

- *all options of [rcs.process](process.md)*

Example:

```js
const rcs = require('rename-css-selectors');

// callback
rcs.process.any('**/*.txt', options, (err) => {
if (err) {
return console.error(err);
}

console.log('Successfully wrote new files and stored values');
});

// promise
rcs.process.any('**/*.txt', options)
.then(() => console.log('Successfully wrote new files and stored values'));
.catch(console.error);

// async/await
(async () => {
try {
await rcs.process.any('**/*.txt', options);

console.log('Successfully wrote new files and stored values')
} catch (err) {
console.error(err);
}
})();
```