Skip to content

Latest commit

 

History

History
62 lines (50 loc) · 2.87 KB

nodejs-setup-project.md

File metadata and controls

62 lines (50 loc) · 2.87 KB

1. Add GitHub workflow

The workflow file will help build and deploy your project, it does the following things:

  1. workflow_dispatch: gives you the option to manually run your workflow from the Actions section of your project

  2. On pushes to main, it will kick off the workflow but ignore the push if it's only changes made to the workflow file.

push:
    branches: [ main ]
    paths-ignore: 
      - .github/workflows/*
  1. It specifies the Node.js version that will be used for building your project:
- name: Set up Node.Js
  uses: actions/setup-node@v2
  with:
    node-version: '17.3.0'
  1. The project's release version is obtained from your plugin.json automatically by the CI, so when built, it will be appended to the zip file later:
- name: get version
  id: version
  uses: notiz-dev/github-action-json-property@release
  with: 
    path: 'plugin.json'
    prop_path: 'Version'
  1. The Install dependencies section is where you will do most of your CI work. It will run npm install, which will output all the dependencies specified in package.json into the 'node_modules' directory. The workflow will then zip them up along with your project using zip -r Flow.Launcher.Plugin.HelloWorldNodeJS.zip . -x '*.git*', where you replace this Flow.Launcher.Plugin.HelloWorldNodeJS with the name of your plugin.
- name: Install dependencies
  run: |
    npm install
    zip -r Flow.Launcher.Plugin.HelloWorldNodeJS.zip . -x '*.git*'

2. Publish as zip

The final step to the workflow file is this Publish section, which will publish the zip file you generated, upload to GitHub Releases page and tag with the version generated from the previous step from your plugin.json file. Remember again to replace Flow.Launcher.Plugin.HelloWorldNodeJS with the name of your plugin.

- name: Publish
  uses: softprops/action-gh-release@v1
  with:
    files: 'Flow.Launcher.Plugin.HelloWorldNodeJS.zip'
    tag_name: "v${{steps.version.outputs.prop}}"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Feel free to also have a read of this blog post which does a simple explanation of how to use GitHub Actions Workflow.

3. Use node_modules directory

Once the node_modules folder is included in your zip release, it can then be used without needing the user to manually npm install the plugin's dependencies. You just have to tell the plugin during runtime to find those modules in your local node_modules directory. Do this by using this exact copy of the following code block in your main.js:

const open = require('./node_modules/open');