forked from sandeep-pesala/connector-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostinstall.js
41 lines (34 loc) · 1.23 KB
/
postinstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const path = require('path');
const os = require('os');
const rootDir = path.resolve(`${os.homedir()}`);
const folderName = '.fs-connector';
const targetPath = path.join(rootDir, folderName);
const sourceTemplatePath = path.join(__dirname, 'template');
const targetTemplatePath = path.join(targetPath, 'template');
function copyFolderSync(source, destination) {
if (!fs.existsSync(destination)) {
fs.mkdirSync(destination, { recursive: true });
}
fs.readdirSync(source).forEach((file) => {
const srcFile = path.join(source, file);
const destFile = path.join(destination, file);
if (fs.lstatSync(srcFile).isDirectory()) {
copyFolderSync(srcFile, destFile);
} else {
fs.copyFileSync(srcFile, destFile);
}
});
}
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath, { recursive: true });
console.log(`Directory ${targetPath} created successfully.`);
} else {
console.log(`Directory ${targetPath} already exists.`);
}
if (fs.existsSync(sourceTemplatePath)) {
copyFolderSync(sourceTemplatePath, targetTemplatePath);
console.log(`Template folder copied to ${targetTemplatePath} successfully.`);
} else {
console.error(`Template folder does not exist in the package.`);
}