@mochabug/adaptkit 0.2.0-alpha.1 → 0.3.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/bin/genproto/google/api/client.d.ts +668 -0
- package/bin/genproto/google/api/client.d.ts.map +1 -0
- package/bin/genproto/google/api/http.d.ts +460 -0
- package/bin/genproto/google/api/http.d.ts.map +1 -0
- package/bin/genproto/google/api/launch_stage.d.ts +78 -0
- package/bin/genproto/google/api/launch_stage.d.ts.map +1 -0
- package/bin/genproto/google/protobuf/descriptor.d.ts +1799 -0
- package/bin/genproto/google/protobuf/descriptor.d.ts.map +1 -0
- package/bin/genproto/google/protobuf/duration.d.ts +113 -0
- package/bin/genproto/google/protobuf/duration.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins.client.d.ts +46 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins.client.d.ts.map +1 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins.d.ts +826 -0
- package/bin/genproto/mochabugapis/adapt/plugins/v1/plugins.d.ts.map +1 -0
- package/bin/index.js +308 -348
- package/bin/index.js.map +1 -1
- package/package.json +12 -9
package/bin/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { ChannelCredentials } from '@grpc/grpc-js';
|
|
3
|
-
import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
|
|
4
|
-
import { MessageType, reflectionMergePartial, UnknownFieldHandler, WireType, MESSAGE_TYPE } from '@protobuf-ts/runtime';
|
|
5
3
|
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
|
|
6
4
|
import chalk from 'chalk';
|
|
7
5
|
import { execSync } from 'child_process';
|
|
@@ -13,33 +11,32 @@ import inquirer from 'inquirer';
|
|
|
13
11
|
import { mkdirp } from 'mkdirp';
|
|
14
12
|
import path from 'path';
|
|
15
13
|
import sharp from 'sharp';
|
|
14
|
+
import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
|
|
15
|
+
import { MessageType, reflectionMergePartial, UnknownFieldHandler, WireType, MESSAGE_TYPE } from '@protobuf-ts/runtime';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
-
});
|
|
42
|
-
}
|
|
17
|
+
var externalConfigTemplate = "import { VertexConfig } from '@mochabug/adapt-plugin-toolkit/api';\nimport { ExternalConfiguratorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new ExternalConfiguratorRouter()\n .useRequestLogging()\n .useBearerAuthorization(['/api'])\n .add('GET', '/api/config', async (_req, api) => {\n const res = await api.getVertexConfig<VertexConfig>();\n if (!res.ok) {\n console.error(res);\n return new Response(res.errorMessage, { status: res.errorStatus });\n }\n return new Response(JSON.stringify(res.data!), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n })\n .add('GET', '(/?)', async () => {\n return new Response(getHelloWorldPage(), {\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n });\n\nfunction getHelloWorldPage(): string {\n return `\n <html>\n <head>\n <style>\n @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');\n @keyframes glow {\n 0% { text-shadow: 0 0 5px #0f0, 0 0 10px #0f0, 0 0 15px #0f0, 0 0 20px #0f0; }\n 100% { text-shadow: 0 0 10px #0f0, 0 0 20px #0f0, 0 0 30px #0f0, 0 0 40px #0f0; }\n }\n body {\n background-color: #000;\n color: #0f0;\n font-family: 'Orbitron', sans-serif;\n text-align: center;\n overflow: hidden;\n margin: 0;\n padding: 0;\n }\n h1 {\n position: absolute;\n top: 30%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-size: 3em;\n text-transform: uppercase;\n letter-spacing: 4px;\n animation: glow 2s infinite alternate;\n }\n #jsonOutput {\n position: absolute;\n top: 70%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-size: 1.5em;\n text-transform: uppercase;\n letter-spacing: 2px;\n animation: glow 2s infinite alternate;\n }\n button {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background-color: #0f0;\n border: none;\n color: black;\n padding: 15px 32px;\n text-align: center;\n text-decoration: none;\n display: inline-block;\n font-size: 20px; /* Increase the font size */\n margin: 4px 2px;\n cursor: pointer;\n transition-duration: 0.4s;\n animation: glow 2s infinite alternate;\n font-family: 'Orbitron', sans-serif;\n border-radius: 15px;\n transform: rotate(-10deg) skew(10deg, 10deg);\n }\n </style>\n </head>\n <body>\n <h1>Hello, World!</h1>\n <button id=\"assimilateButton\">Assimilate</button>\n <pre id=\"jsonOutput\"></pre>\n <script>\n document.getElementById('assimilateButton').addEventListener('click', function() {\n const hash = window.location.hash.substr(1).trim();\n const token = decodeURIComponent(hash); \n fetch('/api/config', {\n method: 'GET',\n headers: {\n 'Authorization': 'Bearer ' + token\n }\n })\n .then(response => response.json())\n .then(data => {\n document.getElementById('jsonOutput').innerText = JSON.stringify(data, null, 2);\n this.style.display = 'none'; /* Hide button after being clicked */\n })\n .catch(error => {\n console.error('Error:', error);\n document.getElementById('jsonOutput').innerText = 'Error occurred while assimilating data';\n });\n });\n </script>\n </body>\n </html>\n `;\n}\n";
|
|
18
|
+
|
|
19
|
+
var internalConfigTemplate = "import { InternalConfiguratorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n/**\n * A `InternalConfiguratorRouter` instance configured to handle internal platform calls for the vertex during configuration.\n *\n * There are no events to handle at the moment\n */\nexport const router = new InternalConfiguratorRouter();\n";
|
|
20
|
+
|
|
21
|
+
var browserExecTempalte = "import { ExternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new ExternalExecutorRouter()\n .useRequestLogging()\n .useBearerAuthorization(['/api'])\n .add('POST', '/api/done', async (req, api, _route, ctx) => {\n const sapi = api.getSessionApi(req.headers.get('Authorization')!);\n ctx.waitUntil(sapi.complete('output', {}));\n return new Response();\n })\n .add('GET', '(/?)', async () => {\n return new Response(getSamplePage(), {\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n });\n\nfunction getSamplePage(): string {\n return `\n <html>\n <head>\n <style>\n @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');\n @keyframes glow {\n 0% { text-shadow: 0 0 5px #0f0, 0 0 10px #0f0, 0 0 15px #0f0, 0 0 20px #0f0; }\n 100% { text-shadow: 0 0 10px #0f0, 0 0 20px #0f0, 0 0 30px #0f0, 0 0 40px #0f0; }\n }\n body {\n background-color: #000;\n color: #0f0;\n font-family: 'Orbitron', sans-serif;\n text-align: center;\n overflow: hidden;\n margin: 0;\n padding: 0;\n }\n button {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background-color: #0f0;\n border: none;\n color: black;\n padding: 15px 32px;\n text-align: center;\n text-decoration: none;\n display: inline-block;\n font-size: 20px;\n margin: 4px 2px;\n cursor: pointer;\n transition-duration: 0.4s;\n animation: glow 2s infinite alternate;\n font-family: 'Orbitron', sans-serif;\n border-radius: 15px;\n transform: rotate(-10deg) skew(10deg, 10deg);\n }\n </style>\n </head>\n <body>\n <button id=\"doneButton\">Done</button>\n <script>\n document.getElementById('doneButton').addEventListener('click', function() {\n const hash = window.location.hash.substr(1).trim();\n const token = decodeURIComponent(hash); \n fetch('/api/done', {\n method: 'POST',\n headers: {\n 'Authorization': 'Bearer ' + token\n }\n })\n .then(data => {\n this.innerText = 'Done';\n })\n .catch(error => {\n console.error('Error:', error);\n });\n });\n </script>\n </body>\n </html>\n `;\n}\n";
|
|
22
|
+
|
|
23
|
+
var cronExecTemplate = "import { CronExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new CronExecutorRouter()\n .onStart(async (req, _api) => {\n const start = await req.json<StartExecutionRequest>();\n console.log('Start has been called');\n console.log(start);\n })\n .onStop(async (_req, _api) => {\n console.log('Stop has been called');\n })\n .onCron(async (_req, _api) => {\n console.log('Received cron event');\n })\n .onStream(async (req, _api, name) => {\n console.log(`Stream ${name} has been called`);\n const res = await req.json<StreamResult>();\n console.log(res);\n })\n .onProcedure(async (req, _api, name) => {\n console.log(`Procedure ${name} has been called`);\n const res = await req.json<ProcedureResult>();\n console.log(res);\n });\n";
|
|
24
|
+
|
|
25
|
+
var triggerExecTemplate = "import { ExternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new ExternalExecutorRouter().add(\n '*',\n '(.*)',\n async (_req, _api, _route, _ctx) => {\n return new Response();\n },\n);\n";
|
|
26
|
+
|
|
27
|
+
var internalExecTemplate = "import { InternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new InternalExecutorRouter()\n .onStart(async (req, _api) => {\n const start = await req.json<StartExecutionRequest>();\n console.log('Start has been called');\n console.log(start);\n })\n .onStop(async (_req, _api) => {\n console.log('Stop has been called');\n })\n .onStream(async (req, _api, name) => {\n console.log(`Stream ${name} has been called`);\n const res = await req.json<StreamResult>();\n console.log(res);\n })\n .onProcedure(async (req, _api, name) => {\n console.log(`Procedure ${name} has been called`);\n const res = await req.json<ProcedureResult>();\n console.log(res);\n });\n";
|
|
28
|
+
|
|
29
|
+
var gitignoreTemplate = "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n.pnpm-debug.log*\n\n# Diagnostic reports (https://nodejs.org/api/report.html)\nreport.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n*.lcov\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# Snowpack dependency directory (https://snowpack.dev/)\nweb_modules/\n\n# TypeScript cache\n*.tsbuildinfo\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional stylelint cache\n.stylelintcache\n\n# Microbundle cache\n.rpt2_cache/\n.rts2_cache_cjs/\n.rts2_cache_es/\n.rts2_cache_umd/\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variable files\n.env\n.env.development.local\n.env.test.local\n.env.production.local\n.env.local\n\n# parcel-bundler cache (https://parceljs.org/)\n.cache\n.parcel-cache\n\n# Next.js build output\n.next\nout\n\n# Nuxt.js build / generate output\n.nuxt\ndist\nbuild\n\n# Gatsby files\n.cache/\n# Comment in the public line in if your project uses Gatsby and not Next.js\n# https://nextjs.org/blog/next-9-1#public-directory-support\n# public\n\n# vuepress build output\n.vuepress/dist\n\n# vuepress v2.x temp and cache directory\n.temp\n.cache\n\n# Stores VSCode versions used for testing VSCode extensions\n.vscode-test\n\n# yarn v2\n.yarn/cache\n.yarn/unplugged\n.yarn/build-state.yml\n.yarn/install-state.gz\n.pnp.*";
|
|
30
|
+
|
|
31
|
+
var jestTemplate = "import type { Config } from \"@jest/types\"\n\nconst config: Config.InitialOptions = {\n preset: \"ts-jest\",\n testEnvironment: \"node\",\n verbose: true,\n automock: true,\n}\nexport default config";
|
|
32
|
+
|
|
33
|
+
var licenseTemplate = "## ISC License\n\nCopyright (c) [year] [fullname]\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.";
|
|
34
|
+
|
|
35
|
+
var readmeTemplate = "# 🐞 Mochabug Adapt's Magnificent Plugin 🐞\n\n[](PLUGIN_REPOSITORY_URL)\n[](https://opensource.org/licenses/ISC)\n\n## 📝 Description\n\nWelcome to the Magnificent Plugin for Mochabug Adapt! Developed by a talented third-party developer, this plugin promises to bring extra flavor to your Mochabug Adapt cloud platform experience. PLUGIN_DESCRIPTION\n\nThis plugin consists of one or more vertices. Each vertex is made up of an Executor and may optionally include a Configurator to help you tailor its behavior.\n\n## 📚 Table of Contents\n\n- [🐞 Mochabug Adapt's Magnificent Plugin 🐞](#-mochabug-adapts-magnificent-plugin-)\n - [📝 Description](#-description)\n - [📚 Table of Contents](#-table-of-contents)\n - [🚀 Getting Started](#-getting-started)\n - [🎯 Usage](#-usage)\n - [⚙️ Configuration](#️-configuration)\n - [📖 Documentation](#-documentation)\n - [🤝 Contributing](#-contributing)\n - [📜 License](#-license)\n - [👤 Author](#-author)\n\n## 🚀 Getting Started\n\nTo begin using Mochabug Adapt's Magnificent Plugin, simply start incorporating its vertices into your workflows within the Mochabug Adapt platform. No installation is required.\n\n## 🎯 Usage\n\nYou can start using the vertices by incorporating them into your workflows on the Mochabug Adapt platform. Each vertex will delight you with a specific task, and the usage will vary depending on your requirements. Consult the plugin documentation for a comprehensive guide on each vertex's usage.\n\n## ⚙️ Configuration\n\nEach vertex in the plugin may have a Configurator, which allows you to tailor the vertex's behavior to your liking. Configuration options may include settings for the Executor, input/output data formats, and other essential options.\n\n## 📖 Documentation\n\nFor more insights into the plugin, its vertices, and their features, visit the [homepage](PLUGIN_HOMEPAGE) and the [repository](PLUGIN_REPOSITORY_URL).\n\n## 🤝 Contributing\n\nReady to make the Magnificent Plugin for Mochabug Adapt even more magical? Contributions are welcome! Check the [repository](PLUGIN_REPOSITORY_URL) for open issues and guidelines on how to contribute.\n\n## 📜 License\n\nThis plugin is licensed under the [ISC License](https://opensource.org/licenses/ISC).\n\n## 👤 Author\n\nPLUGIN_AUTHOR\n";
|
|
36
|
+
|
|
37
|
+
var rollupTemplate = "import fs from 'fs';\nimport typescript from '@rollup/plugin-typescript';\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\nimport terser from '@rollup/plugin-terser';\nimport commonjs from '@rollup/plugin-commonjs';\n\nconst config = [\n {\n input: 'src/executors.ts',\n output: {\n file: 'dist/executors.js',\n format: 'esm'\n },\n plugins: [typescript(), nodeResolve(), commonjs(), terser()]\n }\n];\n\n// Check if 'src/configurators.ts' exists\nif (fs.existsSync('src/configurators.ts')) {\n config.push({\n input: 'src/configurators.ts',\n output: {\n file: 'dist/configurators.js',\n format: 'esm'\n },\n plugins: [typescript(), nodeResolve(), commonjs(), terser()]\n });\n}\n\nexport default config;\n";
|
|
38
|
+
|
|
39
|
+
var tsconfig = "{\n \"exclude\": [\n \"**/*.test.*\",\n \"**/__mocks__/*\",\n \"**/__tests__/*\"\n ],\n \"compilerOptions\": {\n \"rootDir\": \"src\",\n \"jsx\": \"react\",\n \"target\": \"esnext\",\n \"module\": \"esnext\",\n \"lib\": [\n \"esnext\"\n ],\n \"moduleResolution\": \"node\",\n \"types\": [\n \"@mochabug/adapt-plugin-typings\",\n \"jest\"\n ],\n \"resolveJsonModule\": true,\n \"allowJs\": true,\n \"checkJs\": false,\n \"noEmit\": true,\n \"isolatedModules\": true,\n \"allowSyntheticDefaultImports\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"strict\": true,\n \"skipLibCheck\": true,\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"noFallthroughCasesInSwitch\": true,\n \"noImplicitReturns\": true,\n \"useUnknownInCatchVariables\": true,\n \"noUncheckedIndexedAccess\": true,\n \"noPropertyAccessFromIndexSignature\": true\n }\n}";
|
|
43
40
|
|
|
44
41
|
// @generated by protobuf-ts 2.9.1
|
|
45
42
|
// @generated from protobuf file "mochabugapis/adapt/plugins/v1/plugins.proto" (package "mochabugapis.adapt.plugins.v1", syntax proto3)
|
|
@@ -852,12 +849,11 @@ const PluginService = new ServiceType("mochabugapis.adapt.plugins.v1.PluginServi
|
|
|
852
849
|
* @generated from protobuf service mochabugapis.adapt.plugins.v1.PluginService
|
|
853
850
|
*/
|
|
854
851
|
class PluginServiceClient {
|
|
855
|
-
_transport;
|
|
856
|
-
typeName = PluginService.typeName;
|
|
857
|
-
methods = PluginService.methods;
|
|
858
|
-
options = PluginService.options;
|
|
859
852
|
constructor(_transport) {
|
|
860
853
|
this._transport = _transport;
|
|
854
|
+
this.typeName = PluginService.typeName;
|
|
855
|
+
this.methods = PluginService.methods;
|
|
856
|
+
this.options = PluginService.options;
|
|
861
857
|
}
|
|
862
858
|
/**
|
|
863
859
|
* UploadPlugin is a streaming RPC method that allows uploading a plugin in
|
|
@@ -873,30 +869,6 @@ class PluginServiceClient {
|
|
|
873
869
|
}
|
|
874
870
|
}
|
|
875
871
|
|
|
876
|
-
var externalConfigTemplate = "import { VertexConfig } from '@mochabug/adapt-plugin-toolkit/api';\nimport { ExternalConfiguratorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new ExternalConfiguratorRouter()\n .useRequestLogging()\n .useBearerAuthorization(['/api'])\n .add('GET', '/api/config', async (req, api) => {\n const res = await api.getVertexConfig<VertexConfig>();\n if (!res.ok) {\n console.error(res);\n return new Response(res.errorMessage, { status: res.errorStatus });\n }\n return new Response(JSON.stringify(res.data!), {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n })\n .add('GET', '(/?)', async () => {\n return new Response(getHelloWorldPage(), {\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n });\n\nfunction getHelloWorldPage(): string {\n return `\n <html>\n <head>\n <style>\n @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');\n @keyframes glow {\n 0% { text-shadow: 0 0 5px #0f0, 0 0 10px #0f0, 0 0 15px #0f0, 0 0 20px #0f0; }\n 100% { text-shadow: 0 0 10px #0f0, 0 0 20px #0f0, 0 0 30px #0f0, 0 0 40px #0f0; }\n }\n body {\n background-color: #000;\n color: #0f0;\n font-family: 'Orbitron', sans-serif;\n text-align: center;\n overflow: hidden;\n margin: 0;\n padding: 0;\n }\n h1 {\n position: absolute;\n top: 30%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-size: 3em;\n text-transform: uppercase;\n letter-spacing: 4px;\n animation: glow 2s infinite alternate;\n }\n #jsonOutput {\n position: absolute;\n top: 70%;\n left: 50%;\n transform: translate(-50%, -50%);\n font-size: 1.5em;\n text-transform: uppercase;\n letter-spacing: 2px;\n animation: glow 2s infinite alternate;\n }\n button {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background-color: #0f0;\n border: none;\n color: black;\n padding: 15px 32px;\n text-align: center;\n text-decoration: none;\n display: inline-block;\n font-size: 20px; /* Increase the font size */\n margin: 4px 2px;\n cursor: pointer;\n transition-duration: 0.4s;\n animation: glow 2s infinite alternate;\n font-family: 'Orbitron', sans-serif;\n border-radius: 15px;\n transform: rotate(-10deg) skew(10deg, 10deg);\n }\n </style>\n </head>\n <body>\n <h1>Hello, World!</h1>\n <button id=\"assimilateButton\">Assimilate</button>\n <pre id=\"jsonOutput\"></pre>\n <script>\n document.getElementById('assimilateButton').addEventListener('click', function() {\n const hash = window.location.hash.substr(1).trim();\n const token = decodeURIComponent(hash); \n fetch('/api/config', {\n method: 'GET',\n headers: {\n 'Authorization': 'Bearer ' + token\n }\n })\n .then(response => response.json())\n .then(data => {\n document.getElementById('jsonOutput').innerText = JSON.stringify(data, null, 2);\n this.style.display = 'none'; /* Hide button after being clicked */\n })\n .catch(error => {\n console.error('Error:', error);\n document.getElementById('jsonOutput').innerText = 'Error occurred while assimilating data';\n });\n });\n </script>\n </body>\n </html>\n `;\n}\n";
|
|
877
|
-
|
|
878
|
-
var internalConfigTemplate = "import { InternalConfiguratorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n/**\n * A `InternalConfiguratorRouter` instance configured to handle internal platform calls for the vertex during configuration.\n *\n * There are no events to handle at the moment\n */\nexport const router = new InternalConfiguratorRouter();\n";
|
|
879
|
-
|
|
880
|
-
var browserExecTempalte = "import { ExternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new ExternalExecutorRouter()\n .useRequestLogging()\n .useBearerAuthorization(['/api'])\n .add('POST', '/api/done', async (req, api, route, ctx) => {\n const sapi = api.getSessionApi(req.headers.get('Authorization')!);\n ctx.waitUntil(sapi.complete('output', {}));\n return new Response();\n })\n .add('GET', '(/?)', async () => {\n return new Response(getSamplePage(), {\n headers: {\n 'Content-Type': 'text/html',\n },\n });\n });\n\nfunction getSamplePage(): string {\n return `\n <html>\n <head>\n <style>\n @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap');\n @keyframes glow {\n 0% { text-shadow: 0 0 5px #0f0, 0 0 10px #0f0, 0 0 15px #0f0, 0 0 20px #0f0; }\n 100% { text-shadow: 0 0 10px #0f0, 0 0 20px #0f0, 0 0 30px #0f0, 0 0 40px #0f0; }\n }\n body {\n background-color: #000;\n color: #0f0;\n font-family: 'Orbitron', sans-serif;\n text-align: center;\n overflow: hidden;\n margin: 0;\n padding: 0;\n }\n button {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background-color: #0f0;\n border: none;\n color: black;\n padding: 15px 32px;\n text-align: center;\n text-decoration: none;\n display: inline-block;\n font-size: 20px;\n margin: 4px 2px;\n cursor: pointer;\n transition-duration: 0.4s;\n animation: glow 2s infinite alternate;\n font-family: 'Orbitron', sans-serif;\n border-radius: 15px;\n transform: rotate(-10deg) skew(10deg, 10deg);\n }\n </style>\n </head>\n <body>\n <button id=\"doneButton\">Done</button>\n <script>\n document.getElementById('doneButton').addEventListener('click', function() {\n const hash = window.location.hash.substr(1).trim();\n const token = decodeURIComponent(hash); \n fetch('/api/done', {\n method: 'POST',\n headers: {\n 'Authorization': 'Bearer ' + token\n }\n })\n .then(data => {\n this.innerText = 'Done';\n })\n .catch(error => {\n console.error('Error:', error);\n });\n });\n </script>\n </body>\n </html>\n `;\n}\n";
|
|
881
|
-
|
|
882
|
-
var cronExecTemplate = "import { CronExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new CronExecutorRouter()\n .onStart(async (req, api) => {\n const start = await req.json<StartExecutionRequest>();\n console.log('Start has been called');\n console.log(start);\n })\n .onStop(async (req, api) => {\n console.log('Stop has been called');\n })\n .onCron(async (req, api) => {\n console.log('Received cron event');\n })\n .onStream(async (req, api, name) => {\n console.log(`Stream ${name} has been called`);\n const res = await req.json<StreamResult>();\n console.log(res);\n })\n .onProcedure(async (req, api, name) => {\n console.log(`Procedure ${name} has been called`);\n const res = await req.json<ProcedureResult>();\n console.log(res);\n });\n";
|
|
883
|
-
|
|
884
|
-
var triggerExecTemplate = "import { ExternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new ExternalExecutorRouter().add('*', '(.*)', async () => {\n return new Response();\n});\n";
|
|
885
|
-
|
|
886
|
-
var internalExecTemplate = "import { InternalExecutorRouter } from '@mochabug/adapt-plugin-toolkit/router';\n\nexport const router = new InternalExecutorRouter()\n .onStart(async (req, api) => {\n const start = await req.json<StartExecutionRequest>();\n console.log('Start has been called');\n console.log(start);\n })\n .onStop(async (req, api) => {\n console.log('Stop has been called');\n })\n .onStream(async (req, api, name) => {\n console.log(`Stream ${name} has been called`);\n const res = await req.json<StreamResult>();\n console.log(res);\n })\n .onProcedure(async (req, api, name) => {\n console.log(`Procedure ${name} has been called`);\n const res = await req.json<ProcedureResult>();\n console.log(res);\n });\n";
|
|
887
|
-
|
|
888
|
-
var gitignoreTemplate = "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n.pnpm-debug.log*\n\n# Diagnostic reports (https://nodejs.org/api/report.html)\nreport.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n*.lcov\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# Snowpack dependency directory (https://snowpack.dev/)\nweb_modules/\n\n# TypeScript cache\n*.tsbuildinfo\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional stylelint cache\n.stylelintcache\n\n# Microbundle cache\n.rpt2_cache/\n.rts2_cache_cjs/\n.rts2_cache_es/\n.rts2_cache_umd/\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variable files\n.env\n.env.development.local\n.env.test.local\n.env.production.local\n.env.local\n\n# parcel-bundler cache (https://parceljs.org/)\n.cache\n.parcel-cache\n\n# Next.js build output\n.next\nout\n\n# Nuxt.js build / generate output\n.nuxt\ndist\nbuild\n\n# Gatsby files\n.cache/\n# Comment in the public line in if your project uses Gatsby and not Next.js\n# https://nextjs.org/blog/next-9-1#public-directory-support\n# public\n\n# vuepress build output\n.vuepress/dist\n\n# vuepress v2.x temp and cache directory\n.temp\n.cache\n\n# Stores VSCode versions used for testing VSCode extensions\n.vscode-test\n\n# yarn v2\n.yarn/cache\n.yarn/unplugged\n.yarn/build-state.yml\n.yarn/install-state.gz\n.pnp.*";
|
|
889
|
-
|
|
890
|
-
var jestTemplate = "import type { Config } from \"@jest/types\"\n\nconst config: Config.InitialOptions = {\n preset: \"ts-jest\",\n testEnvironment: \"node\",\n verbose: true,\n automock: true,\n}\nexport default config";
|
|
891
|
-
|
|
892
|
-
var licenseTemplate = "## ISC License\n\nCopyright (c) [year] [fullname]\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.";
|
|
893
|
-
|
|
894
|
-
var readmeTemplate = "# 🐞 Mochabug Adapt's Magnificent Plugin 🐞\n\n[](PLUGIN_REPOSITORY_URL)\n[](https://opensource.org/licenses/ISC)\n\n## 📝 Description\n\nWelcome to the Magnificent Plugin for Mochabug Adapt! Developed by a talented third-party developer, this plugin promises to bring extra flavor to your Mochabug Adapt cloud platform experience. PLUGIN_DESCRIPTION\n\nThis plugin consists of one or more vertices. Each vertex is made up of an Executor and may optionally include a Configurator to help you tailor its behavior.\n\n## 📚 Table of Contents\n\n- [🐞 Mochabug Adapt's Magnificent Plugin 🐞](#-mochabug-adapts-magnificent-plugin-)\n - [📝 Description](#-description)\n - [📚 Table of Contents](#-table-of-contents)\n - [🚀 Getting Started](#-getting-started)\n - [🎯 Usage](#-usage)\n - [⚙️ Configuration](#️-configuration)\n - [📖 Documentation](#-documentation)\n - [🤝 Contributing](#-contributing)\n - [📜 License](#-license)\n - [👤 Author](#-author)\n\n## 🚀 Getting Started\n\nTo begin using Mochabug Adapt's Magnificent Plugin, simply start incorporating its vertices into your workflows within the Mochabug Adapt platform. No installation is required.\n\n## 🎯 Usage\n\nYou can start using the vertices by incorporating them into your workflows on the Mochabug Adapt platform. Each vertex will delight you with a specific task, and the usage will vary depending on your requirements. Consult the plugin documentation for a comprehensive guide on each vertex's usage.\n\n## ⚙️ Configuration\n\nEach vertex in the plugin may have a Configurator, which allows you to tailor the vertex's behavior to your liking. Configuration options may include settings for the Executor, input/output data formats, and other essential options.\n\n## 📖 Documentation\n\nFor more insights into the plugin, its vertices, and their features, visit the [homepage](PLUGIN_HOMEPAGE) and the [repository](PLUGIN_REPOSITORY_URL).\n\n## 🤝 Contributing\n\nReady to make the Magnificent Plugin for Mochabug Adapt even more magical? Contributions are welcome! Check the [repository](PLUGIN_REPOSITORY_URL) for open issues and guidelines on how to contribute.\n\n## 📜 License\n\nThis plugin is licensed under the [ISC License](https://opensource.org/licenses/ISC).\n\n## 👤 Author\n\nPLUGIN_AUTHOR\n";
|
|
895
|
-
|
|
896
|
-
var rollupTemplate = "import fs from 'fs';\nimport typescript from '@rollup/plugin-typescript';\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\nimport terser from '@rollup/plugin-terser';\nimport commonjs from '@rollup/plugin-commonjs';\n\nconst config = [\n {\n input: 'src/executors.ts',\n output: {\n file: 'dist/executors.js',\n format: 'esm'\n },\n plugins: [typescript(), nodeResolve(), commonjs(), terser()]\n }\n];\n\n// Check if 'src/configurators.ts' exists\nif (fs.existsSync('src/configurators.ts')) {\n config.push({\n input: 'src/configurators.ts',\n output: {\n file: 'dist/configurators.js',\n format: 'esm'\n },\n plugins: [typescript(), nodeResolve(), commonjs(), terser()]\n });\n}\n\nexport default config;\n";
|
|
897
|
-
|
|
898
|
-
var tsconfig = "{\n \"exclude\": [\n \"**/*.test.*\",\n \"**/__mocks__/*\",\n \"**/__tests__/*\"\n ],\n \"compilerOptions\": {\n \"rootDir\": \"src\",\n \"jsx\": \"react\",\n \"target\": \"esnext\",\n \"module\": \"esnext\",\n \"lib\": [\"esnext\"],\n \"moduleResolution\": \"node\",\n \"types\": [\n \"@mochabug/adapt-plugin-typings\",\n \"jest\"\n ],\n \"resolveJsonModule\": true,\n \"allowJs\": true,\n \"checkJs\": false,\n \"noEmit\": true,\n \"isolatedModules\": true,\n \"allowSyntheticDefaultImports\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"strict\": true,\n \"skipLibCheck\": true\n }\n}";
|
|
899
|
-
|
|
900
872
|
// Copyright 2023, mochabug AB
|
|
901
873
|
//
|
|
902
874
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -922,29 +894,27 @@ function readManifest() {
|
|
|
922
894
|
function capitilize(val) {
|
|
923
895
|
return val.charAt(0).toUpperCase() + val.substring(1);
|
|
924
896
|
}
|
|
925
|
-
function resize(filepath, height, width) {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
throw new Error('Invalid logotype');
|
|
947
|
-
});
|
|
897
|
+
async function resize(filepath, height, width) {
|
|
898
|
+
const extname = path.extname(filepath);
|
|
899
|
+
switch (extname) {
|
|
900
|
+
case '.avif':
|
|
901
|
+
return await sharp(filepath).resize(height, width).avif().toBuffer();
|
|
902
|
+
case '.gif':
|
|
903
|
+
return await sharp(filepath).resize(height, width).gif().toBuffer();
|
|
904
|
+
case '.jpg':
|
|
905
|
+
case '.jpeg':
|
|
906
|
+
case '.jfif':
|
|
907
|
+
case '.pjpeg':
|
|
908
|
+
case '.pjp':
|
|
909
|
+
return await sharp(filepath).resize(height, width).jpeg().toBuffer();
|
|
910
|
+
case '.png':
|
|
911
|
+
return await sharp(filepath).resize(height, width).png().toBuffer();
|
|
912
|
+
case '.svg':
|
|
913
|
+
return fs.readFileSync(filepath);
|
|
914
|
+
case '.webp':
|
|
915
|
+
return await sharp(filepath).resize(height, width).webp().toBuffer();
|
|
916
|
+
}
|
|
917
|
+
throw new Error('Invalid logotype');
|
|
948
918
|
}
|
|
949
919
|
function convertVertexType(type) {
|
|
950
920
|
switch (type) {
|
|
@@ -979,7 +949,7 @@ function addVertex(cwd, name, type, hasConfigurator) {
|
|
|
979
949
|
hasConfigurator,
|
|
980
950
|
mtls: [],
|
|
981
951
|
oauth2: [],
|
|
982
|
-
variables: []
|
|
952
|
+
variables: []
|
|
983
953
|
};
|
|
984
954
|
// Write the new task
|
|
985
955
|
let importString;
|
|
@@ -1031,20 +1001,20 @@ function addVertex(cwd, name, type, hasConfigurator) {
|
|
|
1031
1001
|
{
|
|
1032
1002
|
name: 'input',
|
|
1033
1003
|
description: 'Default input receiver',
|
|
1034
|
-
bindings: []
|
|
1035
|
-
}
|
|
1004
|
+
bindings: []
|
|
1005
|
+
}
|
|
1036
1006
|
],
|
|
1037
1007
|
transmitters: [
|
|
1038
1008
|
{
|
|
1039
1009
|
name: 'output',
|
|
1040
1010
|
description: 'Default output transmitter',
|
|
1041
1011
|
signals: [],
|
|
1042
|
-
failure: false
|
|
1043
|
-
}
|
|
1012
|
+
failure: false
|
|
1013
|
+
}
|
|
1044
1014
|
],
|
|
1045
1015
|
procedures: [],
|
|
1046
1016
|
streams: [],
|
|
1047
|
-
bindings: []
|
|
1017
|
+
bindings: []
|
|
1048
1018
|
};
|
|
1049
1019
|
if (vertex.type === Vertex_VertexType.CRON_TRIGGER) {
|
|
1050
1020
|
vertexConfig.cronInterval = 5000;
|
|
@@ -1075,291 +1045,281 @@ function addVertex(cwd, name, type, hasConfigurator) {
|
|
|
1075
1045
|
fs.writeFileSync(path.join(cwd, 'src', name, 'config.json'), JSON.stringify(vertexConfig, null, 2));
|
|
1076
1046
|
return vertex;
|
|
1077
1047
|
}
|
|
1078
|
-
function init(dir) {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
return val.trim().toLowerCase();
|
|
1087
|
-
},
|
|
1088
|
-
validate: (val) => {
|
|
1089
|
-
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1090
|
-
},
|
|
1091
|
-
},
|
|
1092
|
-
{
|
|
1093
|
-
type: 'list',
|
|
1094
|
-
name: 'vertexType',
|
|
1095
|
-
message: 'Choose vertex type',
|
|
1096
|
-
choices: ['action', 'browser', 'cron-trigger', 'external-trigger'],
|
|
1097
|
-
},
|
|
1098
|
-
{
|
|
1099
|
-
type: 'input',
|
|
1100
|
-
name: 'vertexName',
|
|
1101
|
-
message: 'Write the vertex name',
|
|
1102
|
-
filter: (val) => {
|
|
1103
|
-
return val.trim().toLowerCase();
|
|
1104
|
-
},
|
|
1105
|
-
validate: (val) => {
|
|
1106
|
-
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1107
|
-
},
|
|
1048
|
+
async function init(dir) {
|
|
1049
|
+
const ans = await inquirer.prompt([
|
|
1050
|
+
{
|
|
1051
|
+
type: 'input',
|
|
1052
|
+
name: 'name',
|
|
1053
|
+
message: 'Type plugin name',
|
|
1054
|
+
filter: (val) => {
|
|
1055
|
+
return val.trim().toLowerCase();
|
|
1108
1056
|
},
|
|
1109
|
-
{
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
test: 'jest --collectCoverage --passWithNoTests',
|
|
1126
|
-
rollup: 'rollup -c rollup.config.js',
|
|
1127
|
-
build: 'run-p rollup',
|
|
1128
|
-
add: 'adaptkit --add',
|
|
1129
|
-
publish: 'npm run build && adaptkit --publish',
|
|
1130
|
-
emulate: 'npm run build && adaptkit --emulate',
|
|
1057
|
+
validate: (val) => {
|
|
1058
|
+
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1059
|
+
}
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
type: 'list',
|
|
1063
|
+
name: 'vertexType',
|
|
1064
|
+
message: 'Choose vertex type',
|
|
1065
|
+
choices: ['action', 'browser', 'cron-trigger', 'external-trigger']
|
|
1066
|
+
},
|
|
1067
|
+
{
|
|
1068
|
+
type: 'input',
|
|
1069
|
+
name: 'vertexName',
|
|
1070
|
+
message: 'Write the vertex name',
|
|
1071
|
+
filter: (val) => {
|
|
1072
|
+
return val.trim().toLowerCase();
|
|
1131
1073
|
},
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
execSync('npm install @mochabug/adapt-plugin-toolkit', {
|
|
1141
|
-
cwd: cwd,
|
|
1142
|
-
stdio: 'inherit',
|
|
1143
|
-
});
|
|
1144
|
-
console.log(chalk.magenta('Setting up project structure...'));
|
|
1145
|
-
writeFile(path.join(cwd, 'tsconfig.json'), tsconfig);
|
|
1146
|
-
writeFile(path.join(cwd, 'jest.config.ts'), jestTemplate);
|
|
1147
|
-
writeFile(path.join(cwd, '.gitignore'), gitignoreTemplate);
|
|
1148
|
-
writeFile(path.join(cwd, 'rollup.config.js'), rollupTemplate);
|
|
1149
|
-
const vertex = addVertex(cwd, ans.vertexName, ans.vertexType, ans.hasConfigurator);
|
|
1150
|
-
console.log(chalk.magenta('Creating manifest...'));
|
|
1151
|
-
mkdirp.sync(path.join(cwd, 'assets'));
|
|
1152
|
-
const manifest = {
|
|
1153
|
-
name: ans.name,
|
|
1154
|
-
version: '0.0.1-beta.1',
|
|
1155
|
-
label: capitilize(ans.name),
|
|
1156
|
-
description: `A nice description of what ${ans.name} does`,
|
|
1157
|
-
author: 'John Doe',
|
|
1158
|
-
bugs: 'bugs@foobar.com',
|
|
1159
|
-
homepage: `https://www.foobar.com`,
|
|
1160
|
-
repository: `https://github.com`,
|
|
1161
|
-
vertices: [vertex],
|
|
1162
|
-
assetsDir: 'assets',
|
|
1163
|
-
executorEsm: 'dist/executors.js',
|
|
1164
|
-
variables: [],
|
|
1165
|
-
oauth2: [],
|
|
1166
|
-
mtls: [],
|
|
1167
|
-
};
|
|
1168
|
-
if (!vertex.defaultConfig) {
|
|
1169
|
-
throw new Error('This cannot happen');
|
|
1074
|
+
validate: (val) => {
|
|
1075
|
+
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
{
|
|
1079
|
+
type: 'confirm',
|
|
1080
|
+
name: 'hasConfigurator',
|
|
1081
|
+
message: 'Need a configurator for the vertex?'
|
|
1170
1082
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1083
|
+
]);
|
|
1084
|
+
mkdirp.sync(dir);
|
|
1085
|
+
const cwd = !path.isAbsolute(dir) ? path.join(process.cwd(), dir) : dir;
|
|
1086
|
+
// Creating a minimal npm package
|
|
1087
|
+
console.log(chalk.magenta('Creating package.json...'));
|
|
1088
|
+
const defPackage = {
|
|
1089
|
+
name: ans.name,
|
|
1090
|
+
version: '',
|
|
1091
|
+
private: true,
|
|
1092
|
+
type: 'module',
|
|
1093
|
+
scripts: {
|
|
1094
|
+
test: 'jest --collectCoverage --passWithNoTests',
|
|
1095
|
+
rollup: 'rollup -c rollup.config.js',
|
|
1096
|
+
build: 'run-p rollup',
|
|
1097
|
+
add: 'adaptkit --add',
|
|
1098
|
+
publish: 'npm run build && adaptkit --publish',
|
|
1099
|
+
emulate: 'npm run build && adaptkit --emulate'
|
|
1174
1100
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1101
|
+
};
|
|
1102
|
+
writeFile(path.join(cwd, 'package.json'), JSON.stringify(defPackage, null, 2));
|
|
1103
|
+
writeFile(path.join(cwd, 'README.md'), readmeTemplate);
|
|
1104
|
+
writeFile(path.join(cwd, 'LICENSE.md'), licenseTemplate);
|
|
1105
|
+
execSync('npm install --save-dev @mochabug/adapt-plugin-typings typescript jest @jest/globals ts-jest @types/jest ts-node tslib rollup @rollup/plugin-typescript @rollup/plugin-terser @rollup/plugin-node-resolve @rollup/plugin-commonjs npm-run-all', {
|
|
1106
|
+
cwd: cwd,
|
|
1107
|
+
stdio: 'inherit'
|
|
1182
1108
|
});
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
const ans = yield inquirer.prompt([
|
|
1187
|
-
{
|
|
1188
|
-
type: 'input',
|
|
1189
|
-
name: 'vertexName',
|
|
1190
|
-
message: 'Type a new unused vertex name',
|
|
1191
|
-
filter: (val) => {
|
|
1192
|
-
return val.trim();
|
|
1193
|
-
},
|
|
1194
|
-
validate: (val) => {
|
|
1195
|
-
val = val.trim();
|
|
1196
|
-
if (manifest.vertices.filter((item) => item.name === val).length > 0) {
|
|
1197
|
-
return false;
|
|
1198
|
-
}
|
|
1199
|
-
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1200
|
-
},
|
|
1201
|
-
},
|
|
1202
|
-
{
|
|
1203
|
-
type: 'list',
|
|
1204
|
-
name: 'vertexType',
|
|
1205
|
-
message: 'Choose your vertex type',
|
|
1206
|
-
choices: ['action', 'browser', 'cron-trigger', 'external-trigger'],
|
|
1207
|
-
},
|
|
1208
|
-
{
|
|
1209
|
-
type: 'confirm',
|
|
1210
|
-
name: 'hasConfigurator',
|
|
1211
|
-
message: 'Need a configurator for the vertex?',
|
|
1212
|
-
},
|
|
1213
|
-
]);
|
|
1214
|
-
console.log(chalk.magenta('Creating new vertex templates...'));
|
|
1215
|
-
const vertex = addVertex('.', ans.vertexName, ans.vertexType, ans.hasConfigurator);
|
|
1216
|
-
manifest.vertices.push(vertex);
|
|
1217
|
-
if (!manifest.configuratorEsm && vertex.hasConfigurator) {
|
|
1218
|
-
manifest.configuratorEsm = 'dist/configurators.js';
|
|
1219
|
-
}
|
|
1220
|
-
console.log(chalk.magenta('Updating manifest...'));
|
|
1221
|
-
fs.writeFileSync('manifest.json', Manifest.toJsonString(manifest, {
|
|
1222
|
-
enumAsInteger: false,
|
|
1223
|
-
prettySpaces: 2,
|
|
1224
|
-
emitDefaultValues: true,
|
|
1225
|
-
}));
|
|
1226
|
-
console.log(chalk.bgGreen('Success'));
|
|
1109
|
+
execSync('npm install @mochabug/adapt-plugin-toolkit', {
|
|
1110
|
+
cwd: cwd,
|
|
1111
|
+
stdio: 'inherit'
|
|
1227
1112
|
});
|
|
1113
|
+
console.log(chalk.magenta('Setting up project structure...'));
|
|
1114
|
+
writeFile(path.join(cwd, 'tsconfig.json'), tsconfig);
|
|
1115
|
+
writeFile(path.join(cwd, 'jest.config.ts'), jestTemplate);
|
|
1116
|
+
writeFile(path.join(cwd, '.gitignore'), gitignoreTemplate);
|
|
1117
|
+
writeFile(path.join(cwd, 'rollup.config.js'), rollupTemplate);
|
|
1118
|
+
const vertex = addVertex(cwd, ans.vertexName, ans.vertexType, ans.hasConfigurator);
|
|
1119
|
+
console.log(chalk.magenta('Creating manifest...'));
|
|
1120
|
+
mkdirp.sync(path.join(cwd, 'assets'));
|
|
1121
|
+
const manifest = {
|
|
1122
|
+
name: ans.name,
|
|
1123
|
+
version: '0.0.1-beta.1',
|
|
1124
|
+
label: capitilize(ans.name),
|
|
1125
|
+
description: `A nice description of what ${ans.name} does`,
|
|
1126
|
+
author: 'John Doe',
|
|
1127
|
+
bugs: 'bugs@foobar.com',
|
|
1128
|
+
homepage: `https://www.foobar.com`,
|
|
1129
|
+
repository: `https://github.com`,
|
|
1130
|
+
vertices: [vertex],
|
|
1131
|
+
assetsDir: 'assets',
|
|
1132
|
+
executorEsm: 'dist/executors.js',
|
|
1133
|
+
variables: [],
|
|
1134
|
+
oauth2: [],
|
|
1135
|
+
mtls: []
|
|
1136
|
+
};
|
|
1137
|
+
if (!vertex.defaultConfig) {
|
|
1138
|
+
throw new Error('This cannot happen');
|
|
1139
|
+
}
|
|
1140
|
+
// Add the esm if we have a schema => this means that it has a configurator
|
|
1141
|
+
if (vertex.hasConfigurator) {
|
|
1142
|
+
manifest.configuratorEsm = 'dist/configurators.js';
|
|
1143
|
+
}
|
|
1144
|
+
// Write out the actual manifest and we're done
|
|
1145
|
+
fs.writeFileSync(path.join(cwd, 'manifest.json'), Manifest.toJsonString(manifest, {
|
|
1146
|
+
enumAsInteger: false,
|
|
1147
|
+
prettySpaces: 2,
|
|
1148
|
+
emitDefaultValues: true
|
|
1149
|
+
}));
|
|
1150
|
+
console.log(chalk.bgGreen('Success'));
|
|
1228
1151
|
}
|
|
1229
|
-
function
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
const lookup = {};
|
|
1238
|
-
function send(filePath, imgOpts) {
|
|
1239
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1240
|
-
if (!filePath || lookup[filePath]) {
|
|
1241
|
-
return;
|
|
1242
|
-
}
|
|
1243
|
-
if (!fs.existsSync(filePath)) {
|
|
1244
|
-
throw new Error(`The file does not exists: ${filePath}. Invalid manifest`);
|
|
1245
|
-
}
|
|
1246
|
-
// If image file, we need to compress it
|
|
1247
|
-
let buffer;
|
|
1248
|
-
if (imgOpts) {
|
|
1249
|
-
buffer = yield resize(filePath, imgOpts[0], imgOpts[1]);
|
|
1250
|
-
console.log(`Compressed: ${filePath} to ${imgOpts[0]}x${imgOpts[1]} size`);
|
|
1251
|
-
}
|
|
1252
|
-
else {
|
|
1253
|
-
buffer = fs.readFileSync(filePath);
|
|
1254
|
-
}
|
|
1255
|
-
console.log(`Sending: ${filePath}`);
|
|
1256
|
-
const message = {
|
|
1257
|
-
data: {
|
|
1258
|
-
oneofKind: 'file',
|
|
1259
|
-
file: {
|
|
1260
|
-
data: buffer,
|
|
1261
|
-
path: filePath,
|
|
1262
|
-
},
|
|
1263
|
-
},
|
|
1264
|
-
};
|
|
1265
|
-
yield stream.requests.send(message);
|
|
1266
|
-
lookup[filePath] = true;
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
// The first message must be the manifest
|
|
1270
|
-
// All the other messages must be files and must be described in the manifest
|
|
1271
|
-
const request = {
|
|
1272
|
-
data: {
|
|
1273
|
-
oneofKind: 'manifest',
|
|
1274
|
-
manifest: manifest,
|
|
1152
|
+
async function add(manifest) {
|
|
1153
|
+
const ans = await inquirer.prompt([
|
|
1154
|
+
{
|
|
1155
|
+
type: 'input',
|
|
1156
|
+
name: 'vertexName',
|
|
1157
|
+
message: 'Type a new unused vertex name',
|
|
1158
|
+
filter: (val) => {
|
|
1159
|
+
return val.trim();
|
|
1275
1160
|
},
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
yield send(manifest.executorEsm);
|
|
1281
|
-
yield send(manifest.configuratorEsm);
|
|
1282
|
-
yield send(manifest.logo, [80, 80]);
|
|
1283
|
-
// Send everything inside the asset directory as assets
|
|
1284
|
-
if (manifest.assetsDir && fs.existsSync(manifest.assetsDir)) {
|
|
1285
|
-
const paths = yield fg(path.join(manifest.assetsDir, '**', '*'));
|
|
1286
|
-
console.log('Found in assets directory:');
|
|
1287
|
-
console.log(paths);
|
|
1288
|
-
for (let filepath of paths) {
|
|
1289
|
-
if (fs.statSync(filepath).isFile()) {
|
|
1290
|
-
yield send(filepath);
|
|
1161
|
+
validate: (val) => {
|
|
1162
|
+
val = val.trim();
|
|
1163
|
+
if (manifest.vertices.filter((item) => item.name === val).length > 0) {
|
|
1164
|
+
return false;
|
|
1291
1165
|
}
|
|
1166
|
+
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1292
1167
|
}
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
type: 'list',
|
|
1171
|
+
name: 'vertexType',
|
|
1172
|
+
message: 'Choose your vertex type',
|
|
1173
|
+
choices: ['action', 'browser', 'cron-trigger', 'external-trigger']
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
type: 'confirm',
|
|
1177
|
+
name: 'hasConfigurator',
|
|
1178
|
+
message: 'Need a configurator for the vertex?'
|
|
1293
1179
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1180
|
+
]);
|
|
1181
|
+
console.log(chalk.magenta('Creating new vertex templates...'));
|
|
1182
|
+
const vertex = addVertex('.', ans.vertexName, ans.vertexType, ans.hasConfigurator);
|
|
1183
|
+
manifest.vertices.push(vertex);
|
|
1184
|
+
if (!manifest.configuratorEsm && vertex.hasConfigurator) {
|
|
1185
|
+
manifest.configuratorEsm = 'dist/configurators.js';
|
|
1186
|
+
}
|
|
1187
|
+
console.log(chalk.magenta('Updating manifest...'));
|
|
1188
|
+
fs.writeFileSync('manifest.json', Manifest.toJsonString(manifest, {
|
|
1189
|
+
enumAsInteger: false,
|
|
1190
|
+
prettySpaces: 2,
|
|
1191
|
+
emitDefaultValues: true
|
|
1192
|
+
}));
|
|
1193
|
+
console.log(chalk.bgGreen('Success'));
|
|
1194
|
+
}
|
|
1195
|
+
async function publish(manifest, address) {
|
|
1196
|
+
const transport = new GrpcTransport({
|
|
1197
|
+
host: address,
|
|
1198
|
+
channelCredentials: ChannelCredentials.createInsecure()
|
|
1199
|
+
});
|
|
1200
|
+
const client = new PluginServiceClient(transport);
|
|
1201
|
+
const stream = client.uploadPlugin();
|
|
1202
|
+
const lookup = {};
|
|
1203
|
+
async function send(filePath, imgOpts) {
|
|
1204
|
+
if (!filePath || lookup[filePath]) {
|
|
1205
|
+
return;
|
|
1301
1206
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
yield send(mtls.trustedCa);
|
|
1207
|
+
if (!fs.existsSync(filePath)) {
|
|
1208
|
+
throw new Error(`The file does not exists: ${filePath}. Invalid manifest`);
|
|
1305
1209
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
console.log(
|
|
1311
|
-
console.log(chalk.bgGreen('SUCCESS'));
|
|
1210
|
+
// If image file, we need to compress it
|
|
1211
|
+
let buffer;
|
|
1212
|
+
if (imgOpts) {
|
|
1213
|
+
buffer = await resize(filePath, imgOpts[0], imgOpts[1]);
|
|
1214
|
+
console.log(`Compressed: ${filePath} to ${imgOpts[0]}x${imgOpts[1]} size`);
|
|
1312
1215
|
}
|
|
1313
1216
|
else {
|
|
1314
|
-
|
|
1315
|
-
console.log(chalk.bgRed('FAILURE'));
|
|
1217
|
+
buffer = fs.readFileSync(filePath);
|
|
1316
1218
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
.option('-i, --init [dir]', "initialize a new plugin project in the specified directory (default './')", undefined)
|
|
1326
|
-
.option('-a, --add', 'add a new vertex to the plugin. Working directory need to contain a manifest.json file')
|
|
1327
|
-
.option('-p, --publish [url]', 'publish the plugin to your organization (default [HERE])', undefined)
|
|
1328
|
-
.option('-e, --emulate [url]', 'run the plugin in the emulator on the given url (default [HERE]', undefined)
|
|
1329
|
-
.parse(process.argv);
|
|
1330
|
-
const options = program.opts();
|
|
1331
|
-
if (options.init) {
|
|
1332
|
-
console.log(chalk.blueBright(figlet.textSync('Adaptkit')));
|
|
1333
|
-
let dir = '.';
|
|
1334
|
-
if (typeof options.init !== 'boolean') {
|
|
1335
|
-
dir = options.init;
|
|
1219
|
+
console.log(`Sending: ${filePath}`);
|
|
1220
|
+
const message = {
|
|
1221
|
+
data: {
|
|
1222
|
+
oneofKind: 'file',
|
|
1223
|
+
file: {
|
|
1224
|
+
data: buffer,
|
|
1225
|
+
path: filePath
|
|
1226
|
+
}
|
|
1336
1227
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1228
|
+
};
|
|
1229
|
+
await stream.requests.send(message);
|
|
1230
|
+
lookup[filePath] = true;
|
|
1231
|
+
}
|
|
1232
|
+
// The first message must be the manifest
|
|
1233
|
+
// All the other messages must be files and must be described in the manifest
|
|
1234
|
+
const request = {
|
|
1235
|
+
data: {
|
|
1236
|
+
oneofKind: 'manifest',
|
|
1237
|
+
manifest: manifest
|
|
1342
1238
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1239
|
+
};
|
|
1240
|
+
await stream.requests.send(request);
|
|
1241
|
+
await send('README.md');
|
|
1242
|
+
await send('LICENSE.md');
|
|
1243
|
+
await send(manifest.executorEsm);
|
|
1244
|
+
await send(manifest.configuratorEsm);
|
|
1245
|
+
await send(manifest.logo, [80, 80]);
|
|
1246
|
+
// Send everything inside the asset directory as assets
|
|
1247
|
+
if (manifest.assetsDir && fs.existsSync(manifest.assetsDir)) {
|
|
1248
|
+
const paths = await fg(path.join(manifest.assetsDir, '**', '*'));
|
|
1249
|
+
console.log('Found in assets directory:');
|
|
1250
|
+
console.log(paths);
|
|
1251
|
+
for (let filepath of paths) {
|
|
1252
|
+
if (fs.statSync(filepath).isFile()) {
|
|
1253
|
+
await send(filepath);
|
|
1347
1254
|
}
|
|
1348
|
-
yield publish(readManifest(), address);
|
|
1349
1255
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1256
|
+
}
|
|
1257
|
+
// Send everything related to the vertices. Logos, schemas and configs
|
|
1258
|
+
for (let vertex of manifest.vertices) {
|
|
1259
|
+
await send(vertex.logo, [40, 40]);
|
|
1260
|
+
await send(vertex.defaultConfig);
|
|
1261
|
+
for (let mtls of vertex.mtls) {
|
|
1262
|
+
await send(mtls.trustedCa);
|
|
1356
1263
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1264
|
+
}
|
|
1265
|
+
// Send the ca bundles
|
|
1266
|
+
for (let mtls of manifest.mtls) {
|
|
1267
|
+
await send(mtls.trustedCa);
|
|
1268
|
+
}
|
|
1269
|
+
stream.requests.complete();
|
|
1270
|
+
const result = await stream;
|
|
1271
|
+
console.log(result);
|
|
1272
|
+
if (result.status.code === 'OK') {
|
|
1273
|
+
console.log(chalk.green('Publishing done'));
|
|
1274
|
+
console.log(chalk.bgGreen('SUCCESS'));
|
|
1275
|
+
}
|
|
1276
|
+
else {
|
|
1277
|
+
console.log('The publishing failed. See log messages for error');
|
|
1278
|
+
console.log(chalk.bgRed('FAILURE'));
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
async function main() {
|
|
1282
|
+
program
|
|
1283
|
+
.name('Adaptkit')
|
|
1284
|
+
.version('1.0.0')
|
|
1285
|
+
.description('A CLI util to create, manage and publish plugins for mochabug adapt.')
|
|
1286
|
+
.option('-i, --init [dir]', "initialize a new plugin project in the specified directory (default './')", undefined)
|
|
1287
|
+
.option('-a, --add', 'add a new vertex to the plugin. Working directory need to contain a manifest.json file')
|
|
1288
|
+
.option('-p, --publish [url]', 'publish the plugin to your organization (default [HERE])', undefined)
|
|
1289
|
+
.option('-e, --emulate [url]', 'run the plugin in the emulator on the given url (default [HERE]', undefined)
|
|
1290
|
+
.parse(process.argv);
|
|
1291
|
+
const options = program.opts();
|
|
1292
|
+
if (options.init) {
|
|
1293
|
+
console.log(chalk.blueBright(figlet.textSync('Adaptkit')));
|
|
1294
|
+
let dir = '.';
|
|
1295
|
+
if (typeof options.init !== 'boolean') {
|
|
1296
|
+
dir = options.init;
|
|
1360
1297
|
}
|
|
1361
|
-
|
|
1362
|
-
}
|
|
1298
|
+
await init(dir);
|
|
1299
|
+
}
|
|
1300
|
+
else if (options.add) {
|
|
1301
|
+
console.log(chalk.blueBright(figlet.textSync('Adaptkit')));
|
|
1302
|
+
await add(readManifest());
|
|
1303
|
+
}
|
|
1304
|
+
else if (options.publish) {
|
|
1305
|
+
let address = 'localhost:51002';
|
|
1306
|
+
if (typeof options.publish !== 'boolean') {
|
|
1307
|
+
address = options.publish;
|
|
1308
|
+
}
|
|
1309
|
+
await publish(readManifest(), address);
|
|
1310
|
+
}
|
|
1311
|
+
else if (options.emulate) {
|
|
1312
|
+
let address = 'localhost:51002';
|
|
1313
|
+
if (typeof options.emulate !== 'boolean') {
|
|
1314
|
+
address = options.emulate;
|
|
1315
|
+
}
|
|
1316
|
+
await publish(readManifest(), address);
|
|
1317
|
+
}
|
|
1318
|
+
else {
|
|
1319
|
+
console.log(chalk.blueBright(figlet.textSync('Adaptkit')));
|
|
1320
|
+
program.outputHelp();
|
|
1321
|
+
}
|
|
1322
|
+
process.exit();
|
|
1363
1323
|
}
|
|
1364
1324
|
main();
|
|
1365
1325
|
//# sourceMappingURL=index.js.map
|