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).

196 lines (164 loc) 8.39 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."); }; }); parcelRegister("67Y3J", function(module, exports) { /** * Gets the output path from command line arguments or defaults to current working directory * @returns {string} The resolved output path */ const $4761fc068f0672f1$var$getOutputPath = ()=>{ $9TgTs$nconf.argv(); return $9TgTs$nconf.get("output") || process.cwd(); }; /** * Writes data to a file in the specified output directory * @param {string} data - The data to write * @param {string} filename - The name of the file to create * @param {string} outputPath - The output directory path (optional, defaults to current working directory) */ const $4761fc068f0672f1$var$writeFile = (data, filename, outputPath = null)=>{ const outputDir = $9TgTs$path.resolve(outputPath || $4761fc068f0672f1$var$getOutputPath()); const outputFile = $9TgTs$path.join(outputDir, filename); // Ensure the output directory exists if (!$9TgTs$fs.existsSync(outputDir)) $9TgTs$fs.mkdirSync(outputDir, { recursive: true }); $9TgTs$fs.writeFile(outputFile, data, "utf8", (err)=>{ if (err) console.error(`Error writing ${filename}:`, err); else console.log(`${filename} has been saved successfully to: ${outputFile}`); }); }; /** * Writes JSON data to a file in the specified output directory * @param {Object} data - The data object to stringify and write * @param {string} filename - The name of the file to create * @param {string} outputPath - The output directory path (optional, defaults to current working directory) * @param {number} indent - Number of spaces for indentation (optional, defaults to 2) */ const $4761fc068f0672f1$var$writeJsonFile = (data, filename, outputPath = null, indent = 2)=>{ const jsonData = JSON.stringify(data, null, indent); $4761fc068f0672f1$var$writeFile(jsonData, filename, outputPath); }; module.exports = { getOutputPath: $4761fc068f0672f1$var$getOutputPath, writeFile: $4761fc068f0672f1$var$writeFile, writeJsonFile: $4761fc068f0672f1$var$writeJsonFile }; }); 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(); var $67Y3J = parcelRequire("67Y3J"); var $217549c0d571b90f$require$writeFile = $67Y3J.writeFile; 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$writeTokenFile = (data)=>{ $217549c0d571b90f$require$writeFile(data, "tokens.json"); }; const $217549c0d571b90f$var$generate = (data, toFile)=>{ if (!toFile) console.log(data); return toFile ? $217549c0d571b90f$var$writeTokenFile(data) : data; }; // Export the function writeFile as default module.exports = $217549c0d571b90f$var$generate($217549c0d571b90f$var$tokensData, $217549c0d571b90f$var$generateToFile); //# sourceMappingURL=generateTokens.js.map