@constructor-io/constructorio-connect-cli
Version:
CLI tool to enable users to interface with the Constructor Connect Ecosystem
44 lines (43 loc) • 1.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTemplateFiles = getTemplateFiles;
const path_1 = __importDefault(require("path"));
const find_deep_files_1 = require("../helpers/find-deep-files");
const path_2 = require("../customer/path");
/**
* Get a prompt-ready list of template files in the user repository
*/
async function getTemplateFiles() {
const filePath = path_1.default.join("src", "templates");
const files = getTemplatePaths(filePath);
const filteredFiles = files.filter((file) => file.endsWith(".jsonata") && !file.includes("helpers"));
return filteredFiles.map((file) => {
const relativePath = (0, path_2.cleanupPath)(file);
return {
name: relativePath,
value: relativePath,
};
});
}
/**
* @param typePath The full type path. E.g.
* - src/templates/item
* - src/templates/variation
* @returns A list of template paths for the given type. E.g.
* - src/templates/item/1.jsonata
* - src/templates/item/2.jsonata
*/
function getTemplatePaths(typePath) {
try {
return (0, find_deep_files_1.findDeepFiles)(typePath);
}
catch (error) {
if (error instanceof Error && error.message.includes("ENOENT")) {
return [];
}
throw error;
}
}