Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(1.8.0): add automatic update course button #278

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Released]

##[1.8.0](#v1.8.0) (2022-03-30)

### Added

- Prompt Camper to update course, when update is detected
- Provide a button to automatically update course

##[1.7.4](#v1.7.4) (2022-03-30)

### Updated
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ This extension helps run the freeCodeCamp courses found here: [./resources/cours

## Published Courses

- [NEAR Curriculum](https://github.com/freeCodeCamp/near-curriculum/)
- [Project Euler: Rust](https://github.com/freeCodeCamp/euler-rust/)
- [Solana Curriculum](https://github.com/freeCodeCamp/solana-curriculum/)
- [Web3 Curriculum](https://github.com/freeCodeCamp/web3-curriculum/)

## Course Config

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion 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.4",
"version": "1.8.0",
"author": "freeCodeCamp",
"publisher": "freeCodeCamp",
"galleryBanner": {
Expand Down
12 changes: 2 additions & 10 deletions src/commands/create-new-course.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { window } from "vscode";
import { handleConnection, handleEmptyDirectory } from "../handles";
import { handleMessage } from "../flash";
import { createBackgroundTerminal } from "../handles";
import { showInputBox } from "../inputs";
import { FlashTypes } from "../typings";
import { gitClone } from "../usefuls";

export default async function createNewCourse() {
const course = await showInputBox();
if (!course) {
handleMessage({
message: "No course name provided.",
type: FlashTypes.ERROR,
});
window.showErrorMessage("No course name provided.");
return Promise.reject();
}
try {
Expand All @@ -27,10 +22,7 @@ export default async function createNewCourse() {
return Promise.resolve();
} catch (e) {
console.error(e);
handleMessage({
message: "Error cloning course. See console for details.",
type: FlashTypes.ERROR,
});
window.showErrorMessage("Error cloning course. See console for details.");
return Promise.reject();
}
}
24 changes: 13 additions & 11 deletions src/commands/develop-course.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { window } from "vscode";
import { handleConfig } from "../handles";
import { handleMessage } from "../flash";
import { FlashTypes } from "../typings";
import { getConfig, getPackageJson } from "../usefuls";
import { checkForCourseUpdates } from "../updates";
import { updateRepository } from "../update-repository";

export default async function developCourse() {
try {
Expand All @@ -11,18 +11,20 @@ export default async function developCourse() {
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,
});
const camperChoice = await window.showWarningMessage(
"This course has been updated. It is recommended you re-clone the repository.",
"Update",
"Dismiss"
);
if (camperChoice === "Update") {
return updateRepository();
}
}
handleConfig(config, "develop-course");
} catch (e) {
console.error("freeCodeCamp > runCourse: ", e);
return handleMessage({
message: "Unable to develop course. See dev console for more details.",
type: FlashTypes.ERROR,
});
return window.showErrorMessage(
"Unable to develop course. See dev console for more details."
);
}
}
28 changes: 17 additions & 11 deletions src/commands/run-course.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { handleConfig } from "../handles";
import { handleMessage } from "../flash";
import { FlashTypes } from "../typings";
import { window } from "vscode";
import { getConfig, getPackageJson } from "../usefuls";
import { checkForCourseUpdates } from "../updates";
import { updateRepository } from "../update-repository";

export default async function runCourse() {
try {
Expand All @@ -11,18 +11,24 @@ export default async function runCourse() {
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,
});
/**
* There is an update to the curriculum, it is recommended that you update your local copy of the curriculum and rebuild the container.
* NOTE: You will lose any progress in your container.
*/
const camperChoice = await window.showWarningMessage(
"This course has been updated. It is recommended you update the repository.",
"Update",
"Dismiss"
);
if (camperChoice === "Update") {
return updateRepository();
}
}
handleConfig(config, "run-course");
} catch (e) {
console.error("freeCodeCamp > runCourse: ", e);
return handleMessage({
message: "Unable to run course. See dev console for more details.",
type: FlashTypes.ERROR,
});
return window.showErrorMessage(
"Unable to run course. See dev console for more details."
);
}
}
7 changes: 3 additions & 4 deletions src/components.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { commands, Uri, workspace, window } from "vscode";
import fetch from "node-fetch";
import { Course, FlashTypes } from "./typings";
import { handleMessage } from "./flash";
import { Course } from "./typings";

export async function openTerminal() {
const terminal = window.createTerminal("freeCodeCamp");
Expand Down Expand Up @@ -32,7 +31,7 @@ export async function currentDirectoryCourse(): Promise<
return Promise.resolve(courseGithubLink);
} catch (e) {
console.error(e);
handleMessage({ message: e as string, type: FlashTypes.INFO });
window.showInformationMessage(e as string);
return Promise.resolve(null);
}
}
Expand All @@ -43,7 +42,7 @@ export async function getRootWorkspaceDir() {
return Promise.resolve(path.path);
} catch (e) {
console.error(e);
handleMessage({ message: e as string, type: FlashTypes.INFO });
window.showInformationMessage(e as string);
return Promise.resolve(null);
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/flash.ts

This file was deleted.

49 changes: 14 additions & 35 deletions src/handles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Bashrc, Config, FlashTypes, Test } from "./typings";
import { Bashrc, Config, Test } from "./typings";
import { exampleConfig } from "./fixture";
import { commands, Terminal, TerminalExitStatus, window } from "vscode";
import { isConnectedToInternet, openSimpleBrowser } from "./components";
import { cd, checkIfURLIsAvailable, ensureDirectoryIsEmpty } from "./usefuls";
import { handleMessage } from "./flash";
import { everythingButHandles } from ".";
import { createLoaderWebView } from "./loader";

Expand Down Expand Up @@ -82,10 +81,9 @@ export function rebuildAndReopenInContainer() {
export async function handleConnection() {
const isConnected = await isConnectedToInternet();
if (!isConnected) {
handleMessage({
message: "No connection found. Please check your internet connection",
type: FlashTypes.ERROR,
});
window.showErrorMessage(
"No connection found. Please check your internet connection"
);
return Promise.reject();
}
return Promise.resolve();
Expand All @@ -94,15 +92,7 @@ export async function handleConnection() {
export async function handleEmptyDirectory() {
const isEmpty = await ensureDirectoryIsEmpty();
if (!isEmpty) {
handleMessage({
message: "Directory is not empty.",
type: FlashTypes.WARNING,
opts: {
detail: "Please empty working directory, and try again.",
modal: true,
},
});

window.showWarningMessage("Directory is not empty.");
return Promise.reject();
}
return Promise.resolve();
Expand Down Expand Up @@ -148,10 +138,7 @@ export async function handleWorkspace(
for (const preview of workspace!.previews) {
const notSets = getNotSets(preview, compulsoryKeys);
if (notSets.length) {
handleMessage({
message: `Preview missing keys: ${notSets.join(", ")}`,
type: FlashTypes.ERROR,
});
window.showErrorMessage(`Preview missing keys: ${notSets.join(", ")}`);
return Promise.reject();
}
if (preview.showLoader) {
Expand Down Expand Up @@ -186,10 +173,9 @@ export async function handleWorkspace(
for (const term of workspace!.terminals) {
const notSets = getNotSets(term, compulsoryKeys);
if (notSets.length) {
handleMessage({
message: `Terminals missing keys: ${notSets.join(", ")}`,
type: FlashTypes.ERROR,
});
window.showErrorMessage(
`Terminals missing keys: ${notSets.join(", ")}`
);
return Promise.reject();
}
if (term?.name) {
Expand All @@ -209,10 +195,7 @@ export async function handleWorkspace(
for (const file of workspace!.files) {
const notSets = getNotSets(file, compulsoryKeys);
if (notSets.length) {
handleMessage({
message: `Files missing keys: ${notSets.join(", ")}`,
type: FlashTypes.ERROR,
});
window.showErrorMessage(`Files missing keys: ${notSets.join(", ")}`);
return Promise.reject();
}
// TODO: Open file
Expand Down Expand Up @@ -240,10 +223,7 @@ export async function handleConfig(

const notSets = getNotSets<Config>(config, compulsoryKeys);
if (notSets.length) {
return handleMessage({
type: FlashTypes.ERROR,
message: `${notSets.join(", and ")} not set.`,
});
return window.showErrorMessage(`${notSets.join(", and ")} not set.`);
}

// Run prepare script
Expand Down Expand Up @@ -307,9 +287,8 @@ export function ensureNoExtraKeys(obj: any, exampleObject: any) {
console.log(
"There are keys that are not recognised in the `freecodecamp.conf.json` file. Double-check the specification."
);
handleMessage({
type: FlashTypes.WARNING,
message: `Unrecognised keys: ${unrecognisedKeys.join(", ")}`,
});
window.showWarningMessage(
`Unrecognised keys: ${unrecognisedKeys.join(", ")}`
);
}
}
4 changes: 0 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
cd,
} from "./usefuls";

import { handleMessage, showMessage } from "./flash";

export const everythingButHandles = {
currentDirectoryCourse,
ensureDirectoryIsEmpty,
Expand All @@ -26,7 +24,5 @@ export const everythingButHandles = {
openSimpleBrowser,
openTerminal,
showInputBox,
handleMessage,
showMessage,
cd,
};
15 changes: 0 additions & 15 deletions src/typings.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
export enum FlashTypes {
ERROR = "error",
INFO = "info",
WARNING = "warning",
}

export type Flash = {
message: string;
opts?: {
detail: string;
modal?: boolean;
};
type: FlashTypes;
};

export interface Course {
githubLink: string;
name: string;
Expand Down
27 changes: 27 additions & 0 deletions src/update-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { window } from "vscode";
import { currentDirectoryCourse } from "./components";
import { createBackgroundTerminal } from "./handles";

/**
* Pulls the latest changes from the remote repository.
*/
export async function updateRepository() {
const courseGitDownloaded = await currentDirectoryCourse();

// git checkout -b "<timestamp>"
// git commit -m "test"
// git checkout main
// git pull upstream main
// git reset --hard upstream/main
// Tell camper where to find history
const termStatus = await createBackgroundTerminal(
"freeCodeCamp: Git Pull",
`git pull ${courseGitDownloaded} main`
);

if (termStatus.code !== 0) {
window.showErrorMessage("Error updating course.");
} else {
window.showInformationMessage("Course updated successfully.");
}
}
Loading