Skip to content

Commit 214381f

Browse files
Merge pull request #9 from explore-node-js/master
sync. with main repository
2 parents ff252a5 + 4229b79 commit 214381f

File tree

3 files changed

+112
-5
lines changed

3 files changed

+112
-5
lines changed

src/file.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
module.exports = class File {
2-
}
2+
constructor() {
3+
this.sourcePath = '';
4+
this.outputPath = '';
5+
this.content = '';
6+
}
7+
8+
/**
9+
* @returns {string}
10+
*/
11+
getSourcePath() {
12+
return this.sourcePath;
13+
}
14+
15+
/**
16+
* @param {string} path
17+
*
18+
* @returns {File}
19+
*/
20+
setSourcePath(path) {
21+
this.sourcePath = path;
22+
23+
return this;
24+
}
25+
26+
/**
27+
* @returns {string}
28+
*/
29+
getOutputPath() {
30+
return this.outputPath;
31+
}
32+
33+
/**
34+
* @param {string} path
35+
*
36+
* @returns {File}
37+
*/
38+
setOutputPath(path) {
39+
this.outputPath = path;
40+
41+
return this;
42+
}
43+
44+
/**
45+
* @returns {string}
46+
*/
47+
getContent() {
48+
return this.content;
49+
}
50+
51+
/**
52+
* @param {string} content
53+
*
54+
* @returns {File}
55+
*/
56+
setContent(content) {
57+
this.content = content;
58+
59+
return this;
60+
}
61+
};

src/processor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = class Processor {
1919
}
2020

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

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

44-
file.source = pathSource;
45-
file.output = pathOutput;
46-
file.content = completedJson;
44+
file.setSourcePath(pathSource)
45+
.setOutputPath(pathOutput)
46+
.setContent(completedJson);
4747

4848
return file;
4949
}

tests/file.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"use strict";
2+
3+
const File = require('../src/file');
4+
5+
describe('file', () => {
6+
describe('::constructor', () => {
7+
it('fields [content|sourcePath|outputPath] should be defined', () => {
8+
const file = new File();
9+
10+
expect(file.content).toBeDefined();
11+
expect(file.sourcePath).toBeDefined();
12+
expect(file.outputPath).toBeDefined();
13+
})
14+
});
15+
16+
describe('::(get|set)Content', () => {
17+
it('getter should return content, what been set though setter', () => {
18+
const file = new File();
19+
const content = 'test content';
20+
21+
file.setContent(content);
22+
23+
expect(file.getContent()).toMatch(content);
24+
})
25+
});
26+
27+
describe('::(get|set)SourcePath', () => {
28+
it('getter should return content, what been set though setter', () => {
29+
const file = new File();
30+
const content = 'test content';
31+
32+
file.setSourcePath(content);
33+
34+
expect(file.getSourcePath()).toMatch(content);
35+
})
36+
});
37+
38+
describe('::(get|set)OutputPath', () => {
39+
it('getter should return content, what been set though setter', () => {
40+
const file = new File();
41+
const content = 'test content';
42+
43+
file.setOutputPath(content);
44+
45+
expect(file.getOutputPath()).toMatch(content);
46+
})
47+
});
48+
});

0 commit comments

Comments
 (0)