@digicroz/node-backend-kit 1.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.
Files changed (59) hide show
  1. package/README.md +255 -0
  2. package/dist/b2fPortalV3/b2fPortal.d.ts +2 -0
  3. package/dist/b2fPortalV3/b2fPortal.js +199 -0
  4. package/dist/b2fPortalV3/checkModuleRecords.d.ts +1 -0
  5. package/dist/b2fPortalV3/checkModuleRecords.js +60 -0
  6. package/dist/b2fPortalV3/checkModuleZodRecords.d.ts +1 -0
  7. package/dist/b2fPortalV3/checkModuleZodRecords.js +60 -0
  8. package/dist/b2fPortalV3/moduleFileCreator.d.ts +1 -0
  9. package/dist/b2fPortalV3/moduleFileCreator.js +42 -0
  10. package/dist/b2fPortalV3/moduleZodCreator.d.ts +1 -0
  11. package/dist/b2fPortalV3/moduleZodCreator.js +41 -0
  12. package/dist/b2fPortalV3/stripExtensions.d.ts +12 -0
  13. package/dist/b2fPortalV3/stripExtensions.js +51 -0
  14. package/dist/b2fPortalV3/syncProjectCommons.d.ts +8 -0
  15. package/dist/b2fPortalV3/syncProjectCommons.js +180 -0
  16. package/dist/bin/nbk.d.ts +2 -0
  17. package/dist/bin/nbk.js +83 -0
  18. package/dist/cli/addDevVersion.d.ts +1 -0
  19. package/dist/cli/addDevVersion.js +51 -0
  20. package/dist/cli/addProdVersion.d.ts +1 -0
  21. package/dist/cli/addProdVersion.js +71 -0
  22. package/dist/cli/createInitWorkspaceShellFile.d.ts +1 -0
  23. package/dist/cli/createInitWorkspaceShellFile.js +129 -0
  24. package/dist/cli/deleteAllRepos.d.ts +1 -0
  25. package/dist/cli/deleteAllRepos.js +62 -0
  26. package/dist/cli/deleteAndCopy.d.ts +6 -0
  27. package/dist/cli/deleteAndCopy.js +88 -0
  28. package/dist/cli/deployAllRepos.d.ts +1 -0
  29. package/dist/cli/deployAllRepos.js +202 -0
  30. package/dist/cli/fixConfigFile.d.ts +5 -0
  31. package/dist/cli/fixConfigFile.js +76 -0
  32. package/dist/cli/gitAcpAllRepos.d.ts +1 -0
  33. package/dist/cli/gitAcpAllRepos.js +156 -0
  34. package/dist/cli/gitPushAllRepos.d.ts +1 -0
  35. package/dist/cli/gitPushAllRepos.js +70 -0
  36. package/dist/cli/initConfig.d.ts +1 -0
  37. package/dist/cli/initConfig.js +23 -0
  38. package/dist/cli/transfer2Shared.d.ts +1 -0
  39. package/dist/cli/transfer2Shared.js +180 -0
  40. package/dist/configs/environment.d.ts +4 -0
  41. package/dist/configs/environment.js +7 -0
  42. package/dist/helpers/checkCrossProjectImports.d.ts +2 -0
  43. package/dist/helpers/checkCrossProjectImports.js +73 -0
  44. package/dist/index.d.ts +18 -0
  45. package/dist/index.js +47 -0
  46. package/dist/types.d.ts +34 -0
  47. package/dist/types.js +4 -0
  48. package/dist/utils/jsonFile.d.ts +7 -0
  49. package/dist/utils/jsonFile.js +24 -0
  50. package/dist/utils/loadConfig.d.ts +8 -0
  51. package/dist/utils/loadConfig.js +203 -0
  52. package/dist/utils/path.d.ts +6 -0
  53. package/dist/utils/path.js +16 -0
  54. package/dist/utils/progress.d.ts +65 -0
  55. package/dist/utils/progress.js +108 -0
  56. package/dist/utils/vscodeSettings.d.ts +1 -0
  57. package/dist/utils/vscodeSettings.js +67 -0
  58. package/nbk.schema.json +95 -0
  59. package/package.json +80 -0
@@ -0,0 +1,88 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { startProgress, successProgress, failProgress, updateProgress } from '../utils/progress.js';
4
+ /**
5
+ * Deletes all files in the target directory and copies all files from source directory
6
+ * @param sourcePath - Source directory path
7
+ * @param targetPath - Target directory path
8
+ */
9
+ export async function deleteAndCopy(sourcePath, targetPath) {
10
+ const spinner = startProgress(`Preparing to copy files from ${path.basename(sourcePath)} to ${path.basename(targetPath)}`);
11
+ try {
12
+ // Ensure target directory exists
13
+ if (!fs.existsSync(targetPath)) {
14
+ updateProgress(spinner, `Creating target directory: ${targetPath}`);
15
+ fs.mkdirSync(targetPath, { recursive: true });
16
+ }
17
+ else {
18
+ // Delete existing files and directories in target
19
+ updateProgress(spinner, `Cleaning target directory: ${targetPath}`);
20
+ const items = fs.readdirSync(targetPath);
21
+ for (const item of items) {
22
+ const itemPath = path.join(targetPath, item);
23
+ if (fs.lstatSync(itemPath).isDirectory()) {
24
+ fs.rmSync(itemPath, { recursive: true, force: true });
25
+ }
26
+ else {
27
+ fs.unlinkSync(itemPath);
28
+ }
29
+ }
30
+ }
31
+ // Copy all files from source to target
32
+ updateProgress(spinner, `Copying files from ${sourcePath} to ${targetPath}`);
33
+ await copyDirectoryRecursive(sourcePath, targetPath, spinner);
34
+ successProgress(spinner, `Successfully copied all files from ${path.basename(sourcePath)} to ${path.basename(targetPath)}`);
35
+ }
36
+ catch (error) {
37
+ failProgress(spinner, `Error during deleteAndCopy operation`);
38
+ console.error(`Error during deleteAndCopy operation:`, error);
39
+ throw error;
40
+ }
41
+ }
42
+ /**
43
+ * Counts the total number of files in a directory recursively
44
+ * @param directory - Directory to count files in
45
+ * @returns Total number of files
46
+ */
47
+ function countFiles(directory) {
48
+ let count = 0;
49
+ const items = fs.readdirSync(directory);
50
+ for (const item of items) {
51
+ const itemPath = path.join(directory, item);
52
+ if (fs.lstatSync(itemPath).isDirectory()) {
53
+ count += countFiles(itemPath);
54
+ }
55
+ else {
56
+ count++;
57
+ }
58
+ }
59
+ return count;
60
+ }
61
+ /**
62
+ * Copies directory contents recursively
63
+ * @param source - Source directory
64
+ * @param target - Target directory
65
+ * @param spinner - Progress spinner
66
+ */
67
+ async function copyDirectoryRecursive(source, target, spinner) {
68
+ // Create target directory if it doesn't exist
69
+ if (!fs.existsSync(target)) {
70
+ fs.mkdirSync(target, { recursive: true });
71
+ }
72
+ // Get all files and directories in the source
73
+ const items = fs.readdirSync(source);
74
+ for (const item of items) {
75
+ const sourcePath = path.join(source, item);
76
+ const targetPath = path.join(target, item);
77
+ if (fs.lstatSync(sourcePath).isDirectory()) {
78
+ // Update progress for directories
79
+ updateProgress(spinner, `Copying directory: ${item}`);
80
+ // Recursively copy subdirectories
81
+ await copyDirectoryRecursive(sourcePath, targetPath, spinner);
82
+ }
83
+ else {
84
+ // Copy files
85
+ fs.copyFileSync(sourcePath, targetPath);
86
+ }
87
+ }
88
+ }
@@ -0,0 +1 @@
1
+ export declare const deployAllRepos: () => Promise<void>;
@@ -0,0 +1,202 @@
1
+ import fs from "fs";
2
+ import { join } from "path";
3
+ import path from "path";
4
+ import { execSync } from "child_process";
5
+ import { clientRootDirPath } from "../utils/path.js";
6
+ import { simpleGit } from "simple-git";
7
+ import { loadConfig } from "../utils/loadConfig.js";
8
+ import { createMultiProgress, startProgress, successProgress, failProgress, } from "../utils/progress.js";
9
+ const getAllPaths = () => {
10
+ try {
11
+ // Load projects from the configuration file
12
+ const config = loadConfig();
13
+ // Export projects for use in CLI tools
14
+ let b2fPortalProjects = config.projects;
15
+ const allPaths = [];
16
+ allPaths.push(clientRootDirPath);
17
+ for (const project of b2fPortalProjects) {
18
+ if (project.sharedBackendPath) {
19
+ const sharedBackendPath = join(clientRootDirPath, project.sharedBackendPath);
20
+ if (!fs.existsSync(sharedBackendPath)) {
21
+ console.log("sharedBackendPath does not exist");
22
+ console.log({ sharedBackendPath });
23
+ return [];
24
+ }
25
+ allPaths.push(sharedBackendPath);
26
+ }
27
+ for (const section of project.sections) {
28
+ if (section.repository.path) {
29
+ const repositoryPath = join(clientRootDirPath, section.repository.path);
30
+ if (!fs.existsSync(repositoryPath)) {
31
+ console.log("repositoryPath does not exist");
32
+ console.log({ repositoryPath });
33
+ return [];
34
+ }
35
+ allPaths.push(repositoryPath);
36
+ }
37
+ }
38
+ }
39
+ return allPaths;
40
+ }
41
+ catch (error) {
42
+ console.log(error);
43
+ return [];
44
+ }
45
+ };
46
+ const checkRepo = async (repoPath) => {
47
+ try {
48
+ const repositoryPackageJsonPath = join(repoPath, "package.json");
49
+ if (!fs.existsSync(repositoryPackageJsonPath)) {
50
+ console.log("repositoryPackageJsonPath does not exist");
51
+ console.log({ repoPath });
52
+ return;
53
+ }
54
+ const repositoryPackageJson = JSON.parse(fs.readFileSync(repositoryPackageJsonPath, "utf8"));
55
+ if (!repositoryPackageJson.name) {
56
+ console.log("repositoryPackageJson.name does not exist");
57
+ console.log({ repoPath });
58
+ return;
59
+ }
60
+ if (!repositoryPackageJson.scripts?.deploy) {
61
+ console.log("deploy script does not exist, skipping....");
62
+ console.log({ repoPath });
63
+ return;
64
+ }
65
+ const spinner = startProgress(`Checking Repo: ${repositoryPackageJson.name}`);
66
+ const options = {
67
+ baseDir: path.resolve(repoPath),
68
+ binary: "git",
69
+ maxConcurrentProcesses: 6,
70
+ };
71
+ const git = simpleGit(options);
72
+ spinner.text = `${repositoryPackageJson.name}: fetching ...`;
73
+ await git.fetch();
74
+ spinner.text = `${repositoryPackageJson.name}: Checking status ...`;
75
+ let status = await git.status();
76
+ // Save the current branch name
77
+ const currentBranch = status.current;
78
+ // console.log(currentBranch);
79
+ if (currentBranch !== "main") {
80
+ failProgress(spinner, `Current branch is ${currentBranch}, but it should be main.`);
81
+ console.log(`Repo: ${repoPath}`);
82
+ process.exit(1);
83
+ }
84
+ if (status.files.length > 0) {
85
+ failProgress(spinner, "❌ Uncommitted changes detected");
86
+ console.log(`Repo: ${repoPath}`);
87
+ process.exit(1);
88
+ }
89
+ spinner.text = `${repositoryPackageJson.name}: pulling ...`;
90
+ await git.pull();
91
+ spinner.text = `${repositoryPackageJson.name}: Checking status ...`;
92
+ status = await git.status();
93
+ // Check for new uncommitted changes after pulling
94
+ if (status.files.length > 0) {
95
+ failProgress(spinner, "❌ Uncommitted changes detected after pull");
96
+ console.log(`Repo: ${repoPath}`);
97
+ process.exit(1);
98
+ }
99
+ else {
100
+ spinner.text = `${repositoryPackageJson.name}: pushing ...`;
101
+ await git.push();
102
+ }
103
+ spinner.text = `${repositoryPackageJson.name}: fetching branches...`;
104
+ const branches = await git.branch(["-r"]);
105
+ // Check if stable branch exists in remote
106
+ if (!branches.all.includes("origin/stable")) {
107
+ failProgress(spinner, "stable branch does not exist");
108
+ console.log(`Repo: ${repoPath}`);
109
+ process.exit(1);
110
+ }
111
+ successProgress(spinner, `Checking Repo: ${repositoryPackageJson.name} Finished`);
112
+ }
113
+ catch (error) {
114
+ console.error("Error while committing changes:", error.message);
115
+ // Handle edge case where the repository might have conflicting changes
116
+ if (error.message.includes("CONFLICT")) {
117
+ console.error("Merge conflict detected. Please resolve conflicts manually.");
118
+ }
119
+ }
120
+ };
121
+ const runDeployCommand = async (repoPath) => {
122
+ try {
123
+ const repositoryPackageJsonPath = join(repoPath, "package.json");
124
+ if (!fs.existsSync(repositoryPackageJsonPath)) {
125
+ console.log("repositoryPackageJsonPath does not exist");
126
+ console.log({ repoPath });
127
+ return;
128
+ }
129
+ const repositoryPackageJson = JSON.parse(fs.readFileSync(repositoryPackageJsonPath, "utf8"));
130
+ if (!repositoryPackageJson.name) {
131
+ console.log("repositoryPackageJson.name does not exist");
132
+ console.log({ repoPath });
133
+ return;
134
+ }
135
+ if (!repositoryPackageJson.scripts?.deploy) {
136
+ console.log("deploy script does not exist, skipping....");
137
+ console.log({ repoPath });
138
+ return;
139
+ }
140
+ const spinner = startProgress(`Deploying: ${repositoryPackageJson.name}`);
141
+ try {
142
+ execSync("npm run deploy", { cwd: repoPath, stdio: "pipe" });
143
+ successProgress(spinner, `Deployment successful: ${repositoryPackageJson.name}`);
144
+ }
145
+ catch (error) {
146
+ failProgress(spinner, `Deployment failed: ${repositoryPackageJson.name}`);
147
+ throw error;
148
+ }
149
+ }
150
+ catch (error) {
151
+ console.error(`Deployment failed for ${repoPath}`, error);
152
+ }
153
+ };
154
+ export const deployAllRepos = async () => {
155
+ console.log("------------deployAll Started-------------");
156
+ try {
157
+ const allPaths = getAllPaths();
158
+ if (allPaths.length === 0) {
159
+ console.log("No valid repositories found. Exiting.");
160
+ return;
161
+ }
162
+ const progress = createMultiProgress();
163
+ progress.start("Starting repository checks");
164
+ progress.setTotal(allPaths.length);
165
+ // First check all repos
166
+ for (const repoPath of allPaths) {
167
+ try {
168
+ await checkRepo(repoPath);
169
+ progress.incrementCompleted();
170
+ }
171
+ catch (error) {
172
+ progress.incrementFailed();
173
+ console.error(`Error checking repository: ${repoPath}`, error);
174
+ }
175
+ }
176
+ progress.complete("Repository checks completed");
177
+ // Then deploy all repos
178
+ const deployProgress = createMultiProgress();
179
+ deployProgress.start("Starting deployments");
180
+ deployProgress.setTotal(allPaths.length);
181
+ for (const repoPath of allPaths) {
182
+ try {
183
+ await runDeployCommand(repoPath);
184
+ deployProgress.incrementCompleted();
185
+ }
186
+ catch (error) {
187
+ deployProgress.incrementFailed();
188
+ console.error(`Error deploying repository: ${repoPath}`, error);
189
+ }
190
+ }
191
+ deployProgress.complete("Deployments completed");
192
+ }
193
+ catch (error) {
194
+ console.log(error);
195
+ }
196
+ console.log("------------deployAll Ended-------------");
197
+ };
198
+ // if (isDeveloperAdarsh) {
199
+ // deployAllRepos();
200
+ // } else {
201
+ // console.log("This command can only be run by authorized developers.");
202
+ // }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Fixes JSON files by adding double quotes to keys and removing trailing commas
3
+ * @param filePath - Optional custom path to the JSON file to fix
4
+ */
5
+ export declare function fixConfigFile(filePath?: string): Promise<void>;
@@ -0,0 +1,76 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { clientRootDirPath } from "../utils/path.js";
4
+ import { cleanTrailingCommas } from "../utils/jsonFile.js";
5
+ /**
6
+ * Fixes JSON files by adding double quotes to keys and removing trailing commas
7
+ * @param filePath - Optional custom path to the JSON file to fix
8
+ */
9
+ export async function fixConfigFile(filePath) {
10
+ // Default to nbk.config.json if no path is provided
11
+ const configPath = filePath
12
+ ? path.resolve(filePath)
13
+ : path.join(clientRootDirPath, "nbk.config.json");
14
+ // Check if the JSON file exists
15
+ if (!fs.existsSync(configPath)) {
16
+ console.error(`File not found: ${configPath}`);
17
+ return;
18
+ }
19
+ try {
20
+ // Read the config file
21
+ const configContent = fs.readFileSync(configPath, "utf8");
22
+ // Fix unquoted keys and trailing commas
23
+ const fixedContent = fixJsonString(configContent);
24
+ // Write the fixed content back to the file
25
+ fs.writeFileSync(configPath, fixedContent);
26
+ // Verify the fixed JSON is valid
27
+ try {
28
+ JSON.parse(fixedContent);
29
+ console.log(`Successfully fixed: ${configPath}`);
30
+ }
31
+ catch (parseError) {
32
+ console.warn(`Warning: The fixed JSON might still have issues. Manual review recommended.`);
33
+ console.log(`Applied automatic fixes to: ${configPath}`);
34
+ }
35
+ }
36
+ catch (error) {
37
+ console.error(`Failed to fix ${configPath}:`, error);
38
+ }
39
+ }
40
+ /**
41
+ * Comprehensive fixing of JSON string issues
42
+ * @param jsonString - The potentially malformed JSON string
43
+ * @returns Fixed JSON string
44
+ */
45
+ function fixJsonString(jsonString) {
46
+ // Step 1: Strip comments (using existing utility)
47
+ let fixedJson = jsonString;
48
+ // Step 2: Add double quotes to unquoted keys
49
+ // This regex handles various cases of unquoted keys
50
+ fixedJson = fixedJson.replace(/([{,]\s*)([a-zA-Z0-9_$]+)(\s*:)/g, '$1"$2"$3');
51
+ // Step 3: Fix single-quoted keys to double-quoted keys
52
+ fixedJson = fixedJson.replace(/([{,]\s*)'([^']+)'(\s*:)/g, '$1"$2"$3');
53
+ // Step 4: Remove trailing commas
54
+ fixedJson = cleanTrailingCommas(fixedJson);
55
+ // Step 5: Add missing commas between properties
56
+ fixedJson = fixedJson.replace(/("[^"]+"\s*:\s*[^,{[\s][^,{[}]*[^,\s])\s*("[^"]+"\s*:)/g, "$1,$2");
57
+ // Step 6: Ensure properly formatted JSON
58
+ fixedJson = formatJson(fixedJson);
59
+ return fixedJson;
60
+ }
61
+ /**
62
+ * Attempts to format the JSON string with proper indentation
63
+ * @param jsonString - The JSON string to format
64
+ * @returns Formatted JSON string
65
+ */
66
+ function formatJson(jsonString) {
67
+ try {
68
+ // Try to parse and format the JSON
69
+ const parsed = JSON.parse(jsonString);
70
+ return JSON.stringify(parsed, null, 2);
71
+ }
72
+ catch (error) {
73
+ // If parsing fails, return the original string with basic fixes
74
+ return jsonString;
75
+ }
76
+ }
@@ -0,0 +1 @@
1
+ export declare const gitAcpAllRepos: () => Promise<void>;
@@ -0,0 +1,156 @@
1
+ import fs from "fs";
2
+ import { join } from "path";
3
+ import path from "path";
4
+ import readline from "node:readline";
5
+ import { clientRootDirPath } from "../utils/path.js";
6
+ import { simpleGit } from "simple-git";
7
+ import { loadConfig } from "../utils/loadConfig.js";
8
+ import { createMultiProgress, failProgress, startProgress, successProgress, updateProgress, } from "../utils/progress.js";
9
+ const getAllPaths = () => {
10
+ try {
11
+ // Load projects from the configuration file
12
+ const config = loadConfig();
13
+ // Export projects for use in CLI tools
14
+ let b2fPortalProjects = config.projects;
15
+ const allPaths = [];
16
+ allPaths.push(clientRootDirPath);
17
+ for (const project of b2fPortalProjects) {
18
+ if (project.sharedBackendPath) {
19
+ const sharedBackendPath = join(clientRootDirPath, project.sharedBackendPath);
20
+ if (!fs.existsSync(sharedBackendPath)) {
21
+ console.log("sharedBackendPath does not exist");
22
+ console.log({ sharedBackendPath });
23
+ return [];
24
+ }
25
+ allPaths.push(sharedBackendPath);
26
+ }
27
+ for (const section of project.sections) {
28
+ if (section.repository.path) {
29
+ const repositoryPath = join(clientRootDirPath, section.repository.path);
30
+ if (!fs.existsSync(repositoryPath)) {
31
+ console.log("repositoryPath does not exist");
32
+ console.log({ repositoryPath });
33
+ return [];
34
+ }
35
+ allPaths.push(repositoryPath);
36
+ }
37
+ }
38
+ }
39
+ return allPaths;
40
+ }
41
+ catch (error) {
42
+ console.log(error);
43
+ return [];
44
+ }
45
+ };
46
+ const runAcpCommands = async (repoPath, message) => {
47
+ try {
48
+ const repositoryPackageJsonPath = join(repoPath, "package.json");
49
+ if (!fs.existsSync(repositoryPackageJsonPath)) {
50
+ console.log("repositoryPackageJsonPath does not exist");
51
+ console.log({ repositoryPackageJsonPath });
52
+ return;
53
+ }
54
+ const repositoryPackageJson = JSON.parse(fs.readFileSync(repositoryPackageJsonPath, "utf8"));
55
+ if (!repositoryPackageJson.name) {
56
+ console.log("repositoryPackageJson.name does not exist");
57
+ console.log({ repositoryPackageJson });
58
+ return;
59
+ }
60
+ const spinner = startProgress(`Running ACP in ${repositoryPackageJson.name}`);
61
+ const options = {
62
+ baseDir: path.resolve(repoPath),
63
+ binary: "git",
64
+ maxConcurrentProcesses: 6,
65
+ };
66
+ const git = simpleGit(options);
67
+ updateProgress(spinner, `${repositoryPackageJson.name}: fetching ...`);
68
+ await git.fetch();
69
+ updateProgress(spinner, `${repositoryPackageJson.name}: Checking status ...`);
70
+ let status = await git.status();
71
+ // Save the current branch name
72
+ const currentBranch = status.current;
73
+ // console.log(currentBranch);
74
+ if (currentBranch !== "main") {
75
+ failProgress(spinner, `Current branch is ${currentBranch}, but it should be main.`);
76
+ console.log(`Repo: ${repoPath}`);
77
+ process.exit(1);
78
+ }
79
+ if (status.files.length > 0) {
80
+ updateProgress(spinner, `${repositoryPackageJson.name}: Adding files ...`);
81
+ await git.add(".");
82
+ updateProgress(spinner, `${repositoryPackageJson.name}: Committing changes ...`);
83
+ await git.commit(message);
84
+ }
85
+ updateProgress(spinner, `${repositoryPackageJson.name}: pulling ...`);
86
+ await git.pull();
87
+ updateProgress(spinner, `${repositoryPackageJson.name}: Checking status ...`);
88
+ status = await git.status();
89
+ // Check for new uncommitted changes after pulling
90
+ if (status.files.length > 0) {
91
+ updateProgress(spinner, `${repositoryPackageJson.name}: Adding files after pull ...`);
92
+ await git.add(".");
93
+ updateProgress(spinner, `${repositoryPackageJson.name}: Committing changes after pull ...`);
94
+ await git.commit(message);
95
+ }
96
+ updateProgress(spinner, `${repositoryPackageJson.name}: pushing ...`);
97
+ await git.push();
98
+ successProgress(spinner, `Running ACP in ${repositoryPackageJson.name} Finished`);
99
+ }
100
+ catch (error) {
101
+ console.error("Error while committing changes:", error.message);
102
+ // Handle edge case where the repository might have conflicting changes
103
+ if (error.message.includes("CONFLICT")) {
104
+ console.error("Merge conflict detected. Please resolve conflicts manually.");
105
+ }
106
+ }
107
+ };
108
+ export const gitAcpAllRepos = async () => {
109
+ const rl = readline.createInterface({
110
+ input: process.stdin,
111
+ output: process.stdout,
112
+ });
113
+ function askQuestion(query) {
114
+ return new Promise((resolve) => {
115
+ rl.question(query, (answer) => {
116
+ resolve(answer);
117
+ });
118
+ });
119
+ }
120
+ try {
121
+ let commitMessage = await askQuestion("Enter Commit Message: ");
122
+ rl.close();
123
+ if (commitMessage.trim() === "") {
124
+ commitMessage = "Git Acp All Repos";
125
+ }
126
+ console.log("------------gitAcpAllRepos Started-------------");
127
+ const allPaths = getAllPaths();
128
+ if (allPaths.length === 0) {
129
+ console.log("No valid repositories found. Exiting.");
130
+ return;
131
+ }
132
+ const progress = createMultiProgress();
133
+ progress.start("Processing repositories");
134
+ progress.setTotal(allPaths.length);
135
+ for (const repoPath of allPaths) {
136
+ try {
137
+ await runAcpCommands(repoPath, `${new Date().toLocaleString()} : ${commitMessage}`);
138
+ progress.incrementCompleted();
139
+ }
140
+ catch (error) {
141
+ progress.incrementFailed();
142
+ console.error(`Error processing repository: ${repoPath}`, error);
143
+ }
144
+ }
145
+ progress.complete();
146
+ console.log("------------gitAcpAllRepos Ended-------------");
147
+ }
148
+ catch (error) {
149
+ console.log(error);
150
+ }
151
+ };
152
+ // if (isDeveloperAdarsh) {
153
+ // gitAcpAllRepos();
154
+ // } else {
155
+ // console.log("This command can only be run by authorized developers.");
156
+ // }
@@ -0,0 +1 @@
1
+ export declare function gitPushAllRepos(): Promise<void>;
@@ -0,0 +1,70 @@
1
+ import path from "path";
2
+ import { join } from "path";
3
+ import { simpleGit } from "simple-git";
4
+ import { clientRootDirPath } from "../utils/path.js";
5
+ import dotenv from "dotenv";
6
+ import { isDeveloperAdarsh } from "../configs/environment.js";
7
+ import { loadConfig } from "../utils/loadConfig.js";
8
+ dotenv.config();
9
+ async function commitB2fPortalChanges(repoPath) {
10
+ const options = {
11
+ baseDir: path.resolve(repoPath),
12
+ binary: "git",
13
+ maxConcurrentProcesses: 6,
14
+ };
15
+ const git = simpleGit(options);
16
+ try {
17
+ // Fetch the status of the repo
18
+ const status = await git.status();
19
+ const b2fPortalChanges = status.files.some((file) => file.path.startsWith("b2fPortal/"));
20
+ if (!b2fPortalChanges) {
21
+ console.log(`No changes detected in the b2fPortal directory. Skipping commit.`);
22
+ return;
23
+ }
24
+ // Save the current branch name
25
+ const currentBranch = status.current;
26
+ if (currentBranch !== "main") {
27
+ console.error(`Current branch is ${currentBranch}, but it should be main.`);
28
+ process.exit(1);
29
+ }
30
+ // Pull the latest changes
31
+ await git.pull();
32
+ // Add only the b2fPortal folder
33
+ await git.add("b2fPortal/*");
34
+ // Commit with the current date and time
35
+ const currentDate = new Date().toLocaleString();
36
+ const commitMessage = `${currentDate} backend portal updated`;
37
+ await git.commit(commitMessage);
38
+ // Push the commit to the main branch
39
+ await git.push("origin", "main");
40
+ console.log("Changes committed and pushed successfully");
41
+ }
42
+ catch (error) {
43
+ console.error("Error while committing changes:", error.message);
44
+ // Handle edge case where the repository might have conflicting changes
45
+ if (error.message.includes("CONFLICT")) {
46
+ console.error("Merge conflict detected. Please resolve conflicts manually.");
47
+ }
48
+ }
49
+ }
50
+ export async function gitPushAllRepos() {
51
+ // Load projects from the configuration file
52
+ const config = loadConfig();
53
+ // Export projects for use in CLI tools
54
+ let b2fPortalProjects = config.projects;
55
+ for (const project of b2fPortalProjects) {
56
+ for (const section of project.sections) {
57
+ if (isDeveloperAdarsh) {
58
+ const repositoryPath = join(clientRootDirPath, section.repository.path);
59
+ console.log(`\n----------------${section.repository.name} started----------------`);
60
+ await commitB2fPortalChanges(repositoryPath);
61
+ console.log(`----------------${section.repository.name} finished----------------\n`);
62
+ }
63
+ }
64
+ }
65
+ }
66
+ // if (isDeveloperAdarsh) {
67
+ // gitPushAllRepos();
68
+ // } else {
69
+ // console.log("This command can only be run by authorized developers.");
70
+ // }
@@ -0,0 +1 @@
1
+ export declare function initConfig(): Promise<void>;
@@ -0,0 +1,23 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { clientRootDirPath } from "../utils/path.js";
4
+ import { updateVSCodeSettings } from "../utils/vscodeSettings.js";
5
+ export async function initConfig() {
6
+ const configPath = path.join(clientRootDirPath, "nbk.config.json");
7
+ // Check if nbk.config.json already exists
8
+ if (fs.existsSync(configPath)) {
9
+ console.log("nbk.config.json already exists in the project root.");
10
+ }
11
+ else {
12
+ // Create nbk.config.json with default configuration
13
+ const defaultConfig = {
14
+ b2fPortal: true,
15
+ checkCrossProjectImports: true,
16
+ projects: [],
17
+ };
18
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
19
+ console.log("Created nbk.config.json with default configuration in the project root.");
20
+ }
21
+ // Update VSCode settings
22
+ updateVSCodeSettings();
23
+ }
@@ -0,0 +1 @@
1
+ export declare const transfer2Shared: () => Promise<void>;