@nexical/cli 0.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.
Files changed (178) hide show
  1. package/.github/workflows/deploy.yml +34 -0
  2. package/LICENSE +201 -0
  3. package/README.md +183 -0
  4. package/dist/chunk-FDJVHO4O.js +41 -0
  5. package/dist/chunk-FDJVHO4O.js.map +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +15 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/src/commands/admin/create-user.d.ts +15 -0
  10. package/dist/src/commands/admin/create-user.js +49 -0
  11. package/dist/src/commands/admin/create-user.js.map +1 -0
  12. package/dist/src/commands/branch/create.d.ts +19 -0
  13. package/dist/src/commands/branch/create.js +59 -0
  14. package/dist/src/commands/branch/create.js.map +1 -0
  15. package/dist/src/commands/branch/delete.d.ts +15 -0
  16. package/dist/src/commands/branch/delete.js +50 -0
  17. package/dist/src/commands/branch/delete.js.map +1 -0
  18. package/dist/src/commands/branch/get.d.ts +15 -0
  19. package/dist/src/commands/branch/get.js +53 -0
  20. package/dist/src/commands/branch/get.js.map +1 -0
  21. package/dist/src/commands/branch/list.d.ts +15 -0
  22. package/dist/src/commands/branch/list.js +51 -0
  23. package/dist/src/commands/branch/list.js.map +1 -0
  24. package/dist/src/commands/job/get.d.ts +15 -0
  25. package/dist/src/commands/job/get.js +62 -0
  26. package/dist/src/commands/job/get.js.map +1 -0
  27. package/dist/src/commands/job/list.d.ts +15 -0
  28. package/dist/src/commands/job/list.js +57 -0
  29. package/dist/src/commands/job/list.js.map +1 -0
  30. package/dist/src/commands/job/logs.d.ts +15 -0
  31. package/dist/src/commands/job/logs.js +67 -0
  32. package/dist/src/commands/job/logs.js.map +1 -0
  33. package/dist/src/commands/job/trigger.d.ts +19 -0
  34. package/dist/src/commands/job/trigger.js +74 -0
  35. package/dist/src/commands/job/trigger.js.map +1 -0
  36. package/dist/src/commands/login.d.ts +8 -0
  37. package/dist/src/commands/login.js +31 -0
  38. package/dist/src/commands/login.js.map +1 -0
  39. package/dist/src/commands/project/create.d.ts +24 -0
  40. package/dist/src/commands/project/create.js +63 -0
  41. package/dist/src/commands/project/create.js.map +1 -0
  42. package/dist/src/commands/project/delete.d.ts +20 -0
  43. package/dist/src/commands/project/delete.js +58 -0
  44. package/dist/src/commands/project/delete.js.map +1 -0
  45. package/dist/src/commands/project/get.d.ts +15 -0
  46. package/dist/src/commands/project/get.js +49 -0
  47. package/dist/src/commands/project/get.js.map +1 -0
  48. package/dist/src/commands/project/list.d.ts +15 -0
  49. package/dist/src/commands/project/list.js +45 -0
  50. package/dist/src/commands/project/list.js.map +1 -0
  51. package/dist/src/commands/project/update.d.ts +19 -0
  52. package/dist/src/commands/project/update.js +66 -0
  53. package/dist/src/commands/project/update.js.map +1 -0
  54. package/dist/src/commands/team/create.d.ts +19 -0
  55. package/dist/src/commands/team/create.js +45 -0
  56. package/dist/src/commands/team/create.js.map +1 -0
  57. package/dist/src/commands/team/delete.d.ts +20 -0
  58. package/dist/src/commands/team/delete.js +52 -0
  59. package/dist/src/commands/team/delete.js.map +1 -0
  60. package/dist/src/commands/team/get.d.ts +15 -0
  61. package/dist/src/commands/team/get.js +42 -0
  62. package/dist/src/commands/team/get.js.map +1 -0
  63. package/dist/src/commands/team/list.d.ts +8 -0
  64. package/dist/src/commands/team/list.js +30 -0
  65. package/dist/src/commands/team/list.js.map +1 -0
  66. package/dist/src/commands/team/member/invite.d.ts +20 -0
  67. package/dist/src/commands/team/member/invite.js +54 -0
  68. package/dist/src/commands/team/member/invite.js.map +1 -0
  69. package/dist/src/commands/team/member/remove.d.ts +15 -0
  70. package/dist/src/commands/team/member/remove.js +43 -0
  71. package/dist/src/commands/team/member/remove.js.map +1 -0
  72. package/dist/src/commands/team/update.d.ts +19 -0
  73. package/dist/src/commands/team/update.js +55 -0
  74. package/dist/src/commands/team/update.js.map +1 -0
  75. package/dist/src/commands/token/generate.d.ts +19 -0
  76. package/dist/src/commands/token/generate.js +48 -0
  77. package/dist/src/commands/token/generate.js.map +1 -0
  78. package/dist/src/commands/token/list.d.ts +8 -0
  79. package/dist/src/commands/token/list.js +31 -0
  80. package/dist/src/commands/token/list.js.map +1 -0
  81. package/dist/src/commands/token/revoke.d.ts +15 -0
  82. package/dist/src/commands/token/revoke.js +38 -0
  83. package/dist/src/commands/token/revoke.js.map +1 -0
  84. package/dist/src/commands/whoami.d.ts +8 -0
  85. package/dist/src/commands/whoami.js +26 -0
  86. package/dist/src/commands/whoami.js.map +1 -0
  87. package/dist/src/utils/nexical-client.d.ts +10 -0
  88. package/dist/src/utils/nexical-client.js +12 -0
  89. package/dist/src/utils/nexical-client.js.map +1 -0
  90. package/index.ts +14 -0
  91. package/package.json +32 -0
  92. package/src/commands/admin/create-user.ts +46 -0
  93. package/src/commands/branch/create.ts +57 -0
  94. package/src/commands/branch/delete.ts +47 -0
  95. package/src/commands/branch/get.ts +50 -0
  96. package/src/commands/branch/list.ts +50 -0
  97. package/src/commands/job/get.ts +59 -0
  98. package/src/commands/job/list.ts +56 -0
  99. package/src/commands/job/logs.ts +67 -0
  100. package/src/commands/job/trigger.ts +73 -0
  101. package/src/commands/login.ts +31 -0
  102. package/src/commands/project/create.ts +61 -0
  103. package/src/commands/project/delete.ts +56 -0
  104. package/src/commands/project/get.ts +46 -0
  105. package/src/commands/project/list.ts +44 -0
  106. package/src/commands/project/update.ts +63 -0
  107. package/src/commands/team/create.ts +43 -0
  108. package/src/commands/team/delete.ts +50 -0
  109. package/src/commands/team/get.ts +39 -0
  110. package/src/commands/team/list.ts +26 -0
  111. package/src/commands/team/member/invite.ts +56 -0
  112. package/src/commands/team/member/remove.ts +40 -0
  113. package/src/commands/team/update.ts +53 -0
  114. package/src/commands/token/generate.ts +45 -0
  115. package/src/commands/token/list.ts +27 -0
  116. package/src/commands/token/revoke.ts +35 -0
  117. package/src/commands/whoami.ts +21 -0
  118. package/src/utils/nexical-client.ts +40 -0
  119. package/test/e2e/.gitkeep +0 -0
  120. package/test/integration/commands/admin/create-user.test.ts +51 -0
  121. package/test/integration/commands/branch/create.test.ts +51 -0
  122. package/test/integration/commands/branch/delete.test.ts +43 -0
  123. package/test/integration/commands/branch/get.test.ts +49 -0
  124. package/test/integration/commands/branch/list.test.ts +47 -0
  125. package/test/integration/commands/job/get.test.ts +54 -0
  126. package/test/integration/commands/job/list.test.ts +47 -0
  127. package/test/integration/commands/job/logs.test.ts +47 -0
  128. package/test/integration/commands/job/trigger.test.ts +57 -0
  129. package/test/integration/commands/login.test.ts +62 -0
  130. package/test/integration/commands/project/create.test.ts +53 -0
  131. package/test/integration/commands/project/delete.test.ts +43 -0
  132. package/test/integration/commands/project/get.test.ts +51 -0
  133. package/test/integration/commands/project/list.test.ts +47 -0
  134. package/test/integration/commands/project/update.test.ts +53 -0
  135. package/test/integration/commands/team/create.test.ts +53 -0
  136. package/test/integration/commands/team/delete.test.ts +43 -0
  137. package/test/integration/commands/team/get.test.ts +50 -0
  138. package/test/integration/commands/team/list.test.ts +47 -0
  139. package/test/integration/commands/team/member/invite.test.ts +46 -0
  140. package/test/integration/commands/team/member/remove.test.ts +43 -0
  141. package/test/integration/commands/team/update.test.ts +50 -0
  142. package/test/integration/commands/token/generate.test.ts +51 -0
  143. package/test/integration/commands/token/list.test.ts +47 -0
  144. package/test/integration/commands/token/revoke.test.ts +43 -0
  145. package/test/integration/commands/whoami.test.ts +49 -0
  146. package/test/unit/commands/admin/create-user.test.ts +51 -0
  147. package/test/unit/commands/branch/create.test.ts +57 -0
  148. package/test/unit/commands/branch/delete.test.ts +49 -0
  149. package/test/unit/commands/branch/get.test.ts +67 -0
  150. package/test/unit/commands/branch/list.test.ts +62 -0
  151. package/test/unit/commands/job/get.test.ts +76 -0
  152. package/test/unit/commands/job/list.test.ts +62 -0
  153. package/test/unit/commands/job/logs.test.ts +60 -0
  154. package/test/unit/commands/job/trigger.test.ts +75 -0
  155. package/test/unit/commands/login.test.ts +64 -0
  156. package/test/unit/commands/project/create.test.ts +64 -0
  157. package/test/unit/commands/project/delete.test.ts +72 -0
  158. package/test/unit/commands/project/get.test.ts +73 -0
  159. package/test/unit/commands/project/list.test.ts +62 -0
  160. package/test/unit/commands/project/update.test.ts +58 -0
  161. package/test/unit/commands/team/create.test.ts +68 -0
  162. package/test/unit/commands/team/delete.test.ts +71 -0
  163. package/test/unit/commands/team/get.test.ts +70 -0
  164. package/test/unit/commands/team/list.test.ts +56 -0
  165. package/test/unit/commands/team/member/invite.test.ts +52 -0
  166. package/test/unit/commands/team/member/remove.test.ts +49 -0
  167. package/test/unit/commands/team/update.test.ts +63 -0
  168. package/test/unit/commands/token/generate.test.ts +65 -0
  169. package/test/unit/commands/token/list.test.ts +58 -0
  170. package/test/unit/commands/token/revoke.test.ts +49 -0
  171. package/test/unit/commands/whoami.test.ts +49 -0
  172. package/test/unit/utils/nexical-client.test.ts +98 -0
  173. package/test/utils/integration-helpers.ts +22 -0
  174. package/tsconfig.json +26 -0
  175. package/tsup.config.ts +18 -0
  176. package/vitest.config.ts +15 -0
  177. package/vitest.e2e.config.ts +10 -0
  178. package/vitest.integration.config.ts +22 -0
@@ -0,0 +1,47 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class BranchesDeleteCommand extends BaseCommand {
6
+ static description = 'Delete a branch';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ {
21
+ name: 'branchId',
22
+ required: true,
23
+ description: 'Branch ID',
24
+ },
25
+ ],
26
+ };
27
+
28
+ async run(options: any) {
29
+ const client = getClient();
30
+ const { teamId, projectId, branchId } = options;
31
+ const tid = parseInt(teamId, 10);
32
+ const pid = parseInt(projectId, 10);
33
+ const bid = parseInt(branchId, 10);
34
+
35
+ if (isNaN(tid) || isNaN(pid) || isNaN(bid)) {
36
+ this.error('IDs must be numbers.');
37
+ return;
38
+ }
39
+
40
+ try {
41
+ await client.branches.delete(tid, pid, bid);
42
+ this.success(`Branch ${bid} deleted.`);
43
+ } catch (error: any) {
44
+ this.error(`Failed to delete branch: ${error.message}`);
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,50 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class BranchesGetCommand extends BaseCommand {
6
+ static description = 'Get branch details';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ {
21
+ name: 'branchId',
22
+ required: true,
23
+ description: 'Branch ID',
24
+ },
25
+ ],
26
+ };
27
+
28
+ async run(options: any) {
29
+ const client = getClient();
30
+ const { teamId, projectId, branchId } = options;
31
+ const tid = parseInt(teamId, 10);
32
+ const pid = parseInt(projectId, 10);
33
+ const bid = parseInt(branchId, 10);
34
+
35
+ if (isNaN(tid) || isNaN(pid) || isNaN(bid)) {
36
+ this.error('IDs must be numbers.');
37
+ return;
38
+ }
39
+
40
+ try {
41
+ const branch = await client.branches.get(tid, pid, bid);
42
+ this.info(`Branch Details:`);
43
+ this.info(` ID: ${branch.id}`);
44
+ this.info(` Name: ${branch.name}`);
45
+ this.info(` Preview: ${branch.previewUrl || 'N/A'}`);
46
+ } catch (error: any) {
47
+ this.error(`Failed to get branch: ${error.message}`);
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class BranchesListCommand extends BaseCommand {
6
+ static description = 'List branches in a project';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ ],
21
+ };
22
+
23
+ async run(options: any) {
24
+ const client = getClient();
25
+ const { teamId, projectId } = options;
26
+ const tid = parseInt(teamId, 10);
27
+ const pid = parseInt(projectId, 10);
28
+
29
+ if (isNaN(tid) || isNaN(pid)) {
30
+ this.error('IDs must be numbers.');
31
+ return;
32
+ }
33
+
34
+ try {
35
+ const branches = await client.branches.list(tid, pid);
36
+
37
+ if (branches.length === 0) {
38
+ this.info('No branches found.');
39
+ return;
40
+ }
41
+
42
+ this.info(`Branches for Project ${pid}:`);
43
+ for (const branch of branches) {
44
+ this.info(`- ${branch.name} (ID: ${branch.id})`);
45
+ }
46
+ } catch (error: any) {
47
+ this.error(`Failed to list branches: ${error.message}`);
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,59 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class JobsGetCommand extends BaseCommand {
6
+ static description = 'Get job details';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ {
21
+ name: 'branchId',
22
+ required: true,
23
+ description: 'Branch ID',
24
+ },
25
+ {
26
+ name: 'jobId',
27
+ required: true,
28
+ description: 'Job ID',
29
+ },
30
+ ],
31
+ };
32
+
33
+ async run(options: any) {
34
+ const client = getClient();
35
+ const { teamId, projectId, branchId, jobId } = options;
36
+ const tid = parseInt(teamId, 10);
37
+ const pid = parseInt(projectId, 10);
38
+ const bid = parseInt(branchId, 10);
39
+ const jid = parseInt(jobId, 10);
40
+
41
+ if (isNaN(tid) || isNaN(pid) || isNaN(bid) || isNaN(jid)) {
42
+ this.error('IDs must be numbers.');
43
+ return;
44
+ }
45
+
46
+ try {
47
+ const job = await client.jobs.get(tid, pid, bid, jid);
48
+ this.info(`Job Details:`);
49
+ this.info(` ID: ${job.id}`);
50
+ this.info(` Type: ${job.type}`);
51
+ this.info(` Status: ${job.status}`);
52
+ this.info(` Started: ${job.startedAt || 'Waiting'}`);
53
+ this.info(` Ended: ${job.completedAt || 'Running'}`);
54
+ this.info(` Queue: ${job.queue}`);
55
+ } catch (error: any) {
56
+ this.error(`Failed to get job: ${error.message}`);
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,56 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class JobsListCommand extends BaseCommand {
6
+ static description = 'List jobs for a branch';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ {
21
+ name: 'branchId',
22
+ required: true,
23
+ description: 'Branch ID',
24
+ },
25
+ ],
26
+ };
27
+
28
+ async run(options: any) {
29
+ const client = getClient();
30
+ const { teamId, projectId, branchId } = options;
31
+ const tid = parseInt(teamId, 10);
32
+ const pid = parseInt(projectId, 10);
33
+ const bid = parseInt(branchId, 10);
34
+
35
+ if (isNaN(tid) || isNaN(pid) || isNaN(bid)) {
36
+ this.error('IDs must be numbers.');
37
+ return;
38
+ }
39
+
40
+ try {
41
+ const jobs = await client.jobs.list(tid, pid, bid);
42
+
43
+ if (jobs.length === 0) {
44
+ this.info('No jobs found.');
45
+ return;
46
+ }
47
+
48
+ this.info(`Jobs for Branch ${bid}:`);
49
+ for (const job of jobs) {
50
+ this.info(`${job.id} - ${job.type} [${job.status}] (Started: ${job.startedAt || 'Waiting'})`);
51
+ }
52
+ } catch (error: any) {
53
+ this.error(`Failed to list jobs: ${error.message}`);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,67 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class JobsLogsCommand extends BaseCommand {
6
+ static description = 'Get logs for a job';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ {
21
+ name: 'branchId',
22
+ required: true,
23
+ description: 'Branch ID',
24
+ },
25
+ {
26
+ name: 'jobId',
27
+ required: true,
28
+ description: 'Job ID',
29
+ },
30
+ ],
31
+ };
32
+
33
+ async run(options: any) {
34
+ const client = getClient();
35
+ const { teamId, projectId, branchId, jobId } = options;
36
+ const tid = parseInt(teamId, 10);
37
+ const pid = parseInt(projectId, 10);
38
+ const bid = parseInt(branchId, 10);
39
+ const jid = parseInt(jobId, 10);
40
+
41
+ if (isNaN(tid) || isNaN(pid) || isNaN(bid) || isNaN(jid)) {
42
+ this.error('IDs must be numbers.');
43
+ return;
44
+ }
45
+
46
+ try {
47
+ const logs = await client.jobs.getLogs(tid, pid, bid, jid);
48
+
49
+ this.info(`Logs for Job ${jid}:`);
50
+ // Assuming logs is an array of JobLog objects
51
+ for (const log of (logs as any)) { // Casting because SDK return type might be generic array
52
+ const timestamp = new Date(log.timestamp).toLocaleTimeString();
53
+ const color = log.level === 'error' ? 'red' : log.level === 'warn' ? 'yellow' : 'white';
54
+
55
+ if (log.level === 'error') {
56
+ this.error(`[${timestamp}] ${log.message}`);
57
+ } else if (log.level === 'warn') {
58
+ this.warn(`[${timestamp}] ${log.message}`);
59
+ } else {
60
+ this.info(`[${timestamp}] ${log.message}`);
61
+ }
62
+ }
63
+ } catch (error: any) {
64
+ this.error(`Failed to get logs: ${error.message}`);
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,73 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class JobsTriggerCommand extends BaseCommand {
6
+ static description = 'Trigger a new job';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ {
21
+ name: 'branchId',
22
+ required: true,
23
+ description: 'Branch ID',
24
+ },
25
+ {
26
+ name: 'type',
27
+ required: true,
28
+ description: 'Job type (e.g., deploy, build)',
29
+ },
30
+ ],
31
+ options: [
32
+ {
33
+ name: '--input <json>',
34
+ description: 'Input JSON string',
35
+ },
36
+ ],
37
+ };
38
+
39
+ async run(options: any) {
40
+ const client = getClient();
41
+ const { teamId, projectId, branchId, type, input } = options;
42
+ const tid = parseInt(teamId, 10);
43
+ const pid = parseInt(projectId, 10);
44
+ const bid = parseInt(branchId, 10);
45
+
46
+ if (isNaN(tid) || isNaN(pid) || isNaN(bid)) {
47
+ this.error('IDs must be numbers.');
48
+ return;
49
+ }
50
+
51
+ let inputs = {};
52
+ if (input) {
53
+ try {
54
+ inputs = JSON.parse(input);
55
+ } catch (e) {
56
+ this.error('Invalid JSON inputs.');
57
+ return;
58
+ }
59
+ }
60
+
61
+ try {
62
+ const job = await client.jobs.create(tid, pid, bid, {
63
+ type,
64
+ inputs,
65
+ });
66
+
67
+ this.success(`Job ${job.id} triggered successfully!`);
68
+ this.info(`Status: ${job.status}`);
69
+ } catch (error: any) {
70
+ this.error(`Failed to trigger job: ${error.message}`);
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,31 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient, saveToken } from '../utils/nexical-client.js';
4
+
5
+ export default class LoginCommand extends BaseCommand {
6
+ static description = 'Authenticate with Nexical via Device Flow';
7
+
8
+ async run() {
9
+ const client = getClient();
10
+
11
+ this.info('Starting device authentication...');
12
+
13
+ try {
14
+ const token = await client.auth.authenticateDevice('nexical-cli', (userCode, verificationUri) => {
15
+ this.notice(`Please visit: ${verificationUri}`);
16
+ this.notice(`And enter code: ${userCode}`);
17
+
18
+ // Optionally, we could try to open the browser here
19
+ // import open from 'open'; open(verificationUri);
20
+ });
21
+
22
+ saveToken(token);
23
+ client.setToken(token);
24
+
25
+ const user = await client.users.me();
26
+ this.success(`Successfully logged in as ${user.fullName} (${user.email})`);
27
+ } catch (error: any) {
28
+ this.error(`Login failed: ${error.message}`);
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,61 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class ProjectsCreateCommand extends BaseCommand {
6
+ static description = 'Create a new project';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'ID of the team',
14
+ },
15
+ {
16
+ name: 'name',
17
+ required: true,
18
+ description: 'Name of the project',
19
+ },
20
+ ],
21
+ options: [
22
+ {
23
+ name: '--repo <url>',
24
+ description: 'Repository URL',
25
+ },
26
+ {
27
+ name: '--prod <url>',
28
+ description: 'Production URL',
29
+ },
30
+ {
31
+ name: '--mode <mode>',
32
+ description: 'Mode (managed, self_hosted)',
33
+ default: 'managed',
34
+ },
35
+ ],
36
+ };
37
+
38
+ async run(options: any) {
39
+ const client = getClient();
40
+ const { teamId, name, repo, prod, mode } = options;
41
+ const tid = parseInt(teamId, 10);
42
+
43
+ if (isNaN(tid)) {
44
+ this.error('Team ID must be a number.');
45
+ return;
46
+ }
47
+
48
+ try {
49
+ const project = await client.projects.create(tid, {
50
+ name,
51
+ repoUrl: repo,
52
+ productionUrl: prod
53
+ });
54
+
55
+ this.success(`Project "${project.name}" set up successfully!`);
56
+ this.info(`ID: ${project.id}`);
57
+ } catch (error: any) {
58
+ this.error(`Failed to create project: ${error.message}`);
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,56 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class ProjectsDeleteCommand extends BaseCommand {
6
+ static description = 'Delete a project';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ ],
21
+ options: [
22
+ {
23
+ name: '--confirm',
24
+ description: 'Skip confirmation',
25
+ default: false,
26
+ },
27
+ ],
28
+ };
29
+
30
+ async run(options: any) {
31
+ const client = getClient();
32
+ const { teamId, projectId, confirm } = options;
33
+ const tid = parseInt(teamId, 10);
34
+ const pid = parseInt(projectId, 10);
35
+
36
+ if (isNaN(tid) || isNaN(pid)) {
37
+ this.error('IDs must be numbers.');
38
+ return;
39
+ }
40
+
41
+ if (!confirm) {
42
+ const answer = await this.prompt(`Are you sure you want to delete project ${pid}? (yes/no)`);
43
+ if (answer.toLowerCase() !== 'yes') {
44
+ this.info('Aborted.');
45
+ return;
46
+ }
47
+ }
48
+
49
+ try {
50
+ await client.projects.delete(tid, pid);
51
+ this.success(`Project ${pid} deleted.`);
52
+ } catch (error: any) {
53
+ this.error(`Failed to delete project: ${error.message}`);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,46 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class ProjectsGetCommand extends BaseCommand {
6
+ static description = 'Get project details';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'Team ID',
14
+ },
15
+ {
16
+ name: 'projectId',
17
+ required: true,
18
+ description: 'Project ID',
19
+ },
20
+ ],
21
+ };
22
+
23
+ async run(options: any) {
24
+ const client = getClient();
25
+ const { teamId, projectId } = options;
26
+ const tid = parseInt(teamId, 10);
27
+ const pid = parseInt(projectId, 10);
28
+
29
+ if (isNaN(tid) || isNaN(pid)) {
30
+ this.error('IDs must be numbers.');
31
+ return;
32
+ }
33
+
34
+ try {
35
+ const project = await client.projects.get(tid, pid);
36
+ this.info(`Project Details:`);
37
+ this.info(` ID: ${project.id}`);
38
+ this.info(` Name: ${project.name}`);
39
+ this.info(` Repo: ${project.repoUrl || 'N/A'}`);
40
+ this.info(` Prod: ${project.productionUrl || 'N/A'}`);
41
+ this.info(` Mode: ${project.mode}`);
42
+ } catch (error: any) {
43
+ this.error(`Failed to get project: ${error.message}`);
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,44 @@
1
+
2
+ import { BaseCommand } from '@nexical/cli-core';
3
+ import { getClient } from '../../utils/nexical-client.js';
4
+
5
+ export default class ProjectsListCommand extends BaseCommand {
6
+ static description = 'List projects in a team';
7
+
8
+ static args = {
9
+ args: [
10
+ {
11
+ name: 'teamId',
12
+ required: true,
13
+ description: 'ID of the team',
14
+ },
15
+ ],
16
+ };
17
+
18
+ async run(options: any) {
19
+ const client = getClient();
20
+ const { teamId } = options;
21
+ const tid = parseInt(teamId, 10);
22
+
23
+ if (isNaN(tid)) {
24
+ this.error('Team ID must be a number.');
25
+ return;
26
+ }
27
+
28
+ try {
29
+ const projects = await client.projects.list(tid);
30
+
31
+ if (projects.length === 0) {
32
+ this.info(`No projects found in team ${tid}.`);
33
+ return;
34
+ }
35
+
36
+ this.info(`Projects in Team ${tid}:`);
37
+ for (const project of projects) {
38
+ this.info(`- ${project.name} (ID: ${project.id}) [${project.repoUrl || 'No Repo'}]`);
39
+ }
40
+ } catch (error: any) {
41
+ this.error(`Failed to list projects: ${error.message}`);
42
+ }
43
+ }
44
+ }