@superblocksteam/cli 1.3.0 → 1.4.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/README.md CHANGED
@@ -12,7 +12,7 @@ $ npm install -g @superblocksteam/cli
12
12
  $ superblocks COMMAND
13
13
  running command...
14
14
  $ superblocks (--version)
15
- @superblocksteam/cli/1.3.0 linux-x64 node-v18.18.2
15
+ @superblocksteam/cli/1.4.1 linux-x64 node-v18.18.2
16
16
  $ superblocks --help [COMMAND]
17
17
  USAGE
18
18
  $ superblocks COMMAND
@@ -7,7 +7,7 @@
7
7
  "lint:fix": "npx eslint . --fix"
8
8
  },
9
9
  "dependencies": {
10
- "@superblocksteam/custom-components": "1.3.0",
10
+ "@superblocksteam/custom-components": "1.4.1",
11
11
  "react": "^18",
12
12
  "react-dom": "^18"
13
13
  },
@@ -39,7 +39,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
39
39
  },
40
40
  },
41
41
  {
42
- title: "Fetching applications...",
42
+ title: "Fetching applications, workflows and scheduled jobs...",
43
43
  task: (ctx, task) => task.newListr([
44
44
  {
45
45
  title: "Fetching applications...",
@@ -58,6 +58,21 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
58
58
  task.title += `: completed`;
59
59
  },
60
60
  },
61
+ {
62
+ title: "Fetching workflows and scheduled jobs...",
63
+ enabled: () => !args.resource_url,
64
+ task: async (ctx, task) => {
65
+ // jobs and workflows choices
66
+ const apis = await this.getSdk().fetchApis();
67
+ for (const api of apis) {
68
+ ctx.fetchedResources[api.id] = {
69
+ resourceType: "BACKEND",
70
+ name: (0, version_control_1.extractApiName)(api),
71
+ };
72
+ }
73
+ task.title += `: completed`;
74
+ },
75
+ },
61
76
  {
62
77
  title: "Fetching resource by resourceUrl...",
63
78
  enabled: () => !(0, lodash_1.isEmpty)(args.resource_url),
@@ -84,7 +99,7 @@ class Initialize extends authenticated_command_1.AuthenticatedCommand {
84
99
  const api = await this.getSdk().fetchApi(resourceId);
85
100
  ctx.fetchedResources[api.id] = {
86
101
  resourceType,
87
- name: api.actions.name,
102
+ name: (0, version_control_1.extractApiName)(api),
88
103
  };
89
104
  }
90
105
  task.title += `: completed`;
@@ -198,6 +198,41 @@ Would you like to also delete these resources from your filesystem?`,
198
198
  });
199
199
  break;
200
200
  }
201
+ case "BACKEND": {
202
+ subtasks.push({
203
+ title: `Pushing workflow/scheduled job ${resource.location}...`,
204
+ task: async (_ctx, task) => {
205
+ var _a;
206
+ const apiConfig = {
207
+ ...(await (0, version_control_1.readApiFromDisk)(superblocksRootPath, resource.location)),
208
+ commitId: ctx.headCommitId,
209
+ commitMessage: ctx.headCommitMessage,
210
+ };
211
+ task.title += `: read from disk`;
212
+ try {
213
+ await this.getSdk().pushApi({
214
+ apiId: resourceId,
215
+ apiConfig,
216
+ branch: (_a = ctx.branchToPushTo.get(resourceId)) !== null && _a !== void 0 ? _a : ctx.localBranchName,
217
+ });
218
+ }
219
+ catch (error) {
220
+ if ((error === null || error === void 0 ? void 0 : error.name) === "BranchNotCheckedOutError") {
221
+ this.log(`WARN: Workflow/Scheduled Job ${(0, version_control_1.extractApiName)(apiConfig)} failed to push, please check branch out in the Superblocks UI first in order to check this branch out for this resource.`);
222
+ }
223
+ else if (error instanceof sdk_1.CommitAlreadyExistsError) {
224
+ this.log(`WARN: Workflow/Scheduled Job ${(0, version_control_1.extractApiName)(apiConfig)} failed to push as the commit already exists in Superblocks.`);
225
+ }
226
+ else {
227
+ throw error;
228
+ }
229
+ }
230
+ task.title += `: pushed to Superblocks`;
231
+ ctx.pushedResources[resourceId] = resource;
232
+ },
233
+ });
234
+ break;
235
+ }
201
236
  default: {
202
237
  this.error(`Unsupported resource type, resource: ${JSON.stringify(resource)}
203
238
  `);
@@ -214,7 +249,7 @@ Would you like to also delete these resources from your filesystem?`,
214
249
  });
215
250
  return tasks;
216
251
  }
217
- async getResourceIdsToPush(ctx, task, resourcePath, supportedResourceTypes = ["APPLICATION"]) {
252
+ async getResourceIdsToPush(ctx, task, resourcePath, supportedResourceTypes = ["APPLICATION", "BACKEND"]) {
218
253
  var _a, _b, _c;
219
254
  const resources = Object.entries((_b = (_a = ctx.existingSuperblocksRootConfig) === null || _a === void 0 ? void 0 : _a.resources) !== null && _b !== void 0 ? _b : {}).filter(([, resource]) => {
220
255
  return supportedResourceTypes.includes(resource.resourceType);
@@ -36,7 +36,7 @@ class Remove extends authenticated_command_1.AuthenticatedCommand {
36
36
  },
37
37
  },
38
38
  {
39
- title: "Fetching applications...",
39
+ title: "Fetching applications, workflows and scheduled jobs...",
40
40
  task: (ctx, task) => task.newListr([
41
41
  {
42
42
  title: "Fetching applications...",
@@ -53,6 +53,21 @@ class Remove extends authenticated_command_1.AuthenticatedCommand {
53
53
  task.title += `: completed`;
54
54
  },
55
55
  },
56
+ {
57
+ title: "Fetching workflows and scheduled jobs...",
58
+ enabled: () => !args.resource_path,
59
+ task: async (ctx, task) => {
60
+ // jobs and workflows choices
61
+ const apis = await this.getSdk().fetchApis();
62
+ for (const api of apis) {
63
+ ctx.fetchedResources[api.id] = {
64
+ resourceType: "BACKEND",
65
+ name: (0, version_control_1.extractApiName)(api),
66
+ };
67
+ }
68
+ task.title += `: completed`;
69
+ },
70
+ },
56
71
  ]),
57
72
  },
58
73
  {
@@ -31,15 +31,7 @@ class AuthenticatedCommand extends core_1.Command {
31
31
  }
32
32
  async validateGitSetup(resourceType, resourceId, event, overrideLocalBranch, injectedHeaders) {
33
33
  const localGitRepoState = await (0, version_control_1.getLocalGitRepoState)(overrideLocalBranch);
34
- let branchName;
35
- switch (resourceType) {
36
- case "APPLICATION": {
37
- ({ branchName } = await this.getSdk().validateGitSetup(resourceId, resourceType, event, localGitRepoState, injectedHeaders));
38
- break;
39
- }
40
- default:
41
- throw new Error(`Unsupported resource type: ${resourceType}`);
42
- }
34
+ const { branchName } = await this.getSdk().validateGitSetup(resourceId, resourceType, event, localGitRepoState, injectedHeaders);
43
35
  return {
44
36
  branchName,
45
37
  localBranchName: localGitRepoState.status === "IN_A_BRANCH"
@@ -1,4 +1,4 @@
1
- import { ApplicationWrapper, ViewMode } from "@superblocksteam/sdk";
1
+ import { ApiWrapper, ApplicationWrapper, ViewMode } from "@superblocksteam/sdk";
2
2
  import { LocalGitRepoState } from "@superblocksteam/util";
3
3
  import { VersionedResourceConfig } from "@superblocksteam/util";
4
4
  export declare const LATEST_EDITS_MODE = "latest-edits";
@@ -12,6 +12,7 @@ export declare const SELECT_PROMPT_HELP = "Use \u2191/\u2193 arrow keys, Enter t
12
12
  export declare const MULTI_SELECT_PROMPT_HELP = "Type to filter, Use \u2191/\u2193 arrow keys, Space to select, Enter to confirm";
13
13
  export declare const atLeastOneSelection: (value: string[]) => string | true;
14
14
  export declare function readApplicationFromDisk(rootPath: string, existingRelativeLocation: string): Promise<ApplicationWrapper>;
15
+ export declare function readApiFromDisk(rootPath: string, existingRelativeLocation: string): Promise<ApiWrapper>;
15
16
  export declare function writeResourceToDisk(resourceType: string, resourceId: string, resource: any, rootPath: string, existingRelativeLocation?: string): Promise<VersionedResourceConfig>;
16
17
  export declare function removeResourceFromDisk(resourceLocation: string): Promise<void>;
17
18
  export declare function getMode(task: any, mode: ModeFlag): Promise<ViewMode>;
@@ -27,3 +28,4 @@ export declare function getCurrentGitBranchIfGit(): Promise<string | null>;
27
28
  export declare function getCurrentGitBranch(): Promise<string>;
28
29
  export declare function getHeadCommit(branch: string): Promise<[string, string]>;
29
30
  export declare function isGitRepoDirty(): Promise<boolean>;
31
+ export declare function extractApiName(api: ApiWrapper): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isGitRepoDirty = exports.getHeadCommit = exports.getCurrentGitBranch = exports.getCurrentGitBranchIfGit = exports.getLocalGitRepoState = exports.sortByKey = exports.getMode = exports.removeResourceFromDisk = exports.writeResourceToDisk = exports.readApplicationFromDisk = exports.atLeastOneSelection = exports.MULTI_SELECT_PROMPT_HELP = exports.SELECT_PROMPT_HELP = exports.modeFlagToViewMode = exports.modeFlagValuesMap = exports.DEFAULT_BRANCH = exports.DEPLOYED_MODE = exports.MOST_RECENT_COMMIT_MODE = exports.LATEST_EDITS_MODE = void 0;
3
+ exports.extractApiName = exports.isGitRepoDirty = exports.getHeadCommit = exports.getCurrentGitBranch = exports.getCurrentGitBranchIfGit = exports.getLocalGitRepoState = exports.sortByKey = exports.getMode = exports.removeResourceFromDisk = exports.writeResourceToDisk = exports.readApiFromDisk = exports.readApplicationFromDisk = exports.atLeastOneSelection = exports.MULTI_SELECT_PROMPT_HELP = exports.SELECT_PROMPT_HELP = exports.modeFlagToViewMode = exports.modeFlagValuesMap = exports.DEFAULT_BRANCH = exports.DEPLOYED_MODE = exports.MOST_RECENT_COMMIT_MODE = exports.LATEST_EDITS_MODE = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const https = tslib_1.__importStar(require("https"));
6
6
  const node_path_1 = tslib_1.__importDefault(require("node:path"));
@@ -118,10 +118,16 @@ async function readApplicationFromDisk(rootPath, existingRelativeLocation) {
118
118
  };
119
119
  }
120
120
  exports.readApplicationFromDisk = readApplicationFromDisk;
121
+ async function readApiFromDisk(rootPath, existingRelativeLocation) {
122
+ return {
123
+ apiPb: await readYamlFile(`${rootPath}/${existingRelativeLocation}/api.yaml`),
124
+ };
125
+ }
126
+ exports.readApiFromDisk = readApiFromDisk;
121
127
  // NOTE: If a change is made to how applications are written to disk, please update
122
128
  // logic to read applications from disk in the "readApplicationFromDisk" function accordingly.
123
129
  async function writeResourceToDisk(resourceType, resourceId, resource, rootPath, existingRelativeLocation) {
124
- var _a, _b, _c, _d, _e, _f;
130
+ var _a, _b, _c;
125
131
  switch (resourceType) {
126
132
  case "APPLICATION": {
127
133
  const parentDirName = "apps";
@@ -153,7 +159,7 @@ async function writeResourceToDisk(resourceType, resourceId, resource, rootPath,
153
159
  };
154
160
  if (resource.apis) {
155
161
  for (const api of resource.apis) {
156
- const originalApiName = api.apiPb.metadata.name;
162
+ const originalApiName = extractApiName(api);
157
163
  const apiName = slugifyName(originalApiName);
158
164
  const apiContent = (0, yaml_1.stringify)(api.apiPb, {
159
165
  sortMapEntries: true,
@@ -196,7 +202,7 @@ async function writeResourceToDisk(resourceType, resourceId, resource, rootPath,
196
202
  }
197
203
  case "BACKEND": {
198
204
  const parentDirName = "backends";
199
- const apiName = slugifyName((_f = (_e = (_d = resource.apiPb) === null || _d === void 0 ? void 0 : _d.metadata) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : resource.actions.name);
205
+ const apiName = slugifyName(extractApiName(resource));
200
206
  const newRelativeLocation = `${parentDirName}/${apiName}`;
201
207
  const relativeLocation = existingRelativeLocation !== null && existingRelativeLocation !== void 0 ? existingRelativeLocation : newRelativeLocation;
202
208
  const backendDirName = node_path_1.default.resolve(rootPath, relativeLocation);
@@ -269,7 +275,8 @@ async function getLocalGitRepoState(overrideLocalBranch) {
269
275
  const git = (0, simple_git_1.simpleGit)();
270
276
  let status;
271
277
  try {
272
- status = await git.status();
278
+ // do not return untracked files which can be slow, we only care about the branch info
279
+ status = await git.status(["--untracked-files=no"]);
273
280
  }
274
281
  catch {
275
282
  return { status: "NO_GIT" };
@@ -320,7 +327,8 @@ exports.getLocalGitRepoState = getLocalGitRepoState;
320
327
  async function getCurrentGitBranchIfGit() {
321
328
  const git = (0, simple_git_1.simpleGit)();
322
329
  try {
323
- const status = await git.status();
330
+ // do not return untracked files which can be slow, we only care about the branch info
331
+ const status = await git.status(["--untracked-files=no"]);
324
332
  const currentBranch = status.current;
325
333
  return currentBranch;
326
334
  }
@@ -367,3 +375,8 @@ async function isGitRepoDirty() {
367
375
  return !status.isClean();
368
376
  }
369
377
  exports.isGitRepoDirty = isGitRepoDirty;
378
+ function extractApiName(api) {
379
+ var _a, _b, _c, _d;
380
+ return (_d = (_c = (_b = (_a = api.apiPb) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : api === null || api === void 0 ? void 0 : api.name) !== null && _d !== void 0 ? _d : "Unknown";
381
+ }
382
+ exports.extractApiName = extractApiName;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0",
2
+ "version": "1.4.1",
3
3
  "commands": {
4
4
  "init": {
5
5
  "id": "init",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/cli",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Official Superblocks CLI",
5
5
  "bin": {
6
6
  "superblocks": "bin/run"
@@ -18,11 +18,11 @@
18
18
  "@oclif/core": "^2.11.7",
19
19
  "@oclif/plugin-help": "^5.2.16",
20
20
  "@oclif/plugin-plugins": "^3.1.10",
21
- "@superblocksteam/css-plugin": "1.3.0",
22
- "@superblocksteam/react-shim": "1.3.0",
23
- "@superblocksteam/sdk": "1.3.0",
24
- "@superblocksteam/util": "1.3.0",
25
- "@superblocksteam/vite-custom-component-reload-plugin": "1.3.0",
21
+ "@superblocksteam/css-plugin": "1.4.1",
22
+ "@superblocksteam/react-shim": "1.4.1",
23
+ "@superblocksteam/sdk": "1.4.1",
24
+ "@superblocksteam/util": "1.4.1",
25
+ "@superblocksteam/vite-custom-component-reload-plugin": "1.4.1",
26
26
  "@vitejs/plugin-react": "^4.1.0",
27
27
  "colorette": "^2.0.19",
28
28
  "enquirer": "^2.3.6",