track-cli 4.1.0-rc2 → 4.1.0-rc4

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.
@@ -1,20 +1,38 @@
1
1
  import * as dntShim from "../../_dnt.shims.js";
2
2
  import { load as loadConfig } from "../shared/config.js";
3
3
  import { archiveExistingChallengeFiles, downloadChallengeFilesTo, getCommonChallengeContext, trackClientFromConfig, } from "../shared/mod.js";
4
+ import { ChallengeStyle, } from "../shared/types.js";
4
5
  export async function reset() {
5
6
  const config = await loadConfig();
6
7
  const api = trackClientFromConfig(config);
7
- const [_codingContext, _challenge] = await getCommonChallengeContext(config, api);
8
- console.log("Your existing code will be archived in this directory and the original challenge code will be downloaded");
8
+ const [codingContext, challenge] = await getCommonChallengeContext(config, api);
9
+ console.log("A copy of your existing code will be archived in this directory, and the original challenge code will be re-downloaded.");
9
10
  const shouldContinue = dntShim.confirm("Are you sure you want to reset this challenge?");
10
11
  if (!shouldContinue) {
11
12
  return;
12
13
  }
14
+ // Update the remote files without modifying the local copy
15
+ await resetRemoteFiles(api, codingContext, challenge);
16
+ // Once the remote update succeeded,
17
+ // archive the local files before re-downloading the remote files following the reset.
13
18
  const currentDir = dntShim.Deno.cwd();
14
19
  await archiveExistingChallengeFiles(config.orgName);
15
- await api.reset();
16
20
  const newCodingContext = await api.context();
17
21
  const showFileDiff = false;
18
22
  const includeTarball = true;
19
23
  await downloadChallengeFilesTo(newCodingContext, currentDir, api, showFileDiff, includeTarball);
20
24
  }
25
+ async function resetRemoteFiles(api, codingContext, challenge) {
26
+ if (challenge.style === ChallengeStyle.Frontend) {
27
+ const seriesCode = codingContext.selectedFrontendTemplate?.seriesCode ??
28
+ // In the unlikely event that no template is selected, arbitrarily pick the first available one
29
+ codingContext.availableFrontendTemplates?.[0]?.seriesCode ??
30
+ // Extremely unlikely fallback:
31
+ (await api.frontendTemplates())[0].seriesCode;
32
+ await api.updateFrontendTemplate(seriesCode);
33
+ }
34
+ else {
35
+ // For non-frontend (Algorithm/Development/Function) use the reset API
36
+ await api.reset();
37
+ }
38
+ }
@@ -1,10 +1,10 @@
1
1
  import * as dntShim from "../../_dnt.shims.js";
2
+ import { OrcaClient } from "../orca/client.js";
3
+ import { FileType } from "../orca/types.js";
2
4
  import { load as loadConfig } from "../shared/config.js";
3
5
  import { CantReadFile } from "../shared/errors.js";
4
6
  import { getCommonChallengeContext, listFileNames, printTimeLeft, trackClientFromConfig, } from "../shared/mod.js";
5
7
  import { EnvSettings, FileListType, } from "../shared/types.js";
6
- import { OrcaClient } from "../orca/client.js";
7
- import { FileType } from "../orca/types.js";
8
8
  import * as colors from "../../deps/deno.land/std@0.195.0/fmt/colors.js";
9
9
  import { exists } from "../../deps/deno.land/std@0.195.0/fs/mod.js";
10
10
  import { FileNotFound } from "../shared/errors.js";
@@ -15,7 +15,7 @@ export async function run(options) {
15
15
  const [codingContext, challenge] = await getCommonChallengeContext(config, api);
16
16
  // const orcaHost = Deno.env.get("ORCA_HOST") || "track-prod-frontend.orca.run";
17
17
  // Temporary code to retrieve the Orca host. Will be able to get from CodingContext in the future.
18
- const orcaHost = codingContext.orcaHost || await api.orcaHost();
18
+ const orcaHost = codingContext.orcaHost || (await api.orcaHost());
19
19
  const token = await api.orcaToken(codingContext);
20
20
  const orca = new OrcaClient(orcaHost, token);
21
21
  await orca.connect();
@@ -32,20 +32,23 @@ export async function run(options) {
32
32
  if (codingContext.answers.appCommand) {
33
33
  envVars["APP_COMMAND"] = codingContext.answers.appCommand;
34
34
  }
35
+ if (codingContext.answers?.frontendSettings?.target) {
36
+ // Currently, the `envConfig.variables` from Track Test does not including the frontend template's FRONTEND_TARGET.
37
+ envVars["FRONTEND_TARGET"] = codingContext.answers?.frontendSettings?.target;
38
+ }
35
39
  await orca.envVars(envVars);
36
- const files = Object.entries(await getAllEditableFileContent(codingContext))
37
- .map(([name, content]) => ({
40
+ const updatedFiles = await getAllEditableFileContent(codingContext);
41
+ const files = Object.entries(updatedFiles).map(([name, content]) => ({
38
42
  name,
39
43
  content,
40
44
  type: FileType.UTF8,
41
45
  }));
42
46
  let saveFilesRequest;
43
47
  if (!options?.noSave) {
44
- const updatedFiles = await getAllEditableFileContent(codingContext);
45
48
  saveFilesRequest = {
46
49
  versionId: codingContext.challengeVersionId,
47
50
  addedFiles: codingContext.answers.addedFiles || [],
48
- updatedFiles: updatedFiles,
51
+ updatedFiles,
49
52
  };
50
53
  console.log("Saving challenge files");
51
54
  await api.saveFiles(saveFilesRequest);
package/esm/src/meta.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const VERSION = "4.1.0-rc2";
1
+ export declare const VERSION = "4.1.0-rc4";
2
2
  export declare const DESCRIPTION = "A CLI for interacting with tracks.run and running code tests on track's servers";
3
3
  export declare function checkUpdates(): Promise<boolean>;
package/esm/src/meta.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as colors from "../deps/deno.land/std@0.195.0/fmt/colors.js";
2
2
  // @ts-ignore: has no exported member
3
3
  import { CookieJar, fetch } from "node-fetch-cookies";
4
- export const VERSION = "4.1.0-rc2";
4
+ export const VERSION = "4.1.0-rc4";
5
5
  export const DESCRIPTION = "A CLI for interacting with tracks.run and running code tests on track's servers";
6
6
  const VERSION_RE = /^(\d+)\.(\d+)\.(\d+)(?:-?(.*))$/;
7
7
  function parseSemver(s) {
@@ -114,6 +114,10 @@ export interface CodingAnswers {
114
114
  addedFiles?: string[];
115
115
  fileVersions: object;
116
116
  envConfig?: EnvSettings;
117
+ frontendSettings?: {
118
+ /** The directory containing compiled frontend assets */
119
+ target?: string;
120
+ };
117
121
  }
118
122
  export interface SaveFilesRequest {
119
123
  versionId: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "track-cli",
3
- "version": "4.1.0-rc2",
3
+ "version": "4.1.0-rc4",
4
4
  "description": "A CLI for interacting with tracks.run and running code tests on track's servers",
5
5
  "repository": {
6
6
  "type": "git",