-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement recursive and flat copy (#77)
- Loading branch information
Showing
8 changed files
with
467 additions
and
163 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 |
---|---|---|
|
@@ -12,8 +12,6 @@ jobs: | |
node-version: | ||
- 14 | ||
- 12 | ||
- 10 | ||
- 8 | ||
os: | ||
- ubuntu-latest | ||
- macos-latest | ||
|
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,64 @@ | ||
'use strict'; | ||
const glob = require('globby'); | ||
const junk = require('junk'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
class GlobPattern { | ||
/** | ||
* @param {string} pattern | ||
* @param {string} destination | ||
* @param {import('.').Options} options | ||
*/ | ||
constructor(pattern, destination, options) { | ||
this.path = pattern; | ||
this.originalPath = pattern; | ||
this.destination = destination; | ||
this.options = options; | ||
|
||
if ( | ||
!glob.hasMagic(pattern) && | ||
fs.existsSync(pattern) && | ||
fs.lstatSync(pattern).isDirectory() | ||
) { | ||
this.path = [pattern, '**'].join('/'); | ||
} | ||
} | ||
|
||
get name() { | ||
return path.basename(this.originalPath); | ||
} | ||
|
||
get normalizedPath() { | ||
const segments = this.originalPath.split('/'); | ||
const magicIndex = segments.findIndex(item => item ? glob.hasMagic(item) : false); | ||
const normalized = segments.slice(0, magicIndex).join('/'); | ||
|
||
if (normalized) { | ||
return path.isAbsolute(normalized) ? normalized : path.join(this.options.cwd, normalized); | ||
} | ||
|
||
return this.destination; | ||
} | ||
|
||
hasMagic() { | ||
return glob.hasMagic(this.options.flat ? this.path : this.originalPath); | ||
} | ||
|
||
getMatches() { | ||
let matches = glob.sync(this.path, { | ||
...this.options, | ||
dot: true, | ||
absolute: true, | ||
onlyFiles: true | ||
}); | ||
|
||
if (this.options.ignoreJunk) { | ||
matches = matches.filter(file => junk.not(path.basename(file))); | ||
} | ||
|
||
return matches; | ||
} | ||
} | ||
|
||
module.exports = GlobPattern; |
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
Oops, something went wrong.