Skip to content

Instantly share code, notes, and snippets.

@GreepTheSheep
Last active May 27, 2022 17:58
Show Gist options
  • Save GreepTheSheep/d95921bc9cb10287c39611bd429d9273 to your computer and use it in GitHub Desktop.
Save GreepTheSheep/d95921bc9cb10287c39611bd429d9273 to your computer and use it in GitHub Desktop.
Making .op files easily with a VSCode shortcut

How to build Openplanet plugins easily with VSCode build tasks

1. Setting up your environment

When making a new plugin, make sure you set up your plugin's folder as follows:

OpenplanetNext/
├── Plugins/
│   ├── <PluginName>/
│   │   ├── info.toml
│   │   ├── build.bat
│   │   ├── src/
│   │   │   ├── <your code>.as

Here, "PluginName" is the name of your plugin, "your code".as would be your code files.

This structure is important for the build process because it allows our build script to take the info.toml file and the files in the src folder as input.

2. Setting up your build.bat file

As you seen in the structure, the build.bat file is the build script for your plugin.

Create a new file called build.ps1 in your plugin's folder and use this code below:

:: We will hide our commands
@echo off

:: Set here your path to 7-Zip, including 7z.exe
SET zip="C:\Program Files\7-Zip\7z.exe"

:: This will get the current directory name,
:: Keep in mind that the Plugin ID (not the site ID) must be the same name as the current directory
for %%I in (.) do SET CurrDirName=%%~nxI

:: Check if we have already a .op built
:: If we have one, we need to delete, because 7-Zip will add files on it but not delete older ones
IF EXIST %CurrDirName%.op (
    del %CurrDirName%.op
)

:: Then compress it
%zip% a -mx1 -tzip %CurrDirName%.op info.toml src

echo Done!

3. Setting up your task.json file

On your VS Code workspace, create a new task.json file.

  1. Open your command palette with F1.
  2. Select "Configure Task" from the "Tasks" category.
  3. Select "Create tasks.json file from template".
  4. Select "Other"

This will create a new task.json file in your workspace. Now replace this json to make run your bat script.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build .op file",
            "type": "shell",
            "command": "${workspaceFolder}/build.bat",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Don't forget to add the "group" property to your task so it will be a default build task.

Make it run!

To run your build task, open the command palette with F1 and select "Run Build Task".

You can make a keyboard shortcut for this command. By default, it is Ctrl+Shift+B.

You can now publish your plugin to the Openplanet website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment