Skip to content

Commit 97fa919

Browse files
Added copydir to file utils
1 parent 9d572b9 commit 97fa919

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/utils/files.util.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {
2+
copySync,
23
createWriteStream,
34
existsSync,
45
readdirSync,
56
readFileSync,
6-
writeFileSync
7-
} from 'fs';
7+
writeFileSync,
8+
} from 'fs-extra';
89
import * as http from 'http';
910
import * as https from 'https';
1011
import * as yaml from 'js-yaml';
@@ -24,18 +25,16 @@ const isHttpsRegex = /^https/i;
2425
* @returns The resolved path to the resource
2526
* @throws Exception if path not exist or not found
2627
*/
27-
export function resolvePluggablePath(elementPath: string, internalPath: string) {
28+
export function resolvePluggablePath(
29+
elementPath: string,
30+
internalPath: string,
31+
) {
2832
// Generate the template path
2933
if (existsSync(elementPath)) {
3034
return elementPath;
3135
}
3236

33-
const resolvedPath = pathResolve(
34-
__dirname,
35-
'..',
36-
internalPath,
37-
elementPath,
38-
);
37+
const resolvedPath = pathResolve(__dirname, '..', internalPath, elementPath);
3938
if (existsSync(resolvedPath)) {
4039
return resolvedPath;
4140
}
@@ -53,6 +52,24 @@ export function makeDir(dest): void {
5352
mkdirSync(dest);
5453
}
5554

55+
56+
function copyDirFilter(src, dst): boolean {
57+
return dst.indexOf('node_modules') === -1;
58+
}
59+
60+
export function copyDir(
61+
src: string,
62+
dest: string,
63+
overwrite: boolean = false,
64+
): void {
65+
console.debug('Copying', src, 'to', dest);
66+
copySync(src, dest, {
67+
overwrite: true,
68+
errorOnExist: true,
69+
filter: copyDirFilter,
70+
});
71+
}
72+
5673
export async function downloadFile(url, dest): Promise<string> {
5774
makeDir(dirname(dest));
5875
return new Promise((resolve, error) => {

0 commit comments

Comments
 (0)