@constructor-io/constructorio-connect-cli
Version:
CLI tool to enable users to interface with the Constructor Connect Ecosystem
45 lines (44 loc) • 1.86 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCandidateFixtures = getCandidateFixtures;
const path_1 = __importDefault(require("path"));
const errors_1 = require("@oclif/core/errors");
const find_deep_files_1 = require("../helpers/find-deep-files");
const extract_template_type_1 = require("../helpers/extract-template-type");
const path_2 = require("../customer/path");
/**
* @returns The CLEANED fixtures paths as prompt choices
*/
function getCandidateFixtures(templatePath) {
const templateType = (0, extract_template_type_1.extractTemplateType)(templatePath);
const fixtureType = templateType === "grouping"
? "variation" //
: templateType;
let fixtureFullPaths;
try {
fixtureFullPaths = (0, find_deep_files_1.findDeepFiles)(path_1.default.join("src", "fixtures", fixtureType));
}
catch (error) {
if (error instanceof Error && error.message.includes("ENOENT")) {
throw new errors_1.CLIError(`Directory for ${fixtureType} fixtures (at src/fixtures/${fixtureType}) does not exist.`, {
suggestions: [
`If the ${fixtureType} directory has been deleted, recreate it and add fixtures to it.`,
`Ensure the ${fixtureType} directory is named correctly`,
],
});
}
throw error;
}
return fixtureFullPaths
.filter((fixturePath) => path_1.default.extname(fixturePath) === ".json")
.map((fixturePath) => {
const fixtureRelativePath = (0, path_2.cleanupPath)(fixturePath);
return {
name: fixtureRelativePath,
value: fixtureRelativePath,
};
});
}