Skip to content

Commit 3ce8731

Browse files
committed
Refactor: satisfy rcs-core@1.0.0-alpha.1
1 parent 90ac993 commit 3ce8731

File tree

9 files changed

+73
-25
lines changed

9 files changed

+73
-25
lines changed

lib/mapping/generateMapping.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const _ = require('lodash');
44
const rcs = require('rcs-core');
55
const path = require('path');
6+
const json = require('json-extra');
67

78
/**
89
* @typedef {Object} generateMappingOptions
@@ -63,7 +64,7 @@ const generateMapping = (pathString, options, cb) => {
6364
isSelectors: options.isSelectors
6465
});
6566

66-
let cssMappingJsonString = rcs.helper.objectToJson(cssMappingArray);
67+
let cssMappingJsonString = json.check(cssMappingArray) ? cssMappingArray : json.stringify(cssMappingArray, null, '\t');
6768
let writeData = cssMappingJsonString;
6869
let newPath = path.join(pathString, fileName);
6970

lib/mapping/generateMappingSync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const _ = require('lodash');
44
const rcs = require('rcs-core');
55
const path = require('path');
6+
const json = require('json-extra');
67

78
/**
89
* The synchronous method of generateMapping
@@ -45,7 +46,7 @@ const generateMappingSync = (pathString, options) => {
4546
isSelectors: options.isSelectors
4647
});
4748

48-
let cssMappingJsonString = rcs.helper.objectToJson(cssMappingArray);
49+
let cssMappingJsonString = json.check(cssMappingArray) ? cssMappingArray : json.stringify(cssMappingArray, null, '\t');
4950
let writeData = cssMappingJsonString;
5051
let newPath = path.join(pathString, fileName);
5152

lib/process/process.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const rcsProcess = (pathString, options, cb) => {
9898
// all selectors are collected
9999
// ⚡️ speed it up with async ⚡️
100100
async.each(filesArray, (filePath, callback) => {
101-
fs.readFile(path.join(options.cwd, filePath), (err, bufferData) => {
101+
fs.readFile(path.join(options.cwd, filePath), 'utf8', (err, bufferData) => {
102102
let data;
103103
let joinedPath;
104104
let shouldOverwrite = options.overwrite;
@@ -107,9 +107,7 @@ const rcsProcess = (pathString, options, cb) => {
107107

108108
// check wether to replace javascript files or not
109109
if (options.replaceJs) {
110-
const isJsx = !!options.jsx;
111-
112-
data = rcs.replace.bufferJs(bufferData, { jsx: isJsx });
110+
data = rcs.replace.bufferJs(bufferData);
113111
} else {
114112
data = rcs.replace.buffer(bufferData);
115113
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"glob": "^7.1.1",
3838
"json-extra": "^0.5.0",
3939
"lodash": "^4.17.4",
40-
"rcs-core": "^0.12.0"
40+
"rcs-core": "1.0.0-alpha.1"
4141
},
4242
"devDependencies": {
4343
"chai": "^3.5.0",

test/files/fixtures/js/main.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// jQuery example
2-
$('.jp-block');
2+
$(".jp-block");
33

44
// vanillaJS example
5-
document.getElementsByClassName('jp-block__element');
6-
document.getElementById('jp-block__element--modifier');
5+
document.getElementsByClassName(" jp-block__element");
6+
document.getElementById("jp-block__element--modifier");
77

8-
angular.module('service.reveal');
8+
angular.module("service.reveal");

test/files/fixtures/js/react.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class Events extends Component {
1818

1919
renderEvent() {
2020
if (this.props.events.length === 0) {
21-
return (<p class="jp-block jp-pseudo">is</p>);
21+
return <p class="jp-block jp-pseudo">is</p>;
2222
}
2323

24-
return (<ListView class="jp-block__element" data={this.props.events} />);
24+
return <ListView class="jp-block__element" data={this.props.events} />;
2525
}
2626

2727
render() {

test/files/results/js/main.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// jQuery example
2-
$('.a');
2+
$(".a");
33

44
// vanillaJS example
5-
document.getElementsByClassName('b');
6-
document.getElementById('c');
5+
document.getElementsByClassName(" b");
6+
document.getElementById("c");
77

8-
angular.module('service.reveal');
8+
angular.module("service.reveal");

test/files/results/js/react.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class Events extends Component {
1818

1919
renderEvent() {
2020
if (this.props.events.length === 0) {
21-
return (<p class="a e">is</p>);
21+
return <p class="a e">is</p>;
2222
}
2323

24-
return (<ListView class="b" data={this.props.events} />);
24+
return <ListView class="b" data={this.props.events} />;
2525
}
2626

2727
render() {

yarn.lock

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ assertion-error@^1.0.1:
6969
version "1.0.2"
7070
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"
7171

72+
ast-traverse@^0.1.1:
73+
version "0.1.1"
74+
resolved "https://registry.yarnpkg.com/ast-traverse/-/ast-traverse-0.1.1.tgz#69cf2b8386f19dcda1bb1e05d68fe359d8897de6"
75+
76+
ast-types@0.9.11:
77+
version "0.9.11"
78+
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.11.tgz#371177bb59232ff5ceaa1d09ee5cad705b1a5aa9"
79+
7280
async@1.x, async@^1.4.0:
7381
version "1.5.2"
7482
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
@@ -185,6 +193,10 @@ concat-map@0.0.1:
185193
version "0.0.1"
186194
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
187195

196+
core-js@^2.4.1:
197+
version "2.4.1"
198+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e"
199+
188200
core-util-is@~1.0.0:
189201
version "1.0.2"
190202
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@@ -256,7 +268,7 @@ ecc-jsbn@~0.1.1:
256268
dependencies:
257269
jsbn "~0.1.0"
258270

259-
es-abstract@^1.5.0:
271+
es-abstract@^1.5.0, es-abstract@^1.6.1:
260272
version "1.7.0"
261273
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.7.0.tgz#dfade774e01bfcd97f96180298c449c8623fb94c"
262274
dependencies:
@@ -299,6 +311,10 @@ esprima@2.7.x, esprima@^2.6.0, esprima@^2.7.1:
299311
version "2.7.3"
300312
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
301313

314+
esprima@~3.1.0:
315+
version "3.1.3"
316+
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"
317+
302318
estraverse@^1.9.1:
303319
version "1.9.3"
304320
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.9.3.tgz#af67f2dc922582415950926091a4005d29c9bb44"
@@ -354,7 +370,7 @@ fs.realpath@^1.0.0:
354370
version "1.0.0"
355371
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
356372

357-
function-bind@^1.1.0:
373+
function-bind@^1.0.2, function-bind@^1.1.0:
358374
version "1.1.0"
359375
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771"
360376

@@ -447,6 +463,12 @@ has-flag@^1.0.0:
447463
version "1.0.0"
448464
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
449465

466+
has@^1.0.1:
467+
version "1.0.1"
468+
resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28"
469+
dependencies:
470+
function-bind "^1.0.2"
471+
450472
hawk@~3.1.3:
451473
version "3.1.3"
452474
resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
@@ -757,6 +779,15 @@ object-keys@^1.0.8:
757779
version "1.0.11"
758780
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
759781

782+
object.entries@^1.0.4:
783+
version "1.0.4"
784+
resolved "https://registry.yarnpkg.com/object.entries/-/object.entries-1.0.4.tgz#1bf9a4dd2288f5b33f3a993d257661f05d161a5f"
785+
dependencies:
786+
define-properties "^1.1.2"
787+
es-abstract "^1.6.1"
788+
function-bind "^1.1.0"
789+
has "^1.0.1"
790+
760791
once@1.x, once@^1.3.0:
761792
version "1.4.0"
762793
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
@@ -799,6 +830,10 @@ prelude-ls@~1.1.2:
799830
version "1.1.2"
800831
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
801832

833+
private@~0.1.5:
834+
version "0.1.7"
835+
resolved "https://registry.yarnpkg.com/private/-/private-0.1.7.tgz#68ce5e8a1ef0a23bb570cc28537b5332aba63ef1"
836+
802837
process-nextick-args@~1.0.6:
803838
version "1.0.7"
804839
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"
@@ -811,16 +846,19 @@ qs@~6.2.0:
811846
version "6.2.1"
812847
resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.1.tgz#ce03c5ff0935bc1d9d69a9f14cbd18e568d67625"
813848

814-
rcs-core@^0.12.0:
815-
version "0.12.0"
816-
resolved "https://registry.yarnpkg.com/rcs-core/-/rcs-core-0.12.0.tgz#2ebaac3a0ca1d0a930b2793d5e3d0b3b77463b66"
849+
rcs-core@1.0.0-alpha.1:
850+
version "1.0.0-alpha.1"
851+
resolved "https://registry.yarnpkg.com/rcs-core/-/rcs-core-1.0.0-alpha.1.tgz#a09005fffa4b2e720501f097e2a60c716a0f7f5c"
817852
dependencies:
818853
array-includes "^3.0.2"
854+
ast-traverse "^0.1.1"
819855
decimal-to-any "1.0.0"
820856
espree "^3.4.3"
821857
fs-extra "^2.0.0"
822858
json-extra "^0.5.0"
823859
lodash "^4.17.4"
860+
object.entries "^1.0.4"
861+
recast "^0.12.5"
824862

825863
readable-stream@~2.0.5:
826864
version "2.0.6"
@@ -833,6 +871,16 @@ readable-stream@~2.0.5:
833871
string_decoder "~0.10.x"
834872
util-deprecate "~1.0.1"
835873

874+
recast@^0.12.5:
875+
version "0.12.5"
876+
resolved "https://registry.yarnpkg.com/recast/-/recast-0.12.5.tgz#1f21a04f0ffd8dea35c222492ffcfe3201c1e977"
877+
dependencies:
878+
ast-types "0.9.11"
879+
core-js "^2.4.1"
880+
esprima "~3.1.0"
881+
private "~0.1.5"
882+
source-map "~0.5.0"
883+
836884
repeat-string@^1.5.2:
837885
version "1.6.1"
838886
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"
@@ -891,7 +939,7 @@ source-map@~0.2.0:
891939
dependencies:
892940
amdefine ">=0.0.4"
893941

894-
source-map@~0.5.1:
942+
source-map@~0.5.0, source-map@~0.5.1:
895943
version "0.5.6"
896944
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
897945

0 commit comments

Comments
 (0)