@nestbox-ai/cli 1.0.26 → 1.0.27
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/dist/commands/project/add.d.ts +2 -0
- package/dist/commands/project/add.js +49 -0
- package/dist/commands/project/add.js.map +1 -0
- package/dist/commands/project/apiUtils.d.ts +8 -0
- package/dist/commands/project/apiUtils.js +18 -0
- package/dist/commands/project/apiUtils.js.map +1 -0
- package/dist/commands/project/config.d.ts +11 -0
- package/dist/commands/project/config.js +32 -0
- package/dist/commands/project/config.js.map +1 -0
- package/dist/commands/project/index.d.ts +4 -0
- package/dist/commands/project/index.js +11 -0
- package/dist/commands/project/index.js.map +1 -0
- package/dist/commands/project/list.d.ts +2 -0
- package/dist/commands/project/list.js +83 -0
- package/dist/commands/project/list.js.map +1 -0
- package/dist/commands/project/use.d.ts +2 -0
- package/dist/commands/project/use.js +57 -0
- package/dist/commands/project/use.js.map +1 -0
- package/dist/commands/projects.d.ts +5 -12
- package/dist/commands/projects.js +18 -188
- package/dist/commands/projects.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/project/add.ts +47 -0
- package/src/commands/project/apiUtils.ts +20 -0
- package/src/commands/project/config.ts +37 -0
- package/src/commands/project/index.ts +5 -0
- package/src/commands/project/list.ts +78 -0
- package/src/commands/project/use.ts +45 -0
- package/src/commands/projects.ts +26 -201
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerAddCommand = registerAddCommand;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const config_1 = require("./config");
|
|
9
|
+
const apiUtils_1 = require("./apiUtils");
|
|
10
|
+
function registerAddCommand(projectCommand) {
|
|
11
|
+
projectCommand
|
|
12
|
+
.command('add <project-name> [alias]')
|
|
13
|
+
.description('Add a project with optional alias')
|
|
14
|
+
.action((projectName, alias) => {
|
|
15
|
+
try {
|
|
16
|
+
const apis = (0, apiUtils_1.createApis)();
|
|
17
|
+
const config = (0, config_1.readNestboxConfig)();
|
|
18
|
+
config.projects = config.projects || {};
|
|
19
|
+
// Check if the project already exists
|
|
20
|
+
if (config.projects[projectName]) {
|
|
21
|
+
console.error(chalk_1.default.red(`Project '${projectName}' already exists.`));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// Check if the alias already exists
|
|
25
|
+
if (alias && config.projects[alias]) {
|
|
26
|
+
console.error(chalk_1.default.red(`Alias '${alias}' already exists.`));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (alias) {
|
|
30
|
+
config.projects[alias] = projectName;
|
|
31
|
+
console.log(chalk_1.default.green(`Added project '${projectName}' with alias '${alias}'`));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
config.projects[projectName] = projectName;
|
|
35
|
+
console.log(chalk_1.default.green(`Added project '${projectName}'`));
|
|
36
|
+
}
|
|
37
|
+
// If this is the first project, set it as default
|
|
38
|
+
if (!config.projects.default) {
|
|
39
|
+
config.projects.default = projectName;
|
|
40
|
+
console.log(chalk_1.default.green(`Set '${projectName}' as the default project`));
|
|
41
|
+
}
|
|
42
|
+
(0, config_1.writeNestboxConfig)(config);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(chalk_1.default.red('Error adding project:'), error instanceof Error ? error.message : 'Unknown error');
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../../src/commands/project/add.ts"],"names":[],"mappings":";;;;;AAKA,gDAyCC;AA7CD,kDAA0B;AAC1B,qCAAiE;AACjE,yCAAwC;AAExC,SA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,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC;gBACtC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,QAAQ,WAAW,0BAA0B,CAAC,CAAC,CAAC;YAC1E,CAAC;YAED,IAAA,2BAAkB,EAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;QAC9G,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createApis = createApis;
|
|
4
|
+
const admin_1 = require("@nestbox-ai/admin");
|
|
5
|
+
const api_1 = require("../../utils/api");
|
|
6
|
+
/**
|
|
7
|
+
* Create API instances with current authentication using setupAuthAndConfig
|
|
8
|
+
*/
|
|
9
|
+
function createApis() {
|
|
10
|
+
const authResult = (0, api_1.setupAuthAndConfig)();
|
|
11
|
+
if (!authResult) {
|
|
12
|
+
throw new Error('No authentication token found. Please log in first.');
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
projectsApi: new admin_1.ProjectsApi(authResult.configuration),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=apiUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiUtils.js","sourceRoot":"","sources":["../../../src/commands/project/apiUtils.ts"],"names":[],"mappings":";;AAUA,gCASC;AAnBD,6CAA+D;AAC/D,yCAAsE;AAMtE;;GAEG;AACH,SAAgB,UAAU;IACxB,MAAM,UAAU,GAAG,IAAA,wBAAkB,GAAE,CAAC;IACxC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,OAAO;QACL,WAAW,EAAE,IAAI,mBAAW,CAAC,UAAU,CAAC,aAAa,CAAC;KACvD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ProjectsConfig {
|
|
2
|
+
default?: string;
|
|
3
|
+
[key: string]: string | undefined;
|
|
4
|
+
}
|
|
5
|
+
interface NestboxConfig {
|
|
6
|
+
projects: ProjectsConfig;
|
|
7
|
+
}
|
|
8
|
+
export declare function getNestboxConfigPath(): string;
|
|
9
|
+
export declare function readNestboxConfig(): NestboxConfig;
|
|
10
|
+
export declare function writeNestboxConfig(config: NestboxConfig): void;
|
|
11
|
+
export type { ProjectsConfig, NestboxConfig };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getNestboxConfigPath = getNestboxConfigPath;
|
|
7
|
+
exports.readNestboxConfig = readNestboxConfig;
|
|
8
|
+
exports.writeNestboxConfig = writeNestboxConfig;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
// Utility functions for project configuration
|
|
12
|
+
function getNestboxConfigPath() {
|
|
13
|
+
return path_1.default.join(process.cwd(), '.nestboxrc');
|
|
14
|
+
}
|
|
15
|
+
function readNestboxConfig() {
|
|
16
|
+
const configPath = getNestboxConfigPath();
|
|
17
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
18
|
+
try {
|
|
19
|
+
const content = fs_1.default.readFileSync(configPath, 'utf8');
|
|
20
|
+
return JSON.parse(content);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return { projects: {} };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { projects: {} };
|
|
27
|
+
}
|
|
28
|
+
function writeNestboxConfig(config) {
|
|
29
|
+
const configPath = getNestboxConfigPath();
|
|
30
|
+
fs_1.default.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/commands/project/config.ts"],"names":[],"mappings":";;;;;AAcA,oDAEC;AAED,8CAWC;AAED,gDAGC;AAlCD,4CAAoB;AACpB,gDAAwB;AAYxB,8CAA8C;AAC9C,SAAgB,oBAAoB;IAChC,OAAO,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;AAClD,CAAC;AAED,SAAgB,iBAAiB;IAC7B,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;IAC1C,IAAI,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACpD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QAC5B,CAAC;IACL,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AAC5B,CAAC;AAED,SAAgB,kBAAkB,CAAC,MAAqB;IACpD,MAAM,UAAU,GAAG,oBAAoB,EAAE,CAAC;IAC1C,YAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createApis = exports.getNestboxConfigPath = exports.writeNestboxConfig = exports.readNestboxConfig = void 0;
|
|
4
|
+
// Export utility functions that might be used by other modules
|
|
5
|
+
var config_1 = require("./config");
|
|
6
|
+
Object.defineProperty(exports, "readNestboxConfig", { enumerable: true, get: function () { return config_1.readNestboxConfig; } });
|
|
7
|
+
Object.defineProperty(exports, "writeNestboxConfig", { enumerable: true, get: function () { return config_1.writeNestboxConfig; } });
|
|
8
|
+
Object.defineProperty(exports, "getNestboxConfigPath", { enumerable: true, get: function () { return config_1.getNestboxConfigPath; } });
|
|
9
|
+
var apiUtils_1 = require("./apiUtils");
|
|
10
|
+
Object.defineProperty(exports, "createApis", { enumerable: true, get: function () { return apiUtils_1.createApis; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/project/index.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAC/D,mCAAuF;AAA9E,2GAAA,iBAAiB,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAEpE,uCAAwC;AAA/B,sGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.registerListCommand = registerListCommand;
|
|
16
|
+
const error_1 = require("../../utils/error");
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const config_1 = require("./config");
|
|
19
|
+
const apiUtils_1 = require("./apiUtils");
|
|
20
|
+
function registerListCommand(projectCommand) {
|
|
21
|
+
projectCommand
|
|
22
|
+
.command('list')
|
|
23
|
+
.description('List all projects')
|
|
24
|
+
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
const apis = (0, apiUtils_1.createApis)();
|
|
27
|
+
// Execute with token refresh support
|
|
28
|
+
yield (0, error_1.withTokenRefresh)(() => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
// Get projects from API
|
|
30
|
+
const response = yield apis.projectsApi.projectControllerGetAllProjects();
|
|
31
|
+
const apiProjects = response.data.data.projects;
|
|
32
|
+
if (!apiProjects || apiProjects.length === 0) {
|
|
33
|
+
console.log(chalk_1.default.yellow('No projects found.'));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Read local config to get default project and aliases
|
|
37
|
+
const config = (0, config_1.readNestboxConfig)();
|
|
38
|
+
const localProjects = config.projects || {};
|
|
39
|
+
const defaultProject = localProjects.default;
|
|
40
|
+
console.log(chalk_1.default.blue('Available Projects:'));
|
|
41
|
+
console.log(''); // Empty line for better formatting
|
|
42
|
+
// Display each project from the API
|
|
43
|
+
apiProjects.forEach((project) => {
|
|
44
|
+
const projectName = project.name;
|
|
45
|
+
const isDefault = defaultProject === projectName;
|
|
46
|
+
// Find aliases for this project
|
|
47
|
+
const aliases = Object.entries(localProjects)
|
|
48
|
+
.filter(([key, value]) => value === projectName && key !== 'default' && key !== projectName)
|
|
49
|
+
.map(([alias]) => alias);
|
|
50
|
+
// Build the display line
|
|
51
|
+
let displayLine = ` ${projectName}`;
|
|
52
|
+
if (aliases.length > 0) {
|
|
53
|
+
displayLine += chalk_1.default.gray(` (aliases: ${aliases.join(', ')})`);
|
|
54
|
+
}
|
|
55
|
+
if (isDefault) {
|
|
56
|
+
displayLine += chalk_1.default.green(' [DEFAULT]');
|
|
57
|
+
}
|
|
58
|
+
console.log(displayLine);
|
|
59
|
+
});
|
|
60
|
+
// Show summary
|
|
61
|
+
console.log(''); // Empty line
|
|
62
|
+
if (defaultProject) {
|
|
63
|
+
console.log(chalk_1.default.gray(`Default project: ${defaultProject}`));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.log(chalk_1.default.gray('No default project set. Use "nestbox project use <project-name>" to set one.'));
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error.message && error.message.includes('Authentication')) {
|
|
72
|
+
console.error(chalk_1.default.red(error.message));
|
|
73
|
+
}
|
|
74
|
+
else if (error.message) {
|
|
75
|
+
console.error(chalk_1.default.red('Error listing projects:'), error.message);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
console.error(chalk_1.default.red('Error listing projects:'), 'Unknown error');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/project/list.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAMA,kDAuEC;AA5ED,6CAAqD;AACrD,kDAA0B;AAC1B,qCAA6C;AAC7C,yCAAwC;AAExC,SAAgB,mBAAmB,CAAC,cAAuB;IACzD,cAAc;SACX,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,mBAAmB,CAAC;SAChC,MAA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;YACrE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,eAAe,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC,CAAA,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.registerUseCommand = registerUseCommand;
|
|
16
|
+
const error_1 = require("../../utils/error");
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const config_1 = require("./config");
|
|
19
|
+
const apiUtils_1 = require("./apiUtils");
|
|
20
|
+
function registerUseCommand(projectCommand) {
|
|
21
|
+
projectCommand
|
|
22
|
+
.command('use <project-name>')
|
|
23
|
+
.description('Set default project for all commands')
|
|
24
|
+
.action((projectName) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
try {
|
|
26
|
+
const apis = (0, apiUtils_1.createApis)();
|
|
27
|
+
// Execute with token refresh support
|
|
28
|
+
yield (0, error_1.withTokenRefresh)(() => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const config = (0, config_1.readNestboxConfig)();
|
|
30
|
+
config.projects = config.projects || {};
|
|
31
|
+
config.projects.default = projectName;
|
|
32
|
+
// Check if the project exists
|
|
33
|
+
const response = yield apis.projectsApi.projectControllerGetAllProjects();
|
|
34
|
+
const projectExists = response.data.data.projects.some((project) => project.name === projectName);
|
|
35
|
+
if (!projectExists) {
|
|
36
|
+
console.error(chalk_1.default.red(`Project '${projectName}' does not exist.`));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Write the configuration
|
|
40
|
+
(0, config_1.writeNestboxConfig)(config);
|
|
41
|
+
console.log(chalk_1.default.green(`Default project set to '${projectName}'`));
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error.message && error.message.includes('Authentication')) {
|
|
46
|
+
console.error(chalk_1.default.red(error.message));
|
|
47
|
+
}
|
|
48
|
+
else if (error.message) {
|
|
49
|
+
console.error(chalk_1.default.red('Error setting default project:'), error.message);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.error(chalk_1.default.red('Error setting default project:'), 'Unknown error');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=use.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../src/commands/project/use.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAMA,gDAsCC;AA3CD,6CAAqD;AACrD,kDAA0B;AAC1B,qCAAiE;AACjE,yCAAwC;AAExC,SAAgB,kBAAkB,CAAC,cAAuB;IACxD,cAAc;SACX,OAAO,CAAC,oBAAoB,CAAC;SAC7B,WAAW,CAAC,sCAAsC,CAAC;SACnD,MAAM,CAAC,CAAO,WAAmB,EAAE,EAAE;QACpC,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAA,qBAAU,GAAE,CAAC;YAE1B,qCAAqC;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AAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,EAAE,eAAe,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC;IACH,CAAC,CAAA,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
interface NestboxConfig {
|
|
7
|
-
projects: ProjectsConfig;
|
|
8
|
-
}
|
|
9
|
-
export declare function getNestboxConfigPath(): string;
|
|
10
|
-
export declare function readNestboxConfig(): NestboxConfig;
|
|
11
|
-
export declare function writeNestboxConfig(config: NestboxConfig): void;
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* Register all project-related commands
|
|
4
|
+
*/
|
|
12
5
|
export declare function registerProjectCommands(program: Command): void;
|
|
13
|
-
export {};
|
|
6
|
+
export { readNestboxConfig, writeNestboxConfig, getNestboxConfigPath, type ProjectsConfig, type NestboxConfig } from "./project";
|
|
@@ -1,196 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getNestboxConfigPath =
|
|
16
|
-
exports.readNestboxConfig = readNestboxConfig;
|
|
17
|
-
exports.writeNestboxConfig = writeNestboxConfig;
|
|
3
|
+
exports.getNestboxConfigPath = exports.writeNestboxConfig = exports.readNestboxConfig = void 0;
|
|
18
4
|
exports.registerProjectCommands = registerProjectCommands;
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function getNestboxConfigPath() {
|
|
26
|
-
return path_1.default.join(process.cwd(), '.nestboxrc');
|
|
27
|
-
}
|
|
28
|
-
function readNestboxConfig() {
|
|
29
|
-
const configPath = getNestboxConfigPath();
|
|
30
|
-
if (fs_1.default.existsSync(configPath)) {
|
|
31
|
-
try {
|
|
32
|
-
const content = fs_1.default.readFileSync(configPath, 'utf8');
|
|
33
|
-
return JSON.parse(content);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
return { projects: {} };
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return { projects: {} };
|
|
40
|
-
}
|
|
41
|
-
function writeNestboxConfig(config) {
|
|
42
|
-
const configPath = getNestboxConfigPath();
|
|
43
|
-
fs_1.default.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
44
|
-
}
|
|
5
|
+
const use_1 = require("./project/use");
|
|
6
|
+
const add_1 = require("./project/add");
|
|
7
|
+
const list_1 = require("./project/list");
|
|
8
|
+
/**
|
|
9
|
+
* Register all project-related commands
|
|
10
|
+
*/
|
|
45
11
|
function registerProjectCommands(program) {
|
|
46
|
-
const authResult = (0, api_1.setupAuthAndConfig)();
|
|
47
|
-
if (!authResult) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const { authToken, configuration } = authResult;
|
|
51
|
-
const projectsApi = new admin_1.ProjectsApi(configuration);
|
|
52
12
|
// Create the main project command
|
|
53
13
|
const projectCommand = program
|
|
54
|
-
.command(
|
|
55
|
-
.description(
|
|
56
|
-
//
|
|
57
|
-
projectCommand
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.action((projectName) => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
try {
|
|
62
|
-
const config = readNestboxConfig();
|
|
63
|
-
config.projects = config.projects || {};
|
|
64
|
-
config.projects.default = projectName;
|
|
65
|
-
// Check if the project exists
|
|
66
|
-
try {
|
|
67
|
-
const response = yield projectsApi.projectControllerGetAllProjects();
|
|
68
|
-
const projectExists = response.data.data.projects.some((project) => project.name === projectName);
|
|
69
|
-
if (!projectExists) {
|
|
70
|
-
console.error(chalk_1.default.red(`Project '${projectName}' does not exist.`));
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
if (error.response && error.response.status === 401) {
|
|
76
|
-
console.error(chalk_1.default.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
// Write the configuration
|
|
82
|
-
writeNestboxConfig(config);
|
|
83
|
-
console.log(chalk_1.default.green(`Default project set to '${projectName}'`));
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
if (error.message && error.message.includes('Authentication')) {
|
|
87
|
-
console.error(chalk_1.default.red(error.message));
|
|
88
|
-
}
|
|
89
|
-
else if (error.message) {
|
|
90
|
-
console.error(chalk_1.default.red('Error setting default project:'), error.message);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
console.error(chalk_1.default.red('Error setting default project:'), 'Unknown error');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}));
|
|
97
|
-
// Add basic 'add' subcommand
|
|
98
|
-
projectCommand
|
|
99
|
-
.command('add <project-name> [alias]')
|
|
100
|
-
.description('Add a project with optional alias')
|
|
101
|
-
.action((projectName, alias) => {
|
|
102
|
-
try {
|
|
103
|
-
if (!authToken) {
|
|
104
|
-
console.error(chalk_1.default.red('No authentication token found. Please log in first.'));
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const config = readNestboxConfig();
|
|
108
|
-
config.projects = config.projects || {};
|
|
109
|
-
// Check if the project already exists
|
|
110
|
-
if (config.projects[projectName]) {
|
|
111
|
-
console.error(chalk_1.default.red(`Project '${projectName}' already exists.`));
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// Check if the alias already exists
|
|
115
|
-
if (alias && config.projects[alias]) {
|
|
116
|
-
console.error(chalk_1.default.red(`Alias '${alias}' already exists.`));
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (alias) {
|
|
120
|
-
config.projects[alias] = projectName;
|
|
121
|
-
console.log(chalk_1.default.green(`Added project '${projectName}' with alias '${alias}'`));
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
config.projects[projectName] = projectName;
|
|
125
|
-
console.log(chalk_1.default.green(`Added project '${projectName}'`));
|
|
126
|
-
}
|
|
127
|
-
// If this is the first project, set it as default
|
|
128
|
-
if (!config.projects.default) {
|
|
129
|
-
config.projects.default = projectName;
|
|
130
|
-
console.log(chalk_1.default.green(`Set '${projectName}' as the default project`));
|
|
131
|
-
}
|
|
132
|
-
writeNestboxConfig(config);
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
console.error(chalk_1.default.red('Error adding project:'), error instanceof Error ? error.message : 'Unknown error');
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
projectCommand
|
|
139
|
-
.command('list')
|
|
140
|
-
.description('List all projects')
|
|
141
|
-
.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
try {
|
|
143
|
-
// Get projects from API
|
|
144
|
-
const response = yield projectsApi.projectControllerGetAllProjects();
|
|
145
|
-
const apiProjects = response.data.data.projects;
|
|
146
|
-
if (!apiProjects || apiProjects.length === 0) {
|
|
147
|
-
console.log(chalk_1.default.yellow('No projects found.'));
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
// Read local config to get default project and aliases
|
|
151
|
-
const config = readNestboxConfig();
|
|
152
|
-
const localProjects = config.projects || {};
|
|
153
|
-
const defaultProject = localProjects.default;
|
|
154
|
-
console.log(chalk_1.default.blue('Available Projects:'));
|
|
155
|
-
console.log(''); // Empty line for better formatting
|
|
156
|
-
// Display each project from the API
|
|
157
|
-
apiProjects.forEach((project) => {
|
|
158
|
-
const projectName = project.name;
|
|
159
|
-
const isDefault = defaultProject === projectName;
|
|
160
|
-
// Find aliases for this project
|
|
161
|
-
const aliases = Object.entries(localProjects)
|
|
162
|
-
.filter(([key, value]) => value === projectName && key !== 'default' && key !== projectName)
|
|
163
|
-
.map(([alias]) => alias);
|
|
164
|
-
// Build the display line
|
|
165
|
-
let displayLine = ` ${projectName}`;
|
|
166
|
-
if (aliases.length > 0) {
|
|
167
|
-
displayLine += chalk_1.default.gray(` (aliases: ${aliases.join(', ')})`);
|
|
168
|
-
}
|
|
169
|
-
if (isDefault) {
|
|
170
|
-
displayLine += chalk_1.default.green(' [DEFAULT]');
|
|
171
|
-
}
|
|
172
|
-
console.log(displayLine);
|
|
173
|
-
});
|
|
174
|
-
// Show summary
|
|
175
|
-
console.log(''); // Empty line
|
|
176
|
-
if (defaultProject) {
|
|
177
|
-
console.log(chalk_1.default.gray(`Default project: ${defaultProject}`));
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
console.log(chalk_1.default.gray('No default project set. Use "nestbox project use <project-name>" to set one.'));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
catch (error) {
|
|
184
|
-
if (error.message && error.message.includes('Authentication')) {
|
|
185
|
-
console.error(chalk_1.default.red(error.message));
|
|
186
|
-
}
|
|
187
|
-
else if (error.message) {
|
|
188
|
-
console.error(chalk_1.default.red('Error listing projects:'), error.message);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
console.error(chalk_1.default.red('Error listing projects:'), 'Unknown error');
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}));
|
|
14
|
+
.command("project")
|
|
15
|
+
.description("Manage Nestbox projects");
|
|
16
|
+
// Register all subcommands
|
|
17
|
+
(0, use_1.registerUseCommand)(projectCommand);
|
|
18
|
+
(0, add_1.registerAddCommand)(projectCommand);
|
|
19
|
+
(0, list_1.registerListCommand)(projectCommand);
|
|
195
20
|
}
|
|
21
|
+
// Export project utilities for use in other modules
|
|
22
|
+
var project_1 = require("./project");
|
|
23
|
+
Object.defineProperty(exports, "readNestboxConfig", { enumerable: true, get: function () { return project_1.readNestboxConfig; } });
|
|
24
|
+
Object.defineProperty(exports, "writeNestboxConfig", { enumerable: true, get: function () { return project_1.writeNestboxConfig; } });
|
|
25
|
+
Object.defineProperty(exports, "getNestboxConfigPath", { enumerable: true, get: function () { return project_1.getNestboxConfigPath; } });
|
|
196
26
|
//# sourceMappingURL=projects.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/commands/projects.ts"],"names":[],"mappings":";;;AAQA,0DAUC;AAjBD,uCAAmD;AACnD,uCAAmD;AACnD,yCAAqD;AAErD;;GAEG;AACH,SAAgB,uBAAuB,CAAC,OAAgB;IACtD,kCAAkC;IAClC,MAAM,cAAc,GAAG,OAAO;SAC3B,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,yBAAyB,CAAC,CAAC;IAE1C,2BAA2B;IAC3B,IAAA,wBAAkB,EAAC,cAAc,CAAC,CAAC;IACnC,IAAA,wBAAkB,EAAC,cAAc,CAAC,CAAC;IACnC,IAAA,0BAAmB,EAAC,cAAc,CAAC,CAAC;AACtC,CAAC;AAED,oDAAoD;AACpD,qCAMmB;AALjB,4GAAA,iBAAiB,OAAA;AACjB,6GAAA,kBAAkB,OAAA;AAClB,+GAAA,oBAAoB,OAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { readNestboxConfig, writeNestboxConfig } from "./config";
|
|
4
|
+
import { createApis } from "./apiUtils";
|
|
5
|
+
|
|
6
|
+
export function registerAddCommand(projectCommand: Command): void {
|
|
7
|
+
projectCommand
|
|
8
|
+
.command('add <project-name> [alias]')
|
|
9
|
+
.description('Add a project with optional alias')
|
|
10
|
+
.action((projectName: string, alias?: string) => {
|
|
11
|
+
try {
|
|
12
|
+
const apis = createApis();
|
|
13
|
+
|
|
14
|
+
const config = readNestboxConfig();
|
|
15
|
+
config.projects = config.projects || {};
|
|
16
|
+
|
|
17
|
+
// Check if the project already exists
|
|
18
|
+
if (config.projects[projectName]) {
|
|
19
|
+
console.error(chalk.red(`Project '${projectName}' already exists.`));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Check if the alias already exists
|
|
23
|
+
if (alias && config.projects[alias]) {
|
|
24
|
+
console.error(chalk.red(`Alias '${alias}' already exists.`));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (alias) {
|
|
29
|
+
config.projects[alias] = projectName;
|
|
30
|
+
console.log(chalk.green(`Added project '${projectName}' with alias '${alias}'`));
|
|
31
|
+
} else {
|
|
32
|
+
config.projects[projectName] = projectName;
|
|
33
|
+
console.log(chalk.green(`Added project '${projectName}'`));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// If this is the first project, set it as default
|
|
37
|
+
if (!config.projects.default) {
|
|
38
|
+
config.projects.default = projectName;
|
|
39
|
+
console.log(chalk.green(`Set '${projectName}' as the default project`));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
writeNestboxConfig(config);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(chalk.red('Error adding project:'), error instanceof Error ? error.message : 'Unknown error');
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Configuration, ProjectsApi } from "@nestbox-ai/admin";
|
|
2
|
+
import { setupAuthAndConfig, type AuthResult } from "../../utils/api";
|
|
3
|
+
|
|
4
|
+
export interface ApiInstances {
|
|
5
|
+
projectsApi: ProjectsApi;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create API instances with current authentication using setupAuthAndConfig
|
|
10
|
+
*/
|
|
11
|
+
export function createApis(): ApiInstances {
|
|
12
|
+
const authResult = setupAuthAndConfig();
|
|
13
|
+
if (!authResult) {
|
|
14
|
+
throw new Error('No authentication token found. Please log in first.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
projectsApi: new ProjectsApi(authResult.configuration),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// Define a type for the projects configuration
|
|
5
|
+
interface ProjectsConfig {
|
|
6
|
+
default?: string;
|
|
7
|
+
[key: string]: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface NestboxConfig {
|
|
11
|
+
projects: ProjectsConfig;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Utility functions for project configuration
|
|
15
|
+
export function getNestboxConfigPath(): string {
|
|
16
|
+
return path.join(process.cwd(), '.nestboxrc');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function readNestboxConfig(): NestboxConfig {
|
|
20
|
+
const configPath = getNestboxConfigPath();
|
|
21
|
+
if (fs.existsSync(configPath)) {
|
|
22
|
+
try {
|
|
23
|
+
const content = fs.readFileSync(configPath, 'utf8');
|
|
24
|
+
return JSON.parse(content);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return { projects: {} };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { projects: {} };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function writeNestboxConfig(config: NestboxConfig): void {
|
|
33
|
+
const configPath = getNestboxConfigPath();
|
|
34
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type { ProjectsConfig, NestboxConfig };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Export utility functions that might be used by other modules
|
|
2
|
+
export { readNestboxConfig, writeNestboxConfig, getNestboxConfigPath } from "./config";
|
|
3
|
+
export type { ProjectsConfig, NestboxConfig } from "./config";
|
|
4
|
+
export { createApis } from "./apiUtils";
|
|
5
|
+
export type { ApiInstances } from "./apiUtils";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { withTokenRefresh } from "../../utils/error";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readNestboxConfig } from "./config";
|
|
5
|
+
import { createApis } from "./apiUtils";
|
|
6
|
+
|
|
7
|
+
export function registerListCommand(projectCommand: Command): void {
|
|
8
|
+
projectCommand
|
|
9
|
+
.command('list')
|
|
10
|
+
.description('List all projects')
|
|
11
|
+
.action(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const apis = createApis();
|
|
14
|
+
|
|
15
|
+
// Execute with token refresh support
|
|
16
|
+
await withTokenRefresh(
|
|
17
|
+
async () => {
|
|
18
|
+
// Get projects from API
|
|
19
|
+
const response = await apis.projectsApi.projectControllerGetAllProjects();
|
|
20
|
+
const apiProjects = response.data.data.projects;
|
|
21
|
+
|
|
22
|
+
if (!apiProjects || apiProjects.length === 0) {
|
|
23
|
+
console.log(chalk.yellow('No projects found.'));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Read local config to get default project and aliases
|
|
28
|
+
const config = readNestboxConfig();
|
|
29
|
+
const localProjects = config.projects || {};
|
|
30
|
+
const defaultProject = localProjects.default;
|
|
31
|
+
|
|
32
|
+
console.log(chalk.blue('Available Projects:'));
|
|
33
|
+
console.log(''); // Empty line for better formatting
|
|
34
|
+
|
|
35
|
+
// Display each project from the API
|
|
36
|
+
apiProjects.forEach((project: any) => {
|
|
37
|
+
const projectName = project.name;
|
|
38
|
+
const isDefault = defaultProject === projectName;
|
|
39
|
+
|
|
40
|
+
// Find aliases for this project
|
|
41
|
+
const aliases = Object.entries(localProjects)
|
|
42
|
+
.filter(([key, value]) => value === projectName && key !== 'default' && key !== projectName)
|
|
43
|
+
.map(([alias]) => alias);
|
|
44
|
+
|
|
45
|
+
// Build the display line
|
|
46
|
+
let displayLine = ` ${projectName}`;
|
|
47
|
+
|
|
48
|
+
if (aliases.length > 0) {
|
|
49
|
+
displayLine += chalk.gray(` (aliases: ${aliases.join(', ')})`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isDefault) {
|
|
53
|
+
displayLine += chalk.green(' [DEFAULT]');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log(displayLine);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Show summary
|
|
60
|
+
console.log(''); // Empty line
|
|
61
|
+
if (defaultProject) {
|
|
62
|
+
console.log(chalk.gray(`Default project: ${defaultProject}`));
|
|
63
|
+
} else {
|
|
64
|
+
console.log(chalk.gray('No default project set. Use "nestbox project use <project-name>" to set one.'));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
} catch (error: any) {
|
|
69
|
+
if (error.message && error.message.includes('Authentication')) {
|
|
70
|
+
console.error(chalk.red(error.message));
|
|
71
|
+
} else if (error.message) {
|
|
72
|
+
console.error(chalk.red('Error listing projects:'), error.message);
|
|
73
|
+
} else {
|
|
74
|
+
console.error(chalk.red('Error listing projects:'), 'Unknown error');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { withTokenRefresh } from "../../utils/error";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { readNestboxConfig, writeNestboxConfig } from "./config";
|
|
5
|
+
import { createApis } from "./apiUtils";
|
|
6
|
+
|
|
7
|
+
export function registerUseCommand(projectCommand: Command): void {
|
|
8
|
+
projectCommand
|
|
9
|
+
.command('use <project-name>')
|
|
10
|
+
.description('Set default project for all commands')
|
|
11
|
+
.action(async (projectName: string) => {
|
|
12
|
+
try {
|
|
13
|
+
const apis = createApis();
|
|
14
|
+
|
|
15
|
+
// Execute with token refresh support
|
|
16
|
+
await withTokenRefresh(
|
|
17
|
+
async () => {
|
|
18
|
+
const config = readNestboxConfig();
|
|
19
|
+
config.projects = config.projects || {};
|
|
20
|
+
config.projects.default = projectName;
|
|
21
|
+
|
|
22
|
+
// Check if the project exists
|
|
23
|
+
const response = await apis.projectsApi.projectControllerGetAllProjects();
|
|
24
|
+
const projectExists = response.data.data.projects.some((project: any) => project.name === projectName);
|
|
25
|
+
if (!projectExists) {
|
|
26
|
+
console.error(chalk.red(`Project '${projectName}' does not exist.`));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Write the configuration
|
|
31
|
+
writeNestboxConfig(config);
|
|
32
|
+
console.log(chalk.green(`Default project set to '${projectName}'`));
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
} catch (error: any) {
|
|
36
|
+
if (error.message && error.message.includes('Authentication')) {
|
|
37
|
+
console.error(chalk.red(error.message));
|
|
38
|
+
} else if (error.message) {
|
|
39
|
+
console.error(chalk.red('Error setting default project:'), error.message);
|
|
40
|
+
} else {
|
|
41
|
+
console.error(chalk.red('Error setting default project:'), 'Unknown error');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
package/src/commands/projects.ts
CHANGED
|
@@ -1,203 +1,28 @@
|
|
|
1
|
-
import { Command } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
interface ProjectsConfig {
|
|
10
|
-
default?: string;
|
|
11
|
-
[key: string]: string | undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface NestboxConfig {
|
|
15
|
-
projects: ProjectsConfig;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Utility functions for project configuration
|
|
19
|
-
export function getNestboxConfigPath(): string {
|
|
20
|
-
return path.join(process.cwd(), '.nestboxrc');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function readNestboxConfig(): NestboxConfig {
|
|
24
|
-
const configPath = getNestboxConfigPath();
|
|
25
|
-
if (fs.existsSync(configPath)) {
|
|
26
|
-
try {
|
|
27
|
-
const content = fs.readFileSync(configPath, 'utf8');
|
|
28
|
-
return JSON.parse(content);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
return { projects: {} };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return { projects: {} };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function writeNestboxConfig(config: NestboxConfig): void {
|
|
37
|
-
const configPath = getNestboxConfigPath();
|
|
38
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
39
|
-
}
|
|
40
|
-
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { registerUseCommand } from "./project/use";
|
|
3
|
+
import { registerAddCommand } from "./project/add";
|
|
4
|
+
import { registerListCommand } from "./project/list";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Register all project-related commands
|
|
8
|
+
*/
|
|
41
9
|
export function registerProjectCommands(program: Command): void {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const projectCommand = program
|
|
53
|
-
.command('project')
|
|
54
|
-
.description('Manage Nestbox projects');
|
|
55
|
-
|
|
56
|
-
// Add the basic 'use' subcommand
|
|
57
|
-
projectCommand
|
|
58
|
-
.command('use <project-name>')
|
|
59
|
-
.description('Set default project for all commands')
|
|
60
|
-
.action(async (projectName: string) => {
|
|
61
|
-
try {
|
|
62
|
-
const config = readNestboxConfig();
|
|
63
|
-
config.projects = config.projects || {};
|
|
64
|
-
config.projects.default = projectName;
|
|
65
|
-
|
|
66
|
-
// Check if the project exists
|
|
67
|
-
try {
|
|
68
|
-
const response = await projectsApi.projectControllerGetAllProjects();
|
|
69
|
-
const projectExists = response.data.data.projects.some((project: any) => project.name === projectName);
|
|
70
|
-
if (!projectExists) {
|
|
71
|
-
console.error(chalk.red(`Project '${projectName}' does not exist.`));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
} catch (error: any) {
|
|
75
|
-
if (error.response && error.response.status === 401) {
|
|
76
|
-
console.error(chalk.red('Authentication token has expired. Please login again using "nestbox login <domain>".'));
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Write the configuration
|
|
83
|
-
writeNestboxConfig(config);
|
|
84
|
-
console.log(chalk.green(`Default project set to '${projectName}'`));
|
|
85
|
-
} catch (error: any) {
|
|
86
|
-
if (error.message && error.message.includes('Authentication')) {
|
|
87
|
-
console.error(chalk.red(error.message));
|
|
88
|
-
} else if (error.message) {
|
|
89
|
-
console.error(chalk.red('Error setting default project:'), error.message);
|
|
90
|
-
} else {
|
|
91
|
-
console.error(chalk.red('Error setting default project:'), 'Unknown error');
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Add basic 'add' subcommand
|
|
97
|
-
projectCommand
|
|
98
|
-
.command('add <project-name> [alias]')
|
|
99
|
-
.description('Add a project with optional alias')
|
|
100
|
-
.action((projectName: string, alias?: string) => {
|
|
101
|
-
try {
|
|
102
|
-
if (!authToken) {
|
|
103
|
-
console.error(chalk.red('No authentication token found. Please log in first.'));
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const config = readNestboxConfig();
|
|
107
|
-
config.projects = config.projects || {};
|
|
108
|
-
|
|
109
|
-
// Check if the project already exists
|
|
110
|
-
if (config.projects[projectName]) {
|
|
111
|
-
console.error(chalk.red(`Project '${projectName}' already exists.`));
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// Check if the alias already exists
|
|
115
|
-
if (alias && config.projects[alias]) {
|
|
116
|
-
console.error(chalk.red(`Alias '${alias}' already exists.`));
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (alias) {
|
|
121
|
-
config.projects[alias] = projectName;
|
|
122
|
-
console.log(chalk.green(`Added project '${projectName}' with alias '${alias}'`));
|
|
123
|
-
} else {
|
|
124
|
-
config.projects[projectName] = projectName;
|
|
125
|
-
console.log(chalk.green(`Added project '${projectName}'`));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// If this is the first project, set it as default
|
|
129
|
-
if (!config.projects.default) {
|
|
130
|
-
config.projects.default = projectName;
|
|
131
|
-
console.log(chalk.green(`Set '${projectName}' as the default project`));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
writeNestboxConfig(config);
|
|
135
|
-
} catch (error) {
|
|
136
|
-
console.error(chalk.red('Error adding project:'), error instanceof Error ? error.message : 'Unknown error');
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
projectCommand
|
|
141
|
-
.command('list')
|
|
142
|
-
.description('List all projects')
|
|
143
|
-
.action(async () => {
|
|
144
|
-
try {
|
|
145
|
-
// Get projects from API
|
|
146
|
-
const response = await projectsApi.projectControllerGetAllProjects();
|
|
147
|
-
const apiProjects = response.data.data.projects;
|
|
148
|
-
|
|
149
|
-
if (!apiProjects || apiProjects.length === 0) {
|
|
150
|
-
console.log(chalk.yellow('No projects found.'));
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Read local config to get default project and aliases
|
|
155
|
-
const config = readNestboxConfig();
|
|
156
|
-
const localProjects = config.projects || {};
|
|
157
|
-
const defaultProject = localProjects.default;
|
|
158
|
-
|
|
159
|
-
console.log(chalk.blue('Available Projects:'));
|
|
160
|
-
console.log(''); // Empty line for better formatting
|
|
161
|
-
|
|
162
|
-
// Display each project from the API
|
|
163
|
-
apiProjects.forEach((project: any) => {
|
|
164
|
-
const projectName = project.name;
|
|
165
|
-
const isDefault = defaultProject === projectName;
|
|
166
|
-
|
|
167
|
-
// Find aliases for this project
|
|
168
|
-
const aliases = Object.entries(localProjects)
|
|
169
|
-
.filter(([key, value]) => value === projectName && key !== 'default' && key !== projectName)
|
|
170
|
-
.map(([alias]) => alias);
|
|
171
|
-
|
|
172
|
-
// Build the display line
|
|
173
|
-
let displayLine = ` ${projectName}`;
|
|
174
|
-
|
|
175
|
-
if (aliases.length > 0) {
|
|
176
|
-
displayLine += chalk.gray(` (aliases: ${aliases.join(', ')})`);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (isDefault) {
|
|
180
|
-
displayLine += chalk.green(' [DEFAULT]');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
console.log(displayLine);
|
|
184
|
-
});
|
|
10
|
+
// Create the main project command
|
|
11
|
+
const projectCommand = program
|
|
12
|
+
.command("project")
|
|
13
|
+
.description("Manage Nestbox projects");
|
|
14
|
+
|
|
15
|
+
// Register all subcommands
|
|
16
|
+
registerUseCommand(projectCommand);
|
|
17
|
+
registerAddCommand(projectCommand);
|
|
18
|
+
registerListCommand(projectCommand);
|
|
19
|
+
}
|
|
185
20
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (error.message && error.message.includes('Authentication')) {
|
|
195
|
-
console.error(chalk.red(error.message));
|
|
196
|
-
} else if (error.message) {
|
|
197
|
-
console.error(chalk.red('Error listing projects:'), error.message);
|
|
198
|
-
} else {
|
|
199
|
-
console.error(chalk.red('Error listing projects:'), 'Unknown error');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
21
|
+
// Export project utilities for use in other modules
|
|
22
|
+
export {
|
|
23
|
+
readNestboxConfig,
|
|
24
|
+
writeNestboxConfig,
|
|
25
|
+
getNestboxConfigPath,
|
|
26
|
+
type ProjectsConfig,
|
|
27
|
+
type NestboxConfig
|
|
28
|
+
} from "./project";
|