xtra-cli 0.1.3 → 0.1.6
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/init.js +26 -6
- package/dist/commands/login.js +5 -1
- package/dist/commands/project.js +1 -0
- package/dist/lib/api.js +3 -1
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -81,12 +81,16 @@ exports.initCommand = new commander_1.Command("init")
|
|
|
81
81
|
const { api } = await Promise.resolve().then(() => __importStar(require("../lib/api")));
|
|
82
82
|
remoteProjects = await api.getProjects();
|
|
83
83
|
apiSpinner.succeed(`Found ${remoteProjects.length} projects`);
|
|
84
|
+
if (remoteProjects.length === 0) {
|
|
85
|
+
console.log(chalk_1.default.yellow("\nYou don't have any projects in this workspace yet."));
|
|
86
|
+
console.log(chalk_1.default.yellow("Create one in the web dashboard first, or manually paste a Project ID below."));
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
89
|
catch (err) {
|
|
86
90
|
apiSpinner.warn(chalk_1.default.yellow("Could not fetch projects. You will need to enter the ID manually."));
|
|
87
91
|
}
|
|
88
92
|
const fallbackProject = project || (0, config_1.getConfigValue)("project") || "";
|
|
89
|
-
const
|
|
93
|
+
const { project: selectedProject } = await inquirer_1.default.prompt([
|
|
90
94
|
{
|
|
91
95
|
type: remoteProjects.length > 0 ? "list" : "input",
|
|
92
96
|
name: "project",
|
|
@@ -96,7 +100,21 @@ exports.initCommand = new commander_1.Command("init")
|
|
|
96
100
|
: undefined,
|
|
97
101
|
default: fallbackProject,
|
|
98
102
|
validate: (v) => v.trim() ? true : "Project ID is required",
|
|
99
|
-
}
|
|
103
|
+
}
|
|
104
|
+
]);
|
|
105
|
+
project = selectedProject.trim();
|
|
106
|
+
// Fetch branches for selected project
|
|
107
|
+
let remoteBranches = [];
|
|
108
|
+
const branchSpinner = ora("Fetching branches...").start();
|
|
109
|
+
try {
|
|
110
|
+
const { api } = await Promise.resolve().then(() => __importStar(require("../lib/api")));
|
|
111
|
+
remoteBranches = await api.getBranches(project);
|
|
112
|
+
branchSpinner.stop();
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
branchSpinner.warn(chalk_1.default.yellow("Could not fetch branches."));
|
|
116
|
+
}
|
|
117
|
+
const answers = await inquirer_1.default.prompt([
|
|
100
118
|
{
|
|
101
119
|
type: "list",
|
|
102
120
|
name: "env",
|
|
@@ -105,10 +123,13 @@ exports.initCommand = new commander_1.Command("init")
|
|
|
105
123
|
default: env || "development",
|
|
106
124
|
},
|
|
107
125
|
{
|
|
108
|
-
type: "input",
|
|
126
|
+
type: remoteBranches.length > 0 ? "list" : "input",
|
|
109
127
|
name: "branch",
|
|
110
|
-
message: "Default branch:",
|
|
111
|
-
|
|
128
|
+
message: remoteBranches.length > 0 ? "Default branch:" : "Default branch name:",
|
|
129
|
+
choices: remoteBranches.length > 0
|
|
130
|
+
? remoteBranches.map(b => ({ name: b.name, value: b.name }))
|
|
131
|
+
: undefined,
|
|
132
|
+
default: branch || (remoteBranches.length > 0 ? remoteBranches[0].name : "main"),
|
|
112
133
|
},
|
|
113
134
|
{
|
|
114
135
|
type: "confirm",
|
|
@@ -117,7 +138,6 @@ exports.initCommand = new commander_1.Command("init")
|
|
|
117
138
|
default: true,
|
|
118
139
|
},
|
|
119
140
|
]);
|
|
120
|
-
project = answers.project.trim();
|
|
121
141
|
env = answers.env;
|
|
122
142
|
branch = answers.branch;
|
|
123
143
|
// Add to .gitignore
|
package/dist/commands/login.js
CHANGED
|
@@ -167,7 +167,11 @@ async function handleSSOLogin() {
|
|
|
167
167
|
const address = server.address();
|
|
168
168
|
const port = typeof address === 'string' ? 0 : address?.port;
|
|
169
169
|
const callbackUrl = `http://localhost:${port}`;
|
|
170
|
-
|
|
170
|
+
let { apiUrl } = require("../lib/config").getConfig();
|
|
171
|
+
// Hard fallback if getConfig somehow returned the old cached localhost
|
|
172
|
+
if (apiUrl.includes("localhost")) {
|
|
173
|
+
apiUrl = "https://xtra-security.vercel.app/api";
|
|
174
|
+
}
|
|
171
175
|
const ssoUrl = `${apiUrl}/auth/cli/sso?callbackUrl=${encodeURIComponent(callbackUrl)}`;
|
|
172
176
|
console.log(chalk_1.default.blue(`Waiting for browser login... (Opening ${ssoUrl})`));
|
|
173
177
|
await open(ssoUrl);
|
package/dist/commands/project.js
CHANGED
|
@@ -11,6 +11,7 @@ const inquirer_1 = __importDefault(require("inquirer"));
|
|
|
11
11
|
const config_1 = require("../lib/config");
|
|
12
12
|
const api_1 = require("../lib/api");
|
|
13
13
|
exports.projectCommand = new commander_1.Command("project")
|
|
14
|
+
.alias("projects")
|
|
14
15
|
.description("Manage project context");
|
|
15
16
|
// SET
|
|
16
17
|
exports.projectCommand
|
package/dist/lib/api.js
CHANGED
|
@@ -99,7 +99,9 @@ exports.api = {
|
|
|
99
99
|
},
|
|
100
100
|
// Project Management
|
|
101
101
|
getProjects: async () => {
|
|
102
|
-
const
|
|
102
|
+
const { workspace } = (0, config_1.getConfig)();
|
|
103
|
+
const url = workspace ? `/project?workspaceId=${workspace}` : "/project";
|
|
104
|
+
const response = await getClient().get(url);
|
|
103
105
|
return response.data;
|
|
104
106
|
},
|
|
105
107
|
// Branch Management
|