New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@icon-magic/distribute

Package Overview
Dependencies
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@icon-magic/distribute - npm Package Compare versions

Comparing version 2.2.10-beta.0 to 2.2.11-beta.0

icon-magic-distribute-2.2.4-beta.0.tgz

5

package.json
{
"name": "@icon-magic/distribute",
"version": "2.2.10-beta.0",
"version": "2.2.11-beta.0",
"description": "Icon magic distribute package.",

@@ -26,4 +26,3 @@ "main": "dist/src/index.js",

"xmldom": "^0.5.0"
},
"gitHead": "86fd6a15b3e33f23b8f2574e30b968eb43dbd5ce"
}
}

12

src/create-icon-template.ts

@@ -14,2 +14,3 @@

* @param outputPath path to write to
* @param doNotRemoveSuffix boolean, when true will keep the "-mixed" suffix in file name when distributing to hbs.
*/

@@ -19,2 +20,3 @@ export async function createHbs(

outputPath: string,
doNotRemoveSuffix: boolean
): Promise<void> {

@@ -30,5 +32,9 @@ for (const asset of assets) {

const id = el.getAttributeNode('id');
const iconName = id ? id.value : '';
let iconName = id ? id.value : '';
// Strip id
el.removeAttribute('id');
// Remove the "-mixed" suffix from the name. File will have same name as light version.
if (!doNotRemoveSuffix && asset.colorScheme === 'mixed') {
iconName = iconName.replace(/-mixed$/, '');
}

@@ -41,7 +47,5 @@ // add splattributes to the hbs file

// the string replace below is an ugly hack to remove the empty string
fs.writeFile(path.join(outputPath, `${iconName}.hbs`), serializeToString(xml).replace(/...attributes=\"\"/g, '...attributes'), (err) => {
if (err) throw err;
});
fs.writeFileSync(path.join(outputPath, `${iconName}.hbs`), serializeToString(xml).replace(/...attributes=\"\"/g, '...attributes'));
}
}

@@ -21,2 +21,4 @@ import { Asset, Icon, IconSet, SpriteConfig } from '@icon-magic/icon-models';

* @param groupByCategory (for sprite creation) whether to group by the category attribute
* @param colorScheme array of strings matching the colorScheme attributes of the icon i.e: `light`, `dark`, `mixed`.
* @param doNotRemoveSuffix boolean, when true will keep the "-mixed" suffix in file name when distributing to hbs.
* @returns promise after completion

@@ -29,2 +31,4 @@ */

outputAsHbs: boolean,
colorScheme: string[],
doNotRemoveSuffix: boolean
): Promise<void> {

@@ -38,4 +42,18 @@ // Sort icons so it looks pretty in .diff

for (const icon of icons) {
LOGGER.debug(`calling distributeSvg on ${icon.iconName}: ${icon.iconPath}`);
LOGGER.debug(`calling distributeSvg on ${icon.iconName}: ${icon.iconPath} with colorScheme: ${colorScheme}`);
if (!doNotRemoveSuffix && colorScheme.includes('mixed')){
LOGGER.warn(`Warning: By default the "-mixed" suffix is trimmed from the file name when distributed to hbs. The file name will be the SAME as the light variant. Use the --doNotRemoveSuffix flag to keep the "-mixed" in the file name.`);
}
const assets = getIconFlavorsByType(icon, 'svg');
// Further filter the icons by matching the assets's colorScheme to the commander option --colorScheme
const assetsByColorScheme = assets.filter(asset => {
if (asset.colorScheme) {
return colorScheme.includes(asset.colorScheme);
}
// Light variants can either have colorScheme: `light`, null, or undefined
return colorScheme.includes('light');
});
const distributeConfig = icon.distribute;

@@ -52,4 +70,4 @@ const svgConfig = distributeConfig && distributeConfig.svg;

variantsToFilter && variantsToFilter.length
? partitionAssetsForSprite(assets, variantsToFilter)
: { assetsToAddToSprite: assets, assetsNoSprite: assets };
? partitionAssetsForSprite(assetsByColorScheme, variantsToFilter)
: { assetsToAddToSprite: assetsByColorScheme, assetsNoSprite: assetsByColorScheme };

@@ -67,3 +85,3 @@ const iconHasSpriteConfig = !(

: outputPath;
await createHbs(assets, destPath);
await createHbs(assetsByColorScheme, destPath, doNotRemoveSuffix);
}

@@ -70,0 +88,0 @@ catch(e) {

@@ -17,2 +17,4 @@ import { IconConfigHash, IconSet } from '@icon-magic/icon-models';

* @param groupByCategory (for sprite creation) whether to group by the category attribute
* @param colorScheme array of strings matching the colorScheme attributes of the icon ie: `light`, `dark`, `mixed`.
* @param doNotRemoveSuffix boolean, when true will keep the "-mixed" suffix in file name when distributing to hbs.
* @retuns promise after completion

@@ -25,5 +27,7 @@ */

groupByCategory = true,
outputAsHbs = false
outputAsHbs = false,
colorScheme: string[] = ['light', 'dark'],
doNotRemoveSuffix = false
): Promise<void> {
LOGGER.debug(`entering distribute with ${type}`);
LOGGER.debug(`entering distribute with ${type} and colorSchemes: ${colorScheme}`);
const iconSet = new IconSet(iconConfig, true);

@@ -40,3 +44,3 @@ switch (type) {

case 'svg': {
await distributeSvg(iconSet, outputPath, groupByCategory, outputAsHbs);
await distributeSvg(iconSet, outputPath, groupByCategory, outputAsHbs, colorScheme, doNotRemoveSuffix);
break;

@@ -47,5 +51,5 @@ }

await distributeByResolution(iconSet, outputPath);
await distributeSvg(iconSet, outputPath, groupByCategory, outputAsHbs);
await distributeSvg(iconSet, outputPath, groupByCategory, outputAsHbs, colorScheme, doNotRemoveSuffix);
}
}
}

@@ -340,2 +340,26 @@ import * as configReader from '@icon-magic/config-reader';

it('it trims "-mixed" from end of hbs file name', async () => {
const iconSetWordmark = configReader.getIconConfigSet(new Array(path.resolve(FIXTURES, 'input/wordmark')));
await distributeByType(iconSetWordmark, `${output}/wordmark`, 'svg', false, true, ['mixed'], false);
try {
const files = fs.readdirSync(`${output}/wordmark`);
assert.ok(files.includes('wordmark-large.hbs'));
assert.ok(files.includes('wordmark-medium.hbs'));
} catch (err) {
assert.ok(false, err);
}
});
it('it does not trim "-mixed" from end of hbs file name', async () => {
const iconSetWordmark = configReader.getIconConfigSet(new Array(path.resolve(FIXTURES, 'input/wordmark')));
await distributeByType(iconSetWordmark, `${output}/wordmark/untrimmed`, 'svg', false, true, ['mixed'], true);
try {
const files = fs.readdirSync(`${output}/wordmark/untrimmed`);
assert.ok(files.includes('wordmark-large-mixed.hbs'));
assert.ok(files.includes('wordmark-medium-mixed.hbs'));
} catch (err) {
assert.ok(false, err);
}
});
it('sprites are always arranged alphabetically', async () => {

@@ -342,0 +366,0 @@ await distributeByType(iconSet, output, 'svg', true);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc