From 82f65b6fee5d70108f8d64e0c6e828dc4362dbdc Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sat, 2 Oct 2021 15:21:00 +0300 Subject: [PATCH] Include schemas in deployments --- README.md | 12 +++++++----- package.json | 2 +- src/build/repository/build.ts | 12 +++++++++++- src/build/repository/deployment/develop.ts | 3 ++- src/build/repository/deployment/ssh.ts | 8 +++++--- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index cc707c2..31e59f2 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,11 @@ For example, installing core plugins (Interactive mode `-i` on `squeebotd`): ## Interactive mode commands The following commands are available when starting in interactive mode: -* `repository help` -* `plugin help` -* `channel help` -* `quit` +* `repository help` - Repository management commands +* `plugin help` - Plugin management commands +* `channel help` - Channel management commands +* `quit` - Exit Squeebot +* `inspector` - Enter JavaScript REPL (basically the same as running `node` without arguments) ## Creating a repository In order to create a repository, you need to do the following: @@ -41,8 +42,9 @@ The build command supports a `-w` argument which will execute the entire build c Within your new repository, each directory you make will be a plugin. The plugin **must** contain the following: 1. `plugin.json` - Manifest for your plugin. 2. `plugin.js` - Has to be a JavaScript file which exports a class inherited from `Plugin` at `@squeebot/core/lib/plugin`. +3. `schema.json` - (optionally) include a JSON schema for the plugin's configuration. -**Note:** `plugin.js` only has to exist in the distribution, so `.ts` is fine, but you have to use `$ squeebot repository build ` +**Note:** `plugin.js` only has to exist in the distribution, so `.ts` is fine, but you **have** to use `$ squeebot repository build ` to build them into JavaScript files. Plugin manifest (`plugin.json`) example: diff --git a/package.json b/package.json index 252a85b..cff1b66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@squeebot/cli", - "version": "3.4.1", + "version": "3.4.2", "description": "Squeebot v3 runtime, environments and configuration", "main": "dist/squeebot.js", "bin": { diff --git a/src/build/repository/build.ts b/src/build/repository/build.ts index 396f17d..8fc6458 100644 --- a/src/build/repository/build.ts +++ b/src/build/repository/build.ts @@ -99,7 +99,7 @@ export async function buildRepository( } if (meta.typescript) { - console.log('Stripping source files'); + console.log('Stripping TypeScript source files'); for (const plugin of plugins) { const plOut = path.join(outDir, plugin.name); const listAllFiles = await fs.readdir(plOut); @@ -111,6 +111,16 @@ export async function buildRepository( } } + console.log('Copying configuration schemas'); + for (const plugin of plugins) { + const plOut = path.join(outDir, plugin.name); + const schemaFile = path.join(plOut, 'schema.json'); + const outSchemaFile = path.join(outDir, `${plugin.name}.schema.json`); + if (await fs.pathExists(schemaFile)) { + await fs.copy(schemaFile, outSchemaFile); + } + } + console.log('Creating tarballs'); for (const plugin of plugins) { const plOut = path.join(outDir, plugin.name); diff --git a/src/build/repository/deployment/develop.ts b/src/build/repository/deployment/develop.ts index 3719ddb..5359361 100644 --- a/src/build/repository/deployment/develop.ts +++ b/src/build/repository/deployment/develop.ts @@ -33,9 +33,10 @@ export async function developDeploy( console.log('Copying plugins to', pluginsPath); const listAllFiles = await fs.readdir(outDir); for (const f of listAllFiles) { - if (f === 'repository' || f.indexOf('.tgz') !== -1) { + if (f === 'repository' || f.endsWith('.tgz') || f.endsWith('.json')) { continue; } + const dst = path.join(pluginsPath, f); await fs.copy(path.join(outDir, f), dst, { overwrite: true, diff --git a/src/build/repository/deployment/ssh.ts b/src/build/repository/deployment/ssh.ts index 5a3853d..dee6b65 100644 --- a/src/build/repository/deployment/ssh.ts +++ b/src/build/repository/deployment/ssh.ts @@ -26,9 +26,11 @@ export async function sshDeploy( console.log('Deploying to %s@%s:%d%s', username, host, port, target); - const fileList = (await fs.readdir(outDir)).filter((val) => { - return val === 'repository.json' || val.match('.tgz$'); - }).map((x) => path.join(outDir, x)); + const fileList = (await fs.readdir(outDir)).filter((val) => + val === 'repository.json' + || val.endsWith('.tgz') + || val.endsWith('schema.json') + ).map((x) => path.join(outDir, x)); const pargs = [ 'rsync',