-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper for copying files and dirs
- Loading branch information
1 parent
17b8299
commit fbbe36f
Showing
6 changed files
with
61 additions
and
2 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
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 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 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,34 @@ | ||
// utility packages | ||
const fs = require('fs-extra'); | ||
const ora = require('ora'); | ||
|
||
// internal | ||
const { COPY_SUCCESS } = require('./constants'); | ||
|
||
const spinner = ora(); | ||
|
||
const copyDirs = async dirMap => { | ||
try { | ||
await fs.copy(dirMap.in, dirMap.out, { preserveTimestamps: true }); | ||
} catch (err) { | ||
spinner.warn( | ||
'Copying assets: Note that if input is a file, output cannot be a directory.' | ||
); | ||
throw err | ||
} | ||
return COPY_SUCCESS; | ||
}; | ||
|
||
module.exports = async dirs => { | ||
spinner.start('Copying assets'); | ||
|
||
return Promise.all(dirs.map(dirMap => copyDirs(dirMap))) | ||
.then(resp => { | ||
spinner.succeed(); | ||
return resp; | ||
}) | ||
.catch(error => { | ||
spinner.fail(); | ||
throw new Error(error.message); | ||
}); | ||
}; |
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 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,8 @@ | ||
const { copy } = require('../lib'); | ||
const { COPY_MAP } = require('../examples/paths'); | ||
const { COPY_SUCCESS } = require('../lib/constants'); | ||
|
||
it('Copies directories or files', async () => { | ||
const data = await copy(COPY_MAP); | ||
expect(data).toStrictEqual([COPY_SUCCESS, COPY_SUCCESS]); | ||
}); |