-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚙️ Chore(configs/tsup,cli init,copyFile): fix coping files by
tsup
,…
… change `init` cli cmd, add error handler for copyfile
- Loading branch information
1 parent
bc8d608
commit 5c0049a
Showing
11 changed files
with
103 additions
and
116 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
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
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 |
---|---|---|
@@ -1,16 +1,41 @@ | ||
import logging from "@/utils/logging"; | ||
import { copyFileSync, existsSync, mkdirSync, readdirSync } from "fs"; | ||
import type { TFunctionReturn, TMyErrorList } from "oh-my-error"; | ||
import { myErrorWrapper } from "oh-my-error"; | ||
import { join } from "path"; | ||
|
||
const copyFiles = async (source: string, target: string, emptyDirs = true): Promise<void> => | ||
new Promise(() => { | ||
if (!existsSync(target)) mkdirSync(target); | ||
const MyErrorList = { | ||
CANT_MKDIR: { | ||
code: "CP001", | ||
hint: {}, | ||
message: { user: "Can't make dir" } | ||
}, | ||
CANT_COPY_FILE: { | ||
code: "CP002", | ||
hint: {}, | ||
message: { user: "Can't Copy File" } | ||
} | ||
} as const satisfies TMyErrorList; | ||
|
||
const copyFiles = (source: string, target: string, emptyDirs = true): TFunctionReturn<void> => { | ||
if (!existsSync(target)) { | ||
const [, isError] = myErrorWrapper(mkdirSync)(target); | ||
if (isError) return [MyErrorList.CANT_MKDIR, true]; | ||
} | ||
|
||
const [, isError] = myErrorWrapper(() => { | ||
readdirSync(source, { withFileTypes: true }).forEach(file => { | ||
logging.debug("File info: ", file); | ||
const curSource = join(source, file.name); | ||
if (file.isDirectory()) copyFiles(curSource, join(target, file.name), emptyDirs); | ||
else copyFileSync(curSource, join(target, file.name)); | ||
}); | ||
}); | ||
})(); | ||
if (isError) return [MyErrorList.CANT_COPY_FILE, true]; | ||
|
||
// ERROR HANDLING DOKONCZ | ||
|
||
return [, false]; | ||
}; | ||
|
||
export { copyFiles }; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.