Skip to content

Commit

Permalink
Feat: move to previous .config instead of .Config.getInstance()
Browse files Browse the repository at this point in the history
  • Loading branch information
JPeer264 committed Jun 22, 2021
1 parent 9931075 commit f5bff64
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
45 changes: 22 additions & 23 deletions __tests__/config.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import path from 'path';
import fs from 'fs-extra';
import rcs from 'rcs-core';

import Config from '../lib/Config';
import rcsCore from 'rcs-core';
import rcs from '../lib';

const testFiles = path.join(process.cwd(), '/__tests__/files');

beforeEach(() => {
rcs.selectorsLibrary.getClassSelector().nameGenerator.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
rcs.selectorsLibrary.getIdSelector().nameGenerator.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
rcs.selectorsLibrary.reset();
rcs.keyframesLibrary.reset();
rcsCore.selectorsLibrary.getClassSelector().nameGenerator.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
rcsCore.selectorsLibrary.getIdSelector().nameGenerator.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
rcsCore.selectorsLibrary.reset();
rcsCore.keyframesLibrary.reset();
});

it('should set the config with package.json', () => {
// include config
Config.getInstance().load();
rcs.config.load();

// include new settings
rcs.selectorsLibrary.set(['.js', '.any-value']);
rcsCore.selectorsLibrary.set(['.js', '.any-value']);

expect(rcs.selectorsLibrary.get('js')).toBe('js');
expect(rcs.selectorsLibrary.get('any-value')).toBe('a');
expect(rcsCore.selectorsLibrary.get('js')).toBe('js');
expect(rcsCore.selectorsLibrary.get('any-value')).toBe('a');
});

it('should set the config with .rcsrc', () => {
Expand All @@ -40,26 +39,26 @@ it('should set the config with .rcsrc', () => {
});

// include config
Config.getInstance().load();
rcs.config.load();

// include new settings
rcs.selectorsLibrary.set(['.flexbox', '.any-value']);
rcsCore.selectorsLibrary.set(['.flexbox', '.any-value']);

expect(rcs.selectorsLibrary.get('flexbox')).toBe('flexbox');
expect(rcs.selectorsLibrary.get('any-value')).toBe('a');
expect(rcsCore.selectorsLibrary.get('flexbox')).toBe('flexbox');
expect(rcsCore.selectorsLibrary.get('any-value')).toBe('a');

fs.removeSync(file);
});

it('should set the config with package.json', () => {
// include config
Config.getInstance().load(path.join(testFiles, '/config.json'));
rcs.config.load(path.join(testFiles, '/config.json'));

// include new settings
rcs.selectorsLibrary.set(['.own-file', '.any-value']);
rcsCore.selectorsLibrary.set(['.own-file', '.any-value']);

expect(rcs.selectorsLibrary.get('own-file')).toBe('own-file');
expect(rcs.selectorsLibrary.get('any-value')).toBe('a');
expect(rcsCore.selectorsLibrary.get('own-file')).toBe('own-file');
expect(rcsCore.selectorsLibrary.get('any-value')).toBe('a');
});

it('should load ignored patterns', () => {
Expand All @@ -75,11 +74,11 @@ it('should load ignored patterns', () => {
});

// include config
Config.getInstance().load();
rcs.config.load();

expect(Config.getInstance().isIgnored('a.js')).toBe(true);
expect(Config.getInstance().isIgnored('b.min.js')).toBe(true);
expect(Config.getInstance().isIgnored('b.js')).toBe(false);
expect(rcs.config.isIgnored('a.js')).toBe(true);
expect(rcs.config.isIgnored('b.min.js')).toBe(true);
expect(rcs.config.isIgnored('b.js')).toBe(false);

fs.removeSync(file);
});
5 changes: 2 additions & 3 deletions docs/api/config.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Config

**Config.getInstance().load([pathLocation])**
**config.load([pathLocation])**

> All available configs [here](#rcs-config)
Expand All @@ -14,7 +14,7 @@ Example:
```js
const rcs = require('rename-css-selectors');

rcs.Config.getInstance().load();
rcs.config.load();
```

## RCS config
Expand All @@ -24,7 +24,6 @@ rcs.Config.getInstance().load();
- [Example](#example)
- [Exclude](#exclude-classes-and-ids)
- [Ignore](#ignore-files)
- [Include from other projects](#include-renamed-classes-from-other-project)

### Example

Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export default {
generate: generateMapping,
load: loadMapping,
},
Config,
config: Config.getInstance(),
};

0 comments on commit f5bff64

Please sign in to comment.