@mochabug/adaptkit 0.2.0-alpha.2 → 0.4.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/add.d.ts +3 -0
- package/bin/add.d.ts.map +1 -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 +467 -372
- package/bin/init.d.ts +2 -0
- package/bin/init.d.ts.map +1 -0
- package/bin/publish.d.ts +3 -0
- package/bin/publish.d.ts.map +1 -0
- package/bin/utils.d.ts +5 -0
- package/bin/utils.d.ts.map +1 -0
- package/bin/vertices.d.ts +3 -0
- package/bin/vertices.d.ts.map +1 -0
- package/package.json +21 -18
- package/LICENSE.txt +0 -12
- package/bin/index.js.map +0 -1
package/bin/index.js
CHANGED
|
@@ -1,46 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
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
|
-
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
|
|
6
2
|
import chalk from 'chalk';
|
|
7
|
-
import { execSync } from 'child_process';
|
|
8
3
|
import { program } from 'commander';
|
|
9
|
-
import fg from 'fast-glob';
|
|
10
4
|
import figlet from 'figlet';
|
|
11
5
|
import fs from 'fs';
|
|
12
6
|
import inquirer from 'inquirer';
|
|
7
|
+
import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
|
|
8
|
+
import { MessageType, reflectionMergePartial, UnknownFieldHandler, WireType, MESSAGE_TYPE } from '@protobuf-ts/runtime';
|
|
13
9
|
import { mkdirp } from 'mkdirp';
|
|
14
10
|
import path from 'path';
|
|
11
|
+
import { execSync } from 'child_process';
|
|
12
|
+
import { ChannelCredentials } from '@grpc/grpc-js';
|
|
13
|
+
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
|
|
14
|
+
import fg from 'fast-glob';
|
|
15
15
|
import sharp from 'sharp';
|
|
16
16
|
|
|
17
|
-
/******************************************************************************
|
|
18
|
-
Copyright (c) Microsoft Corporation.
|
|
19
|
-
|
|
20
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
21
|
-
purpose with or without fee is hereby granted.
|
|
22
|
-
|
|
23
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
24
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
25
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
26
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
27
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
28
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
29
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
30
|
-
***************************************************************************** */
|
|
31
|
-
/* global Reflect, Promise */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
35
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
17
|
// @generated by protobuf-ts 2.9.1
|
|
45
18
|
// @generated from protobuf file "mochabugapis/adapt/plugins/v1/plugins.proto" (package "mochabugapis.adapt.plugins.v1", syntax proto3)
|
|
46
19
|
// tslint:disable
|
|
@@ -846,33 +819,6 @@ const PluginService = new ServiceType("mochabugapis.adapt.plugins.v1.PluginServi
|
|
|
846
819
|
{ name: "UploadPlugin", clientStreaming: true, options: { "google.api.http": { post: "/v1/plugins/upload", body: "*" } }, I: UploadPluginRequest, O: UploadPluginResponse }
|
|
847
820
|
], { "google.api.default_host": "adapt.mochabugapis.com", "google.api.oauth_scopes": "https://www.mochabugapis.com/auth/adapt.plugins" });
|
|
848
821
|
|
|
849
|
-
/**
|
|
850
|
-
* PluginService provides a service for uploading a plugin.
|
|
851
|
-
*
|
|
852
|
-
* @generated from protobuf service mochabugapis.adapt.plugins.v1.PluginService
|
|
853
|
-
*/
|
|
854
|
-
class PluginServiceClient {
|
|
855
|
-
_transport;
|
|
856
|
-
typeName = PluginService.typeName;
|
|
857
|
-
methods = PluginService.methods;
|
|
858
|
-
options = PluginService.options;
|
|
859
|
-
constructor(_transport) {
|
|
860
|
-
this._transport = _transport;
|
|
861
|
-
}
|
|
862
|
-
/**
|
|
863
|
-
* UploadPlugin is a streaming RPC method that allows uploading a plugin in
|
|
864
|
-
* chunks. The client can send multiple UploadPluginRequest messages, and the
|
|
865
|
-
* server will respond with a single UploadPluginResponse after processing all
|
|
866
|
-
* requests.
|
|
867
|
-
*
|
|
868
|
-
* @generated from protobuf rpc: UploadPlugin(stream mochabugapis.adapt.plugins.v1.UploadPluginRequest) returns (mochabugapis.adapt.plugins.v1.UploadPluginResponse);
|
|
869
|
-
*/
|
|
870
|
-
uploadPlugin(options) {
|
|
871
|
-
const method = this.methods[0], opt = this._transport.mergeOptions(options);
|
|
872
|
-
return stackIntercept("clientStreaming", this._transport, method, opt);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
822
|
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
823
|
|
|
878
824
|
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";
|
|
@@ -885,18 +831,6 @@ var triggerExecTemplate = "import { ExternalExecutorRouter } from '@mochabug/ada
|
|
|
885
831
|
|
|
886
832
|
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
833
|
|
|
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\": [\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}";
|
|
899
|
-
|
|
900
834
|
// Copyright 2023, mochabug AB
|
|
901
835
|
//
|
|
902
836
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -915,37 +849,39 @@ function writeFile(filePath, content) {
|
|
|
915
849
|
mkdirp.sync(dir);
|
|
916
850
|
fs.writeFileSync(filePath, content);
|
|
917
851
|
}
|
|
918
|
-
function readManifest() {
|
|
919
|
-
const
|
|
920
|
-
|
|
852
|
+
function readManifest(filePath) {
|
|
853
|
+
const fullPath = path.resolve(filePath);
|
|
854
|
+
if (!fs.existsSync(fullPath)) {
|
|
855
|
+
console.error(chalk.red(`Invalid command: Manifest file not found at ${fullPath}.`));
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
try {
|
|
859
|
+
const manifestData = fs.readFileSync(fullPath).toString();
|
|
860
|
+
return Manifest.fromJsonString(manifestData);
|
|
861
|
+
}
|
|
862
|
+
catch (error) {
|
|
863
|
+
console.error(chalk.red(`An error occurred while reading the manifest`));
|
|
864
|
+
console.error(error.message);
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
921
867
|
}
|
|
922
868
|
function capitilize(val) {
|
|
923
869
|
return val.charAt(0).toUpperCase() + val.substring(1);
|
|
924
870
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
case '.png':
|
|
940
|
-
return yield sharp(filepath).resize(height, width).png().toBuffer();
|
|
941
|
-
case '.svg':
|
|
942
|
-
return fs.readFileSync(filepath);
|
|
943
|
-
case '.webp':
|
|
944
|
-
return yield sharp(filepath).resize(height, width).webp().toBuffer();
|
|
945
|
-
}
|
|
946
|
-
throw new Error('Invalid logotype');
|
|
947
|
-
});
|
|
948
|
-
}
|
|
871
|
+
|
|
872
|
+
// Copyright 2023, mochabug AB
|
|
873
|
+
//
|
|
874
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
875
|
+
// you may not use this file except in compliance with the License.
|
|
876
|
+
// You may obtain a copy of the License at
|
|
877
|
+
//
|
|
878
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
879
|
+
//
|
|
880
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
881
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
882
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
883
|
+
// See the License for the specific language governing permissions and
|
|
884
|
+
// limitations under the License.
|
|
949
885
|
function convertVertexType(type) {
|
|
950
886
|
switch (type) {
|
|
951
887
|
case 'action':
|
|
@@ -979,7 +915,7 @@ function addVertex(cwd, name, type, hasConfigurator) {
|
|
|
979
915
|
hasConfigurator,
|
|
980
916
|
mtls: [],
|
|
981
917
|
oauth2: [],
|
|
982
|
-
variables: []
|
|
918
|
+
variables: []
|
|
983
919
|
};
|
|
984
920
|
// Write the new task
|
|
985
921
|
let importString;
|
|
@@ -1031,20 +967,20 @@ function addVertex(cwd, name, type, hasConfigurator) {
|
|
|
1031
967
|
{
|
|
1032
968
|
name: 'input',
|
|
1033
969
|
description: 'Default input receiver',
|
|
1034
|
-
bindings: []
|
|
1035
|
-
}
|
|
970
|
+
bindings: []
|
|
971
|
+
}
|
|
1036
972
|
],
|
|
1037
973
|
transmitters: [
|
|
1038
974
|
{
|
|
1039
975
|
name: 'output',
|
|
1040
976
|
description: 'Default output transmitter',
|
|
1041
977
|
signals: [],
|
|
1042
|
-
failure: false
|
|
1043
|
-
}
|
|
978
|
+
failure: false
|
|
979
|
+
}
|
|
1044
980
|
],
|
|
1045
981
|
procedures: [],
|
|
1046
982
|
streams: [],
|
|
1047
|
-
bindings: []
|
|
983
|
+
bindings: []
|
|
1048
984
|
};
|
|
1049
985
|
if (vertex.type === Vertex_VertexType.CRON_TRIGGER) {
|
|
1050
986
|
vertexConfig.cronInterval = 5000;
|
|
@@ -1075,291 +1011,450 @@ function addVertex(cwd, name, type, hasConfigurator) {
|
|
|
1075
1011
|
fs.writeFileSync(path.join(cwd, 'src', name, 'config.json'), JSON.stringify(vertexConfig, null, 2));
|
|
1076
1012
|
return vertex;
|
|
1077
1013
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
{
|
|
1099
|
-
|
|
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
|
-
},
|
|
1108
|
-
},
|
|
1109
|
-
{
|
|
1110
|
-
type: 'confirm',
|
|
1111
|
-
name: 'hasConfigurator',
|
|
1112
|
-
message: 'Need a configurator for the vertex?',
|
|
1113
|
-
},
|
|
1114
|
-
]);
|
|
1115
|
-
mkdirp.sync(dir);
|
|
1116
|
-
const cwd = !path.isAbsolute(dir) ? path.join(process.cwd(), dir) : dir;
|
|
1117
|
-
// Creating a minimal npm package
|
|
1118
|
-
console.log(chalk.magenta('Creating package.json...'));
|
|
1119
|
-
const defPackage = {
|
|
1120
|
-
name: ans.name,
|
|
1121
|
-
version: '',
|
|
1122
|
-
private: true,
|
|
1123
|
-
type: 'module',
|
|
1124
|
-
scripts: {
|
|
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',
|
|
1014
|
+
|
|
1015
|
+
// Copyright 2023, mochabug AB
|
|
1016
|
+
//
|
|
1017
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
1018
|
+
// you may not use this file except in compliance with the License.
|
|
1019
|
+
// You may obtain a copy of the License at
|
|
1020
|
+
//
|
|
1021
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
1022
|
+
//
|
|
1023
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
1024
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
1025
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1026
|
+
// See the License for the specific language governing permissions and
|
|
1027
|
+
// limitations under the License.
|
|
1028
|
+
async function add(manifest) {
|
|
1029
|
+
const ans = await inquirer.prompt([
|
|
1030
|
+
{
|
|
1031
|
+
type: 'input',
|
|
1032
|
+
name: 'vertexName',
|
|
1033
|
+
message: 'Type a new unused vertex name',
|
|
1034
|
+
filter: (val) => {
|
|
1035
|
+
return val.trim();
|
|
1131
1036
|
},
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
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');
|
|
1170
|
-
}
|
|
1171
|
-
// Add the esm if we have a schema => this means that it has a configurator
|
|
1172
|
-
if (vertex.hasConfigurator) {
|
|
1173
|
-
manifest.configuratorEsm = 'dist/configurators.js';
|
|
1037
|
+
validate: (val) => {
|
|
1038
|
+
val = val.trim();
|
|
1039
|
+
if (manifest.vertices.filter((item) => item.name === val).length > 0) {
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
type: 'list',
|
|
1047
|
+
name: 'vertexType',
|
|
1048
|
+
message: 'Choose your vertex type',
|
|
1049
|
+
choices: ['action', 'browser', 'cron-trigger', 'external-trigger']
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
type: 'confirm',
|
|
1053
|
+
name: 'hasConfigurator',
|
|
1054
|
+
message: 'Need a configurator for the vertex?'
|
|
1174
1055
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1056
|
+
]);
|
|
1057
|
+
console.log(chalk.magenta('Creating new vertex templates...'));
|
|
1058
|
+
const vertex = addVertex('.', ans.vertexName, ans.vertexType, ans.hasConfigurator);
|
|
1059
|
+
manifest.vertices.push(vertex);
|
|
1060
|
+
if (!manifest.configuratorEsm && vertex.hasConfigurator) {
|
|
1061
|
+
manifest.configuratorEsm = 'dist/configurators.js';
|
|
1062
|
+
}
|
|
1063
|
+
console.log(chalk.magenta('Updating manifest...'));
|
|
1064
|
+
fs.writeFileSync('manifest.json', Manifest.toJsonString(manifest, {
|
|
1065
|
+
enumAsInteger: false,
|
|
1066
|
+
prettySpaces: 2,
|
|
1067
|
+
emitDefaultValues: true
|
|
1068
|
+
}));
|
|
1069
|
+
console.log(chalk.bgGreen('Success'));
|
|
1183
1070
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1071
|
+
|
|
1072
|
+
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.*";
|
|
1073
|
+
|
|
1074
|
+
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";
|
|
1075
|
+
|
|
1076
|
+
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.";
|
|
1077
|
+
|
|
1078
|
+
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";
|
|
1079
|
+
|
|
1080
|
+
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";
|
|
1081
|
+
|
|
1082
|
+
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}";
|
|
1083
|
+
|
|
1084
|
+
// Copyright 2023, mochabug AB
|
|
1085
|
+
//
|
|
1086
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
1087
|
+
// you may not use this file except in compliance with the License.
|
|
1088
|
+
// You may obtain a copy of the License at
|
|
1089
|
+
//
|
|
1090
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
1091
|
+
//
|
|
1092
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
1093
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
1094
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1095
|
+
// See the License for the specific language governing permissions and
|
|
1096
|
+
// limitations under the License.
|
|
1097
|
+
async function init(dir) {
|
|
1098
|
+
const ans = await inquirer.prompt([
|
|
1099
|
+
{
|
|
1100
|
+
type: 'input',
|
|
1101
|
+
name: 'name',
|
|
1102
|
+
message: 'Type plugin name',
|
|
1103
|
+
filter: (val) => {
|
|
1104
|
+
return val.trim().toLowerCase();
|
|
1207
1105
|
},
|
|
1208
|
-
{
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1106
|
+
validate: (val) => {
|
|
1107
|
+
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1108
|
+
}
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
type: 'list',
|
|
1112
|
+
name: 'vertexType',
|
|
1113
|
+
message: 'Choose vertex type',
|
|
1114
|
+
choices: ['action', 'browser', 'cron-trigger', 'external-trigger']
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
type: 'input',
|
|
1118
|
+
name: 'vertexName',
|
|
1119
|
+
message: 'Write the vertex name',
|
|
1120
|
+
filter: (val) => {
|
|
1121
|
+
return val.trim().toLowerCase();
|
|
1212
1122
|
},
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1123
|
+
validate: (val) => {
|
|
1124
|
+
return /[a-zA-Z][0-9a-zA-Z_]*/.test(val);
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
type: 'confirm',
|
|
1129
|
+
name: 'hasConfigurator',
|
|
1130
|
+
message: 'Need a configurator for the vertex?'
|
|
1131
|
+
}
|
|
1132
|
+
]);
|
|
1133
|
+
mkdirp.sync(dir);
|
|
1134
|
+
const cwd = !path.isAbsolute(dir) ? path.join(process.cwd(), dir) : dir;
|
|
1135
|
+
// Creating a minimal npm package
|
|
1136
|
+
console.log(chalk.magenta('Creating package.json...'));
|
|
1137
|
+
const defPackage = {
|
|
1138
|
+
name: ans.name,
|
|
1139
|
+
version: '',
|
|
1140
|
+
private: true,
|
|
1141
|
+
type: 'module',
|
|
1142
|
+
scripts: {
|
|
1143
|
+
test: 'jest --collectCoverage --passWithNoTests',
|
|
1144
|
+
rollup: 'rollup -c rollup.config.js',
|
|
1145
|
+
build: 'run-p rollup',
|
|
1146
|
+
add: 'adaptkit add',
|
|
1147
|
+
publish: 'npm run build && adaptkit publish',
|
|
1148
|
+
emulate: 'npm run build && adaptkit emulate'
|
|
1219
1149
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1150
|
+
};
|
|
1151
|
+
writeFile(path.join(cwd, 'package.json'), JSON.stringify(defPackage, null, 2));
|
|
1152
|
+
writeFile(path.join(cwd, 'README.md'), readmeTemplate);
|
|
1153
|
+
writeFile(path.join(cwd, 'LICENSE.md'), licenseTemplate);
|
|
1154
|
+
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', {
|
|
1155
|
+
cwd: cwd,
|
|
1156
|
+
stdio: 'inherit'
|
|
1157
|
+
});
|
|
1158
|
+
execSync('npm install @mochabug/adapt-plugin-toolkit', {
|
|
1159
|
+
cwd: cwd,
|
|
1160
|
+
stdio: 'inherit'
|
|
1227
1161
|
});
|
|
1162
|
+
console.log(chalk.magenta('Setting up project structure...'));
|
|
1163
|
+
writeFile(path.join(cwd, 'tsconfig.json'), tsconfig);
|
|
1164
|
+
writeFile(path.join(cwd, 'jest.config.ts'), jestTemplate);
|
|
1165
|
+
writeFile(path.join(cwd, '.gitignore'), gitignoreTemplate);
|
|
1166
|
+
writeFile(path.join(cwd, 'rollup.config.js'), rollupTemplate);
|
|
1167
|
+
const vertex = addVertex(cwd, ans.vertexName, ans.vertexType, ans.hasConfigurator);
|
|
1168
|
+
console.log(chalk.magenta('Creating manifest...'));
|
|
1169
|
+
mkdirp.sync(path.join(cwd, 'assets'));
|
|
1170
|
+
const manifest = {
|
|
1171
|
+
name: ans.name,
|
|
1172
|
+
version: '0.0.1-beta.1',
|
|
1173
|
+
label: capitilize(ans.name),
|
|
1174
|
+
description: `A nice description of what ${ans.name} does`,
|
|
1175
|
+
author: 'John Doe',
|
|
1176
|
+
bugs: 'bugs@foobar.com',
|
|
1177
|
+
homepage: `https://www.foobar.com`,
|
|
1178
|
+
repository: `https://github.com`,
|
|
1179
|
+
vertices: [vertex],
|
|
1180
|
+
assetsDir: 'assets',
|
|
1181
|
+
executorEsm: 'dist/executors.js',
|
|
1182
|
+
variables: [],
|
|
1183
|
+
oauth2: [],
|
|
1184
|
+
mtls: []
|
|
1185
|
+
};
|
|
1186
|
+
if (!vertex.defaultConfig) {
|
|
1187
|
+
throw new Error('This cannot happen');
|
|
1188
|
+
}
|
|
1189
|
+
// Add the esm if we have a schema => this means that it has a configurator
|
|
1190
|
+
if (vertex.hasConfigurator) {
|
|
1191
|
+
manifest.configuratorEsm = 'dist/configurators.js';
|
|
1192
|
+
}
|
|
1193
|
+
// Write out the actual manifest and we're done
|
|
1194
|
+
fs.writeFileSync(path.join(cwd, 'manifest.json'), Manifest.toJsonString(manifest, {
|
|
1195
|
+
enumAsInteger: false,
|
|
1196
|
+
prettySpaces: 2,
|
|
1197
|
+
emitDefaultValues: true
|
|
1198
|
+
}));
|
|
1199
|
+
console.log(chalk.bgGreen('Success'));
|
|
1228
1200
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* PluginService provides a service for uploading a plugin.
|
|
1204
|
+
*
|
|
1205
|
+
* @generated from protobuf service mochabugapis.adapt.plugins.v1.PluginService
|
|
1206
|
+
*/
|
|
1207
|
+
class PluginServiceClient {
|
|
1208
|
+
constructor(_transport) {
|
|
1209
|
+
this._transport = _transport;
|
|
1210
|
+
this.typeName = PluginService.typeName;
|
|
1211
|
+
this.methods = PluginService.methods;
|
|
1212
|
+
this.options = PluginService.options;
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* UploadPlugin is a streaming RPC method that allows uploading a plugin in
|
|
1216
|
+
* chunks. The client can send multiple UploadPluginRequest messages, and the
|
|
1217
|
+
* server will respond with a single UploadPluginResponse after processing all
|
|
1218
|
+
* requests.
|
|
1219
|
+
*
|
|
1220
|
+
* @generated from protobuf rpc: UploadPlugin(stream mochabugapis.adapt.plugins.v1.UploadPluginRequest) returns (mochabugapis.adapt.plugins.v1.UploadPluginResponse);
|
|
1221
|
+
*/
|
|
1222
|
+
uploadPlugin(options) {
|
|
1223
|
+
const method = this.methods[0], opt = this._transport.mergeOptions(options);
|
|
1224
|
+
return stackIntercept("clientStreaming", this._transport, method, opt);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
// Copyright 2023, mochabug AB
|
|
1229
|
+
//
|
|
1230
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
1231
|
+
// you may not use this file except in compliance with the License.
|
|
1232
|
+
// You may obtain a copy of the License at
|
|
1233
|
+
//
|
|
1234
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
1235
|
+
//
|
|
1236
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
1237
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
1238
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1239
|
+
// See the License for the specific language governing permissions and
|
|
1240
|
+
// limitations under the License.
|
|
1241
|
+
async function resize(filepath, height, width) {
|
|
1242
|
+
const extname = path.extname(filepath);
|
|
1243
|
+
switch (extname) {
|
|
1244
|
+
case '.avif':
|
|
1245
|
+
return await sharp(filepath).resize(height, width).avif().toBuffer();
|
|
1246
|
+
case '.gif':
|
|
1247
|
+
return await sharp(filepath).resize(height, width).gif().toBuffer();
|
|
1248
|
+
case '.jpg':
|
|
1249
|
+
case '.jpeg':
|
|
1250
|
+
case '.jfif':
|
|
1251
|
+
case '.pjpeg':
|
|
1252
|
+
case '.pjp':
|
|
1253
|
+
return await sharp(filepath).resize(height, width).jpeg().toBuffer();
|
|
1254
|
+
case '.png':
|
|
1255
|
+
return await sharp(filepath).resize(height, width).png().toBuffer();
|
|
1256
|
+
case '.svg':
|
|
1257
|
+
return fs.readFileSync(filepath);
|
|
1258
|
+
case '.webp':
|
|
1259
|
+
return await sharp(filepath).resize(height, width).webp().toBuffer();
|
|
1260
|
+
}
|
|
1261
|
+
throw new Error('Invalid logotype');
|
|
1262
|
+
}
|
|
1263
|
+
async function publish(manifest, address) {
|
|
1264
|
+
const transport = new GrpcTransport({
|
|
1265
|
+
host: address,
|
|
1266
|
+
channelCredentials: ChannelCredentials.createInsecure()
|
|
1267
|
+
});
|
|
1268
|
+
const client = new PluginServiceClient(transport);
|
|
1269
|
+
const stream = client.uploadPlugin();
|
|
1270
|
+
const lookup = {};
|
|
1271
|
+
async function send(filePath, imgOpts) {
|
|
1272
|
+
if (!filePath || lookup[filePath]) {
|
|
1273
|
+
return;
|
|
1301
1274
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
yield send(mtls.trustedCa);
|
|
1275
|
+
if (!fs.existsSync(filePath)) {
|
|
1276
|
+
throw new Error(`The file does not exists: ${filePath}. Invalid manifest`);
|
|
1305
1277
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
console.log(
|
|
1311
|
-
console.log(chalk.bgGreen('SUCCESS'));
|
|
1278
|
+
// If image file, we need to compress it
|
|
1279
|
+
let buffer;
|
|
1280
|
+
if (imgOpts) {
|
|
1281
|
+
buffer = await resize(filePath, imgOpts[0], imgOpts[1]);
|
|
1282
|
+
console.log(`Compressed: ${filePath} to ${imgOpts[0]}x${imgOpts[1]} size`);
|
|
1312
1283
|
}
|
|
1313
1284
|
else {
|
|
1314
|
-
|
|
1315
|
-
console.log(chalk.bgRed('FAILURE'));
|
|
1285
|
+
buffer = fs.readFileSync(filePath);
|
|
1316
1286
|
}
|
|
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;
|
|
1336
|
-
}
|
|
1337
|
-
yield init(dir);
|
|
1338
|
-
}
|
|
1339
|
-
else if (options.add) {
|
|
1340
|
-
console.log(chalk.blueBright(figlet.textSync('Adaptkit')));
|
|
1341
|
-
yield add(readManifest());
|
|
1342
|
-
}
|
|
1343
|
-
else if (options.publish) {
|
|
1344
|
-
let address = 'localhost:51002';
|
|
1345
|
-
if (typeof options.publish !== 'boolean') {
|
|
1346
|
-
address = options.publish;
|
|
1287
|
+
console.log(`Sending: ${filePath}`);
|
|
1288
|
+
const message = {
|
|
1289
|
+
data: {
|
|
1290
|
+
oneofKind: 'file',
|
|
1291
|
+
file: {
|
|
1292
|
+
data: buffer,
|
|
1293
|
+
path: filePath
|
|
1294
|
+
}
|
|
1347
1295
|
}
|
|
1348
|
-
|
|
1296
|
+
};
|
|
1297
|
+
await stream.requests.send(message);
|
|
1298
|
+
lookup[filePath] = true;
|
|
1299
|
+
}
|
|
1300
|
+
// The first message must be the manifest
|
|
1301
|
+
// All the other messages must be files and must be described in the manifest
|
|
1302
|
+
const request = {
|
|
1303
|
+
data: {
|
|
1304
|
+
oneofKind: 'manifest',
|
|
1305
|
+
manifest: manifest
|
|
1349
1306
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1307
|
+
};
|
|
1308
|
+
await stream.requests.send(request);
|
|
1309
|
+
await send('README.md');
|
|
1310
|
+
await send('LICENSE.md');
|
|
1311
|
+
await send(manifest.executorEsm);
|
|
1312
|
+
await send(manifest.configuratorEsm);
|
|
1313
|
+
await send(manifest.logo, [80, 80]);
|
|
1314
|
+
// Send everything inside the asset directory as assets
|
|
1315
|
+
if (manifest.assetsDir && fs.existsSync(manifest.assetsDir)) {
|
|
1316
|
+
const paths = await fg(path.join(manifest.assetsDir, '**', '*'));
|
|
1317
|
+
console.log('Found in assets directory:');
|
|
1318
|
+
console.log(paths);
|
|
1319
|
+
for (let filepath of paths) {
|
|
1320
|
+
if (fs.statSync(filepath).isFile()) {
|
|
1321
|
+
await send(filepath);
|
|
1354
1322
|
}
|
|
1355
|
-
yield publish(readManifest(), address);
|
|
1356
1323
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1324
|
+
}
|
|
1325
|
+
// Send everything related to the vertices. Logos, schemas and configs
|
|
1326
|
+
for (let vertex of manifest.vertices) {
|
|
1327
|
+
await send(vertex.logo, [40, 40]);
|
|
1328
|
+
await send(vertex.defaultConfig);
|
|
1329
|
+
for (let mtls of vertex.mtls) {
|
|
1330
|
+
await send(mtls.trustedCa);
|
|
1360
1331
|
}
|
|
1361
|
-
|
|
1332
|
+
}
|
|
1333
|
+
// Send the ca bundles
|
|
1334
|
+
for (let mtls of manifest.mtls) {
|
|
1335
|
+
await send(mtls.trustedCa);
|
|
1336
|
+
}
|
|
1337
|
+
stream.requests.complete();
|
|
1338
|
+
const result = await stream;
|
|
1339
|
+
console.log(result);
|
|
1340
|
+
if (result.status.code === 'OK') {
|
|
1341
|
+
console.log(chalk.green('Publishing done'));
|
|
1342
|
+
console.log(chalk.bgGreen('SUCCESS'));
|
|
1343
|
+
}
|
|
1344
|
+
else {
|
|
1345
|
+
console.log('The publishing failed. See log messages for error');
|
|
1346
|
+
console.log(chalk.bgRed('FAILURE'));
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// Copyright 2023, mochabug AB
|
|
1351
|
+
//
|
|
1352
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
1353
|
+
// you may not use this file except in compliance with the License.
|
|
1354
|
+
// You may obtain a copy of the License at
|
|
1355
|
+
//
|
|
1356
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
1357
|
+
//
|
|
1358
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
1359
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
1360
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1361
|
+
// See the License for the specific language governing permissions and
|
|
1362
|
+
// limitations under the License.
|
|
1363
|
+
const DEFAULT_DIRECTORY = './';
|
|
1364
|
+
const DEFAULT_ADDRESS = 'localhost:51002';
|
|
1365
|
+
function banner() {
|
|
1366
|
+
return chalk.yellowBright(figlet.textSync('Adaptkit'));
|
|
1367
|
+
}
|
|
1368
|
+
function getAddress(optionValue) {
|
|
1369
|
+
return typeof optionValue !== 'boolean' ? optionValue : DEFAULT_ADDRESS;
|
|
1370
|
+
}
|
|
1371
|
+
async function handleInit(dir, cmd) {
|
|
1372
|
+
// Check for unexpected arguments
|
|
1373
|
+
if (cmd.args.length >= 1) {
|
|
1374
|
+
console.error(chalk.red(`Error: Invalid sub-command or arguments provided.`));
|
|
1375
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help init')}`);
|
|
1376
|
+
process.exit(1);
|
|
1377
|
+
}
|
|
1378
|
+
// Continue with the usual logic if no unexpected arguments are found
|
|
1379
|
+
await init(dir);
|
|
1380
|
+
}
|
|
1381
|
+
async function handleAdd(cmd) {
|
|
1382
|
+
if (cmd.args.length >= 1) {
|
|
1383
|
+
console.error(chalk.red(`Error: Invalid sub-command or arguments provided.`));
|
|
1384
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help add')}`);
|
|
1385
|
+
process.exit(1);
|
|
1386
|
+
}
|
|
1387
|
+
const manifest = readManifest('manifest.json');
|
|
1388
|
+
if (!manifest) {
|
|
1389
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help add')}`);
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
await add(manifest);
|
|
1393
|
+
}
|
|
1394
|
+
async function handlePublish(address, cmd) {
|
|
1395
|
+
if (cmd.args.length >= 1) {
|
|
1396
|
+
console.error(chalk.red(`Error: Invalid sub-command or arguments provided.`));
|
|
1397
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help publish')}`);
|
|
1398
|
+
process.exit(1);
|
|
1399
|
+
}
|
|
1400
|
+
const manifest = readManifest('manifest.json');
|
|
1401
|
+
if (!manifest) {
|
|
1402
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help publish')}`);
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
await publish(manifest, address);
|
|
1406
|
+
}
|
|
1407
|
+
async function handleEmulate(address, cmd) {
|
|
1408
|
+
if (cmd.args.length >= 1) {
|
|
1409
|
+
console.error(chalk.red(`Error: Invalid sub-command or arguments provided.`));
|
|
1410
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help emulate')}`);
|
|
1411
|
+
process.exit(1);
|
|
1412
|
+
}
|
|
1413
|
+
const manifest = readManifest('manifest.json');
|
|
1414
|
+
if (!manifest) {
|
|
1415
|
+
console.log(`For more information, use: ${chalk.blue('adaptkit help emulate')}`);
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
await publish(manifest, address); // Assuming this should be emulate instead of publish
|
|
1419
|
+
}
|
|
1420
|
+
async function main() {
|
|
1421
|
+
program
|
|
1422
|
+
.name('Adaptkit')
|
|
1423
|
+
.version('1.0.0')
|
|
1424
|
+
.description(`Unleash the power of seamless plugin development with Adaptkit, your premier CLI companion for Mochabug Adapt. Effortlessly create, manage, and deploy plugins with finesse. Explore the full potential of Adaptkit at ${chalk.underline.blue('https://www.mochabug.com')}.`)
|
|
1425
|
+
.configureHelp({
|
|
1426
|
+
sortSubcommands: true,
|
|
1427
|
+
sortOptions: true,
|
|
1428
|
+
showGlobalOptions: true,
|
|
1429
|
+
helpWidth: 140
|
|
1362
1430
|
});
|
|
1431
|
+
program
|
|
1432
|
+
.command('init')
|
|
1433
|
+
.option('-d, --dir <dir>', `Choose the directory to initiate your plugin's journey. Default: '${DEFAULT_DIRECTORY}'`, DEFAULT_DIRECTORY)
|
|
1434
|
+
.description('Kickstart your plugin adventure. This command scaffolds a ready-to-go project structure.')
|
|
1435
|
+
.action(({ dir }, cmd) => handleInit(dir, cmd));
|
|
1436
|
+
program
|
|
1437
|
+
.command('add')
|
|
1438
|
+
.description("Expand your plugin's capabilities. Ensure you're in the directory with manifest.json.")
|
|
1439
|
+
.action((cmd) => handleAdd(cmd));
|
|
1440
|
+
program
|
|
1441
|
+
.command('publish')
|
|
1442
|
+
.option('-u, --url <url>', `Choose the destination URL for your plugin's deployment. Note: Primarily for testing purposes. ${chalk.red('Use with caution')}`, DEFAULT_ADDRESS)
|
|
1443
|
+
.description("Ready for liftoff? Publish your plugin to your organization with this command. Ensure you're in the directory with manifest.json.")
|
|
1444
|
+
.action(({ url }, cmd) => handlePublish(getAddress(url), cmd));
|
|
1445
|
+
program
|
|
1446
|
+
.command('emulate')
|
|
1447
|
+
.option('-u, --url <url>', 'Specify the URL to test your plugin in the emulator. Ideal for custom port configurations.', DEFAULT_ADDRESS)
|
|
1448
|
+
.description("Take your plugin for a test drive. Best used in conjunction with your build pipeline. Ensure you're in the directory with manifest.json.")
|
|
1449
|
+
.action(({ url }, cmd) => handleEmulate(getAddress(url), cmd));
|
|
1450
|
+
// Set a custom help action
|
|
1451
|
+
program.addHelpText('beforeAll', banner() + '\n');
|
|
1452
|
+
program.showHelpAfterError();
|
|
1453
|
+
try {
|
|
1454
|
+
await program.parseAsync(process.argv);
|
|
1455
|
+
}
|
|
1456
|
+
catch (error) {
|
|
1457
|
+
console.error('An error occurred:', error.message);
|
|
1458
|
+
}
|
|
1363
1459
|
}
|
|
1364
1460
|
main();
|
|
1365
|
-
//# sourceMappingURL=index.js.map
|