Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

The replace property is not mandatory anymore (#57) #86

Merged
merged 3 commits into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var Kubozer = function () {
key: 'replace',
value: function replace() {
this._ensureWorkspace();

var defaultOptions = { files: 'nothing', from: 'nothing', to: 'nothing' };
var optionCSS = {};
var optionJS = {};

Expand All @@ -159,14 +159,10 @@ var Kubozer = function () {
});
}

if (optionJS.files === undefined && optionCSS.files === undefined) {
throw new Error('WARNING REPLACE(): replace method called but "files" not found in configuration');
}

return new Promise(function (resolve, reject) {
try {
var changedCSS = _replaceInFile2.default.sync(optionCSS);
var changedJS = _replaceInFile2.default.sync(optionJS);
var changedCSS = _replaceInFile2.default.sync(optionCSS.files ? optionCSS : defaultOptions);
var changedJS = _replaceInFile2.default.sync(optionJS.files ? optionJS : defaultOptions);

return resolve((0, _result.success)(REPLACE_COMPLETED, { changedCSS: changedCSS, changedJS: changedJS }));
} catch (err) {
Expand Down
10 changes: 3 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Kubozer {

replace() {
this._ensureWorkspace();

const defaultOptions = {files: 'nothing', from: 'nothing', to: 'nothing'};
const optionCSS = {};
const optionJS = {};

Expand Down Expand Up @@ -133,14 +133,10 @@ class Kubozer {
});
}

if (optionJS.files === undefined && optionCSS.files === undefined) {
throw new Error('WARNING REPLACE(): replace method called but "files" not found in configuration');
}

return new Promise((resolve, reject) => {
try {
const changedCSS = replaceInFile.sync(optionCSS);
const changedJS = replaceInFile.sync(optionJS);
const changedCSS = replaceInFile.sync(optionCSS.files ? optionCSS : defaultOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LasaleFamine maybe you can use Ramda's merge method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discuss, we can introduce new logic (and libs) during the refactor.

const changedJS = replaceInFile.sync(optionJS.files ? optionJS : defaultOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LasaleFamine same as previous comment


return resolve(success(REPLACE_COMPLETED, {changedCSS, changedJS}));
} catch (err) {
Expand Down
12 changes: 12 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ test('replace() products correct output', async t => {
t.is(fileReplace, `<!DOCTYPE html><html><head>\n <meta charset=\"utf-8\">\n <title></title>\n\n \n <link rel=\"stylesheet\" href=\"/assets/style.css\">\n \n\n \n <script src=\"/assets/javascript.js\"></script>\n \n\n </head>\n <body>\n\n \n\n</body></html>`);
});

test('when running replace() the "replace" property of configuration is not mandatory', async t => {
const {tmpDir, webpackConfig} = t.context;
const config = hconf(tmpDir, ['FOLDERS', 'VULCANIZE_NO_JS', 'MANIFEST']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LasaleFamine maybe 'MANIFEST' configuration is useless here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now should be correct.

const kubozer = new Kubozer(config, webpackConfig);

const res = await kubozer.replace();
t.deepEqual(res.data.changedCSS, []);
t.deepEqual(res.data.changedJS, []);
t.is(res.message, 'Replace-in-file completed.');
t.is(res.error, undefined);
});

test('correct bump() method', async t => {
const {tmpDir, webpackConfig} = t.context;
const config = hconf(tmpDir, ['FOLDERS', 'BUMP']);
Expand Down