Skip to content

Commit

Permalink
feat: Inital version
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuerike committed Aug 4, 2023
0 parents commit 5bf1d5c
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish to NPM

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: https://registry.npmjs.org/

- name: Publish package on NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Insomnia Python Script

Run any complex logic with python and get the result with Insomnia.

## Prerequisites

- Have `python3` configured at your `$PATH`

## Install

1. Open Insomnia
2. Go to Application > Preferences > Plugins
3. Type `insomnia-plugin-python-script`
4. Install the plugin

## Usage

### Write your complex python script

Your script must return de desired result by printing it.

At `~/path/to/file.py`:
```
def complex_logic():
return ("complex_result")
print(complex_logic())
```

### Add the plugin to desired field

Type `CTRL + SPACE` then search for Python Script, and select the plugin

![Screenshot](https://raw.githubusercontent.com/wuerike/insomnia-plugin-python-script/main/npm/content/example1.png)


### Set the path of your python script

You'd better use a global path starting with `~/` to avoid any problem

![Screenshot](https://raw.githubusercontent.com/wuerike/insomnia-plugin-python-script/main/npm/content/example2.png)
26 changes: 26 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const execSync = require("child_process").execSync;

module.exports.templateTags = [
{
name: "pyScript",
displayName: "Python Script",
description: "Run python3 script.",
args: [
{
displayName: "File path",
placeholder: '~/file.py',
type: "string",
},
],
async run(context, path) {
try {
var resp = execSync( `python3 ${path}`, { encoding: "utf-8" });
} catch (failed) {
console.log("Command execution failed with " + failed);
return failed.stderr;
}

return resp.trim();
},
},
];
Binary file added npm/content/example1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added npm/content/example2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added npm/content/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "insomnia-plugin-python-script",
"version": "0.1.0",
"insomnia": {
"name": "python-script",
"displayName": "Python Script",
"description": "Run python3 script.",
"images": {
"icon": "npm/content/logo.png"
}
},
"keywords": [
"insomnia",
"plugin",
"python",
"script"
],
"main": "main.js"
}

0 comments on commit 5bf1d5c

Please sign in to comment.