@prismatic-io/spectral
Version:
Utility library for building Prismatic connectors and code-native integrations
141 lines (140 loc) • 5.93 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runMain = void 0;
const node_fs_1 = require("node:fs");
const node_path_1 = __importDefault(require("node:path"));
const createActions_1 = require("../componentManifest/createActions");
const createConnections_1 = require("../componentManifest/createConnections");
const createDataSources_1 = require("../componentManifest/createDataSources");
const createTriggers_1 = require("../componentManifest/createTriggers");
const removeComponentManifest_1 = require("../componentManifest/removeComponentManifest");
const createFlagHelpText_1 = require("../utils/createFlagHelpText");
const createTemplate_1 = require("../utils/createTemplate");
const getFlagBooleanValue_1 = require("../utils/getFlagBooleanValue");
const _1 = require(".");
const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
const args = process.argv.slice(2);
const componentKey = args[0];
const cniDir = process.cwd();
const flags = {
isPrivate: {
flag: ["--private"],
value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
args,
flags: ["--private"],
}),
description: "Denotes if the component is private. If not specified, the component is assumed to be public.",
},
dryRun: {
flag: ["--dry-run", "-d"],
value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
args,
flags: ["--dry-run", "-d"],
}),
description: "Perform a dry run without generating the component manifest. This provides a preview of what you could expect to happen when running the command without this flag.",
},
verbose: {
flag: ["--verbose", "-v"],
value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
args,
flags: ["--verbose", "-v"],
}),
description: "Provides more detailed or extensive information about the files being generated during the process.",
},
help: {
flag: ["--help", "-h"],
value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
args,
flags: ["--help", "-h"],
}),
description: "Show this help message.",
},
};
if (flags.help.value || !componentKey) {
(0, createFlagHelpText_1.createFlagHelpText)({
command: "cni-component-manifest COMPONENT_KEY",
flags,
});
if (!componentKey) {
console.error("\nError: COMPONENT_KEY is required.");
}
process.exit(!componentKey ? 1 : 0);
}
if (!cniDir) {
console.error("Please run this script using npm or yarn.");
process.exit(1);
}
// Fetch component data from API
const component = yield (0, _1.fetchComponentDataForManifest)({
componentKey,
isPrivate: flags.isPrivate.value || false,
});
const reusableConnectionStableKeys = yield (0, _1.fetchConnectionStableKeys)({
componentKey: component.key,
isPrivate: flags.isPrivate.value || false,
});
// Generate the manifest
const destinationDir = node_path_1.default.join(process.cwd(), "src", "manifests", component.key);
const templatesDir = node_path_1.default.join(__dirname, "..", "componentManifest", "templates");
const dryRun = flags.dryRun.value;
const verbose = flags.verbose.value;
if (verbose) {
console.info(`Creating component manifest for ${component.display.label}...`);
}
(0, removeComponentManifest_1.removeComponentManifest)({ destinationDir, verbose });
// Create the directory structure
(0, node_fs_1.mkdirSync)(destinationDir, { recursive: true });
// Generate the source files
yield yield (0, createTemplate_1.createTemplate)({
source: node_path_1.default.join(templatesDir, "index.ts.ejs"),
destination: node_path_1.default.join(destinationDir, "index.ts"),
data: {
component,
},
verbose,
dryRun,
});
yield (0, createActions_1.createActions)({
component,
dryRun,
verbose,
sourceDir: templatesDir,
destinationDir,
});
yield (0, createTriggers_1.createTriggers)({
component,
dryRun,
verbose,
sourceDir: templatesDir,
destinationDir,
});
yield (0, createConnections_1.createConnections)({
component,
dryRun,
verbose,
sourceDir: templatesDir,
destinationDir,
reusableConnectionStableKeys,
});
yield (0, createDataSources_1.createDataSources)({
component,
dryRun,
verbose: flags.verbose.value,
sourceDir: templatesDir,
destinationDir,
});
console.info(`Component manifest created successfully for ${component.display.label} in ${destinationDir}!\nEnsure that you update your componentRegistry file accordingly.`);
});
exports.runMain = runMain;