@prismatic-io/spectral
Version:
Utility library for building Prismatic connectors and code-native integrations
140 lines (139 loc) • 6.57 kB
JavaScript
;
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
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 fs_extra_1 = require("fs-extra");
const path_1 = __importDefault(require("path"));
const util_1 = require("../../util");
const createFlagHelpText_1 = require("../utils/createFlagHelpText");
const getFlagBooleanValue_1 = require("../utils/getFlagBooleanValue");
const getFlagStringValue_1 = require("../utils/getFlagStringValue");
const index_1 = require("./index");
const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
const componentDir = process.cwd();
const componentDistDir = path_1.default.join(componentDir, "dist", "index.js");
const args = process.argv.slice(2);
const flags = {
name: {
flag: ["--name", "-n"],
value: (0, getFlagStringValue_1.getFlagsStringValue)({
args,
flags: ["--name", "-n"],
}),
description: "The name of the component manifest. Defaults to the name of the current component being generated.",
},
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.",
},
output_dir: {
flag: ["--output-dir", "-o"],
value: (0, getFlagStringValue_1.getFlagsStringValue)({
args,
flags: ["--output-dir", "-o"],
}),
description: "The output directory for the component manifest. Defaults to the sibling of the current component directory.",
},
registry: {
flag: ["--registry", "-r"],
value: (0, getFlagStringValue_1.getFlagsStringValue)({
args,
flags: ["--registry", "-r"],
}),
description: "The registry to publish the component manifest to (as a URI). This is where your package will be published. If not specified, it defaults to your system's default registry.",
},
dry_run: {
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.",
},
skip_signature_verify: {
flag: ["--skip-signature-verify"],
value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
args,
flags: ["--skip-signature-verify"],
}),
description: "This skips the signature verification process, always returning a component signature in the component manifest.",
},
version: {
flag: ["--version"],
value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({ args, flags: ["--version"] }),
description: "Display the version of @prismatic-io/spectral this component manifest generator uses.",
},
help: {
flag: ["--help", "-h"],
value: (0, getFlagBooleanValue_1.getFlagsBooleanValue)({
args,
flags: ["--help", "-h"],
}),
description: "Show this help message.",
},
};
if (flags.version.value) {
const { version } = require("../../../package.json");
console.log(version);
process.exit(0);
}
if (flags.help.value) {
(0, createFlagHelpText_1.createFlagHelpText)({
command: "component-manifest",
flags,
});
process.exit(0);
}
if (!componentDir) {
console.error("Please run this script using npm or yarn.");
process.exit(1);
}
if (!(0, fs_extra_1.existsSync)(componentDistDir)) {
console.error("Component build directory `dist` does not exist. Please verify that the component has been built.");
process.exit(1);
}
const component = require(componentDistDir).default;
if (!component ||
!(0, util_1.isObjectWithTruthyKeys)(component, ["key", "display"]) ||
!(0, util_1.isObjectWithOneTruthyKey)(component, ["actions", "connections", "dataSources"])) {
console.error("Component is invalid.");
process.exit(1);
}
const packageJson = (0, fs_extra_1.readJsonSync)(path_1.default.join(__dirname, "../../../package.json"));
yield (0, index_1.createComponentManifest)({
component,
dryRun: flags.dry_run.value,
skipSignatureVerify: flags.skip_signature_verify.value,
packageName: (_a = flags.name.value) !== null && _a !== void 0 ? _a : `@component-manifests/${component.key}`,
dependencies: {
spectral: packageJson.version,
dependencies: packageJson.dependencies,
devDependencies: packageJson.devDependencies,
},
verbose: flags.verbose.value,
sourceDir: path_1.default.join(__dirname, "templates"),
destinationDir: flags.output_dir.value
? flags.output_dir.value
: path_1.default.join(componentDir, "..", flags.name.value ? flags.name.value : `${path_1.default.basename(componentDir)}-manifest`),
registry: (_b = flags.registry.value) !== null && _b !== void 0 ? _b : null,
});
});
exports.runMain = runMain;