nitor 0.0.1 → 1.1.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/CHANGELOG.md +7 -53
- package/README.md +28 -22
- package/package.json +1 -1
- package/services/cleanup.js +63 -0
- package/services/enums/actions.enum.js +7 -6
- package/services/merge.js +1 -1
- package/services/process-commands.js +38 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [1.0.0] - 2025-
|
|
3
|
+
## [1.0.0] - 2025-11-14
|
|
4
4
|
|
|
5
5
|
### Initial Release
|
|
6
6
|
|
|
7
|
-
We are pleased to announce the first official release of **
|
|
7
|
+
We are pleased to announce the first official release of **Nitor**.
|
|
8
8
|
|
|
9
9
|
#### Features
|
|
10
10
|
|
|
@@ -15,58 +15,12 @@ We are pleased to announce the first official release of **Nithin Utils**.
|
|
|
15
15
|
- Utility functions for parameter parsing and object cleanup.
|
|
16
16
|
- Scriptable and extensible for automation and integration into larger workflows.
|
|
17
17
|
|
|
18
|
-
For a complete list of changes and discussion, see [Issue #1](https://github.com/codebynithin/
|
|
18
|
+
For a complete list of changes and discussion, see [Issue #1](https://github.com/codebynithin/nitor/issues/1).
|
|
19
19
|
|
|
20
|
-
## [1.0
|
|
20
|
+
## [1.1.0] - 2025-11-14
|
|
21
21
|
|
|
22
|
-
###
|
|
22
|
+
### New Features
|
|
23
23
|
|
|
24
|
-
-
|
|
24
|
+
- Added cleanup command to delete all local branches except master/main.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## [1.1.0] - 2025-08-14
|
|
29
|
-
|
|
30
|
-
### Features
|
|
31
|
-
|
|
32
|
-
- Added support for creating git branches, see [Issue #3](https://github.com/codebynithin/nithin-utils/issues/3).
|
|
33
|
-
|
|
34
|
-
## [1.2.0] - 2025-08-15
|
|
35
|
-
|
|
36
|
-
### Features
|
|
37
|
-
|
|
38
|
-
- Added support for automating AI Review, see [Issue #4](https://github.com/codebynithin/nithin-utils/issues/4).
|
|
39
|
-
|
|
40
|
-
## [1.2.1] - 2025-08-25
|
|
41
|
-
|
|
42
|
-
### Bug Fixes
|
|
43
|
-
|
|
44
|
-
- Fixed Review review url, see [Issue #6](https://github.com/codebynithin/nithin-utils/issues/6).
|
|
45
|
-
|
|
46
|
-
## [1.2.2] - 2025-09-15
|
|
47
|
-
|
|
48
|
-
### Features
|
|
49
|
-
|
|
50
|
-
- Added support for automating build, see [Issue #7](https://github.com/codebynithin/nithin-utils/issues/7).
|
|
51
|
-
|
|
52
|
-
### Bug Fixes
|
|
53
|
-
|
|
54
|
-
- Fixed build branch, see [Issue #8](https://github.com/codebynithin/nithin-utils/issues/8).
|
|
55
|
-
|
|
56
|
-
## [1.3.0] - 2025-09-21
|
|
57
|
-
|
|
58
|
-
### Features
|
|
59
|
-
|
|
60
|
-
- Added support for automating build, see [Issue #9](https://github.com/codebynithin/nithin-utils/issues/9).
|
|
61
|
-
|
|
62
|
-
## [1.4.0] - 2025-10-10
|
|
63
|
-
|
|
64
|
-
### Features
|
|
65
|
-
|
|
66
|
-
- Added support for automating backup, see [Issue #12](https://github.com/codebynithin/nithin-utils/issues/12).
|
|
67
|
-
|
|
68
|
-
## [1.5.0] - 2025-10-22
|
|
69
|
-
|
|
70
|
-
### Features
|
|
71
|
-
|
|
72
|
-
- Added support for automating merge, see [Issue #14](https://github.com/codebynithin/nithin-utils/issues/14).
|
|
26
|
+
- [Issue #6](https://github.com/codebynithin/nitor/issues/6)
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# nitor
|
|
2
2
|
|
|
3
3
|
<a name="readme-top"></a>
|
|
4
4
|
|
|
@@ -23,68 +23,73 @@ A CLI utility toolkit for automating and managing build, deploy, and status oper
|
|
|
23
23
|
- AI text refactoring
|
|
24
24
|
- Backup and restore MongoDB
|
|
25
25
|
- Merge git branches
|
|
26
|
+
- Cleanup local git branches
|
|
26
27
|
|
|
27
28
|
## Requirements
|
|
28
29
|
|
|
29
30
|
- Node.js >= 14.x
|
|
30
31
|
- npm >= 6.x
|
|
31
32
|
- A properly configured `.env.nu` file in your `~/Desktop` directory with required tokens and URLs:
|
|
32
|
-
- `CSRF_TOKEN`
|
|
33
|
-
- `COOKIE`
|
|
34
|
-
- `ORIGIN`
|
|
35
|
-
- `GITLAB_TOKEN`
|
|
36
|
-
- `MR_PROMPT`
|
|
37
|
-
- `MR_LANG`
|
|
38
|
-
- `AI_API_KEY`
|
|
39
|
-
- `AI_MODEL`
|
|
40
|
-
- `BACKUP_CONFIG`
|
|
41
|
-
- `RESTORE_CONFIG`
|
|
33
|
+
- `CSRF_TOKEN` - CSRF token for Gitlab (Copy from browser)
|
|
34
|
+
- `COOKIE` - Cookie for Gitlab (Copy from browser)
|
|
35
|
+
- `ORIGIN` - Origin for Gitlab website url, eg: `https://gitlab.com/`
|
|
36
|
+
- `GITLAB_TOKEN` - Gitlab token
|
|
37
|
+
- `MR_PROMPT` - Merge request prompt
|
|
38
|
+
- `MR_LANG` - Merge request language
|
|
39
|
+
- `AI_API_KEY` - AI API key
|
|
40
|
+
- `AI_MODEL` - AI model
|
|
41
|
+
- `BACKUP_CONFIG` - Backup configuration
|
|
42
|
+
- `RESTORE_CONFIG` - Restore configuration
|
|
42
43
|
|
|
43
44
|
## Usage
|
|
44
45
|
|
|
45
|
-
You can use the CLI via the `
|
|
46
|
+
You can use the CLI via the `nitor` command:
|
|
46
47
|
|
|
47
48
|
```bash
|
|
48
|
-
|
|
49
|
+
nitor <command> [options]
|
|
49
50
|
```
|
|
50
51
|
|
|
51
52
|
### Example Commands
|
|
52
53
|
|
|
53
54
|
- **Build:**
|
|
54
55
|
```bash
|
|
55
|
-
|
|
56
|
+
nitor build -project <project name> -components <component name> -instance <instance name>
|
|
56
57
|
```
|
|
57
58
|
- **Deploy:**
|
|
58
59
|
```bash
|
|
59
|
-
|
|
60
|
+
nitor deploy -project <project name> -components <component name> -instance <instance name>
|
|
60
61
|
```
|
|
61
62
|
- **Build & Deploy:**
|
|
62
63
|
```bash
|
|
63
|
-
|
|
64
|
+
nitor build-deploy -project <project name> -components <component name> -instance <instance name>
|
|
64
65
|
```
|
|
65
66
|
- **Create branch:**
|
|
66
67
|
```bash
|
|
67
|
-
|
|
68
|
+
nitor create-branch -task <task number> -type <feat|fix> -description <description> -repository <repository name>
|
|
68
69
|
```
|
|
69
70
|
- **Review:**
|
|
70
71
|
```bash
|
|
71
|
-
|
|
72
|
+
nitor review -project <project short name> -mergeId <merge id> -repository <repository name>
|
|
72
73
|
```
|
|
73
74
|
- **Refactor Text:**
|
|
74
75
|
```bash
|
|
75
|
-
|
|
76
|
+
nitor refactor <text>
|
|
76
77
|
```
|
|
77
78
|
- **Backup:**
|
|
78
79
|
```bash
|
|
79
|
-
|
|
80
|
+
nitor backup <text>
|
|
80
81
|
```
|
|
81
82
|
- **Restore:**
|
|
82
83
|
```bash
|
|
83
|
-
|
|
84
|
+
nitor restore <text>
|
|
84
85
|
```
|
|
85
86
|
- **Merge:**
|
|
86
87
|
```bash
|
|
87
|
-
|
|
88
|
+
nitor merge -source <source branch> -target <target branch>
|
|
89
|
+
```
|
|
90
|
+
- **Cleanup:**
|
|
91
|
+
```bash
|
|
92
|
+
nitor cleanup
|
|
88
93
|
```
|
|
89
94
|
|
|
90
95
|
### Command Reference
|
|
@@ -101,6 +106,7 @@ nu <command> [options]
|
|
|
101
106
|
- `backup` : Backup specified projects
|
|
102
107
|
- `restore` : Restore specified projects
|
|
103
108
|
- `merge` : Merge source branch into target branch
|
|
109
|
+
- `cleanup` : Cleanup local git branches (checkout to master and delete all other branches)
|
|
104
110
|
|
|
105
111
|
### Options
|
|
106
112
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
|
|
3
|
+
const cleanup = async () => {
|
|
4
|
+
try {
|
|
5
|
+
console.log('Starting cleanup process...\n');
|
|
6
|
+
|
|
7
|
+
// Get current branch
|
|
8
|
+
const currentBranch = execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
|
|
9
|
+
console.log(`Current branch: ${currentBranch}`);
|
|
10
|
+
|
|
11
|
+
// Checkout to master
|
|
12
|
+
console.log('\nChecking out to master branch...');
|
|
13
|
+
try {
|
|
14
|
+
execSync('git checkout master', { encoding: 'utf-8', stdio: 'inherit' });
|
|
15
|
+
} catch (error) {
|
|
16
|
+
// Try main if master doesn't exist
|
|
17
|
+
console.log('Master branch not found, trying main...');
|
|
18
|
+
execSync('git checkout main', { encoding: 'utf-8', stdio: 'inherit' });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Get all local branches except master/main
|
|
22
|
+
console.log('\nFetching list of local branches...');
|
|
23
|
+
const branches = execSync('git branch', { encoding: 'utf-8' })
|
|
24
|
+
.split('\n')
|
|
25
|
+
.map((branch) => branch.trim().replace('* ', ''))
|
|
26
|
+
.filter((branch) => branch && branch !== 'master' && branch !== 'main');
|
|
27
|
+
|
|
28
|
+
if (!branches.length) {
|
|
29
|
+
console.log('\nNo branches to delete. Cleanup complete!');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log(`\nFound ${branches.length} branch(es) to delete:`);
|
|
34
|
+
|
|
35
|
+
// Delete each branch
|
|
36
|
+
console.log('\nDeleting branches...');
|
|
37
|
+
let deletedCount = 0;
|
|
38
|
+
let failedCount = 0;
|
|
39
|
+
|
|
40
|
+
for (const branch of branches) {
|
|
41
|
+
try {
|
|
42
|
+
execSync(`git branch -D ${branch}`, { encoding: 'utf-8' });
|
|
43
|
+
console.log(` ✓ Deleted: ${branch}`);
|
|
44
|
+
deletedCount++;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.log(` ✗ Failed to delete: ${branch}`);
|
|
47
|
+
failedCount++;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log(`\nCleanup complete!`);
|
|
52
|
+
console.log(` Deleted: ${deletedCount} branch(es)`);
|
|
53
|
+
|
|
54
|
+
if (failedCount > 0) {
|
|
55
|
+
console.log(` Failed: ${failedCount} branch(es)`);
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error('Error during cleanup:', error.message);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = { cleanup };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
ACTIONS: {
|
|
3
|
+
BACKUP: 'backup',
|
|
4
|
+
BUILD_DEPLOY: 'build-deploy',
|
|
3
5
|
BUILD: 'build',
|
|
6
|
+
CLEANUP: 'cleanup',
|
|
7
|
+
CREATE_BRANCH: 'create-branch',
|
|
4
8
|
DEPLOY: 'deploy',
|
|
5
|
-
BUILD_DEPLOY: 'build-deploy',
|
|
6
|
-
VERSION: 'version',
|
|
7
9
|
HELP: 'help',
|
|
8
|
-
CREATE_BRANCH: 'create-branch',
|
|
9
|
-
REVIEW: 'review',
|
|
10
|
-
REFACTOR: 'refactor',
|
|
11
|
-
BACKUP: 'backup',
|
|
12
10
|
MERGE: 'merge',
|
|
11
|
+
REFACTOR: 'refactor',
|
|
12
|
+
REVIEW: 'review',
|
|
13
|
+
VERSION: 'version',
|
|
13
14
|
},
|
|
14
15
|
};
|
package/services/merge.js
CHANGED
|
@@ -5,7 +5,7 @@ const merge = async (values) => {
|
|
|
5
5
|
|
|
6
6
|
if (!source || !target) {
|
|
7
7
|
console.error('Error: Both -source and -target branch parameters are required');
|
|
8
|
-
console.log('Usage:
|
|
8
|
+
console.log('Usage: nitor merge -source <source branch> -target <target branch>');
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -8,6 +8,7 @@ const { mrAIReview } = require('./review');
|
|
|
8
8
|
const { refactor } = require('./refactor');
|
|
9
9
|
const { backup } = require('./mongodb-backup');
|
|
10
10
|
const { merge } = require('./merge');
|
|
11
|
+
const { cleanup } = require('./cleanup');
|
|
11
12
|
|
|
12
13
|
const processArgs = async (type, value) => {
|
|
13
14
|
try {
|
|
@@ -16,6 +17,7 @@ const processArgs = async (type, value) => {
|
|
|
16
17
|
if (
|
|
17
18
|
type !== ACTIONS.HELP &&
|
|
18
19
|
type !== ACTIONS.VERSION &&
|
|
20
|
+
type !== ACTIONS.CLEANUP &&
|
|
19
21
|
!value.includes('--h') &&
|
|
20
22
|
!value.includes('-help')
|
|
21
23
|
) {
|
|
@@ -224,6 +226,26 @@ This command will:
|
|
|
224
226
|
break;
|
|
225
227
|
}
|
|
226
228
|
|
|
229
|
+
case ACTIONS.CLEANUP: {
|
|
230
|
+
if (value === '-help' || value === '--h') {
|
|
231
|
+
console.log(`usage: \tnu cleanup
|
|
232
|
+
|
|
233
|
+
Cleanup local git branches
|
|
234
|
+
|
|
235
|
+
This command will:
|
|
236
|
+
1. Checkout to master (or main) branch
|
|
237
|
+
2. Delete all other local branches
|
|
238
|
+
|
|
239
|
+
Note: This operation cannot be undone. Make sure you have pushed any important changes.`);
|
|
240
|
+
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
await cleanup();
|
|
245
|
+
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
|
|
227
249
|
case ACTIONS.VERSION: {
|
|
228
250
|
const path = require('path');
|
|
229
251
|
const packageJson = require(path.resolve(__dirname, '../package.json'));
|
|
@@ -235,9 +257,10 @@ This command will:
|
|
|
235
257
|
}
|
|
236
258
|
|
|
237
259
|
case ACTIONS.HELP: {
|
|
238
|
-
console.log(`usage:
|
|
260
|
+
console.log(`usage: nitor \t[${ACTIONS.VERSION}] [${ACTIONS.HELP}]
|
|
239
261
|
\t[${ACTIONS.BUILD}] [${ACTIONS.DEPLOY}] [${ACTIONS.BUILD_DEPLOY}]
|
|
240
|
-
\t[${ACTIONS.CREATE_BRANCH}] [${ACTIONS.REVIEW}] [${ACTIONS.MERGE}]
|
|
262
|
+
\t[${ACTIONS.CREATE_BRANCH}] [${ACTIONS.REVIEW}] [${ACTIONS.MERGE}]
|
|
263
|
+
\t[${ACTIONS.CLEANUP}]\n
|
|
241
264
|
Available commands:\n
|
|
242
265
|
build : Build specified components
|
|
243
266
|
deploy : Deploy specified components
|
|
@@ -246,26 +269,28 @@ Available commands:\n
|
|
|
246
269
|
review : AI Review specified merge request
|
|
247
270
|
refactor : REFACTOR the provided text for improved clarity, conciseness, and professional quality.
|
|
248
271
|
merge : Merge source branch into target branch
|
|
272
|
+
cleanup : Cleanup local git branches (checkout to master and delete all other branches)
|
|
249
273
|
version : Show version info
|
|
250
274
|
help : Show help
|
|
251
275
|
|
|
252
|
-
For details of each actions run '
|
|
276
|
+
For details of each actions run 'nitor <action> -help'
|
|
253
277
|
|
|
254
278
|
Example usage:\n
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
279
|
+
nitor build -project <project> -components <components> -instance <instance>
|
|
280
|
+
nitor deploy -project <project> -components <components> -instance <instance>
|
|
281
|
+
nitor build-deploy -project <project> -components <components> -instance <instance>
|
|
282
|
+
nitor create-branch -task <task number> -type <feat|fix> -description <description> -project <project short name>
|
|
283
|
+
nitor review -project <project short name> -mergeId <merge id> -repository <repository name>
|
|
284
|
+
nitor refactor <text>
|
|
285
|
+
nitor merge -source <source branch> -target <target branch>
|
|
286
|
+
nitor cleanup
|
|
287
|
+
|
|
288
|
+
Running 'nitor help' will list available subcommands and provide some conceptual guides.`);
|
|
264
289
|
break;
|
|
265
290
|
}
|
|
266
291
|
|
|
267
292
|
default: {
|
|
268
|
-
console.error(`
|
|
293
|
+
console.error(`nitor: '${type}' is not a nitor command. See 'nitor help'.`);
|
|
269
294
|
|
|
270
295
|
return;
|
|
271
296
|
}
|