Skip to content

Commit

Permalink
Merge pull request #11 from forcedotcom/j.wright-init
Browse files Browse the repository at this point in the history
@W-17006097@ feat: new icon repo for A4D & sfdx plugins
  • Loading branch information
interfaceconjurer authored Oct 29, 2024
2 parents 6312253 + 4bc4470 commit cab1de9
Show file tree
Hide file tree
Showing 20 changed files with 2,676 additions and 4,935 deletions.
29 changes: 29 additions & 0 deletions .fantasticonrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const package = require('./package.json');
const codepoints = require('./src/template/mapping.json');

module.exports = {
name: 'salesforcedx-icons',
prefix: 'salesforcedx-icon',
codepoints: codepoints,
inputDir: './src/icons',
outputDir: './dist',
fontTypes: ['ttf', 'woff2'],
normalize: true,
assetTypes: ['css', 'html'],
templates: {
html: './src/template/preview.hbs',
css: './src/template/styles.hbs'
},
formatOptions: {
ttf: {
url: package.url,
description: package.description,
version: package.fontVersion
},
woff2: {
url: package.url,
description: package.description,
version: package.fontVersion
}
}
};
28 changes: 0 additions & 28 deletions .github/workflows/test.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -- CLEAN

# Generated font and icon gallery
dist/

# use yarn by default, so ignore npm
package-lock.json

Expand Down
136 changes: 19 additions & 117 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,133 +1,35 @@
{
"name": "@salesforce/library-template",
"version": "0.0.1",
"description": "Template npm library for Salesforce CLI and VSCode Extensions",
"name": "@salesforce/salesforcedx-icons",
"version": "0.1.0",
"description": "The icon font for SFDX VSCode Extensions",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "BSD-3-Clause",
"scripts": {
"build": "wireit",
"clean": "sf-clean",
"clean-all": "sf-clean all",
"compile": "wireit",
"docs": "sf-docs",
"format": "wireit",
"link-check": "wireit",
"lint": "wireit",
"lint-fix": "yarn sf-lint --fix",
"prepack": "sf-prepack",
"prepare": "sf-install",
"test": "wireit",
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"test:nuts:local": "mocha \"**/local/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"test:only": "wireit"
"clean": "node ./scripts/reset.js",
"svgo": "svgo -f ./src/icons/ --config svgo.config.js",
"sprite": "node ./scripts/svg-sprite.js --outDir dist --outFile salesforcedx-icons.svg",
"export-to-ts": "node ./scripts/export-to-ts.js -f ./src/template/mapping.json > ./dist/salesforcedx-iconsLibrary.ts",
"export-to-csv": "node ./scripts/export-to-csv.js -f ./dist/salesforcedx-icons.ttf > ./dist/salesforcedx-icons.csv",
"fonts": "fantasticon",
"build": "npm run clean && npm run svgo && npm run fonts && npm run export-to-ts && npm run export-to-csv && npm run sprite",
"release": "release-it"
},
"repository": "forcedotcom/library-template",
"bugs": {
"url": "https://github.com/forcedotcom/library-template/issues"
},
"homepage": "https://github.com/forcedotcom/library-template#readme",
"files": [
"lib",
"!lib/**/*.map",
"messages"
],
"dependencies": {
"@salesforce/core": "^6.7.6",
"@salesforce/kit": "^3.0.15",
"@salesforce/ts-types": "^2.0.9"
},
"devDependencies": {
"@salesforce/cli-plugins-testkit": "^5.3.35",
"@salesforce/dev-scripts": "^8.4.2",
"eslint-plugin-sf-plugin": "^1.20.10",
"ts-node": "^10.9.2",
"ts-patch": "^3.2.1",
"typescript": "^5.6.3"
"ansi-regex": ">=5.0.1",
"fantasticon": "^1.2.3",
"opentype.js": "^1.3.3",
"release-it": "^17.10.0",
"svg-sprite": "^2.0.4",
"svgo": "2.7.0"
},
"publishConfig": {
"access": "public"
},
"wireit": {
"build": {
"dependencies": [
"compile",
"lint"
]
},
"compile": {
"command": "tsc -p . --pretty --incremental",
"files": [
"src/**/*.ts",
"**/tsconfig.json",
"messages/**"
],
"output": [
"lib/**",
"*.tsbuildinfo"
],
"clean": "if-file-deleted"
},
"format": {
"command": "prettier --write \"+(src|test|schemas)/**/*.+(ts|js|json)|command-snapshot.json\"",
"files": [
"src/**/*.ts",
"test/**/*.ts",
"schemas/**/*.json",
"command-snapshot.json",
".prettier*"
],
"output": []
},
"lint": {
"command": "eslint src test --color --cache --cache-location .eslintcache",
"files": [
"src/**/*.ts",
"test/**/*.ts",
"messages/**",
"**/.eslint*",
"**/tsconfig.json"
],
"output": []
},
"test:compile": {
"command": "tsc -p \"./test\" --pretty",
"files": [
"test/**/*.ts",
"**/tsconfig.json"
],
"output": []
},
"test": {
"dependencies": [
"test:only",
"test:compile",
"link-check"
]
},
"test:only": {
"command": "nyc mocha \"test/**/*.test.ts\"",
"env": {
"FORCE_COLOR": "2"
},
"files": [
"test/**/*.ts",
"src/**/*.ts",
"**/tsconfig.json",
".mocha*",
"!*.nut.ts",
".nycrc"
],
"output": []
},
"link-check": {
"command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error",
"files": [
"./*.md",
"./!(CHANGELOG).md",
"messages/**/*.md"
],
"output": []
}
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
49 changes: 49 additions & 0 deletions scripts/export-to-csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// https://github.com/bitinn/character-map

var opts = require("minimist")(process.argv.slice(2));
var opentype = require("opentype.js");

if (!opts.f || typeof opts.f !== "string") {
console.log(
"use -f to specify your font path, TrueType and OpenType supported"
);
return;
}

opentype.load(opts.f, function(err, font) {
if (err) {
console.log(err);
return;
}

var glyphs = font.glyphs.glyphs;
if (!glyphs || glyphs.length === 0) {
console.log("no glyphs found in this font");
return;
}

var table = "short_name,character,unicode";
for (glyphIndex in glyphs) {
var glyph = glyphs[glyphIndex];
var name = glyph.name;
var unicode = glyph.unicodes.map(formatUnicode).join(", ");
unicode = unicode.split(",")[0];
// var character = String.fromCharCode(glyph.unicode);
var character = String.fromCharCode(parseInt(glyph.unicodes.map(formatUnicode)[0], 16));
if (unicode) {
table += "\n" + name + "," + character + "," + unicode;
}

}

console.log(table);
});

function formatUnicode(unicode) {
unicode = unicode.toString(16);
if (unicode.length > 4) {
return ("000000" + unicode.toUpperCase()).substr(-6);
} else {
return ("0000" + unicode.toUpperCase()).substr(-4);
}
}
49 changes: 49 additions & 0 deletions scripts/export-to-ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require('fs');
var opts = require("minimist")(process.argv.slice(2));

if (!opts.f || typeof opts.f !== "string") {
console.log("use -f to specify your mapping.json path");
return;
}


fs.readFile(opts.f, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}

try {
const mapping = JSON.parse(data);

console.log("/*---------------------------------------------------------------------------------------------");
console.log(" * Copyright (c) Microsoft Corporation. All rights reserved.");
console.log(" * Licensed under the MIT License. See License.txt in the project root for license information.");
console.log(" *--------------------------------------------------------------------------------------------*/");
console.log("import { register } from 'vs/base/common/codiconsUtil';");
console.log("");
console.log("");
console.log("// This file is automatically generated by (microsoft/vscode-codicons)/scripts/export-to-ts.js");
console.log("// Please don't edit it, as your changes will be overwritten.");
console.log("// Instead, add mappings to codiconsDerived in codicons.ts.");
console.log("export const salesforcedx_iconsLibrary = {");

Object.entries(mapping).forEach(([name, value]) => {
console.log(`\t${toCamelCase(name)}: register('${name}', ${decimalToHex(value)}),`);
});

console.log("} as const;");

} catch (error) {
console.error('Error parsing JSON:', error);
}
});


function toCamelCase(name) {
return name.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
}

function decimalToHex(decimal) {
return '0x' + decimal.toString(16);
}
13 changes: 13 additions & 0 deletions scripts/reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fs = require("fs");
const rimraf = require("rimraf");

const outputDirectory = "dist";

// clear dist folder
rimraf(outputDirectory, function () {

console.log(`deleted "${outputDirectory}" folder`);

// re-create dist folder
fs.mkdirSync(outputDirectory);
});
39 changes: 39 additions & 0 deletions scripts/svg-sprite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const SVGSpriter = require("svg-sprite");
const path = require("path");
const fs = require("fs");
const opts = require("minimist")(process.argv.slice(2));
const config = {
mode: {
symbol: {
dest: opts.outDir,
sprite: opts.outFile,
},
},
};
const spriter = new SVGSpriter(config);
const mapping = require("../src/template/mapping.json");

const mappingEntries = Object.entries(mapping);

const findNames = (symbol) => {
return mappingEntries.filter(([_, s]) => s === symbol).map(([name]) => name);
};

mappingEntries.forEach(([mappedName, symbol]) => {
const file = path.resolve(`./src/icons/${mappedName}.svg`);

if (fs.existsSync(file)) {
for (const name of findNames(symbol)) {
spriter.add(
path.resolve(`./src/icons/${name}.svg`),
name + ".svg",
fs.readFileSync(file, "utf-8"),
);
}
}
});

spriter.compile(function (error, result, data) {
fs.mkdirSync(path.resolve(opts.outDir), { recursive: true });
fs.writeFileSync(result.symbol.sprite.path, result.symbol.sprite.contents);
});
Loading

0 comments on commit cab1de9

Please sign in to comment.