Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion src/file.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,61 @@
module.exports = class File {
}
constructor() {
this.sourcePath = '';
this.outputPath = '';
this.content = '';
}

/**
* @returns {string}
*/
getSourcePath() {
return this.sourcePath;
}

/**
* @param {string} path
*
* @returns {File}
*/
setSourcePath(path) {
this.sourcePath = path;

return this;
}

/**
* @returns {string}
*/
getOutputPath() {
return this.outputPath;
}

/**
* @param {string} path
*
* @returns {File}
*/
setOutputPath(path) {
this.outputPath = path;

return this;
}

/**
* @returns {string}
*/
getContent() {
return this.content;
}

/**
* @param {string} content
*
* @returns {File}
*/
setContent(content) {
this.content = content;

return this;
}
};
8 changes: 4 additions & 4 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = class Processor {
}

write() {
this.files.forEach(file => fs.writeFile(file.output, JSON.stringify(file.content, null, 2), 'UTF-8'));
this.files.forEach(file => fs.writeFile(file.getOutputPath(), JSON.stringify(file.getContent(), null, 2), 'UTF-8'));
}

/**
Expand All @@ -41,9 +41,9 @@ module.exports = class Processor {
solvedJson = this.resolveOverwritten(config.envMap),
completedJson = this.constructor.getMergedData(packageJson, solvedJson);

file.source = pathSource;
file.output = pathOutput;
file.content = completedJson;
file.setSourcePath(pathSource)
.setOutputPath(pathOutput)
.setContent(completedJson);

return file;
}
Expand Down
48 changes: 48 additions & 0 deletions tests/file.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";

const File = require('../src/file');

describe('file', () => {
describe('::constructor', () => {
it('fields [content|sourcePath|outputPath] should be defined', () => {
const file = new File();

expect(file.content).toBeDefined();
expect(file.sourcePath).toBeDefined();
expect(file.outputPath).toBeDefined();
})
});

describe('::(get|set)Content', () => {
it('getter should return content, what been set though setter', () => {
const file = new File();
const content = 'test content';

file.setContent(content);

expect(file.getContent()).toMatch(content);
})
});

describe('::(get|set)SourcePath', () => {
it('getter should return content, what been set though setter', () => {
const file = new File();
const content = 'test content';

file.setSourcePath(content);

expect(file.getSourcePath()).toMatch(content);
})
});

describe('::(get|set)OutputPath', () => {
it('getter should return content, what been set though setter', () => {
const file = new File();
const content = 'test content';

file.setOutputPath(content);

expect(file.getOutputPath()).toMatch(content);
})
});
});