Skip to content

Commit

Permalink
Feat: update rcs-core and add parserOptions in processJs (closes #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
JPeer264 committed Jun 18, 2018
1 parent 448747a commit b9a751d
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Options:
- cwd (string): the working directory in which to seach. Default is `process.cwd()`
- newPath (string): in which folder the new files should go. Default is `rcs`
- flatten (boolean): flatten the hierarchie - no subfolders. Default is `false`
- jsx (boolean): if the file is a react jsx file. Default is `false`
- parserOptions (object): all available options from `espree`: Default is [here](https://github.com/JPeer264/node-rcs-core/blob/master/docs/api/replace.md#js)

Example:

Expand Down
12 changes: 8 additions & 4 deletions lib/process/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ const rcsProcess = (pathString, options, cb) => {
if (err) return callback(err);

// check wether to replace javascript files or not
if (options.replaceJs) {
data = rcs.replace.js(bufferData);
} else {
data = rcs.replace.any(bufferData);
try {
if (options.replaceJs) {
data = rcs.replace.js(bufferData, options.parserOptions);
} else {
data = rcs.replace.any(bufferData);
}
} catch (e) {
return callback(e);
}

const joinedPath = path.join(options.newPath, filePath);
Expand Down
14 changes: 7 additions & 7 deletions lib/processJs/tests/processJs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('processJs/processJs', () => {
processJs('js/react.txt', {
newPath: testCwd,
cwd: fixturesCwd,
jsx: true,
}, err => {
let newFile = fs.readFileSync(testCwd + '/js/react.txt', 'utf8');
let expectedFile = fs.readFileSync(resultsCwd + '/js/react.txt', 'utf8');
Expand All @@ -60,12 +59,13 @@ describe('processJs/processJs', () => {
processJs('js/react.txt', {
newPath: testCwd,
cwd: fixturesCwd,
parserOptions: {
ecmaFeatures: {
jsx: false,
},
},
}, err => {
let newFile = fs.readFileSync(testCwd + '/js/react.txt', 'utf8');
let expectedFile = fs.readFileSync(testCwd + '/js/react.txt', 'utf8');

expect(err).to.not.exist;
expect(newFile).to.equal(expectedFile);
expect(err).to.exist;

done();
});
Expand All @@ -77,7 +77,7 @@ describe('processJs/processJs', () => {
cwd: fixturesCwd,
}, err => {
let newFile = fs.readFileSync(testCwd + '/js/complex.txt', 'utf8');
let expectedFile = fs.readFileSync(testCwd + '/js/complex.txt', 'utf8');
let expectedFile = fs.readFileSync(resultsCwd + '/js/complex.txt', 'utf8');

expect(err).to.not.exist;
expect(newFile).to.equal(expectedFile);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"glob": "^7.1.1",
"json-extra": "^0.5.0",
"lodash": "^4.17.4",
"rcs-core": "^2.0.1"
"rcs-core": "^2.1.0"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down
8 changes: 8 additions & 0 deletions test/files/fixtures/js/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ $(".jp-block");
// vanillaJS example
document.getElementsByClassName(" jp-block__element");
document.getElementById("jp-block__element--modifier");

const restSpread = {
weirdFormatting: true,
shouldRest: true,
};

const extended = { ...restSpread };
const { ...options } = extended;
8 changes: 8 additions & 0 deletions test/files/results/js/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ $(".a");
// vanillaJS example
document.getElementsByClassName(" b");
document.getElementById("c");

const restSpread = {
weirdFormatting: true,
shouldRest: true,
};

const extended = { ...restSpread };
const { ...options } = extended;
54 changes: 28 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ acorn@^5.0.1:
version "5.0.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.0.3.tgz#c460df08491463f028ccb82eab3730bf01087b3d"

acorn@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8"

ajv-keywords@^1.0.0:
version "1.5.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c"
Expand Down Expand Up @@ -127,9 +131,9 @@ ast-traverse@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ast-traverse/-/ast-traverse-0.1.1.tgz#69cf2b8386f19dcda1bb1e05d68fe359d8897de6"

ast-types@0.9.11:
version "0.9.11"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.11.tgz#371177bb59232ff5ceaa1d09ee5cad705b1a5aa9"
ast-types@0.11.5:
version "0.11.5"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.5.tgz#9890825d660c03c28339f315e9fa0a360e31ec28"

async@1.x, async@^1.4.0:
version "1.5.2"
Expand Down Expand Up @@ -342,10 +346,6 @@ contains-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/contains-path/-/contains-path-0.1.0.tgz#fe8cf184ff6670b6baef01a9d4861a5cbec4120a"

core-js@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e"

core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down Expand Up @@ -572,18 +572,21 @@ espree@^3.4.3:
acorn "^5.0.1"
acorn-jsx "^3.0.0"

espree@^3.5.4:
version "3.5.4"
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7"
dependencies:
acorn "^5.5.0"
acorn-jsx "^3.0.0"

esprima@2.7.x, esprima@^2.6.0, esprima@^2.7.1:
version "2.7.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"

esprima@^4.0.0:
esprima@^4.0.0, esprima@~4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"

esprima@~3.1.0:
version "3.1.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"

esquery@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.0.tgz#cfba8b57d7fba93f17298a8a006a04cda13d80fa"
Expand Down Expand Up @@ -1452,20 +1455,20 @@ qs@~6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.1.tgz#ce03c5ff0935bc1d9d69a9f14cbd18e568d67625"

rcs-core@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/rcs-core/-/rcs-core-2.0.1.tgz#b4ec1b9b5e3a3919397ca0dfc68779d22a358e75"
rcs-core@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/rcs-core/-/rcs-core-2.1.0.tgz#eb5fcfdeaf53e79e94a00fc9f8f56b3c253cdf4e"
dependencies:
array-includes "^3.0.2"
ast-traverse "^0.1.1"
decimal-to-any "1.0.0"
espree "^3.4.3"
espree "^3.5.4"
fs-extra "^2.0.0"
json-extra "^0.5.0"
lodash.merge "^4.6.1"
object.entries "^1.0.4"
postcss "^6.0.17"
recast "^0.12.5"
recast "^0.15.0"

read-pkg-up@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -1505,15 +1508,14 @@ readable-stream@~2.0.5:
string_decoder "~0.10.x"
util-deprecate "~1.0.1"

recast@^0.12.5:
version "0.12.5"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.12.5.tgz#1f21a04f0ffd8dea35c222492ffcfe3201c1e977"
recast@^0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.15.0.tgz#b8c8bfdda245e1580c0a4d9fc25d4e820bf57208"
dependencies:
ast-types "0.9.11"
core-js "^2.4.1"
esprima "~3.1.0"
ast-types "0.11.5"
esprima "~4.0.0"
private "~0.1.5"
source-map "~0.5.0"
source-map "~0.6.1"

repeat-string@^1.5.2:
version "1.6.1"
Expand Down Expand Up @@ -1629,7 +1631,7 @@ source-map@^0.4.4:
dependencies:
amdefine ">=0.0.4"

source-map@^0.6.1:
source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"

Expand All @@ -1639,7 +1641,7 @@ source-map@~0.2.0:
dependencies:
amdefine ">=0.0.4"

source-map@~0.5.0, source-map@~0.5.1:
source-map@~0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

Expand Down

0 comments on commit b9a751d

Please sign in to comment.