Skip to content

Commit b9de1d8

Browse files
committed
new folderstructure
1 parent 0577f20 commit b9de1d8

File tree

15 files changed

+689
-486
lines changed

15 files changed

+689
-486
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ renameCssSelectors.processCssSync = require('./lib/processCss/processCssSync');
2222
renameCssSelectors.processCss = require('./lib/processCss/processCss');
2323

2424
// MAPPING
25-
renameCssSelectors.generateMappingSync = require('./lib/mapping/generateSync');
26-
renameCssSelectors.generateMapping = require('./lib/mapping/generate');
27-
renameCssSelectors.loadMapping = require('./lib/mapping/load');
25+
renameCssSelectors.generateMappingSync = require('./lib/mapping/generateMappingSync');
26+
renameCssSelectors.generateMapping = require('./lib/mapping/generateMapping');
27+
renameCssSelectors.loadMapping = require('./lib/mapping/loadMapping');
2828

2929
// CONFIG
30-
renameCssSelectors.includeConfig = require('./lib/config/include');
30+
renameCssSelectors.includeConfig = require('./lib/config/includeConfig');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const include = pathString => {
1111
let configObject;
1212

1313
pathString = pathString || path.join(process.cwd(), '.rcsrc');
14+
1415
configObject = json.readToObjSync(pathString);
1516

1617
if (!configObject) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
3+
const includeConfig = require('../includeConfig');
4+
5+
const fs = require('fs-extra');
6+
const rcs = require('rcs-core');
7+
const expect = require('chai').expect;
8+
9+
const testFiles = process.cwd() + '/test/files';
10+
11+
describe('config/includeConfig', () => {
12+
beforeEach(() => {
13+
// reset counter and selectors for tests
14+
rcs.selectorLibrary.excludes = [];
15+
rcs.selectorLibrary.selectors = {};
16+
rcs.selectorLibrary.attributeSelectors = {};
17+
rcs.selectorLibrary.compressedSelectors = {};
18+
19+
rcs.nameGenerator.resetCountForTests();
20+
});
21+
22+
it('should set the config with package.json', done => {
23+
// include config
24+
includeConfig();
25+
26+
// include new settings
27+
rcs.selectorLibrary.set(['js', 'any-value']);
28+
29+
expect(rcs.selectorLibrary.get('js')).to.equal('js');
30+
expect(rcs.selectorLibrary.get('any-value')).to.equal('a');
31+
32+
done();
33+
});
34+
35+
it('should set the config with .rcsrc', done => {
36+
const file = '.rcsrc';
37+
38+
fs.writeFileSync(file, `{
39+
"exclude": [
40+
"flexbox",
41+
"no-js"
42+
]
43+
}`, {
44+
encoding: 'utf8'
45+
});
46+
47+
// include config
48+
includeConfig();
49+
50+
// include new settings
51+
rcs.selectorLibrary.set(['flexbox', 'any-value']);
52+
53+
expect(rcs.selectorLibrary.get('flexbox')).to.equal('flexbox');
54+
expect(rcs.selectorLibrary.get('any-value')).to.equal('a');
55+
56+
fs.removeSync(file);
57+
58+
done();
59+
});
60+
61+
it('should set the config with package.json', done => {
62+
// include config
63+
includeConfig(testFiles + '/config.json');
64+
65+
// include new settings
66+
rcs.selectorLibrary.set(['own-file', 'any-value']);
67+
68+
expect(rcs.selectorLibrary.get('own-file')).to.equal('own-file');
69+
expect(rcs.selectorLibrary.get('any-value')).to.equal('a');
70+
71+
done();
72+
});
73+
});

lib/mapping/__tests__/generate.spec.js

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const path = require('path');
1919
* @param {String} pathString where it should get saved
2020
* @param {generateMappingOptions} [options]
2121
*/
22-
const generate = (pathString, options, cb) => {
22+
const generateMapping = (pathString, options, cb) => {
2323
let fileName = 'renaming_map';
2424
let fileNameExt = '.json';
2525
let mappingName = 'CSS_NAME_MAPPING';
@@ -78,6 +78,6 @@ const generate = (pathString, options, cb) => {
7878

7979
cb(null, data);
8080
});
81-
}; // /generate
81+
}; // /generateMapping
8282

83-
module.exports = generate;
83+
module.exports = generateMapping;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const path = require('path');
77
/**
88
* The synchronous method of generateMapping
99
*/
10-
const generateSync = (pathString, options) => {
10+
const generateMappingSync = (pathString, options) => {
1111
let fileName = 'renaming_map';
1212
let fileNameExt = '.json';
1313
let mappingName = 'CSS_NAME_MAPPING';
@@ -56,6 +56,6 @@ const generateSync = (pathString, options) => {
5656
}
5757

5858
rcs.helper.saveSync(`${ newPath }${ fileNameExt }`, writeData, { overwrite: options.overwrite });
59-
} // /generateSync
59+
} // /generateMappingSync
6060

61-
module.exports = generateSync;
61+
module.exports = generateMappingSync;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const json = require('json-extra');
1010
* @param {Object | String} pathString could be either the path or the mapping object
1111
* @param {Object} [options]
1212
*/
13-
const load = (pathString, options) => {
13+
const loadMapping = (pathString, options) => {
1414
let selectors = pathString;
1515

1616
const optionsDefault = {
@@ -42,6 +42,6 @@ const load = (pathString, options) => {
4242
}
4343

4444
rcs.selectorLibrary.setValues(selectors);
45-
}; // /load
45+
}; // /loadMapping
4646

47-
module.exports = load;
47+
module.exports = loadMapping;
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
'use strict';
2+
3+
const generateMapping = require('../generateMapping');
4+
const processCss = require('../../processCss/processCss');
5+
6+
const rcs = require('rcs-core');
7+
const fs = require('fs-extra');
8+
const json = require('json-extra');
9+
const expect = require('chai').expect;
10+
11+
const testCwd = process.cwd() + '/test/files/testCache';
12+
const fixturesCwd = process.cwd() + '/test/files/fixtures';
13+
const resultsCwd = process.cwd() + '/test/files/results';
14+
15+
describe('mapping/generateMapping', () => {
16+
beforeEach(done => {
17+
// reset counter and selectors for tests
18+
rcs.selectorLibrary.excludes = [];
19+
rcs.selectorLibrary.selectors = {};
20+
rcs.selectorLibrary.attributeSelectors = {};
21+
rcs.selectorLibrary.compressedSelectors = {};
22+
23+
rcs.nameGenerator.resetCountForTests();
24+
25+
processCss('**/style*.css', {
26+
newPath: testCwd,
27+
cwd: fixturesCwd
28+
}, (err, data) => {
29+
done();
30+
});
31+
});
32+
33+
afterEach(() => {
34+
fs.removeSync(testCwd);
35+
});
36+
37+
it('should create the normal mapping file', done => {
38+
generateMapping(testCwd, (err, data) => {
39+
const cssMapping = json.readToObjSync(testCwd + '/renaming_map.json', 'utf8');
40+
41+
expect(err).to.not.exist;
42+
expect(cssMapping['.jp-block']).to.equal('a');
43+
expect(cssMapping['.jp-block__element']).to.equal('b');
44+
45+
done();
46+
});
47+
});
48+
49+
it('should create the minified mapping file', done => {
50+
generateMapping(testCwd, {
51+
cssMapping: false,
52+
cssMappingMin: true
53+
}, (err, data) => {
54+
const cssMappingMin = json.readToObjSync(testCwd + '/renaming_map_min.json', 'utf8');
55+
56+
expect(err).to.not.exist;
57+
expect(cssMappingMin['.a']).to.equal('jp-block');
58+
expect(cssMappingMin['.b']).to.equal('jp-block__element');
59+
60+
done();
61+
62+
});
63+
});
64+
65+
it('should create the extended normal mapping file', done => {
66+
generateMapping(testCwd, {
67+
extended: true
68+
}, (err, data) => {
69+
const cssMapping = json.readToObjSync(testCwd + '/renaming_map.json', 'utf8');
70+
71+
expect(err).to.not.exist;
72+
expect(cssMapping['.jp-block']).to.be.an('object');
73+
expect(cssMapping['.jp-block']).to.have.any.keys('type', 'typeChar');
74+
expect(cssMapping['.jp-block']['type']).to.equal('class');
75+
76+
done();
77+
78+
});
79+
});
80+
81+
it('should create the minified mapping file', done => {
82+
generateMapping(testCwd, {
83+
cssMapping: false,
84+
cssMappingMin: true,
85+
extended: true
86+
}, (err, data) => {
87+
const cssMappingMin = json.readToObjSync(testCwd + '/renaming_map_min.json', 'utf8');
88+
89+
expect(err).to.not.exist;
90+
expect(cssMappingMin['.a']).to.be.an('object');
91+
expect(cssMappingMin['.a']).to.have.any.keys('type', 'typeChar');
92+
expect(cssMappingMin['.a']['type']).to.equal('class');
93+
94+
done();
95+
96+
});
97+
});
98+
99+
it('should create the minified mapping file with a custom name', done => {
100+
generateMapping(testCwd, {
101+
cssMappingMin: 'custom-name'
102+
}, (err, data) => {
103+
const cssMappingMin = json.readToObjSync(testCwd + '/custom-name.json', 'utf8');
104+
105+
expect(err).to.not.exist;
106+
expect(cssMappingMin['.a']).to.equal('jp-block');
107+
expect(cssMappingMin['.b']).to.equal('jp-block__element');
108+
109+
done();
110+
111+
});
112+
});
113+
114+
it('should create the minified mapping js file', done => {
115+
generateMapping(testCwd, {
116+
json: false
117+
}, (err, data) => {
118+
const cssMapping = fs.readFileSync(testCwd + '/renaming_map.js', 'utf8');
119+
120+
expect(err).to.not.exist;
121+
expect(cssMapping).to.match(/var CSS_NAME_MAPPING = {/);
122+
123+
done();
124+
125+
});
126+
});
127+
128+
it('should overwrite mapping files', done => {
129+
generateMapping(testCwd, (err, data) => {
130+
generateMapping(testCwd, { overwrite: true }, (err2, data) => {
131+
expect(err).to.not.exist;
132+
expect(err2).to.not.exist;
133+
134+
done();
135+
});
136+
});
137+
});
138+
139+
it('should not overwrite mapping files', done => {
140+
generateMapping(testCwd, (err, data) => {
141+
generateMapping(testCwd, (err2, data) => {
142+
expect(err).to.not.exist;
143+
expect(err2).to.exist;
144+
expect(err2.message).to.equal('File exist and cannot be overwritten. Set the option overwrite to true to overwrite files.');
145+
146+
done();
147+
});
148+
});
149+
});
150+
151+
it('should create the custom names minified mapping file', done => {
152+
generateMapping(testCwd, {
153+
cssMapping: 'custom-name'
154+
}, (err, data) => {
155+
const cssMapping = json.readToObjSync(testCwd + '/custom-name.json', 'utf8');
156+
157+
expect(err).to.not.exist;
158+
expect(cssMapping['.jp-block']).to.equal('a');
159+
expect(cssMapping['.jp-block__element']).to.equal('b');
160+
161+
done();
162+
163+
});
164+
});
165+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
const generateMappingSync = require('../generateMappingSync');
4+
const processCss = require('../../processCss/processCss');
5+
6+
const rcs = require('rcs-core');
7+
const fs = require('fs-extra');
8+
const json = require('json-extra');
9+
const expect = require('chai').expect;
10+
11+
const testCwd = process.cwd() + '/test/files/testCache';
12+
const fixturesCwd = process.cwd() + '/test/files/fixtures';
13+
const resultsCwd = process.cwd() + '/test/files/results';
14+
15+
describe('mapping/generateMappingSync', () => {
16+
beforeEach(done => {
17+
// reset counter and selectors for tests
18+
rcs.selectorLibrary.excludes = [];
19+
rcs.selectorLibrary.selectors = {};
20+
rcs.selectorLibrary.attributeSelectors = {};
21+
rcs.selectorLibrary.compressedSelectors = {};
22+
23+
rcs.nameGenerator.resetCountForTests();
24+
25+
processCss('**/style*.css', {
26+
newPath: testCwd,
27+
cwd: fixturesCwd
28+
}, (err, data) => {
29+
done();
30+
});
31+
});
32+
33+
afterEach(() => {
34+
fs.removeSync(testCwd);
35+
});
36+
37+
it('should create the normal mapping file synchornously', () => {
38+
generateMappingSync(testCwd);
39+
40+
const cssMapping = json.readToObjSync(testCwd + '/renaming_map.json', 'utf8');
41+
42+
expect(cssMapping['.jp-block']).to.equal('a');
43+
expect(cssMapping['.jp-block__element']).to.equal('b');
44+
});
45+
});

0 commit comments

Comments
 (0)