gitorial-cli 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/utils.js DELETED
@@ -1,79 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- function copyAllContentsAndReplace(sourceDir, targetDir) {
5
- // Create target directory if it doesn't exist
6
- if (!fs.existsSync(targetDir)) {
7
- fs.mkdirSync(targetDir, { recursive: true });
8
- }
9
-
10
- // Get list of items in source directory
11
- const items = fs.readdirSync(sourceDir);
12
-
13
- // Copy each item to target directory and replace existing items
14
- items.forEach(item => {
15
- const sourcePath = path.join(sourceDir, item);
16
- const targetPath = path.join(targetDir, item);
17
- if (fs.statSync(sourcePath).isDirectory()) {
18
- if (fs.existsSync(targetPath) && fs.statSync(targetPath).isDirectory()) {
19
- fs.rmSync(targetPath, { recursive: true }); // Remove existing directory
20
- }
21
- fs.mkdirSync(targetPath, { recursive: true }); // Create directory in target
22
- copyAllContentsAndReplace(sourcePath, targetPath); // Recursively copy contents of directory
23
- } else {
24
- if (fs.existsSync(targetPath)) {
25
- fs.unlinkSync(targetPath); // Delete existing file
26
- }
27
- fs.copyFileSync(sourcePath, targetPath); // Copy file
28
- }
29
- });
30
- }
31
-
32
- function copyFilesAndDirectories(source, target) {
33
- // Check if source exists
34
- if (!fs.existsSync(source)) {
35
- console.error(`Source directory ${source} does not exist.`);
36
- return;
37
- }
38
-
39
- // Create target directory if it doesn't exist
40
- if (!fs.existsSync(target)) {
41
- fs.mkdirSync(target, { recursive: true });
42
- }
43
-
44
- // Get list of items in source directory
45
- const items = fs.readdirSync(source);
46
-
47
- // Copy each item to target directory
48
- items.forEach(item => {
49
- // Skip .git folder
50
- if (item === '.git') {
51
- return;
52
- }
53
-
54
- const sourcePath = path.join(source, item);
55
- const targetPath = path.join(target, item);
56
- if (fs.statSync(sourcePath).isDirectory()) {
57
- // Recursively copy directories
58
- copyFilesAndDirectories(sourcePath, targetPath);
59
- } else {
60
- // Copy files
61
- fs.copyFileSync(sourcePath, targetPath);
62
- }
63
- });
64
- }
65
-
66
- async function doesBranchExist(git, branchName) {
67
- try {
68
- // Get a list of all local branches
69
- const branches = await git.branchLocal();
70
- // Check if the branch exists in the list of local branches
71
- const branchExists = branches.all.includes(branchName);
72
- return branchExists;
73
- } catch (error) {
74
- console.error('Error checking if branch exists:', error);
75
- return false;
76
- }
77
- }
78
-
79
- module.exports = { copyAllContentsAndReplace, doesBranchExist, copyFilesAndDirectories };