-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ES2015): rewrite in ES2015 + improved build process
- rewrite in ES2015 - only build for LTS versions of node - updated semantic-release no longer needing after_all script - set package version to 0.0.0-development to avoid local build issues - ignore building new greenkeeper branches BREAKING CHANGE: this is re-write, though the API has not changed, check the README for install instructions
- Loading branch information
Ahmad Nassri
committed
Nov 19, 2016
1 parent
5d9007e
commit df068e7
Showing
12 changed files
with
177 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"env": { | ||
"test": { | ||
"presets": [ ["env", { "targets": { "node": "current" } }] ], | ||
"plugins": [] | ||
}, | ||
|
||
"browsers": { | ||
"presets": [ ["env", { "targets": { "browsers": ["last 2 versions"] } }] ], | ||
"plugins": ["babel-plugin-add-module-exports"] | ||
}, | ||
|
||
"v4": { | ||
"presets": [ ["env", { "targets": { "node": 4.0 } }] ], | ||
"plugins": ["babel-plugin-add-module-exports"] | ||
}, | ||
|
||
"v6": { | ||
"presets": [ ["env", { "targets": { "node": 6.0 } }] ], | ||
"plugins": ["babel-plugin-add-module-exports"] | ||
}, | ||
|
||
"v7": { | ||
"presets": [ ["env", { "targets": { "node": 7.0 } }] ], | ||
"plugins": ["babel-plugin-add-module-exports"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
engines: | ||
fixme: | ||
enabled: true | ||
|
||
duplication: | ||
enabled: true | ||
config: | ||
languages: | ||
- javascript | ||
|
||
eslint: | ||
enabled: true | ||
|
||
ratings: | ||
paths: | ||
- src/** | ||
- test/** |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.log | ||
node_modules | ||
coverage | ||
/lib | ||
/node_modules | ||
/.nyc_output |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
sudo: false | ||
|
||
language: node_js | ||
|
||
node_js: | ||
- 4 | ||
- 6 | ||
- 7 | ||
|
||
env: | ||
- BABEL_ENV=test | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
cache: | ||
directories: | ||
- node_modules | ||
|
||
after_script: | ||
before_script: | ||
- npm prune | ||
|
||
after_success: | ||
- npm run coverage | ||
- npm run codeclimate | ||
- BABEL_ENV=v4 npm run compile -- -d lib | ||
- BABEL_ENV=v6 npm run compile -- -d lib/node6 | ||
- BABEL_ENV=v7 npm run compile -- -d lib/node7 | ||
- BABEL_ENV=browsers npm run compile -- -d lib/browsers | ||
- npm run semantic-release | ||
|
||
branches: | ||
except: | ||
- /^v\d+\.\d+\.\d+$/ | ||
- /^greenkeeper\/.+/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,66 @@ | ||
{ | ||
"version": "1.0.3", | ||
"version": "0.0.0-development", | ||
"name": "fs-writefile-promise", | ||
"description": "Promise version of fs.writefile", | ||
"author": "Ahmad Nassri <[email protected]> (https://www.ahmadnassri.com/)", | ||
"homepage": "https://github.com/ahmadnassri/fs-writefile-promise", | ||
"repository": "ahmadnassri/fs-writefile-promise", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ahmadnassri/fs-writefile-promise.git" | ||
}, | ||
"license": "ISC", | ||
"main": "lib/index", | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
"fs-writefile", | ||
"promise" | ||
], | ||
"engines": { | ||
"node": ">= 4" | ||
"node": ">=4" | ||
}, | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"src" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/ahmadnassri/fs-writefile-promise/issues" | ||
}, | ||
"scripts": { | ||
"pretest": "standard && echint --verbose", | ||
"test": "mocha", | ||
"posttest": "npm run coverage", | ||
"coverage": "istanbul cover --dir coverage _mocha -- -R dot", | ||
"codeclimate": "codeclimate-test-reporter < coverage/lcov.info" | ||
"compile": "babel -q src", | ||
"test": "BABEL_ENV=test tap test/*.js --reporter spec --node-arg=--require --node-arg=babel-register", | ||
"pretest": "snazzy && echint", | ||
"coverage": "BABEL_ENV=test tap test/*.js --coverage --nyc-arg=--require --nyc-arg=babel-register", | ||
"codeclimate": "nyc report --reporter=text-lcov | codeclimate-test-reporter", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"lib/**" | ||
] | ||
}, | ||
"echint": { | ||
"ignore": [ | ||
"coverage/**" | ||
"lib/**" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"devDependencies": { | ||
"codeclimate-test-reporter": "0.1.1", | ||
"echint": "^1.2.0", | ||
"istanbul": "^0.3.15", | ||
"mocha": "^3.0.1", | ||
"rimraf": "^2.4.0", | ||
"should": "^11.0.0", | ||
"standard": "^8.0.0" | ||
"babel-cli": "^6.18.0", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-preset-env": "0.0.8", | ||
"babel-register": "^6.18.0", | ||
"codeclimate-test-reporter": "^0.4.0", | ||
"cz-conventional-changelog": "^1.2.0", | ||
"echint": "^1.5.3", | ||
"rimraf": "^2.5.4", | ||
"semantic-release": "^6.3.2", | ||
"snazzy": "^5.0.0", | ||
"tap": "^8.0.1" | ||
}, | ||
"dependencies": { | ||
"mkdirp-promise": "^3.0.1", | ||
"pinkie-promise": "^1.0.0" | ||
"mkdirp-promise": "^4.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import fs from 'fs' | ||
|
||
export default function (filename, data, options) { | ||
return new Promise(function (resolve, reject) { | ||
fs.writeFile(filename, data, options, (err) => err === null ? resolve(filename) : reject(err)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,43 @@ | ||
/* global afterEach, describe, it */ | ||
import fs from 'fs' | ||
import mkdirp from 'mkdirp-promise' | ||
import path from 'path' | ||
import rimraf from 'rimraf' | ||
import write from '../src' | ||
import { test } from 'tap' | ||
|
||
'use strict' | ||
const tmp = path.join('test', 'tmp') | ||
|
||
var fs = require('fs') | ||
var mkdirp = require('mkdirp-promise') | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
var write = require('..') | ||
test('fs-writefile-promise', (tap) => { | ||
tap.plan(3) | ||
tap.afterEach((done) => rimraf(tmp, done)) | ||
|
||
require('should') | ||
tap.test('successfully write file', (assert) => { | ||
assert.plan(2) | ||
|
||
var tmp = path.join('test', 'tmp') | ||
|
||
afterEach(function (done) { | ||
rimraf(tmp, done) | ||
}) | ||
|
||
describe('node module', function () { | ||
it('should successfully write file', function (done) { | ||
var target = path.join(tmp, 'foo') | ||
let target = path.join(tmp, 'foo') | ||
|
||
mkdirp(tmp) | ||
.then(function () { | ||
return write(target, 'bar') | ||
}) | ||
.then(function (filename) { | ||
return fs.readFileSync(filename) | ||
}) | ||
.then(function (content) { | ||
content.should.be.a.Buffer | ||
content.toString().should.eql('bar') | ||
|
||
done() | ||
.then(() => write(target, 'bar')) | ||
.then((filename) => fs.readFileSync(filename)) | ||
.then((content) => { | ||
assert.type(content, Buffer) | ||
assert.equal(content.toString(), 'bar') | ||
}) | ||
}) | ||
|
||
it('should throw a type error when the path isn\'t a string', function (done) { | ||
write(false, 'foo') | ||
.catch(function (err) { | ||
err.message.should.equal('path must be a string') | ||
tap.test("throw a type error when the path isn't a string", (assert) => { | ||
assert.plan(1) | ||
|
||
done() | ||
}) | ||
write(false, 'foo') | ||
.catch((err) => assert.match(err.message, 'path must be a string')) | ||
}) | ||
|
||
it('should throw an error when the encoding is not supported', function (done) { | ||
var target = path.join(tmp, 'fake', 'path') | ||
tap.test('throw an error when the encoding is not supported', (assert) => { | ||
assert.plan(1) | ||
|
||
write(target, 'foo') | ||
.catch(function (err) { | ||
err.code.should.equal('ENOENT') | ||
let target = path.join(tmp, 'fake', 'path') | ||
|
||
done() | ||
}) | ||
write(target, 'foo') | ||
.catch((err) => assert.equal(err.code, 'ENOENT')) | ||
}) | ||
}) |