DEV Community

Cover image for Automate packaging of Visual Studio Code extension
Allan Simonsen
Allan Simonsen

Posted on

1 1

Automate packaging of Visual Studio Code extension

During my work with the Visual Studio Code extension AngularTools I more than once annoyingly forgot one of the steps in the deployment.

Its not a complicated set of tasks but in my list of things to do when packaging a new version I have to:

  • Verify that the version number in the package.json has been updated.
  • Verify that the CHANGELOG.md file has been updated with a description of bugfixes and new features.
  • Create a tag for the version in the Git repository.
  • Run vsce package to create the vsix package file.

So I automated the tasks with the python script below:

import os
import json
import re
from git import Repo, TagReference

def readVersionFromPackageJson():
  packageJson = open("package.json", "r")
  contentRaw = packageJson.read()
  contentJson = json.loads(contentRaw)
  packageJson.close()
  return contentJson["version"]

def isPackageJsonVersionTagged(repo, packageJsonVersion):
  packageJsonVersionTagFound = False
  for tag in repo.tags:
    if tag.name == packageJsonVersion:
      packageJsonVersionTagFound = True
      break
  return packageJsonVersionTagFound

def isChangeLogUpdatedWithPackageJsonVersion(packageJsonVersion):
  packageJsonVersionChangeLogEntryFound = False
  changeLog = open("CHANGELOG.md", "r")
  changeLogContent = changeLog.readlines()
  changeLog.close()
  for line in changeLogContent:
    match = re.search(f"^## Version {packageJsonVersion}$", line)
    if match:
      packageJsonVersionChangeLogEntryFound = True
      break
  return packageJsonVersionChangeLogEntryFound

def packageExtension():
  os.system("vsce package")

def main():
  packageJsonVersion = readVersionFromPackageJson()
  repo = Repo("./")
  packageJsonVersionTagFound = isPackageJsonVersionTagged(repo, packageJsonVersion)
  packageJsonVersionChangeLogEntryFound = isChangeLogUpdatedWithPackageJsonVersion(packageJsonVersion)

  if not packageJsonVersionChangeLogEntryFound:
    print("Fail: CHANGELOG.md not update!")
  else:
    if not packageJsonVersionTagFound:
      print(f"New version found in package.json: {packageJsonVersion}.")
      print("Creating tag in Git...")
      repo.create_tag(packageJsonVersion)
      print("Creating vsix package...")
      packageExtension()
    else:
      print(f"Fail: Version already tagged: {packageJsonVersion}.")
      print("No vsix package created")

main()

Enter fullscreen mode Exit fullscreen mode

I hope you find it useful or that it will inspire you to automate some of your boring or annoying tasks.

You can find the script and the code for AngularTools on GitHub.

The script running

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
๐ŸŽฅ Audio/video file upload with real-time preview
๐Ÿ—ฃ๏ธ Advanced transcription with speaker identification
โญ Automatic highlight extraction of key moments
โœ๏ธ AI-powered article draft generation
๐Ÿ“ค Export interview's subtitles in VTT format

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay