-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0108ebf
commit 8275abb
Showing
4 changed files
with
56 additions
and
6 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,39 @@ | ||
import path from 'node:path'; | ||
import fs from 'fs-extra'; | ||
import chokidar from 'chokidar'; | ||
import { Log, CopyFilesOptions } from '@tsbb/typescript'; | ||
import { watcherCopyFiles } from './watcher/copyFiles.js'; | ||
|
||
export interface CopyOption { | ||
entry?: string[]; | ||
output?: string; | ||
watch?: boolean; | ||
} | ||
|
||
export async function copy(options: CopyOption = {}) { | ||
const { watch, entry, output } = options; | ||
if (!output) { | ||
throw new Error('Please enter the \x1b[33;1moutput\x1b[0m directory'); | ||
} | ||
const watcher = chokidar.watch(entry || [], { | ||
persistent: true, | ||
}); | ||
const log = new Log(); | ||
log.name(); | ||
watcher.on('all', async (eventName, filepath, stats) => { | ||
const outputPath = path.resolve(process.cwd(), output, filepath); | ||
fs.ensureDirSync(path.dirname(outputPath)); | ||
fs.copyFile(filepath, path.resolve(process.cwd(), output, filepath)); | ||
log | ||
.icon('🗞️') | ||
.success(`Copy \x1b[32;1m${filepath}\x1b[0m ┈┈▶ \x1b[35;1m${path.relative(process.cwd(), outputPath)}\x1b[0m`); | ||
}); | ||
watcher.on('error', (error) => { | ||
log.error(`\n \x1b[33;1m${error.message}\x1b[0m.`); | ||
}); | ||
watcher.on('ready', () => { | ||
if (!watch) { | ||
watcher.close(); | ||
} | ||
}); | ||
} |
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