xtra-cli 0.2.3 → 0.2.4
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.js +67 -12
- package/package.json +1 -1
package/dist/commands/project.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -10,9 +43,41 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
10
43
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
11
44
|
const config_1 = require("../lib/config");
|
|
12
45
|
const api_1 = require("../lib/api");
|
|
46
|
+
const fs = __importStar(require("fs"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
13
48
|
exports.projectCommand = new commander_1.Command("project")
|
|
14
49
|
.alias("projects")
|
|
15
50
|
.description("Manage project context");
|
|
51
|
+
const updateConfigs = (projectId, projectName) => {
|
|
52
|
+
const oldProject = (0, config_1.getConfigValue)("project");
|
|
53
|
+
// Always update global
|
|
54
|
+
(0, config_1.setConfig)("project", projectId);
|
|
55
|
+
// Clear branch if project changed
|
|
56
|
+
if (oldProject !== projectId) {
|
|
57
|
+
(0, config_1.setConfig)("branch", "main"); // Reset to main or clear? Projects have different branches.
|
|
58
|
+
}
|
|
59
|
+
// Update local .xtrarc if exists
|
|
60
|
+
const rcPath = path.join(process.cwd(), ".xtrarc");
|
|
61
|
+
if (fs.existsSync(rcPath)) {
|
|
62
|
+
try {
|
|
63
|
+
const rc = JSON.parse(fs.readFileSync(rcPath, "utf-8"));
|
|
64
|
+
rc.project = projectId;
|
|
65
|
+
if (oldProject !== projectId) {
|
|
66
|
+
rc.branch = "main"; // Sync local branch too
|
|
67
|
+
}
|
|
68
|
+
fs.writeFileSync(rcPath, JSON.stringify(rc, null, 2), "utf8");
|
|
69
|
+
console.log(chalk_1.default.gray(` ✔ Updated local .xtrarc`));
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error(chalk_1.default.yellow(` ⚠ Could not update local .xtrarc: ${e instanceof Error ? e.message : 'Unknown error'}`));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
console.log(chalk_1.default.green(`✔ Default project set to '${projectName}'`));
|
|
76
|
+
const currentBranch = (0, config_1.getConfigValue)("branch");
|
|
77
|
+
if (currentBranch) {
|
|
78
|
+
console.log(chalk_1.default.gray(` Active branch: ${currentBranch}`));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
16
81
|
// SET
|
|
17
82
|
exports.projectCommand
|
|
18
83
|
.command("set")
|
|
@@ -21,12 +86,7 @@ exports.projectCommand
|
|
|
21
86
|
.action(async (projectId) => {
|
|
22
87
|
// If projectId is provided, set it directly
|
|
23
88
|
if (projectId) {
|
|
24
|
-
(
|
|
25
|
-
console.log(chalk_1.default.green(`✔ Default project set to '${projectId}'`));
|
|
26
|
-
const currentBranch = (0, config_1.getConfigValue)("branch");
|
|
27
|
-
if (currentBranch) {
|
|
28
|
-
console.log(chalk_1.default.gray(` Active branch: ${currentBranch}`));
|
|
29
|
-
}
|
|
89
|
+
updateConfigs(projectId, projectId);
|
|
30
90
|
return;
|
|
31
91
|
}
|
|
32
92
|
// Otherwise, fetch projects and show interactive selector
|
|
@@ -49,13 +109,8 @@ exports.projectCommand
|
|
|
49
109
|
message: "Select a project:",
|
|
50
110
|
choices
|
|
51
111
|
}]);
|
|
52
|
-
(0, config_1.setConfig)("project", selectedProject);
|
|
53
112
|
const selectedName = projects.find((p) => p.id === selectedProject)?.name || selectedProject;
|
|
54
|
-
|
|
55
|
-
const currentBranch = (0, config_1.getConfigValue)("branch");
|
|
56
|
-
if (currentBranch) {
|
|
57
|
-
console.log(chalk_1.default.gray(` Active branch: ${currentBranch}`));
|
|
58
|
-
}
|
|
113
|
+
updateConfigs(selectedProject, selectedName);
|
|
59
114
|
}
|
|
60
115
|
catch (error) {
|
|
61
116
|
spinner.fail("Failed to fetch projects");
|