@glpkg/config 0.2.1
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/.cli-docs.json +12 -0
- package/README.md +71 -0
- package/api-extractor.json +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +139 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +195 -0
- package/docs/cli/gitlab-config-cli.md +72 -0
- package/docs/cli/index.md +11 -0
- package/docs/typedoc-md/README.md +55 -0
- package/docs/typedoc-md/_media/gitlab-config.md +65 -0
- package/docs/typedoc-md/functions/getToken.md +19 -0
- package/docs/typedoc-md/functions/hasToken.md +19 -0
- package/docs/typedoc-md/functions/removeToken.md +17 -0
- package/docs/typedoc-md/functions/saveToken.md +25 -0
- package/docs/typedoc-md/globals.md +12 -0
- package/package.json +45 -0
package/.cli-docs.json
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @microature/gitlab-config
|
|
2
|
+
|
|
3
|
+
GitLab configuration management - save and load tokens from user config directory (`~/.config/gitlab-config`).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @microature/gitlab-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### CLI
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Save a token
|
|
17
|
+
gitlab-config save glpat-your-token-here
|
|
18
|
+
|
|
19
|
+
# Get saved token
|
|
20
|
+
gitlab-config get
|
|
21
|
+
|
|
22
|
+
# Check if token exists
|
|
23
|
+
gitlab-config check
|
|
24
|
+
|
|
25
|
+
# Remove token
|
|
26
|
+
gitlab-config remove
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
See [CLI Documentation](./docs/cli/gitlab-config-cli.md) for detailed command reference.
|
|
30
|
+
|
|
31
|
+
### Programmatic API
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { saveToken, getToken, hasToken, removeToken } from '@microature/gitlab-config';
|
|
35
|
+
|
|
36
|
+
// Save a token
|
|
37
|
+
saveToken('glpat-your-token-here');
|
|
38
|
+
|
|
39
|
+
// Get the token
|
|
40
|
+
const token = getToken(); // Returns token or null if not found
|
|
41
|
+
|
|
42
|
+
// Check if token exists
|
|
43
|
+
if (hasToken()) {
|
|
44
|
+
console.log('Token is configured');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Remove the token
|
|
48
|
+
removeToken();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
See the [API documentation](./docs/markdown/gitlab-config.md) for detailed information.
|
|
54
|
+
|
|
55
|
+
### Functions
|
|
56
|
+
|
|
57
|
+
- **`saveToken(token: string): void`** - Save GitLab token to `~/.config/gitlab-config/token`
|
|
58
|
+
- **`getToken(): string | null`** - Get GitLab token or null if not found
|
|
59
|
+
- **`hasToken(): boolean`** - Check if token exists
|
|
60
|
+
- **`removeToken(): void`** - Remove saved token
|
|
61
|
+
|
|
62
|
+
## How It Works
|
|
63
|
+
|
|
64
|
+
- Tokens are stored in `~/.config/gitlab-config/token`
|
|
65
|
+
- The config directory is automatically created if it doesn't exist
|
|
66
|
+
- Token file is created with `0600` permissions (read/write for owner only)
|
|
67
|
+
- Returns `null` if token file doesn't exist or is empty
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
ISC
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
|
|
4
|
+
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",
|
|
5
|
+
|
|
6
|
+
"compiler": {
|
|
7
|
+
"tsconfigFilePath": "<projectFolder>/tsconfig.json"
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
"apiReport": {
|
|
11
|
+
"enabled": true,
|
|
12
|
+
"reportFolder": "<projectFolder>/docs",
|
|
13
|
+
"reportFileName": "gitlab-config.api.md"
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
"docModel": {
|
|
17
|
+
"enabled": true,
|
|
18
|
+
"apiJsonFilePath": "<projectFolder>/docs/<unscopedPackageName>.api.json"
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
"dtsRollup": {
|
|
22
|
+
"enabled": false
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
"tsdocMetadata": {
|
|
26
|
+
"enabled": false
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
"messages": {
|
|
30
|
+
"extractorMessageReporting": {
|
|
31
|
+
"default": {
|
|
32
|
+
"logLevel": "warning"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const index_1 = require("./index");
|
|
6
|
+
const packageJson = require('../package.json');
|
|
7
|
+
const program = new commander_1.Command();
|
|
8
|
+
program
|
|
9
|
+
.name('gitlab-config')
|
|
10
|
+
.description('Manage GitLab configuration and tokens')
|
|
11
|
+
.version(packageJson.version);
|
|
12
|
+
// Save token command
|
|
13
|
+
program
|
|
14
|
+
.command('save <token>')
|
|
15
|
+
.description('Save GitLab token to ~/.config/gitlab-config/token')
|
|
16
|
+
.action((token) => {
|
|
17
|
+
try {
|
|
18
|
+
(0, index_1.saveToken)(token);
|
|
19
|
+
console.log('✓ Token saved successfully');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error('✗ Failed to save token:', error.message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
// Get token command
|
|
27
|
+
program
|
|
28
|
+
.command('get')
|
|
29
|
+
.description('Get saved GitLab token')
|
|
30
|
+
.action(() => {
|
|
31
|
+
try {
|
|
32
|
+
const token = (0, index_1.getToken)();
|
|
33
|
+
if (token) {
|
|
34
|
+
console.log(token);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.error('✗ No token found');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('✗ Failed to get token:', error.message);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// Check token command
|
|
47
|
+
program
|
|
48
|
+
.command('check')
|
|
49
|
+
.description('Check if token exists')
|
|
50
|
+
.action(() => {
|
|
51
|
+
if ((0, index_1.hasToken)()) {
|
|
52
|
+
console.log('✓ Token is configured');
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.log('✗ No token found');
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
// Remove token command
|
|
61
|
+
program
|
|
62
|
+
.command('remove')
|
|
63
|
+
.description('Remove saved token')
|
|
64
|
+
.action(() => {
|
|
65
|
+
try {
|
|
66
|
+
(0, index_1.removeToken)();
|
|
67
|
+
console.log('✓ Token removed successfully');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('✗ Failed to remove token:', error.message);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
// Package management commands
|
|
75
|
+
const packageCmd = program
|
|
76
|
+
.command('package')
|
|
77
|
+
.description('Manage package registry metadata');
|
|
78
|
+
// Get package info
|
|
79
|
+
packageCmd
|
|
80
|
+
.command('get <package-name>')
|
|
81
|
+
.description('Get package registry information')
|
|
82
|
+
.action((packageName) => {
|
|
83
|
+
const info = (0, index_1.getPackageInfo)(packageName);
|
|
84
|
+
if (info) {
|
|
85
|
+
console.log(JSON.stringify(info, null, 2));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.error('✗ Package not found:', packageName);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
// List all packages
|
|
93
|
+
packageCmd
|
|
94
|
+
.command('list')
|
|
95
|
+
.description('List all registered packages')
|
|
96
|
+
.option('-g, --group <group>', 'Filter by group name')
|
|
97
|
+
.action((options) => {
|
|
98
|
+
if (options.group) {
|
|
99
|
+
const packages = (0, index_1.searchPackagesByGroup)(options.group);
|
|
100
|
+
console.log(JSON.stringify(packages, null, 2));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const metadata = (0, index_1.getAllPackages)();
|
|
104
|
+
console.log(JSON.stringify(metadata, null, 2));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
// Remove package info
|
|
108
|
+
packageCmd
|
|
109
|
+
.command('remove <package-name>')
|
|
110
|
+
.description('Remove package registry information')
|
|
111
|
+
.action((packageName) => {
|
|
112
|
+
const removed = (0, index_1.removePackageInfo)(packageName);
|
|
113
|
+
if (removed) {
|
|
114
|
+
console.log('✓ Package removed:', packageName);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.error('✗ Package not found:', packageName);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
// Clear all packages
|
|
122
|
+
packageCmd
|
|
123
|
+
.command('clear')
|
|
124
|
+
.description('Clear all package registry metadata')
|
|
125
|
+
.action(() => {
|
|
126
|
+
try {
|
|
127
|
+
(0, index_1.clearAllPackages)();
|
|
128
|
+
console.log('✓ All package metadata cleared');
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
console.error('✗ Failed to clear packages:', error.message);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
program.parse();
|
|
136
|
+
// Show help if no command provided
|
|
137
|
+
if (!process.argv.slice(2).length) {
|
|
138
|
+
program.outputHelp();
|
|
139
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package registry type - where the package is stored
|
|
3
|
+
*/
|
|
4
|
+
export type RegistryType = 'group' | 'project';
|
|
5
|
+
/**
|
|
6
|
+
* Source of package information
|
|
7
|
+
*/
|
|
8
|
+
export type PackageInfoSource = 'published' | 'manual' | 'detected';
|
|
9
|
+
/**
|
|
10
|
+
* Package registry information
|
|
11
|
+
*/
|
|
12
|
+
export interface PackageInfo {
|
|
13
|
+
/** Package name (e.g., "@another/lib-name" or "my-lib") */
|
|
14
|
+
packageName: string;
|
|
15
|
+
/** GitLab group/namespace (e.g., "my-company") */
|
|
16
|
+
group: string;
|
|
17
|
+
/** GitLab group ID (optional) */
|
|
18
|
+
groupId?: number;
|
|
19
|
+
/** GitLab project ID (optional) */
|
|
20
|
+
projectId?: number;
|
|
21
|
+
/** Registry type */
|
|
22
|
+
registryType: RegistryType;
|
|
23
|
+
/** Full registry URL */
|
|
24
|
+
registryUrl: string;
|
|
25
|
+
/** GitLab host (e.g., "gitlab.com") */
|
|
26
|
+
gitlabHost: string;
|
|
27
|
+
/** Last updated timestamp (ISO format) */
|
|
28
|
+
lastUpdated: string;
|
|
29
|
+
/** Source of this information */
|
|
30
|
+
source: PackageInfoSource;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Package registry metadata structure
|
|
34
|
+
*/
|
|
35
|
+
export interface PackageRegistryMetadata {
|
|
36
|
+
packages: Record<string, PackageInfo>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Save GitLab token to user config directory
|
|
40
|
+
* @param token - GitLab personal access token
|
|
41
|
+
*/
|
|
42
|
+
export declare function saveToken(token: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get GitLab token from user config directory
|
|
45
|
+
* @returns GitLab token or null if not found
|
|
46
|
+
*/
|
|
47
|
+
export declare function getToken(): string | null;
|
|
48
|
+
/**
|
|
49
|
+
* Check if token exists
|
|
50
|
+
* @returns true if token exists
|
|
51
|
+
*/
|
|
52
|
+
export declare function hasToken(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Remove saved token
|
|
55
|
+
*/
|
|
56
|
+
export declare function removeToken(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get package information by package name
|
|
59
|
+
* @param packageName - Package name (e.g., "@another/lib-name")
|
|
60
|
+
* @returns Package info or null if not found
|
|
61
|
+
*/
|
|
62
|
+
export declare function getPackageInfo(packageName: string): PackageInfo | null;
|
|
63
|
+
/**
|
|
64
|
+
* Get all package information
|
|
65
|
+
* @returns All package registry metadata
|
|
66
|
+
*/
|
|
67
|
+
export declare function getAllPackages(): PackageRegistryMetadata;
|
|
68
|
+
/**
|
|
69
|
+
* Search packages by group name
|
|
70
|
+
* @param group - GitLab group name
|
|
71
|
+
* @returns Array of package info for the group
|
|
72
|
+
*/
|
|
73
|
+
export declare function searchPackagesByGroup(group: string): PackageInfo[];
|
|
74
|
+
/**
|
|
75
|
+
* Save package information
|
|
76
|
+
* @param info - Package information to save
|
|
77
|
+
*/
|
|
78
|
+
export declare function savePackageInfo(info: PackageInfo): void;
|
|
79
|
+
/**
|
|
80
|
+
* Remove package information
|
|
81
|
+
* @param packageName - Package name to remove
|
|
82
|
+
* @returns true if removed, false if not found
|
|
83
|
+
*/
|
|
84
|
+
export declare function removePackageInfo(packageName: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Check if package information exists
|
|
87
|
+
* @param packageName - Package name to check
|
|
88
|
+
* @returns true if package info exists
|
|
89
|
+
*/
|
|
90
|
+
export declare function hasPackageInfo(packageName: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Clear all package registry metadata
|
|
93
|
+
*/
|
|
94
|
+
export declare function clearAllPackages(): void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.saveToken = saveToken;
|
|
37
|
+
exports.getToken = getToken;
|
|
38
|
+
exports.hasToken = hasToken;
|
|
39
|
+
exports.removeToken = removeToken;
|
|
40
|
+
exports.getPackageInfo = getPackageInfo;
|
|
41
|
+
exports.getAllPackages = getAllPackages;
|
|
42
|
+
exports.searchPackagesByGroup = searchPackagesByGroup;
|
|
43
|
+
exports.savePackageInfo = savePackageInfo;
|
|
44
|
+
exports.removePackageInfo = removePackageInfo;
|
|
45
|
+
exports.hasPackageInfo = hasPackageInfo;
|
|
46
|
+
exports.clearAllPackages = clearAllPackages;
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const os = __importStar(require("os"));
|
|
50
|
+
const CONFIG_DIR = path.join(os.homedir(), '.config', 'gitlab-config');
|
|
51
|
+
const TOKEN_FILE = path.join(CONFIG_DIR, 'token');
|
|
52
|
+
const PACKAGE_REGISTRY_FILE = path.join(CONFIG_DIR, 'package-registry.json');
|
|
53
|
+
/**
|
|
54
|
+
* Ensure the config directory exists
|
|
55
|
+
*/
|
|
56
|
+
function ensureConfigDir() {
|
|
57
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
58
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Save GitLab token to user config directory
|
|
63
|
+
* @param token - GitLab personal access token
|
|
64
|
+
*/
|
|
65
|
+
function saveToken(token) {
|
|
66
|
+
if (!token || token.trim().length === 0) {
|
|
67
|
+
throw new Error('Token cannot be empty');
|
|
68
|
+
}
|
|
69
|
+
ensureConfigDir();
|
|
70
|
+
fs.writeFileSync(TOKEN_FILE, token.trim(), { mode: 0o600 });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get GitLab token from user config directory
|
|
74
|
+
* @returns GitLab token or null if not found
|
|
75
|
+
*/
|
|
76
|
+
function getToken() {
|
|
77
|
+
if (!fs.existsSync(TOKEN_FILE)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const token = fs.readFileSync(TOKEN_FILE, 'utf-8').trim();
|
|
82
|
+
return token.length > 0 ? token : null;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if token exists
|
|
90
|
+
* @returns true if token exists
|
|
91
|
+
*/
|
|
92
|
+
function hasToken() {
|
|
93
|
+
return getToken() !== null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Remove saved token
|
|
97
|
+
*/
|
|
98
|
+
function removeToken() {
|
|
99
|
+
if (fs.existsSync(TOKEN_FILE)) {
|
|
100
|
+
fs.unlinkSync(TOKEN_FILE);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// Package Registry Metadata Management
|
|
105
|
+
// ============================================================================
|
|
106
|
+
/**
|
|
107
|
+
* Load package registry metadata from file
|
|
108
|
+
*/
|
|
109
|
+
function loadPackageRegistry() {
|
|
110
|
+
if (!fs.existsSync(PACKAGE_REGISTRY_FILE)) {
|
|
111
|
+
return { packages: {} };
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const content = fs.readFileSync(PACKAGE_REGISTRY_FILE, 'utf-8');
|
|
115
|
+
return JSON.parse(content);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
// If file is corrupted, return empty metadata
|
|
119
|
+
return { packages: {} };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Save package registry metadata to file
|
|
124
|
+
*/
|
|
125
|
+
function savePackageRegistry(metadata) {
|
|
126
|
+
ensureConfigDir();
|
|
127
|
+
fs.writeFileSync(PACKAGE_REGISTRY_FILE, JSON.stringify(metadata, null, 2), { mode: 0o644 });
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get package information by package name
|
|
131
|
+
* @param packageName - Package name (e.g., "@another/lib-name")
|
|
132
|
+
* @returns Package info or null if not found
|
|
133
|
+
*/
|
|
134
|
+
function getPackageInfo(packageName) {
|
|
135
|
+
const metadata = loadPackageRegistry();
|
|
136
|
+
return metadata.packages[packageName] || null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get all package information
|
|
140
|
+
* @returns All package registry metadata
|
|
141
|
+
*/
|
|
142
|
+
function getAllPackages() {
|
|
143
|
+
return loadPackageRegistry();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Search packages by group name
|
|
147
|
+
* @param group - GitLab group name
|
|
148
|
+
* @returns Array of package info for the group
|
|
149
|
+
*/
|
|
150
|
+
function searchPackagesByGroup(group) {
|
|
151
|
+
const metadata = loadPackageRegistry();
|
|
152
|
+
return Object.values(metadata.packages).filter((pkg) => pkg.group === group);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Save package information
|
|
156
|
+
* @param info - Package information to save
|
|
157
|
+
*/
|
|
158
|
+
function savePackageInfo(info) {
|
|
159
|
+
const metadata = loadPackageRegistry();
|
|
160
|
+
// Update lastUpdated timestamp
|
|
161
|
+
info.lastUpdated = new Date().toISOString();
|
|
162
|
+
// Save package info
|
|
163
|
+
metadata.packages[info.packageName] = info;
|
|
164
|
+
savePackageRegistry(metadata);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Remove package information
|
|
168
|
+
* @param packageName - Package name to remove
|
|
169
|
+
* @returns true if removed, false if not found
|
|
170
|
+
*/
|
|
171
|
+
function removePackageInfo(packageName) {
|
|
172
|
+
const metadata = loadPackageRegistry();
|
|
173
|
+
if (metadata.packages[packageName]) {
|
|
174
|
+
delete metadata.packages[packageName];
|
|
175
|
+
savePackageRegistry(metadata);
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check if package information exists
|
|
182
|
+
* @param packageName - Package name to check
|
|
183
|
+
* @returns true if package info exists
|
|
184
|
+
*/
|
|
185
|
+
function hasPackageInfo(packageName) {
|
|
186
|
+
return getPackageInfo(packageName) !== null;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Clear all package registry metadata
|
|
190
|
+
*/
|
|
191
|
+
function clearAllPackages() {
|
|
192
|
+
if (fs.existsSync(PACKAGE_REGISTRY_FILE)) {
|
|
193
|
+
fs.unlinkSync(PACKAGE_REGISTRY_FILE);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# gitlab-config CLI Reference
|
|
2
|
+
|
|
3
|
+
_Last updated: 2025-10-04T13:52:42.021Z_
|
|
4
|
+
|
|
5
|
+
## Main Command
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Usage: gitlab-config [options] [command]
|
|
9
|
+
|
|
10
|
+
Manage GitLab configuration and tokens
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
-V, --version output the version number
|
|
14
|
+
-h, --help display help for command
|
|
15
|
+
|
|
16
|
+
Commands:
|
|
17
|
+
save <token> Save GitLab token to ~/.config/gitlab-config/token
|
|
18
|
+
get Get saved GitLab token
|
|
19
|
+
check Check if token exists
|
|
20
|
+
remove Remove saved token
|
|
21
|
+
help [command] display help for command
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Subcommands
|
|
25
|
+
|
|
26
|
+
### save
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Usage: gitlab-config save [options] <token>
|
|
30
|
+
|
|
31
|
+
Save GitLab token to ~/.config/gitlab-config/token
|
|
32
|
+
|
|
33
|
+
Options:
|
|
34
|
+
-h, --help display help for command
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### get
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Usage: gitlab-config get [options]
|
|
41
|
+
|
|
42
|
+
Get saved GitLab token
|
|
43
|
+
|
|
44
|
+
Options:
|
|
45
|
+
-h, --help display help for command
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### check
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
Usage: gitlab-config check [options]
|
|
52
|
+
|
|
53
|
+
Check if token exists
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
-h, --help display help for command
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### remove
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
Usage: gitlab-config remove [options]
|
|
63
|
+
|
|
64
|
+
Remove saved token
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
-h, --help display help for command
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
_Generated by [cli-docs](https://gitlab.com/microature/cli-docs)_
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
**@microature/gitlab-config**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# @microature/gitlab-config
|
|
6
|
+
|
|
7
|
+
GitLab configuration management - save and load tokens from user config directory (`~/.config/gitlab-config`).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @microature/gitlab-config
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { saveToken, getToken, hasToken, removeToken } from '@microature/gitlab-config';
|
|
19
|
+
|
|
20
|
+
// Save a token
|
|
21
|
+
saveToken('glpat-your-token-here');
|
|
22
|
+
|
|
23
|
+
// Get the token
|
|
24
|
+
const token = getToken(); // Returns token or null if not found
|
|
25
|
+
|
|
26
|
+
// Check if token exists
|
|
27
|
+
if (hasToken()) {
|
|
28
|
+
console.log('Token is configured');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Remove the token
|
|
32
|
+
removeToken();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
See the [API documentation](_media/gitlab-config.md) for detailed information.
|
|
38
|
+
|
|
39
|
+
### Functions
|
|
40
|
+
|
|
41
|
+
- **`saveToken(token: string): void`** - Save GitLab token to `~/.config/gitlab-config/token`
|
|
42
|
+
- **`getToken(): string | null`** - Get GitLab token or null if not found
|
|
43
|
+
- **`hasToken(): boolean`** - Check if token exists
|
|
44
|
+
- **`removeToken(): void`** - Remove saved token
|
|
45
|
+
|
|
46
|
+
## How It Works
|
|
47
|
+
|
|
48
|
+
- Tokens are stored in `~/.config/gitlab-config/token`
|
|
49
|
+
- The config directory is automatically created if it doesn't exist
|
|
50
|
+
- Token file is created with `0600` permissions (read/write for owner only)
|
|
51
|
+
- Returns `null` if token file doesn't exist or is empty
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
ISC
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@microature/gitlab-config](./gitlab-config.md)
|
|
4
|
+
|
|
5
|
+
## gitlab-config package
|
|
6
|
+
|
|
7
|
+
## Functions
|
|
8
|
+
|
|
9
|
+
<table><thead><tr><th>
|
|
10
|
+
|
|
11
|
+
Function
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
</th><th>
|
|
15
|
+
|
|
16
|
+
Description
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
</th></tr></thead>
|
|
20
|
+
<tbody><tr><td>
|
|
21
|
+
|
|
22
|
+
[getToken()](./gitlab-config.gettoken.md)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
</td><td>
|
|
26
|
+
|
|
27
|
+
Get GitLab token from user config directory
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
</td></tr>
|
|
31
|
+
<tr><td>
|
|
32
|
+
|
|
33
|
+
[hasToken()](./gitlab-config.hastoken.md)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
</td><td>
|
|
37
|
+
|
|
38
|
+
Check if token exists
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
</td></tr>
|
|
42
|
+
<tr><td>
|
|
43
|
+
|
|
44
|
+
[removeToken()](./gitlab-config.removetoken.md)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
</td><td>
|
|
48
|
+
|
|
49
|
+
Remove saved token
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
</td></tr>
|
|
53
|
+
<tr><td>
|
|
54
|
+
|
|
55
|
+
[saveToken(token)](./gitlab-config.savetoken.md)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
</td><td>
|
|
59
|
+
|
|
60
|
+
Save GitLab token to user config directory
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
</td></tr>
|
|
64
|
+
</tbody></table>
|
|
65
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[**@microature/gitlab-config**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@microature/gitlab-config](../globals.md) / getToken
|
|
6
|
+
|
|
7
|
+
# Function: getToken()
|
|
8
|
+
|
|
9
|
+
> **getToken**(): `null` \| `string`
|
|
10
|
+
|
|
11
|
+
Defined in: index.ts:34
|
|
12
|
+
|
|
13
|
+
Get GitLab token from user config directory
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
`null` \| `string`
|
|
18
|
+
|
|
19
|
+
GitLab token or null if not found
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[**@microature/gitlab-config**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@microature/gitlab-config](../globals.md) / hasToken
|
|
6
|
+
|
|
7
|
+
# Function: hasToken()
|
|
8
|
+
|
|
9
|
+
> **hasToken**(): `boolean`
|
|
10
|
+
|
|
11
|
+
Defined in: index.ts:51
|
|
12
|
+
|
|
13
|
+
Check if token exists
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
`boolean`
|
|
18
|
+
|
|
19
|
+
true if token exists
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[**@microature/gitlab-config**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@microature/gitlab-config](../globals.md) / removeToken
|
|
6
|
+
|
|
7
|
+
# Function: removeToken()
|
|
8
|
+
|
|
9
|
+
> **removeToken**(): `void`
|
|
10
|
+
|
|
11
|
+
Defined in: index.ts:58
|
|
12
|
+
|
|
13
|
+
Remove saved token
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
`void`
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[**@microature/gitlab-config**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@microature/gitlab-config](../globals.md) / saveToken
|
|
6
|
+
|
|
7
|
+
# Function: saveToken()
|
|
8
|
+
|
|
9
|
+
> **saveToken**(`token`): `void`
|
|
10
|
+
|
|
11
|
+
Defined in: index.ts:21
|
|
12
|
+
|
|
13
|
+
Save GitLab token to user config directory
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### token
|
|
18
|
+
|
|
19
|
+
`string`
|
|
20
|
+
|
|
21
|
+
GitLab personal access token
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`void`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[**@microature/gitlab-config**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# @microature/gitlab-config
|
|
6
|
+
|
|
7
|
+
## Functions
|
|
8
|
+
|
|
9
|
+
- [getToken](functions/getToken.md)
|
|
10
|
+
- [hasToken](functions/hasToken.md)
|
|
11
|
+
- [removeToken](functions/removeToken.md)
|
|
12
|
+
- [saveToken](functions/saveToken.md)
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@glpkg/config",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "GitLab configuration management - save and load tokens from user config directory",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"gitlab-config": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"test": "vitest",
|
|
14
|
+
"prepublishOnly": "npm run build",
|
|
15
|
+
"docs": "npm run docs:api && npm run docs:cli",
|
|
16
|
+
"docs:api": "typedoc --out docs/typedoc-md --plugin typedoc-plugin-markdown src/index.ts",
|
|
17
|
+
"docs:cli": "cli-docs update",
|
|
18
|
+
"publish:dev": "gitlab-publish dev",
|
|
19
|
+
"publish:minor": "gitlab-publish --bump minor",
|
|
20
|
+
"publish:patch": "gitlab-publish --bump patch"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"gitlab",
|
|
24
|
+
"config",
|
|
25
|
+
"token"
|
|
26
|
+
],
|
|
27
|
+
"author": "",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"registry": "https://registry.npmjs.org/",
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@microsoft/api-documenter": "^7.27.0",
|
|
35
|
+
"@microsoft/api-extractor": "^7.53.0",
|
|
36
|
+
"@types/node": "^24.5.2",
|
|
37
|
+
"typedoc": "^0.28.13",
|
|
38
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
39
|
+
"typescript": "^5.9.2",
|
|
40
|
+
"vitest": "^2.1.9"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"commander": "^14.0.1"
|
|
44
|
+
}
|
|
45
|
+
}
|