1. Home
  2. Docs
  3. Create a package

Create a package

Creating a package in Polypad is very straight forward and very seamless. In this guide we will cover creating a basic package for local development as well as creating a package that you can share with the others.

Initial Folder Structure

Our basic package will have include the minimal amount of information needed to bundle our script. I have started with the HelloPolypad example which simply outputs the text, “Hello Polypad!”.

$ tree
.
├── HelloPolypad.js
├── README.md
└── scriptist.json

Code for your package is placed within the root directory. The convention is to have a main javascript file with the same name as your script, since that gets loaded when the script is added to Polypad.

Your first package

Now that we have gotten the basics of setting up a folder directory out of the way, lets begin writing our very own script and setting up a package.

Create an empty folder hello-polypad and lets change into the directory.

mkdir hello-polypad // creates directory
cd hello-polypad // changes into the directory

We will start off by creating the script file, which will contain the entry point for our script. Create a HelloPolypad.js file.

touch HelloPolypad.js

Now lets open the HelloPolypad.js file and begin writing our script contents. The purpose of this script it to output Hello Polypad! to the textpad.

We will start with setting up our header as every script files needs a header in order to run in Polypad. Let’s create a header file detailing information about our script.

/*
    name: Hello Polypad
    description: Example script created for polypad
    author: Marcell Purham
    tags: script,polypad,hello
    version: 1.0.0
*/

Now that our header is created we will need to write the body of the function so that our script actually performs some action. Let’s create a body for our script.

function main(input) {

}

Every script needs a body function to work properly. In the above case the body function must accept a signature parameter. In our case we simply name it input.

Given our script only outputs text in this example, we will not be transforming any input text, thus we can simply write a one line statement to output our desired text.

function main(input) {
    input.text = "Hello Polypad!";
}

At this point if you do not plan on sharing or publishing this script outside of your machine then the script above will work with Polypad as is. Simply place the HelloPolypad.js file inside of the scripts directory in Polypad (Scripts -> Browse Scripts).

If you are looking to create a package for others to use as well then let’s continue.

Preparing a package

Now that you have written your script, we will need to prepare this script so others can utilize it as well. Lets create a scriptist.json file which will contain information about our script.

touch scriptist.json

Copy the below boilerplate scriptist.json code and change accordingly. The name, description, version, tags, and author name should match the scripts header code. To learn more about the additional fields, checkout the specification reference

{
    "name": "Hello Polypad",
    "description": "Example script created for polypad",
    "version": "1.0.0",
    "tags": [
        "scripts",
        "polypad",
        "hello-world"
    ],
    "homepage": "https://polypad.io",
    "license": "GPL",
    "type": "script",
    "authors": [
        {
            "name": "Marcell Purham",
            "email": "m@marcell.me",
            "homepage": "marcell.me"
        }
    ],
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/mpurham/hello-polypad"
        }
    ]
}

If you are unsure about the repositories url, you can simply leave it blank and add it later after pushing package to your repository.

Finally we will add our README.md which will describe how the script works as well as any additional information needed for the script. Create a readme file.

touch README.md

Copy the below boilerplate README.md text and change accordingly.

# Hello Polypad

This package is pretty basic. It simply outputs `Hello Polypad` to the textpad.

## Usage

## Features and compatability

## Contributing

Any pull requests with bugfixes or efficiency improvements is greatly appreciated.

Was this article helpful to you? Yes No

How can we help?