initial commit

This commit is contained in:
dude
2026-09-01 18:33:56 +00:00
commit c24449ee0a
2761 changed files with 302737 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
{"node":true}
+2
View File
@@ -0,0 +1,2 @@
node_modules
*.swp
+14
View File
@@ -0,0 +1,14 @@
language: node_js
sudo: false
node_js:
- "4"
- "5"
- "6"
- "7"
env:
- ANY_PROMISE=
- ANY_PROMISE=es6-promise
- ANY_PROMISE=bluebird
- ANY_PROMISE=rsvp
- ANY_PROMISE=when
- ANY_PROMISE=q
+19
View File
@@ -0,0 +1,19 @@
Copyright (C) 2013 Kevin Beaty
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+6
View File
@@ -0,0 +1,6 @@
# fs-promise
`fs-promise` is now *deprecated*. Use [`mz/fs`][1] [`fs-extra^3.0`][2].
[1]: https://github.com/normalize/mz
[2]: https://www.npmjs.org/package/fs-extra
+58
View File
@@ -0,0 +1,58 @@
// Type definitions for fs-promise 1.0
// Project: https://github.com/kevinbeaty/fs-promise#readme
// Definitions by: Thiago de Arruda <https://github.com/tarruda>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export * from "mz/fs";
export * from "fs-extra";
export interface WriteOptions {
encoding?: string;
mode?: number;
flag?: string;
}
type JsonReplacerArray = Array<number | string>;
type JsonReplacerFunction = (key: string, value: any) => any;
type JsonReplacer = JsonReplacerArray | JsonReplacerFunction;
export interface WriteJsonOptions extends WriteOptions {
spaces?: number;
replacer?: JsonReplacer;
}
export interface ReadJsonOptions {
encoding: string;
flag?: string;
reviver: (key: any, value: any) => any;
}
export function copy(src: string, dst: string): Promise<void>;
export function emptyDir(dir: string): Promise<void>;
export function ensureFile(file: string): Promise<void>;
export function ensureDir(dir: string): Promise<void>;
export function ensureLink(srcpath: string, dstpath: string): Promise<void>;
export function ensureSymlink(srcpath: string, dstpath: string, type?: "dir" | "file" | "junction"): Promise<void>;
export function mkdirs(dir: string): Promise<void>;
export function move(src: string, dst: string): Promise<void>;
export function outputFile(file: string, data: string | Buffer, options?: WriteOptions): Promise<void>;
export function outputJson(file: string, data: any, options?: WriteJsonOptions): Promise<void>;
export function readJson(file: string, options?: ReadJsonOptions): Promise<any>;
export function remove(path: string): Promise<void>;
export function writeJson(file: string, data: any, options?: WriteJsonOptions): Promise<void>;
// aliases
export {
emptyDir as emptydir,
ensureFile as createFile,
ensureLink as createLink,
ensureSymlink as createSymlink,
mkdirs as mkdirp,
outputJson as outputJSON,
readJson as readJSON,
writeJson as writeJSON
};
+76
View File
@@ -0,0 +1,76 @@
'use strict'
var mzfs = require('mz/fs')
var fsExtra = require('fs-extra')
var Promise = require('any-promise')
var thenifyAll = require('thenify-all')
var slice = Array.prototype.slice
// thenify-all for all fs-extra that make sense to be promises
var fsExtraKeys = [
'copy',
'emptyDir',
'ensureFile',
'ensureDir',
'ensureLink',
'ensureSymlink',
'mkdirs',
'move',
'outputFile',
'outputJson',
'readJson',
'remove',
'writeJson',
// aliases
'createFile',
'createLink',
'createSymlink',
'emptydir',
'mkdirp',
'readJSON',
'outputJSON',
'writeJSON'
]
thenifyAll.withCallback(fsExtra, exports, fsExtraKeys)
// Delegate all normal fs to mz/fs
// (this overwrites anything proxies directly above)
var mzKeys = [
'rename',
'ftruncate',
'chown',
'fchown',
'lchown',
'chmod',
'fchmod',
'stat',
'lstat',
'fstat',
'link',
'symlink',
'readlink',
'realpath',
'unlink',
'rmdir',
'mkdir',
'mkdtemp',
'readdir',
'close',
'open',
'utimes',
'futimes',
'fsync',
'fdatasync',
'write',
'read',
'readFile',
'writeFile',
'appendFile',
'access',
'truncate',
'exists'
]
mzKeys.forEach(function(key){
exports[key] = mzfs[key]
})
+37
View File
@@ -0,0 +1,37 @@
{
"name": "fs-promise",
"version": "2.0.3",
"description": "[DEPRECATED] Use mz or fs-extra^3.0 with Promise Support",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "https://github.com/kevinbeaty/fs-promise.git"
},
"keywords": [
"promise",
"fs",
"file",
"file system"
],
"author": "Kevin Beaty",
"license": "MIT",
"dependencies": {
"any-promise": "^1.3.0",
"fs-extra": "^2.0.0",
"mz": "^2.6.0",
"thenify-all": "^1.6.0"
},
"devDependencies": {
"@types/fs-extra": "0.0.37",
"@types/mz": "0.0.30",
"mocha": "^3.0.0",
"es6-promise": "^4.0.0",
"rsvp": "^3.0.0",
"bluebird": "^3.0.0",
"when": "^3.0.0",
"q": "^1.0.0"
}
}
+119
View File
@@ -0,0 +1,119 @@
'use strict';
/*globals describe, it, beforeEach, afterEach */
var fsp = require('..'),
path = require('path'),
assert = require('assert'),
Prom = require('any-promise'),
testdir = path.join(__dirname, 'tmp'),
testdir2 = path.join(__dirname, 'tmp2')
describe('basic', function(){
beforeEach(function(){
return fsp.mkdir(testdir).then(existstmp(true));
});
afterEach(function(){
return fsp.remove(testdir).then(existstmp(false));
});
it('should create files and readdir', function(){
return fsp.ensureFile(file('hello')).then(readtmp).then(function(files){
assert.deepEqual(files.sort(), ['hello']);
return fsp.ensureFile(file('world'));
}).then(readtmp).then(function(files){
assert.deepEqual(files.sort(), ['hello', 'world']);
return fsp.exists(testdir2)
}).then(function(exists){
assert.equal(exists, false);
return fsp.move(testdir, testdir2)
}).then(function(){
return Prom.all([fsp.exists(testdir), fsp.exists(testdir2)])
}).then(function(exists){
return assert.deepEqual(exists, [false, true])
}).then(function(){
return fsp.copy(testdir2, testdir)
}).then(function(){
return Prom.all([fsp.exists(testdir), fsp.exists(testdir2)])
}).then(function(exists){
return assert.deepEqual(exists, [true, true])
}).then(readtmps).then(function(files){
assert.deepEqual(files[0].sort(), files[1].sort());
return fsp.emptyDir(testdir2);
}).then(readtmp2).then(function(files){
assert.deepEqual(files, []);
}).then(function(){
fsp.remove(testdir2);
})
});
it('should pass through Sync as value', function(){
return fsp.ensureFile(file('hello')).then(function(files){
assert(fsp.existsSync(file('hello')));
assert(!fsp.existsSync(file('world')));
return fsp.ensureFile(file('world'));
}).then(readtmp).then(function(files){
assert(fsp.existsSync(file('hello')));
assert(fsp.existsSync(file('world')));
});
});
it('should copy with pipe read/write stream', function(){
return fsp.writeFile(file('hello1'), 'hello world').then(function(){
return fsp.readFile(file('hello1'), {encoding:'utf8'});
}).then(function(contents){
assert.equal(contents, 'hello world');
var read = fsp.createReadStream(file('hello1')),
write = fsp.createWriteStream(file('hello2')),
promise = new Prom(function(resolve, reject){
read.on('end', resolve);
write.on('error', reject);
read.on('error', reject);
});
read.pipe(write);
return promise;
}).then(function(){
return fsp.readFile(file('hello2'), {encoding:'utf8'});
}).then(function(contents){
assert.equal(contents, 'hello world');
});
});
it('should pass third argument from write #7', function testWriteFsp() {
return fsp.open(file('some.txt'), 'w+').then(function (fd){
return fsp.write(fd, "hello fs-promise").then(function(result) {
var written = result[0];
var text = result[1];
assert.equal(text.substring(0, written), "hello fs-promise".substring(0, written))
return fsp.close(fd);
})
})
});
});
function file(){
var args = [].slice.call(arguments);
args.unshift(testdir);
return path.join.apply(path, args);
}
function existstmp(shouldExist){
return function(){
return fsp.exists(testdir).then(function(exists){
assert.equal(exists, shouldExist);
});
};
}
function readtmp(){
return fsp.readdir(testdir);
}
function readtmp2(){
return fsp.readdir(testdir2);
}
function readtmps(){
return Prom.all([readtmp(), readtmp2()]);
}
+6
View File
@@ -0,0 +1,6 @@
--no-colors
--ui bdd
--reporter spec
--require test/register
test/basic.js
test/mz.js
+57
View File
@@ -0,0 +1,57 @@
// Tests from mz. License MIT
// https://github.com/normalize/mz
var assert = require('assert')
describe('fs', function () {
var fs = require('../')
it('.stat()', function (done) {
fs.stat(__filename).then(function (stats) {
assert.equal(typeof stats.size, 'number')
done()
}).catch(done)
})
it('.mkdtemp()', function (done) {
if (!require('fs').mkdtemp) this.skip()
fs.mkdtemp('/tmp/').then(function (folder) {
fs.rmdirSync(folder)
done()
}).catch(done)
})
it('.statSync()', function () {
var stats = fs.statSync(__filename)
assert.equal(typeof stats.size, 'number')
})
it('.exists()', function (done) {
fs.exists(__filename).then(function (exists) {
assert(exists)
done()
}).catch(done)
})
it('.existsSync()', function () {
var exists = fs.existsSync(__filename)
assert(exists)
})
describe('callback support', function () {
it('.stat()', function (done) {
fs.stat(__filename, function (err, stats) {
assert(!err)
assert.equal(typeof stats.size, 'number')
done()
})
})
it('.exists()', function (done) {
fs.exists(__filename, function (err, exists) {
assert(!err)
assert(exists)
done()
})
})
})
})
+16
View File
@@ -0,0 +1,16 @@
'use strict';
var expectedImpl
if(process.env.ANY_PROMISE){
// should load registration regardless
expectedImpl = process.env.ANY_PROMISE
require('any-promise/register')(expectedImpl)
} else {
expectedImpl = 'global.Promise'
}
var impl = require('any-promise/implementation')
if(impl !== expectedImpl){
throw new Error('Expecting '+expectedImpl+' got '+impl)
}