UNPKG

@plone/registry

Version:

Add-on and configuration registry for Plone and for JavaScript and TypeScript-based apps.

80 lines (77 loc) 3.33 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/addon-registry/create-theme-loader.ts var create_theme_loader_exports = {}; __export(create_theme_loader_exports, { createThemeAddonsLoader: () => createThemeAddonsLoader, getThemeLoaderCode: () => getThemeLoaderCode, nameFromPackage: () => nameFromPackage }); module.exports = __toCommonJS(create_theme_loader_exports); var import_fs = __toESM(require("fs"), 1); var import_tmp = __toESM(require("tmp"), 1); var import_crypto_random_string = __toESM(require("crypto-random-string"), 1); var titleCase = (w) => w.slice(0, 1).toUpperCase() + w.slice(1, w.length); function nameFromPackage(name) { name = name.replace(/[@~./\\:\s]/gi, "") || (0, import_crypto_random_string.default)({ length: 10, characters: "abcdefghijk" }); return name.split("-").map((w, i) => i > 0 ? titleCase(w) : w).join(""); } function getThemeLoaderCode(name, customThemeAddons = []) { let buf = `/* This file is autogenerated. Don't change it directly. Add a ./theme/_${name}.scss in your add-on to load your theme customizations in the current theme. */ `; customThemeAddons.forEach((addon) => { const customization = `${addon}/theme/${name}`; const line = `@import '${customization}'; `; buf += line; }); return buf; } function createThemeAddonsLoader({ main, variables }) { const addonsThemeLoaderVariablesPath = import_tmp.default.tmpNameSync({ postfix: ".scss" }); const addonsThemeLoaderMainPath = import_tmp.default.tmpNameSync({ postfix: ".scss" }); import_fs.default.writeFileSync( addonsThemeLoaderVariablesPath, getThemeLoaderCode("variables", variables) ); import_fs.default.writeFileSync(addonsThemeLoaderMainPath, getThemeLoaderCode("main", main)); return [addonsThemeLoaderVariablesPath, addonsThemeLoaderMainPath]; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createThemeAddonsLoader, getThemeLoaderCode, nameFromPackage });