UNPKG

@salesforce-ux/design-system-data

Version:

This package contains scripts to generate data and data assets for aspects of the Salesforce Lightning Design System (SLDS).

150 lines (124 loc) 6.42 kB
var $9TgTs$path = require("path"); var $9TgTs$fs = require("fs"); var $9TgTs$nconf = require("nconf"); var $9TgTs$immutable = require("immutable"); var $9TgTs$dataeither = require("data.either"); var $9TgTs$theo = require("theo"); var $parcel$global = globalThis; var $parcel$modules = {}; var $parcel$inits = {}; var parcelRequire = $parcel$global["parcelRequire1c17"]; if (parcelRequire == null) { parcelRequire = function(id) { if (id in $parcel$modules) { return $parcel$modules[id].exports; } if (id in $parcel$inits) { var init = $parcel$inits[id]; delete $parcel$inits[id]; var module = {id: id, exports: {}}; $parcel$modules[id] = module; init.call(module.exports, module, module.exports); return module.exports; } var err = new Error("Cannot find module '" + id + "'"); err.code = 'MODULE_NOT_FOUND'; throw err; }; parcelRequire.register = function register(id, init) { $parcel$inits[id] = init; }; $parcel$global["parcelRequire1c17"] = parcelRequire; } var parcelRegister = parcelRequire.register; parcelRegister("18Px7", function(module, exports) { module.exports = function findNodeModules(baseDir) { let currentDir = baseDir; while(currentDir !== $9TgTs$path.resolve(currentDir, "..")){ // Stop when reaching the root const candidatePath = $9TgTs$path.join(currentDir, "node_modules"); if ($9TgTs$fs.existsSync(candidatePath)) return candidatePath; currentDir = $9TgTs$path.resolve(currentDir, ".."); } throw new Error("Unable to find node_modules directory."); }; }); var $8951591ab679419d$exports = {}; // @preval // Copyright (c) 2015-present, Salesforce, Inc. All rights reserved // Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license var $8951591ab679419d$var$$parcel$__dirname = $9TgTs$path.resolve(__dirname, "../src/preval"); var $18Px7 = parcelRequire("18Px7"); const $8951591ab679419d$var$nodeModulesDir = $18Px7($8951591ab679419d$var$$parcel$__dirname); const $8951591ab679419d$var$sldsModule = "@salesforce-ux/design-system"; const $8951591ab679419d$var$tokenPath = $9TgTs$path.resolve.bind($9TgTs$path, `${$8951591ab679419d$var$nodeModulesDir}/${$8951591ab679419d$var$sldsModule}/design-tokens`); const $8951591ab679419d$var$convert = (file)=>$9TgTs$immutable.fromJS({ name: $9TgTs$path.basename(file, ".yml"), tokens: JSON.parse($9TgTs$theo.convertSync({ transform: { type: "web", file: file, includeMeta: true, includeRawValue: true }, format: { type: "raw.json" } })) }); const $8951591ab679419d$var$clean = (tokenSet)=>tokenSet.updateIn([ "tokens", "props" ], (props)=>props.map((prop)=>prop).toList()); const $8951591ab679419d$var$rem2px = (value, baseFontPercentage = 100, baseFontPixel = 16)=>value.match(/rem$/) ? `${value.replace(/rem$/g, "") * baseFontPixel * (baseFontPercentage / 100)}px` : value; const $8951591ab679419d$var$addPxValue = (tokenSet)=>tokenSet.updateIn([ "tokens", "props" ], (props)=>props.map((prop)=>prop.get("value").match(/rem(\s|$)/) ? prop.set("pxValue", prop.get("value").split(/\s+/).map((value)=>$8951591ab679419d$var$rem2px(value)).join(" ")) : prop)); const $8951591ab679419d$var$indexOf = (all, name)=>all.findIndex((tokenSet)=>tokenSet.get("name") === name); const $8951591ab679419d$var$generate = ()=>$9TgTs$dataeither.of(true).map(()=>$9TgTs$immutable.List([ $8951591ab679419d$var$tokenPath("primitive.yml"), $8951591ab679419d$var$tokenPath("theme-one-salesforce.yml"), $8951591ab679419d$var$tokenPath("force-mq-commons.yml"), $8951591ab679419d$var$tokenPath("form-factor-large.yml") ]).map($8951591ab679419d$var$convert)).map((all)=>{ const s1BaseIndex = $8951591ab679419d$var$indexOf(all, "ui-one"); const s1BaseLargeIndex = $8951591ab679419d$var$indexOf(all, "form-factor-large"); const s1BaseLarge = all.getIn([ s1BaseLargeIndex, "tokens" ]); return all.updateIn([ s1BaseIndex, "tokens" ], (tokens)=>$9TgTs$immutable.List.of("aliases", "props").reduce((tokens, key)=>tokens.update(key, (items)=>items.map((item, itemKey)=>s1BaseLarge.get(key).has(itemKey) ? s1BaseLarge.getIn([ key, itemKey ]) : item)), tokens)); }).map((all)=>all.map($8951591ab679419d$var$clean).map($8951591ab679419d$var$addPxValue)).get(); $8951591ab679419d$exports = $8951591ab679419d$var$generate(); const $217549c0d571b90f$var$tokenSets = $9TgTs$immutable.fromJS($8951591ab679419d$exports); const $217549c0d571b90f$var$tokensByCategory = $217549c0d571b90f$var$tokenSets.flatMap((set)=>set.getIn([ "tokens", "props" ])).filter((token)=>token.get("scope") !== "component").filter((token)=>token.get("deprecated") !== true).reduce((tokens, token)=>tokens.set(token.get("name"), token), $9TgTs$immutable.Map()).reduce((categories, token)=>categories.update(token.get("category"), (tokens)=>tokens ? tokens.push(token) : $9TgTs$immutable.List.of(token)), $9TgTs$immutable.Map())// Sort alphanumerically .map((tokenCategory)=>tokenCategory.sort((token1, token2)=>token1.get("name").localeCompare(token2.get("name"), undefined, { numeric: true, sensitivity: "base" }))); $9TgTs$nconf.argv(); const $217549c0d571b90f$var$generateToFile = $9TgTs$nconf.get("to-file"); const $217549c0d571b90f$var$tokensData = JSON.stringify($217549c0d571b90f$var$tokenSets); const $217549c0d571b90f$var$writeFile = (data)=>{ $9TgTs$fs.writeFile("tokens.json", $217549c0d571b90f$var$tokensData, "utf8", (err)=>{ if (err) console.error("Error writing JSON file:", err); else console.log("JSON file has been saved successfully."); }); }; const $217549c0d571b90f$var$generate = (data, toFile)=>{ if (!toFile) console.log(data); return toFile ? $217549c0d571b90f$var$writeFile(data) : data; }; // Export the function writeFile as default module.exports = $217549c0d571b90f$var$generate($217549c0d571b90f$var$tokensData, $217549c0d571b90f$var$generateToFile); //# sourceMappingURL=generateTokens.js.map