Service Now - Sincronia Setup

Sunday Feb 9, 2020

”/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py” -o /tmp/labels.pdf ~/Downloads/n/*.pdf

Sincronia (from https://github.com/nuvolo/sincronia) seems to solve a lot of complaints I have about SN development.

Setup

To setup:

  1. First install the server-side code as a scoped app via github (https://github.com/nuvolo/sincronia-server-scoped-app)
  2. Create a directory for a Node project and npm init
  3. Install the core sincronia package in the new project: npm i -D @sincronia/core
  4. Initilize the project with npx sinc init
  5. Setup various plugins - See the steps below
  6. Run npx sinc dev to start syncing projects
    • We can push with npx sync push to push all scripts and overwrite what’s in SN
    • When we add a new file, we add it in SN and, stop the sinc dev and run npx sinc refresh to pull new files (this does not overwrite existing files)
  7. Import the project into the IDE of your choice, and check it in to SCM.

** DO NOT COMMIT .env ** it has our password in it

Note that what we are doing here is storing compiled JS in ServiceNow, which has a few implications we should be aware of:

Plugins

Plugins are configured in sinc.config.js

We can use the following for Babel and Typescript support:

  @babel/plugin-proposal-class-properties
  @babel/plugin-proposal-object-rest-spread
  @babel/preset-env
  @babel/preset-typescript
  @sincronia/babel-plugin
  @sincronia/babel-plugin-remove-modules
  @sincronia/babel-preset-servicenow
  @sincronia/core
  @sincronia/typescript-plugin
  corejs

For typescript, we can install @nuvolo/servicenow-types to get SN types!

Then, in the configuration we setup Sincronia to process files that have an extension of .sn.js as babel transipiled with corejs V3 support. If a file has an extension of .sn.ts we compile it with babel & typescript!

Our sinc.config.js config looks like this:

module.exports = {
    sourceDirectory: "src",
    buildDirectory: "build",
    rules: [
        {
            match: /\.sn\.js$/,
            plugins: [
                {
                    name: "@sincronia/babel-plugin",
                    options: {
                        plugins: [
                            "@sincronia/remove-modules",
                            "@babel/proposal-class-properties",
                            "@babel/plugin-proposal-object-rest-spread"
                        ],
                        presets: [
                            "@sincronia/servicenow",
                            ["@babel/env", {
                                useBuiltIns: "entry",
                                targets: { ie: "10" },
                                corejs: { version: 3 }
                            }]
                        ]
                    }
                }
            ]
        },
        {
            match: /\.sn\.ts$/,
            plugins: [
                {
                    name: "@sincronia/typescript-plugin",
                    options: {
                        transpile: false,
                    }
                },
                {
                    name: "@sincronia/babel-plugin",
                    options: {
                        plugins: [
                            "@sincronia/remove-modules",
                            "@babel/proposal-class-properties",
                            "@babel/plugin-proposal-object-rest-spread"],
                        presets: [
                            "@sincronia/servicenow",
                            ["@babel/env", {
                                useBuiltIns: "entry",
                                targets: { ie: "10" },
                                corejs: { version: 3 }
                            }],
                            "@babel/typescript"]
                    }
                }
            ]
        }
    ],
    excludes: {},
    includes: {},
    tableOptions: {},
    refreshInterval: 30
};

Workflows

We should always make sure to start npx sinc dev before editing files. If it is not running when files are changed they will not be sent to the instance after the fact.

We can use npx sinc push to push all local scripts to SN, but that will overwrite anything that is currently there.

To create new files (such as a Script Include) we first must create them in SN. Then, we can run npx sinc download to pull only new files (this does not overwrite any existing local files).

We should not use npx sinc download because it will overwrite local files with what is in SN - this will result in our nice JS code getting overwritten by the “compiled” code and will cause problems.

2 Repos

There are a couple of options for workflows - if we want to use git to store our scoped app code we should use 2 repositories:

Other Methods

If we are using update sets to push apps, there are other options for workflows - the Sincronia repository has some suggestions.