@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,65 @@
1
+ import { Ora } from 'ora';
2
+ /**
3
+ * Creates and starts a spinner with the given text
4
+ * @param text The text to display next to the spinner
5
+ * @returns The spinner instance
6
+ */
7
+ export declare function startProgress(text: string): Ora;
8
+ /**
9
+ * Updates the spinner text
10
+ * @param spinner The spinner instance
11
+ * @param text The new text to display
12
+ */
13
+ export declare function updateProgress(spinner: Ora, text: string): void;
14
+ /**
15
+ * Stops the spinner with a success message
16
+ * @param spinner The spinner instance
17
+ * @param text The success message
18
+ */
19
+ export declare function successProgress(spinner: Ora, text: string): void;
20
+ /**
21
+ * Stops the spinner with a failure message
22
+ * @param spinner The spinner instance
23
+ * @param text The failure message
24
+ */
25
+ export declare function failProgress(spinner: Ora, text: string): void;
26
+ /**
27
+ * Shows a spinner for a promise
28
+ * @param text The text to display
29
+ * @param promise The promise to track
30
+ * @param successText The text to display on success
31
+ * @param failText The text to display on failure
32
+ * @returns The result of the promise
33
+ */
34
+ export declare function withProgress<T>(text: string, promise: Promise<T>, successText?: string, failText?: string): Promise<T>;
35
+ /**
36
+ * Creates a progress manager for tracking multiple tasks
37
+ * @returns An object with methods to manage multiple tasks with progress
38
+ */
39
+ export declare function createMultiProgress(): {
40
+ /**
41
+ * Start the progress tracking
42
+ * @param text The initial text to display
43
+ */
44
+ start: (text?: string) => void;
45
+ /**
46
+ * Sets the total number of tasks
47
+ * @param count The total number of tasks
48
+ */
49
+ setTotal: (count: number) => void;
50
+ /**
51
+ * Increment the completed tasks counter
52
+ * @param successText Optional text to display for the completed task
53
+ */
54
+ incrementCompleted: (successText?: string) => void;
55
+ /**
56
+ * Increment the failed tasks counter
57
+ * @param failText Optional text to display for the failed task
58
+ */
59
+ incrementFailed: (failText?: string) => void;
60
+ /**
61
+ * Complete the progress tracking
62
+ * @param text The final text to display
63
+ */
64
+ complete: (text?: string) => void;
65
+ };
@@ -0,0 +1,108 @@
1
+ import ora from 'ora';
2
+ /**
3
+ * Creates and starts a spinner with the given text
4
+ * @param text The text to display next to the spinner
5
+ * @returns The spinner instance
6
+ */
7
+ export function startProgress(text) {
8
+ return ora(text).start();
9
+ }
10
+ /**
11
+ * Updates the spinner text
12
+ * @param spinner The spinner instance
13
+ * @param text The new text to display
14
+ */
15
+ export function updateProgress(spinner, text) {
16
+ spinner.text = text;
17
+ }
18
+ /**
19
+ * Stops the spinner with a success message
20
+ * @param spinner The spinner instance
21
+ * @param text The success message
22
+ */
23
+ export function successProgress(spinner, text) {
24
+ spinner.succeed(text);
25
+ }
26
+ /**
27
+ * Stops the spinner with a failure message
28
+ * @param spinner The spinner instance
29
+ * @param text The failure message
30
+ */
31
+ export function failProgress(spinner, text) {
32
+ spinner.fail(text);
33
+ }
34
+ /**
35
+ * Shows a spinner for a promise
36
+ * @param text The text to display
37
+ * @param promise The promise to track
38
+ * @param successText The text to display on success
39
+ * @param failText The text to display on failure
40
+ * @returns The result of the promise
41
+ */
42
+ export async function withProgress(text, promise, successText = 'Completed successfully', failText = 'Failed') {
43
+ const spinner = startProgress(text);
44
+ try {
45
+ const result = await promise;
46
+ successProgress(spinner, successText);
47
+ return result;
48
+ }
49
+ catch (error) {
50
+ failProgress(spinner, failText);
51
+ throw error;
52
+ }
53
+ }
54
+ /**
55
+ * Creates a progress manager for tracking multiple tasks
56
+ * @returns An object with methods to manage multiple tasks with progress
57
+ */
58
+ export function createMultiProgress() {
59
+ const spinner = ora('Starting tasks...');
60
+ let totalTasks = 0;
61
+ let completedTasks = 0;
62
+ let failedTasks = 0;
63
+ return {
64
+ /**
65
+ * Start the progress tracking
66
+ * @param text The initial text to display
67
+ */
68
+ start: (text = 'Starting tasks...') => {
69
+ spinner.start(text);
70
+ },
71
+ /**
72
+ * Sets the total number of tasks
73
+ * @param count The total number of tasks
74
+ */
75
+ setTotal: (count) => {
76
+ totalTasks = count;
77
+ spinner.text = `0/${totalTasks} tasks completed`;
78
+ },
79
+ /**
80
+ * Increment the completed tasks counter
81
+ * @param successText Optional text to display for the completed task
82
+ */
83
+ incrementCompleted: (successText) => {
84
+ completedTasks++;
85
+ spinner.text = `${completedTasks}/${totalTasks} tasks completed${successText ? ` - ${successText}` : ''}`;
86
+ },
87
+ /**
88
+ * Increment the failed tasks counter
89
+ * @param failText Optional text to display for the failed task
90
+ */
91
+ incrementFailed: (failText) => {
92
+ failedTasks++;
93
+ spinner.text = `${completedTasks}/${totalTasks} tasks completed, ${failedTasks} failed${failText ? ` - ${failText}` : ''}`;
94
+ },
95
+ /**
96
+ * Complete the progress tracking
97
+ * @param text The final text to display
98
+ */
99
+ complete: (text) => {
100
+ if (failedTasks > 0) {
101
+ spinner.fail(text || `Completed with errors: ${completedTasks}/${totalTasks} tasks completed, ${failedTasks} failed`);
102
+ }
103
+ else {
104
+ spinner.succeed(text || `All ${totalTasks} tasks completed successfully`);
105
+ }
106
+ }
107
+ };
108
+ }
@@ -0,0 +1 @@
1
+ export declare function updateVSCodeSettings(): void;
@@ -0,0 +1,67 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { clientRootDirPath } from "./path.js";
4
+ import { cleanTrailingCommas, stripComments } from "./jsonFile.js";
5
+ export function updateVSCodeSettings() {
6
+ const vscodeDir = path.join(clientRootDirPath, ".vscode");
7
+ const settingsPath = path.join(vscodeDir, "settings.json");
8
+ // Create .vscode directory if it doesn't exist
9
+ if (!fs.existsSync(vscodeDir)) {
10
+ fs.mkdirSync(vscodeDir, { recursive: true });
11
+ }
12
+ // Read existing settings or create new ones
13
+ let settings = {};
14
+ let existingContent = "";
15
+ if (fs.existsSync(settingsPath)) {
16
+ try {
17
+ existingContent = fs.readFileSync(settingsPath, "utf-8");
18
+ // Clean the content before parsing
19
+ let cleanedContent = stripComments(existingContent);
20
+ cleanedContent = cleanTrailingCommas(existingContent);
21
+ // Try to parse the cleaned content
22
+ settings = JSON.parse(cleanedContent);
23
+ }
24
+ catch (error) {
25
+ if (error instanceof SyntaxError) {
26
+ // Extract position information from the error message
27
+ const positionMatch = error.message.match(/position (\d+)/);
28
+ const position = positionMatch ? parseInt(positionMatch[1]) : 0;
29
+ // Calculate line and column
30
+ const lines = existingContent.slice(0, position).split("\n");
31
+ const line = lines.length;
32
+ const column = lines[lines.length - 1].length + 1;
33
+ console.error(`JSON Parse Error at line ${line}, column ${column}`);
34
+ console.error(`Error details: ${error.message}`);
35
+ // Keep the existing content as is
36
+ console.log("Keeping existing settings file unchanged due to parse error");
37
+ return;
38
+ }
39
+ console.warn("Error reading .vscode/settings.json:", error);
40
+ return;
41
+ }
42
+ }
43
+ // Create a deep copy of existing settings to preserve all data
44
+ const updatedSettings = JSON.parse(JSON.stringify(settings));
45
+ // Initialize files.associations if it doesn't exist
46
+ if (!updatedSettings["files.associations"]) {
47
+ updatedSettings["files.associations"] = {};
48
+ }
49
+ // Only add nbk.config.json association if not already present
50
+ if (!updatedSettings["files.associations"]["nbk.config.json"]) {
51
+ updatedSettings["files.associations"]["nbk.config.json"] = "jsonc";
52
+ console.log("Added nbk.config.json association to .vscode/settings.json");
53
+ }
54
+ else {
55
+ console.log("nbk.config.json association already exists in .vscode/settings.json");
56
+ }
57
+ // Only write to file if changes were made
58
+ if (JSON.stringify(settings) !== JSON.stringify(updatedSettings)) {
59
+ try {
60
+ fs.writeFileSync(settingsPath, JSON.stringify(updatedSettings, null, 4));
61
+ }
62
+ catch (error) {
63
+ console.error("Error writing to settings file:", error);
64
+ console.log("Keeping existing settings file unchanged");
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,95 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "NBK Configuration Schema",
4
+ "description": "Schema for nbk.config.json configuration file",
5
+ "type": "object",
6
+ "required": [
7
+ "projects",
8
+ "b2fPortal",
9
+ "checkCrossProjectImports"
10
+ ],
11
+ "properties": {
12
+ "projects": {
13
+ "type": "array",
14
+ "description": "Array of projects to manage. Each project can have multiple sections like masterPanel, adminPanel, staffPanel, and webApp.",
15
+ "items": {
16
+ "type": "object",
17
+ "required": [
18
+ "projectName",
19
+ "projectBaseDirPath",
20
+ "sections"
21
+ ],
22
+ "properties": {
23
+ "projectName": {
24
+ "type": "string",
25
+ "description": "Name of the project (e.g., 'demo_project')"
26
+ },
27
+ "projectBaseDirPath": {
28
+ "type": "string",
29
+ "description": "Base directory path for the project relative to the config file"
30
+ },
31
+ "sharedBackendPath": {
32
+ "type": "string",
33
+ "description": "Path to shared backend code, relative to the project root (e.g., '../../shared_one/backend')"
34
+ },
35
+ "sections": {
36
+ "type": "array",
37
+ "description": "Array of project sections. Each section represents a different part of your application (e.g., masterPanel, adminPanel, staffPanel, webApp)",
38
+ "items": {
39
+ "type": "object",
40
+ "required": [
41
+ "sectionName",
42
+ "repository",
43
+ "localPath",
44
+ "isZodCreator"
45
+ ],
46
+ "properties": {
47
+ "sectionName": {
48
+ "type": "string",
49
+ "description": "Name of the section (e.g., 'masterPanel', 'adminPanel', 'staffPanel', 'webApp')"
50
+ },
51
+ "repository": {
52
+ "type": "object",
53
+ "required": [
54
+ "name",
55
+ "path"
56
+ ],
57
+ "properties": {
58
+ "name": {
59
+ "type": "string",
60
+ "description": "Repository name (e.g., 'demo_project_master_panel')"
61
+ },
62
+ "path": {
63
+ "type": "string",
64
+ "description": "Repository path relative to the project root (e.g., '../../demo_project/master_panel')"
65
+ }
66
+ }
67
+ },
68
+ "localPath": {
69
+ "type": "string",
70
+ "description": "Local path where the section code is located relative to the project root (e.g., 'masterPanel')"
71
+ },
72
+ "isZodCreator": {
73
+ "type": "boolean",
74
+ "description": "Whether this section uses Zod for validation. Set to true if the section uses Zod schemas."
75
+ },
76
+ "needNextJsPatch": {
77
+ "type": "boolean",
78
+ "description": "Whether this section needs Next.js patch. Only required for Next.js projects."
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "b2fPortal": {
87
+ "type": "boolean",
88
+ "description": "Whether this is a B2F (Business-to-Frontend) portal project. Set to true if your project is a B2F portal."
89
+ },
90
+ "checkCrossProjectImports": {
91
+ "type": "boolean",
92
+ "description": "Whether to check for cross-project imports. Set to true to enable validation of imports between different project sections."
93
+ }
94
+ }
95
+ }
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@digicroz/node-backend-kit",
3
+ "version": "1.0.0",
4
+ "description": "NodeJS Backend Kit - A powerful TypeScript utility for managing backend projects with features like B2F Portal integration, cross-project validation, and Next.js support",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "nbk.schema.json"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "bin": {
19
+ "nbk": "./dist/bin/nbk.js"
20
+ },
21
+ "engines": {
22
+ "node": ">=16.0.0"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/AdarshHatkar/nbk.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/AdarshHatkar/nbk/issues"
33
+ },
34
+ "homepage": "https://github.com/AdarshHatkar/nbk#readme",
35
+ "scripts": {
36
+ "prepare": "husky install",
37
+ "dev": "npm run clean && tsc -w",
38
+ "clean": "rimraf dist && tsc",
39
+ "release:patch": "npm version patch",
40
+ "postversion": "git push && git push --tags && npm publish",
41
+ "build": "npm run clean && tsc",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest",
44
+ "lint": "tsc --noEmit",
45
+ "prepublishOnly": "npm run build"
46
+ },
47
+ "keywords": [
48
+ "backend",
49
+ "kit",
50
+ "primexop",
51
+ "typescript",
52
+ "node",
53
+ "b2f-portal",
54
+ "nextjs",
55
+ "validation",
56
+ "configuration",
57
+ "cross-project",
58
+ "development-tools",
59
+ "typescript-utilities",
60
+ "backend-management",
61
+ "project-management",
62
+ "api-development"
63
+ ],
64
+ "author": "AdarshHatkar",
65
+ "license": "ISC",
66
+ "devDependencies": {
67
+ "@types/node": "^22.14.1",
68
+ "tsc-path-fix": "^1.0.4",
69
+ "typescript": "^5.8.3",
70
+ "vitest": "^3.1.1"
71
+ },
72
+ "dependencies": {
73
+ "commander": "^13.1.0",
74
+ "dotenv": "^16.5.0",
75
+ "husky": "^9.1.7",
76
+ "ora": "^7.0.1",
77
+ "rimraf": "^6.0.1",
78
+ "simple-git": "^3.27.0"
79
+ }
80
+ }