Skip to content

Commit ed52441

Browse files
authored
Fix travis (#7)
* optmize: optmize fs.sync().mkdir * fix: test travis test * release 0.2.4
1 parent 9fa9fce commit ed52441

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3-
- "0.12"
4-
- "0.10"
53
- "4"
4+
- "6"
5+
- "8"
6+
- "10"

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ install:
77

88
test: install
99
@$(MOCHA) -r jscoverage ./test -R spec
10-
10+
11+
test2:
12+
@$(MOCHA) ./test -R spec
13+
1114
.PHONY: instal test

lib/sync.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ var path = require('path');
88
* @param {Object} [option] file option
99
*/
1010
exports.writeFile = function (fpath, data, option) {
11+
fpath = path.resolve(fpath);
1112
var dir = path.dirname(fpath);
12-
this.mkdir(dir);
13+
exports.mkdir(dir);
1314
fs.writeFileSync(fpath, data, option);
1415
};
1516

@@ -37,7 +38,7 @@ exports.rm = function (fpath) {
3738
ff.forEach(function (v) {
3839
self.rm(path.join(fpath, v));
3940
});
40-
count ++;
41+
count++;
4142
if (count > rm_max) {
4243
throw new Error('rm dir failed:' + fpath);
4344
}
@@ -46,7 +47,7 @@ exports.rm = function (fpath) {
4647

4748
exports.mkdir = function (fpath, mode) {
4849
var p = [];
49-
while (1) {
50+
while (true) {
5051
try {
5152
fs.mkdirSync(fpath);
5253
} catch (e) {
@@ -55,10 +56,12 @@ exports.mkdir = function (fpath, mode) {
5556
} else if (e.code === 'ENOENT') {
5657
p.unshift(fpath);
5758
fpath = path.dirname(fpath);
59+
continue;
5860
} else {
5961
throw e;
6062
}
6163
}
64+
break;
6265
}
6366
p.forEach(function (v) {
6467
fs.mkdirSync(v, mode);
@@ -67,4 +70,4 @@ exports.mkdir = function (fpath, mode) {
6770

6871
exports.copy = function (source, dest) {
6972

70-
};
73+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "fish <[email protected]> (https://github.com/fishbar)",
33
"name": "xfs",
44
"description": "extends fs module, easy way to manipulate file system, support both sync functions and async functions",
5-
"version": "0.2.2",
5+
"version": "0.2.4",
66
"homepage": "https://github.com/fishbar/xfs",
77
"repository": {
88
"type": "git",

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('xfs.sync()', function () {
214214
expect(xfs.readFileSync('./tdir/sync/test.txt').toString()).to.be('abc');
215215
});
216216
if (compareVersion(process.version, 'v0.10.0')) {
217-
it('should ok when save file with option to exist file', function() {
217+
it('should ok when save file with option to exist file', function () {
218218
xfs.sync().save('./tdir/sync/test.txt', 'def', {flag: 'a'});
219219
expect(xfs.readFileSync('./tdir/sync/test.txt').toString()).to.be('abcdef');
220220
});
@@ -225,7 +225,7 @@ describe('xfs.sync()', function () {
225225
});
226226
});
227227
describe('mkdir', function () {
228-
it('should be ok when path not exist', function (){
228+
it('should be ok when path not exist', function () {
229229
var path = './tdir/sync/test';
230230
xfs.sync().mkdir(path);
231231
var stat = xfs.statSync(path);

0 commit comments

Comments
 (0)