UNPKG

@wordpress/e2e-test-utils

Version:
59 lines (58 loc) 1.93 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var templates_exports = {}; __export(templates_exports, { deleteAllTemplates: () => deleteAllTemplates }); module.exports = __toCommonJS(templates_exports); var import_rest_api = require("./rest-api"); const PATH_MAPPING = { wp_template: "/wp/v2/templates", wp_template_part: "/wp/v2/template-parts" }; async function deleteAllTemplates(type) { const path = PATH_MAPPING[type]; if (!path) { throw new Error(`Unsupported template type: ${type}.`); } const templates = await (0, import_rest_api.rest)({ path }); if (!templates?.length) { return; } for (const template of templates) { if (!template?.wp_id) { continue; } try { await (0, import_rest_api.rest)({ path: `${path}/${template.id}?force=true`, method: "DELETE" }); } catch (responseError) { console.warn( `deleteAllTemplates failed to delete template (id: ${template.wp_id}) with the following error`, responseError ); } } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { deleteAllTemplates }); //# sourceMappingURL=templates.js.map