From 622fd7a87054a54b1dc7f3122011bd7c1b5ce6d2 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Mon, 28 Nov 2022 10:35:25 +0100 Subject: [PATCH] Use generate codicon.css with embedded TTF instead of imported one - This removes the need to have codicon as depedency to the sprotty core - Replace rimraf wih shx - Generated file contains license links --- package.json | 3 +- packages/sprotty-elk/package.json | 3 +- packages/sprotty-protocol/package.json | 3 +- packages/sprotty/.gitignore | 1 + packages/sprotty/build/src/buildCodicon.js | 34 +++++++++++++++++++ packages/sprotty/package.json | 9 ++--- .../src/features/command-palette/di.config.ts | 2 +- packages/sprotty/tsconfig.json | 5 ++- yarn.lock | 28 ++++++++++++--- 9 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 packages/sprotty/build/src/buildCodicon.js diff --git a/package.json b/package.json index 2d16b8e6..3371048c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "publish:next": "SHA=$(git rev-parse --short HEAD) && lerna publish preminor --exact --canary --preid next.${SHA} --dist-tag next --no-git-reset --no-git-tag-version --no-push --ignore-scripts --yes --no-verify-access" }, "devDependencies": { - "lerna": "^4.0.0" + "lerna": "^4.0.0", + "shx": "^0.3.4" }, "workspaces": [ "packages/*", diff --git a/packages/sprotty-elk/package.json b/packages/sprotty-elk/package.json index 7275f03d..fb10ad8c 100644 --- a/packages/sprotty-elk/package.json +++ b/packages/sprotty-elk/package.json @@ -58,14 +58,13 @@ "jenkins-mocha": "^8.0.0", "mocha": "^7.2.0", "reflect-metadata": "^0.1.13", - "rimraf": "^3.0.2", "semver": "^7.3.5", "ts-node": "^10.4.0", "typescript": "~4.8.4" }, "scripts": { "prepare": "yarn run clean && yarn run build", - "clean": "rimraf lib artifacts", + "clean": "shx rm -fr lib artifacts", "build": "tsc -p ./tsconfig.json && yarn run lint", "watch": "tsc -w -p ./tsconfig.json", "lint": "eslint -c ../../configs/.eslintrc.js \"src/**/!(*.spec.ts*)\"", diff --git a/packages/sprotty-protocol/package.json b/packages/sprotty-protocol/package.json index ba94e1aa..1bbeca6f 100644 --- a/packages/sprotty-protocol/package.json +++ b/packages/sprotty-protocol/package.json @@ -38,13 +38,12 @@ "eslint-plugin-header": "^3.1.1", "eslint-plugin-no-null": "^1.0.2", "mocha": "^7.2.0", - "rimraf": "^3.0.2", "semver": "^7.3.5", "typescript": "~4.8.4" }, "scripts": { "prepare": "yarn run clean && yarn run build", - "clean": "rimraf lib artifacts", + "clean": "shx rm -fr lib artifacts", "build": "tsc -p ./tsconfig.json && yarn run lint", "watch": "tsc -w -p ./tsconfig.json", "lint": "eslint -c ../../configs/.eslintrc.js \"src/**/!(*.spec.ts*)\"", diff --git a/packages/sprotty/.gitignore b/packages/sprotty/.gitignore index f43ae800..9d9e1b1d 100644 --- a/packages/sprotty/.gitignore +++ b/packages/sprotty/.gitignore @@ -1,2 +1,3 @@ /lib/ /artifacts/ +/css/generated diff --git a/packages/sprotty/build/src/buildCodicon.js b/packages/sprotty/build/src/buildCodicon.js new file mode 100644 index 00000000..28ad3e1c --- /dev/null +++ b/packages/sprotty/build/src/buildCodicon.js @@ -0,0 +1,34 @@ +const fs = require('fs'); + +function transformCodicon() { + fs.readFile('../../node_modules/@vscode/codicons/dist/codicon.css', 'utf8', (err, cssData) => { + if (err) { + console.error(err); + return; + } + + if (!fs.existsSync('./css/generated')) { + fs.mkdirSync('./css/generated'); + } + + fs.readFile('../../node_modules/@vscode/codicons/dist/codicon.ttf', 'base64', (errTtf, dataTtf) => { + if (errTtf) { + console.error(errTtf); + return; + } + const ttfData = `data:font/ttf;base64,${dataTtf}`; + let alteredCssData = cssData.replace(/\"\.\/codicon\.ttf.*\"/gi, ttfData); + const licRef = `/* See license here: + * https://github.com/microsoft/vscode-codicons/blob/main/LICENSE-CODE + * https://github.com/microsoft/vscode-codicons/blob/main/LICENSE + */ + +@font-face {` + alteredCssData = alteredCssData.replace('@font-face {', licRef); + + fs.writeFileSync('./css/generated/codicon.css', alteredCssData); + }); + }); +} + +transformCodicon(); diff --git a/packages/sprotty/package.json b/packages/sprotty/package.json index 4c4c4b9d..de859da7 100644 --- a/packages/sprotty/package.json +++ b/packages/sprotty/package.json @@ -52,7 +52,6 @@ "directory": "packages/sprotty" }, "dependencies": { - "@vscode/codicons": "^0.0.25", "autocompleter": "^5.1.0", "file-saver": "^2.0.2", "inversify": "^5.1.1", @@ -65,8 +64,10 @@ "@types/file-saver": "^2.0.3", "@types/jsdom": "^16.2.13", "@types/mocha": "^7.0.2", + "@types/node": "16.18.3", "@typescript-eslint/eslint-plugin": "^5.3.0", "@typescript-eslint/parser": "^5.3.0", + "@vscode/codicons": "^0.0.32", "chai": "^4.3.6", "eslint": "^8.1.0", "eslint-config-prettier": "^8.3.0", @@ -76,7 +77,6 @@ "jsdom": "^18.0.1", "mocha": "^10.0.0", "reflect-metadata": "^0.1.13", - "rimraf": "^3.0.2", "semver": "^7.3.7", "snabbdom-to-html": "^7.0.0", "ts-mocha": "^10.0.0", @@ -85,8 +85,9 @@ }, "scripts": { "prepare": "yarn run clean && yarn run build", - "clean": "rimraf lib artifacts", - "build": "tsc -p ./tsconfig.json && yarn run lint", + "clean": "shx rm -fr lib artifacts css/generated", + "build:generate": "node ./build/src/buildCodicon.js", + "build": "yarn run build:generate && tsc -p ./tsconfig.json && yarn run lint", "watch": "tsc -w -p ./tsconfig.json", "lint": "eslint -c ../../configs/.eslintrc.js \"src/**/!(*.spec.ts*|test-helper.ts)\"", "test:cli": "ts-mocha \"./src/**/*.spec.?(ts|tsx)\"", diff --git a/packages/sprotty/src/features/command-palette/di.config.ts b/packages/sprotty/src/features/command-palette/di.config.ts index 9a943005..ac7195d3 100644 --- a/packages/sprotty/src/features/command-palette/di.config.ts +++ b/packages/sprotty/src/features/command-palette/di.config.ts @@ -13,7 +13,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import '@vscode/codicons/dist/codicon.css'; +import '../../../css/generated/codicon.css'; import { ContainerModule } from "inversify"; import { TYPES } from "../../base/types"; import { CommandPaletteActionProviderRegistry } from "./action-providers"; diff --git a/packages/sprotty/tsconfig.json b/packages/sprotty/tsconfig.json index 36b256ae..23f13c21 100644 --- a/packages/sprotty/tsconfig.json +++ b/packages/sprotty/tsconfig.json @@ -7,6 +7,9 @@ "src" ], "exclude": [ - "**/*.spec.ts", "**/*.spec.tsx", "src/utils/test-helper.ts" + "build", + "**/*.spec.ts", + "**/*.spec.tsx", + "src/utils/test-helper.ts" ] } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index c83871c1..508db234 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1428,6 +1428,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.6.tgz#6bef7a2a0ad684cf6e90fcfe31cecabd9ce0a3ae" integrity sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w== +"@types/node@16.18.3": + version "16.18.3" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.3.tgz#d7f7ba828ad9e540270f01ce00d391c54e6e0abc" + integrity sha512-jh6m0QUhIRcZpNv7Z/rpN+ZWXOicUUQbSoWks7Htkbb9IjFQj4kzcX/xFCkjstCj5flMsN8FiSvt+q+Tcs4Llg== + "@types/normalize-package-data@^2.4.0": version "2.4.1" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" @@ -1546,10 +1551,10 @@ resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== -"@vscode/codicons@^0.0.25": - version "0.0.25" - resolved "https://registry.yarnpkg.com/@vscode/codicons/-/codicons-0.0.25.tgz#4ebc3e2c9e707ac46aea0becceda79f7738c647c" - integrity sha512-uqPhTdADjwoCh5Ufbv0M6TZiiP2mqbfJVB4grhVx1k+YeP03LDMOHBWPsNwGKn4/0S5Mq9o1w1GeftvR031Gzg== +"@vscode/codicons@^0.0.32": + version "0.0.32" + resolved "https://registry.yarnpkg.com/@vscode/codicons/-/codicons-0.0.32.tgz#9e27de90d509c69762b073719ba3bf46c3cd2530" + integrity sha512-3lgSTWhAzzWN/EPURoY4ZDBEA80OPmnaknNujA3qnI4Iu7AONWd9xF3iE4L+4prIe8E3TUnLQ4pxoaFTEEZNwg== "@webassemblyjs/ast@1.11.1": version "1.11.1" @@ -5117,6 +5122,11 @@ minimist@^1.2.0, minimist@^1.2.5: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== +minimist@^1.2.3: + version "1.2.7" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18" + integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g== + minipass-collect@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/minipass-collect/-/minipass-collect-1.0.2.tgz#22b813bf745dc6edba2576b940022ad6edc8c617" @@ -6778,7 +6788,7 @@ shell-escape@^0.2.0: resolved "https://registry.yarnpkg.com/shell-escape/-/shell-escape-0.2.0.tgz#68fd025eb0490b4f567a027f0bf22480b5f84133" integrity sha1-aP0CXrBJC09WegJ/C/IkgLX4QTM= -shelljs@^0.8.3: +shelljs@^0.8.3, shelljs@^0.8.5: version "0.8.5" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c" integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow== @@ -6787,6 +6797,14 @@ shelljs@^0.8.3: interpret "^1.0.0" rechoir "^0.6.2" +shx@^0.3.4: + version "0.3.4" + resolved "https://registry.yarnpkg.com/shx/-/shx-0.3.4.tgz#74289230b4b663979167f94e1935901406e40f02" + integrity sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g== + dependencies: + minimist "^1.2.3" + shelljs "^0.8.5" + side-channel@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf"