Skip to content

Commit 7e32f5c

Browse files
authored
Feat: enable optimization from rcs-core by default (closes #80) (#81)
1 parent 6a10373 commit 7e32f5c

File tree

6 files changed

+6418
-4127
lines changed

6 files changed

+6418
-4127
lines changed

Diff for: __tests__/processAuto.ts

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import tmp from 'tmp';
22
import path from 'path';
33
import fs from 'fs-extra';
4+
import rcsCore from 'rcs-core';
45
import { minify } from 'html-minifier';
56

67
import rcs from '../lib';
@@ -131,3 +132,30 @@ test('should fillLibraries from html and css | issue #38', async () => {
131132
expect(minify(newFile2, { collapseWhitespace: true }))
132133
.toBe(minify(expectedFile2, { collapseWhitespace: true }));
133134
});
135+
136+
test('should check if optimize has been called', async () => {
137+
const optimizeSpy = jest.spyOn(rcsCore, 'optimize');
138+
139+
await rcs.process.auto(['**/*.{js,html}', 'css/style.css'], {
140+
newPath: testCwd.name,
141+
cwd: fixturesCwd,
142+
});
143+
144+
expect(optimizeSpy).toHaveBeenCalledTimes(1);
145+
146+
optimizeSpy.mockRestore();
147+
});
148+
149+
test('should check if optimize has been called test', async () => {
150+
const optimizeSpy = jest.spyOn(rcsCore, 'optimize');
151+
152+
await rcs.process.auto(['**/*.{js,html}', 'css/style.css'], {
153+
newPath: testCwd.name,
154+
cwd: fixturesCwd,
155+
optimize: false,
156+
});
157+
158+
expect(optimizeSpy).not.toHaveBeenCalled();
159+
160+
optimizeSpy.mockRestore();
161+
});

Diff for: docs/api/processAuto.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Options:
1818
- overwrite `<Boolean>`: ensures that it does not overwrite the same file accidently. Default is `false`
1919
- cwd `<String>`: the working directory in which to serach. Default is `process.cwd()`
2020
- newPath `<String>`: in which folder the new files should go. Default is `rcs`
21+
- optimize `<Boolean>`: checks if the selectors should be [optimized](https://github.com/JPeer264/node-rcs-core/blob/main/docs/api/optimize.md). Default is `true`
2122

2223
Example:
2324

Diff for: docs/api/processCss.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Parameters:
1313

1414
Options:
1515

16+
- optimize `<Boolean>`: checks if the selectors should be [optimized](https://github.com/JPeer264/node-rcs-core/blob/main/docs/api/optimize.md). Default is `true`
1617
- *all options of [rcs.process](process.md)*
1718
- *plus options [rcsCore.fillLibrary](https://github.com/JPeer264/node-rcs-core/blob/master/docs/api/filllibraries.md)*
1819

Diff for: docs/api/processHtml.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Parameters:
1313

1414
Options:
1515

16+
- optimize `<Boolean>`: checks if the selectors should be [optimized](https://github.com/JPeer264/node-rcs-core/blob/main/docs/api/optimize.md). Default is `true`
1617
- *all options of [rcs.process](process.md)*
1718
- *plus options [rcsCore.replace.html](https://github.com/JPeer264/node-rcs-core/blob/master/docs/api/replace.md#html)*
1819

Diff for: lib/process/process.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ReplaceHtmlOptions } from 'rcs-core/dest/replace/html';
1111
import { ReplacePugOptions } from 'rcs-core/dest/replace/pug';
1212
import { ReplaceCssOptions } from 'rcs-core/dest/replace/css';
1313
import { ReplaceJsOptions } from 'rcs-core/dest/replace/js';
14-
import { FillLibrariesOptions } from 'rcs-core/dest/fillLibraries';
14+
import { FillLibrariesOptions as RcsFillLibrariesOptions } from 'rcs-core/dest/fillLibraries';
1515

1616
import save from '../helper/save';
1717
import replaceData from './replaceData';
@@ -26,6 +26,10 @@ export interface BaseOptions {
2626
overwrite?: boolean;
2727
}
2828

29+
export interface FillLibrariesOptions extends RcsFillLibrariesOptions {
30+
optimize?: boolean;
31+
}
32+
2933
export interface AllOptions {
3034
pug: BaseOptions & ReplacePugOptions;
3135
any: BaseOptions & ReplaceStringOptions;
@@ -51,6 +55,7 @@ async function rcsProcess(type: 'pug', pathString: string | string[], opts?: All
5155
async function rcsProcess(type: 'any', pathString: string | string[], opts?: AllOptions['any']): Promise<void>;
5256
async function rcsProcess(type: any, pathString: string | string[], opts: any = {}): Promise<void> {
5357
const options = { ...optionsDefault, ...opts };
58+
const shouldOptimize = options.optimize ?? true;
5459

5560
let globString: string;
5661

@@ -132,6 +137,10 @@ async function rcsProcess(type: any, pathString: string | string[], opts: any =
132137
))
133138
));
134139

140+
if (shouldOptimize) {
141+
rcs.optimize();
142+
}
143+
135144
await new Promise((res, rej) => (
136145
// now all files can be renamed and saved
137146
// can be fired parallel

0 commit comments

Comments
 (0)