Skip to content

Commit 59e82f6

Browse files
committed
first commit
0 parents  commit 59e82f6

25 files changed

+353
-0
lines changed

.editorconfig

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
end_of_line = lf
7+
charset = utf-8
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
insert_final_newline = false
15+
16+
[{,test/}{actual,fixtures}/**]
17+
trim_trailing_whitespace = false
18+
insert_final_newline = false
19+
20+
[templates/**]
21+
trim_trailing_whitespace = false
22+
insert_final_newline = false

.gitattributes

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Enforce Unix newlines
2+
* text eol=lf
3+
4+
# binaries
5+
*.ai binary
6+
*.psd binary
7+
*.jpg binary
8+
*.gif binary
9+
*.png binary
10+
*.jpeg binary

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.DS_Store
2+
*.sublime-*
3+
_gh_pages
4+
bower_components
5+
node_modules
6+
npm-debug.log
7+
actual
8+
test/actual
9+
temp
10+
tmp
11+
TODO.md
12+
vendor
13+
.idea
14+
benchmark
15+
coverage

.jshintrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"asi": false,
3+
"boss": true,
4+
"curly": true,
5+
"eqeqeq": true,
6+
"eqnull": true,
7+
"esnext": true,
8+
"immed": true,
9+
"latedef": false,
10+
"laxcomma": false,
11+
"mocha": true,
12+
"newcap": true,
13+
"noarg": true,
14+
"node": true,
15+
"sub": true,
16+
"undef": true,
17+
"unused": true
18+
}

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "0.10"
5+
- "0.12"
6+
- "0.13"
7+
- "iojs"
8+
matrix:
9+
fast_finish: true
10+
allow_failures:
11+
- node_js: "0.13"

.verb.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# {%= name %} {%= badge("fury") %}
2+
3+
> {%= description %}
4+
5+
## Install
6+
{%= include("install-npm", {save: true}) %}
7+
8+
## Usage
9+
10+
```js
11+
var copy = require('{%= name %}');
12+
```
13+
14+
## API
15+
<!-- add a path or glob pattern for files with code comments to use for docs -->
16+
{%%= apidocs("index.js") %}
17+
18+
## Related projects
19+
<!-- add an array of related projects, then un-escape the helper -->
20+
{%%= related([]) %}
21+
22+
## Running tests
23+
{%= include("tests") %}
24+
25+
## Contributing
26+
{%= include("contributing") %}
27+
28+
## Author
29+
{%= include("author") %}
30+
31+
## License
32+
{%= copyright() %}
33+
{%= license() %}
34+
35+
***
36+
37+
{%= include("footer") %}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015, Jon Schlinkert.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

examples/copy-dir-sync.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
var copy = require('..');
4+
5+
copy.dirSync('fixtures', 'actual');

examples/copy-dir.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
var copy = require('..');
4+
5+
copy.dir('fixtures', 'actual', function (err) {
6+
if (err) {
7+
console.error(err);
8+
}
9+
});

examples/copy-one-sync.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
var copy = require('..');
4+
5+
copy.oneSync('fixtures/a.txt', 'actual');

examples/copy-one.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
var copy = require('..');
4+
5+
copy.one('fixtures/a.txt', 'actual', function (err) {
6+
if (err) {
7+
console.error(err);
8+
}
9+
});

examples/copy-sync.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
var copy = require('..');
4+
5+
copy.sync('fixtures/*.txt', 'actual/nested/nested-deeper');

examples/copy.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
var copy = require('..');
4+
5+
copy('fixtures/*.txt', 'actual/nested/nested-deeper', function (err) {
6+
if (err) {
7+
console.error(err);
8+
}
9+
});

fixtures/a.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AAA
2+
AAA

fixtures/b.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BBB

fixtures/c.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CCC

fixtures/nested/d.txt

Whitespace-only changes.

fixtures/nested/e.txt

Whitespace-only changes.

fixtures/nested/f.txt

Whitespace-only changes.

fixtures/nested/nested-deeper/g.txt

Whitespace-only changes.

fixtures/nested/nested-deeper/h.txt

Whitespace-only changes.

fixtures/nested/nested-deeper/i.txt

Whitespace-only changes.

index.js

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
'use strict';
2+
3+
var fs = require('graceful-fs');
4+
var path = require('path');
5+
var glob = require('lazy-globby');
6+
var extend = require('extend-shallow');
7+
var each = require('async-each');
8+
var mkdir = require('mkdirp');
9+
var lookup = require('./lookup');
10+
11+
module.exports = copy;
12+
13+
function copy(patterns, dest, options, cb) {
14+
if (typeof options === 'function') {
15+
cb = options;
16+
options = {};
17+
}
18+
19+
var opts = defaults(options);
20+
21+
glob()(patterns, opts, function (err, files) {
22+
each(files, function (fp, next) {
23+
fp = path.resolve(opts.cwd, fp);
24+
25+
copy.one(fp, dest, opts, next);
26+
}, cb);
27+
});
28+
}
29+
30+
copy.sync = function copySync(patterns, dest, options) {
31+
var opts = defaults(options);
32+
33+
glob().sync(patterns, opts).forEach(function (fp) {
34+
try {
35+
copy.oneSync(fp, dest, opts);
36+
} catch (err) {
37+
throw new Error(err);
38+
}
39+
});
40+
};
41+
42+
copy.dir = function(dirname, dest, options, cb) {
43+
if (typeof options === 'function') {
44+
cb = options;
45+
options = {};
46+
}
47+
48+
var opts = defaults(options);
49+
50+
lookup(dirname, function (err, files) {
51+
each(files, function (fp, next) {
52+
fp = path.resolve(opts.cwd, fp);
53+
54+
copy.one(fp, dest, opts, next);
55+
}, cb);
56+
});
57+
};
58+
59+
copy.dirSync = function dirSync(dirname, dest, options) {
60+
var opts = defaults(options);
61+
lookup.sync(dirname).forEach(function (fp) {
62+
copy.oneSync(fp, dest, opts);
63+
});
64+
};
65+
66+
copy.one = function copyOne(fp, dest, options, cb) {
67+
if (typeof options === 'function') {
68+
cb = options;
69+
options = {};
70+
}
71+
72+
var opts = defaults(options);
73+
74+
mkdir(dest, opts, function (err) {
75+
if (err) return cb(err);
76+
77+
try {
78+
fp = path.resolve(opts.cwd, fp);
79+
var res = opts.rename(fp, dest);
80+
copyBase(fp, res);
81+
return cb();
82+
} catch(err) {
83+
return cb(err);
84+
}
85+
});
86+
};
87+
88+
copy.oneSync = function copyOneSync(fp, dest, options) {
89+
var opts = defaults(options);
90+
try {
91+
fp = path.resolve(opts.cwd, fp);
92+
mkdir.sync(dest, opts);
93+
var res = opts.rename(fp, dest);
94+
copyBase(fp, res);
95+
} catch (err) {
96+
throw new Error(err);
97+
}
98+
};
99+
100+
function rename(fp, dest) {
101+
return path.resolve(dest, path.basename(fp));
102+
}
103+
104+
function copyBase(src, dest) {
105+
fs.createReadStream(src).pipe(fs.createWriteStream(dest));
106+
}
107+
108+
function defaults(options) {
109+
return extend({cwd: process.cwd(), rename: rename}, options);
110+
}

package.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "copy",
3+
"description": "Copy files or directories using globs.",
4+
"version": "0.1.0",
5+
"homepage": "https://github.com/jonschlinkert/copy",
6+
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7+
"repository": "jonschlinkert/copy",
8+
"bugs": {
9+
"url": "https://github.com/jonschlinkert/copy/issues"
10+
},
11+
"license": "MIT",
12+
"files": [
13+
"index.js"
14+
],
15+
"main": "index.js",
16+
"engines": {
17+
"node": ">=0.10.0"
18+
},
19+
"scripts": {
20+
"test": "mocha"
21+
},
22+
"dependencies": {
23+
"async": "^1.3.0",
24+
"async-each": "^0.1.6",
25+
"bluebird": "^2.9.30",
26+
"extend-shallow": "^2.0.0",
27+
"globby": "^2.1.0",
28+
"graceful-fs": "^4.1.2",
29+
"lazy-globby": "^0.1.1",
30+
"mkdirp": "^0.5.1"
31+
},
32+
"devDependencies": {
33+
"mocha": "*",
34+
"should": "*"
35+
},
36+
"keywords": []
37+
}

test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*!
2+
* copy <https://github.com/jonschlinkert/copy>
3+
*
4+
* Copyright (c) 2015 .
5+
* Licensed under the MIT license.
6+
*/
7+
8+
'use strict';
9+
10+
/* deps:mocha */
11+
var assert = require('assert');
12+
var should = require('should');
13+
var copy = require('./');
14+
15+
describe('copy', function () {
16+
it('should:', function () {
17+
copy('a').should.eql({a: 'b'});
18+
copy('a').should.equal('a');
19+
});
20+
21+
it('should throw an error:', function () {
22+
(function () {
23+
copy();
24+
}).should.throw('copy expects valid arguments');
25+
});
26+
});

0 commit comments

Comments
 (0)