Skip to content

Commit

Permalink
fix(1.7.1): prevent fail-fast on version check (#170)
Browse files Browse the repository at this point in the history
* patch(1.7.1): prevent fail-fast on version check

* feat: improve error messages
  • Loading branch information
ShaunSHamilton authored Nov 9, 2022
1 parent 96c9a5e commit 81c04cb
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Released]

##[1.7.1])(#v1.7.1) (2022-11-07)

### Fixed

- `freeCodeCamp: Run Course` checks for new version of curriculum from `raw.githubusercontent.com`. Prevent fail-fast if fetch fails.

##[1.7.0](#v1.7.0) (2022-10-24)

### Added
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "freecodecamp-courses",
"displayName": "freeCodeCamp - Courses",
"description": "Provides tooling for quick and easy selection of courses offered by freeCodeCamp",
"version": "1.7.0",
"version": "1.7.1",
"author": "freeCodeCamp",
"publisher": "freeCodeCamp",
"galleryBanner": {
Expand All @@ -11,7 +11,7 @@
},
"icon": "images/logo-128X128.png",
"engines": {
"vscode": "^1.72.0",
"vscode": "^1.73.0",
"node": ">=18.0.0"
},
"categories": [
Expand Down Expand Up @@ -83,7 +83,7 @@
"@types/glob": "7.2.0",
"@types/mocha": "9.1.1",
"@types/node": "18.11.9",
"@types/vscode": "1.72.0",
"@types/vscode": "1.73.0",
"@typescript-eslint/eslint-plugin": "5.42.0",
"@typescript-eslint/parser": "5.42.0",
"@vscode/test-electron": "2.2.0",
Expand All @@ -92,7 +92,7 @@
"mocha": "9.2.2",
"ts-loader": "9.4.1",
"typescript": "4.8.4",
"vsce": "2.13.0",
"vsce": "2.14.0",
"webpack": "5.74.0",
"webpack-cli": "4.10.0"
},
Expand All @@ -105,6 +105,6 @@
"url": "https://github.com/freeCodeCamp/courses-vscode-extension/issues"
},
"dependencies": {
"node-fetch": "^3.2.10"
"node-fetch": "3.2.10"
}
}
15 changes: 13 additions & 2 deletions src/commands/develop-course.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { handleConfig } from "../handles";
import { handleMessage } from "../flash";
import { FlashTypes } from "../typings";
import { getConfig } from "../usefuls";
import { getConfig, getPackageJson } from "../usefuls";
import { checkForCourseUpdates } from "../updates";

export default async function developCourse() {
try {
const config = await getConfig();
const rootPackage = await getPackageJson();
const githubLink = rootPackage.repository.url;
const isCourseUpdates = await checkForCourseUpdates(githubLink, config);
if (isCourseUpdates) {
handleMessage({
message:
"This course has been updated. It is recommended you re-clone the repository.",
type: FlashTypes.WARNING,
});
}
handleConfig(config, "develop-course");
} catch (e) {
console.error("freeCodeCamp > runCourse: ", e);
return handleMessage({
message: "Unable to find a `freecodecamp.conf.json` file in workspace.",
message: "Unable to develop course. See dev console for more details.",
type: FlashTypes.ERROR,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/run-course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function runCourse() {
} catch (e) {
console.error("freeCodeCamp > runCourse: ", e);
return handleMessage({
message: "Unable to find a `freecodecamp.conf.json` file in workspace.",
message: "Unable to run course. See dev console for more details.",
type: FlashTypes.ERROR,
});
}
Expand Down
43 changes: 37 additions & 6 deletions src/updates.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import { join } from "path";
import fetch from "node-fetch";
import { Config } from "./typings";
import { Config, FlashTypes } from "./typings";
import { handleMessage } from "./flash";

export async function checkForCourseUpdates(
githubLink: string,
config: Config
): Promise<boolean> {
const currentVersion = config.version;
if (!currentVersion) {
handleMessage({
message:
"Unable to find curriculum version from `freecodecamp.conf.json` file",
type: FlashTypes.WARNING,
});
return false;
}

const repoConfig = await getConfigFromGitHub(githubLink);
if (!repoConfig) {
return false;
}

const repoVersion = repoConfig.version;
if (!repoVersion || currentVersion) {
console.error("Unable to get curriculum version for: ", githubLink);
if (!repoVersion) {
handleMessage({
message: "Unable to get curriculum version from upstream",
type: FlashTypes.WARNING,
});
return false;
}

const [currMajor, currMinor, currPatch] = semVer(currentVersion);
const [repoMajor, repoMinor, repoPatch] = semVer(repoVersion);
return (
Expand All @@ -34,9 +52,22 @@ function semVer(version: string) {
async function getConfigFromGitHub(githubLink: string) {
// Example: https://raw.githubusercontent.com/freeCodeCamp/web3-curriculum/main/freecodecamp.conf.json
const url = githubLinkToURL(githubLink);
const res = await fetch(url.href);
const config = (await res.json()) as Config;
return config;
try {
const res = await fetch(url.href);
const config = (await res.json()) as Config;
return config;
} catch (e) {
console.error(e);
handleMessage({
message: `Unable to check for latest curriculum version: ${url.href}`,
type: FlashTypes.WARNING,
opts: {
detail:
"You might be running a version of the curriculum that does not have bug fixes or new features.",
},
});
}
return null;
}

function githubLinkToURL(githubLink: string) {
Expand Down

0 comments on commit 81c04cb

Please sign in to comment.