How I Built It: The Anatomy of a VS Code Extension

Developer Advocate @ GitHub
Search for a command to run...

Developer Advocate @ GitHub
Thank you!
In this series, I will document technical tutorials for navigating GitHub's awesome features!
Why I built It I built a VS Code Extension that deploys code to GitHub Pages. I’ve always wanted to build a VS code extension, but I never had a reason or enough time. Now that I work in DevRel at GitHub, I finally got the opportunity to do so! The M...
Raise your hand if you've been personally victimized by the question: 'Will AI replace software engineers?' It's a common debate that drives developers to extremes—either avoiding AI entirely or frantically signing up for every AI course available. ...
I recently went down several rabbit holes about building WYSIWYG editors and popovers. While on maternity leave, I finally have time to deeply explore random technical problems without deadlines - a rare opportunity. Thus far, I've focused on contrib...
This blog post uses storytelling to introduce beginners to Verifiable Credentials, followed by a tutorial on creating them in JavaScript and Kotlin. In Our Last Issue... In our previous issue, we met Dawson Webhart, a junior frontend software enginee...

"Our current credit system says, 'Saddle yourself, so we can give you more to saddle.'" Eric Lapin, President of FormFree, stated during a recent TBD live stream. His comment sheds light on a fundamental paradox of the U.S. credit system: it often re...

Technology adoption doesn't happen with one software engineer coding in solitude. Even though big companies like Meta and Microsoft boast of their humble beginnings in a dorm room or a garage, product adoption requires good marketing. Many software e...

Black Girl Bytes
58 posts
I'm a Developer Advocate at GitHub. I'm passionate about community, code, and education! Reach out to me on Twitter ❤️
I built a VS Code Extension that deploys code to GitHub Pages. I’ve always wanted to build a VS code extension, but I never had a reason or enough time. Now that I work in DevRel at GitHub, I finally got the opportunity to do so! The Microsoft VS Code team runs a resume website workshop where participants deploy a resume built with HTML and CSS to GitHub Pages.
I collaborated with the VS Code team to create a VS Code Extension that enables you to quickly deploy your static web page (Jekyll or HTML) to GitHub Pages without leaving your IDE.
My two favorite things are making a positive impact and experimenting with technologies I haven’t used!
To set up a template for my VS Code Extension, I installed the VS Code Extension Generator and Yeoman with the command below:
npm install -g yo generator-code
package.json Extension Manifest to extend VS Code.A VS Code extension includes these three configuration files:

The extension manifest is a package.json file. It includes scripts, devDependencies, a VS Code publisher, VS Code activationEvents, and VS Code contributes. In the screenshot below, I use the contributes to define my command called “extension.deployToGitHubPages”.

The entry point to my VS Code extension is called extension.js. In this entry file, I imported two classes that I created: credentials and repositories. The credentials file handles authentication so that the GitHub API can gain access to the user’s repositories. The repositories file fetches the user’s repositories and posts the chosen repository to a GitHub Page.

I needed an access token to make API calls to retrieve repositories and deploy the code to GitHub Pages. I generated a new access token for each session using the vscode.authentication object. The getSession method attached to that object returns an access token. Note that GitHub’s access tokens have different levels of permissions called scopes. I need the token for my application to have access to the user, repository, and workflow.

The vscode.QuickPick API, enabled me easily collect user input or let the user make a selection from multiple options.

To deploy to GitHub Pages, I made an API call with Octokit. The API call, as mentioned above, is a POST request that takes the user’s login, selected repository, and default branch. If successful, the application will respond with a message stating that your GitHub Actions is building and deploying your site.

I wrote about using the GitHub extension in this blog post.
Honestly, I didn’t invest as much time as I wanted into creating this extension. There’s room for improvement. I’m open to contributions in helping me improve my README, improving the workflow, and my use of the any keyword is embarrassing. Feel free to open up an issue and a pull request in this repository: https://github.com/blackgirlbytes/vscodeextension-deploy-to-gh-pages
Tell me about an open source project you maintain or contribute to in the comments below!