Skip to content

Commit

Permalink
Expose generateManifest as reusable function (#2411)
Browse files Browse the repository at this point in the history
* Expose as module

* Update typescript version

* Make typescript compilation a prebuild command

* Update package.json scripts

* Add config for declarations

* Refacor code

* Refactor project

* Format code

* Refactor project

* Update project structure

* Update imports

* Update comment

* Update dependency to extension module

* Adjust imports

* Update import

* Enable minification

* Fix issue with hash

* Update exposed core modules

* Minor improvements

* Update comment

* Update ignore files

* Update imports

* Update module structure

* Move tests into core

* Update prepublish script

* Update npm scripts

* Update prepublish script

* Update version

* Update version

* Fix unit tests

* Update hash generation

* Update sheriff config

* Update types

* Update custom file paths

* Update IconPack types

* Update project

* Update types

* Update reference to readme

* Update customIconPaths

* Format code
  • Loading branch information
PKief authored Jul 15, 2024
1 parent be9dc3a commit 528f950
Show file tree
Hide file tree
Showing 129 changed files with 1,923 additions and 1,750 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": [
{
"type": "bun",
"script": "bun run build; bun run postcompile",
"script": "bun run build",
"problemMatcher": [],
"label": "bun: build",
"detail": "bun run build",
Expand Down
7 changes: 6 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ scripts/**
**/*.map
.gitignore
tsconfig.json
tsconfig.**.json
biome.jsonc
images/**
vsc-extension-quickstart.md
Expand All @@ -17,9 +18,13 @@ package-lock.json
bun.lockb
yarn.lock
bunfig.toml
devcontainer/**
.devcontainer/**
sheriff.config.ts
build/**
svgo.config.js
.eslintignore
material-colors.yml
changelog.config.json
dist/types/**
dist/module.cjs

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,4 @@ Take a look at the [contribution guidelines](https://github.com/material-extensi
## Related extensions

- [Material Icons for GitHub](https://github.com/Claudiohbsantos/github-material-icons-extension)
- [Material Product Icons](https://github.com/material-extensions/vscode-material-product-icons)
9 changes: 7 additions & 2 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
"enabled": true,
"rules": {
"recommended": false,
"complexity": { "useArrowFunction": "off" },
"correctness": { "noUnsafeFinally": "error" },
"complexity": { "useArrowFunction": "error" },
"correctness": {
"noUnsafeFinally": "error",
"noUnusedVariables": "error",
"noUnusedImports": "error"
},
"security": { "noGlobalEval": "error" },
"style": {
"noVar": "error",
Expand All @@ -28,6 +32,7 @@
},
"suspicious": {
"noDoubleEquals": "error",
"noExplicitAny": "error",
"useNamespaceKeyword": "error"
}
}
Expand Down
4 changes: 2 additions & 2 deletions build/build-with-esbuild.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import esbuild from "esbuild";
import config from "./esbuild.config";
import esbuild from 'esbuild';
import config from './esbuild.config';

esbuild.build(config).catch(() => process.exit(1));
29 changes: 17 additions & 12 deletions build/esbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import type { BuildOptions } from "esbuild";
import type { BuildOptions } from 'esbuild';

const config: BuildOptions = {
entryPoints: ["./src/extension.ts", "./src/web/extension.ts"],
entryPoints: [
'./src/extension/desktop/extension.ts',
'./src/extension/web/extension.ts',
'./src/module/index.ts',
],
minify: false,
bundle: true,
platform: "node",
target: "node12",
outdir: "./dist",
outbase: "./src",
platform: 'node',
target: 'node12',
outdir: './dist',
outbase: './src',
outExtension: {
".js": ".cjs",
'.js': '.cjs',
},
format: "cjs",
external: ["vscode"],
format: 'cjs',
external: ['vscode'],
loader: {
".ts": "ts",
".js": "js",
'.ts': 'ts',
'.js': 'js',
},
logLevel: "info",
logLevel: 'info',
};

export default config;
5 changes: 3 additions & 2 deletions build/watch-with-esbuild.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import esbuild from "esbuild";
import config from "./esbuild.config";
import esbuild from 'esbuild';
import config from './esbuild.config';

try {
const context = await esbuild.context(config);
await context.watch();
} catch (e) {
console.error(e);
process.exit(1);
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion bunfig.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[test]
# Load these modules before running tests.
preload = ["./src/tests/mocks"]
preload = ["./src/core/tests/mocks"]
49 changes: 31 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
"description": "Material Design Icons for Visual Studio Code",
"version": "5.4.2",
"scripts": {
"build": "bun run ./build/build-with-esbuild.ts",
"precompile": "rimraf dist && bun run verify",
"compile": "tsc -p ./",
"compile:declarations": "tsc -p ./tsconfig.declarations.json",
"postcompile": "bun run compile:declarations && bun run generateJson && bun run generateClones && bun run check",
"build": "bun run compile && bun run ./build/build-with-esbuild.ts",
"watch": "bun run ./build/watch-with-esbuild.ts",
"changelog": "changelog-machine --config changelog.config.json",
"check-colors": "bun run ./src/scripts/svg/checkSvgColors.ts",
"check": "bun ./src/scripts/icons/checks",
"contributors": "bun ./src/scripts/contributors/index.ts",
"generateJson": "bun ./src/scripts/icons/generateJson.ts",
"check": "bun ./src/scripts/icons/checks/run.ts",
"contributors": "bun ./src/scripts/contributors/contributors.ts",
"generateJson": "bun ./src/scripts/icons/generateJson.ts > dist/material-icons.json",
"generateClones": "bun ./src/scripts/icons/generateClones.ts",
"lint": "bunx @biomejs/biome check --write ./src",
"format": "bunx @biomejs/biome format --write ./src",
"postcompile": "bun run generateJson && bun run check",
"pretest": "bun run build && tsc -p ./",
"preversion": "bun run contributors && git add images/contributors.png && bun run preview && git add images/fileIcons.png && git add images/folderIcons.png && bun run svgo && git add icons/*.svg",
"preview": "bun ./src/scripts/preview",
"preview": "bun ./src/scripts/preview/run.ts",
"svgo": "svgo -i icons -o icons -q",
"test-compile": "tsc -p ./",
"test": "bun ./out/test/runTest.js",
"test": "bun test",
"version": "bun run changelog && git add CHANGELOG.md",
"vscode:prepublish": "bun run lint && bun run build && bun run postcompile"
"vscode:prepublish": "bun run lint && bun run build",
"verify": "bunx sheriff verify",
"prepublishOnly": "bun run ./src/scripts/module/prepare.ts",
"postpublish": "git checkout package.json && git checkout README.md"
},
"publisher": "PKief",
"author": {
Expand All @@ -39,7 +44,7 @@
"homepage": "https://github.com/material-extensions/vscode-material-icon-theme/blob/main/README.md",
"repository": {
"type": "git",
"url": "https://github.com/material-extensions/vscode-material-icon-theme.git"
"url": "git+https://github.com/material-extensions/vscode-material-icon-theme.git"
},
"bugs": {
"url": "https://github.com/material-extensions/vscode-material-icon-theme/issues"
Expand All @@ -59,10 +64,17 @@
"virtualWorkspaces": true
},
"activationEvents": ["onStartupFinished"],
"main": "./dist/extension.cjs",
"browser": "./dist/web/extension.cjs",
"main": "./dist/extension/desktop/extension.cjs",
"browser": "./dist/extension/web/extension.cjs",
"module": "./dist/module/index.cjs",
"types": "./dist/types/module/index.d.ts",
"sideEffects": false,
"files": ["icons", "dist/material-icons.json"],
"files": [
"icons",
"dist/material-icons.json",
"dist/module/index.cjs",
"dist/types"
],
"contributes": {
"iconThemes": [
{
Expand Down Expand Up @@ -292,14 +304,15 @@
},
"dependencies": {
"chroma-js": "^2.4.2",
"lodash.merge": "4.6.2",
"lodash-es": "^4.17.21",
"svgson": "^5.3.1"
},
"devDependencies": {
"@biomejs/biome": "1.8.2",
"@softarc/sheriff-core": "^0.15.1",
"@types/chroma-js": "^2.4.4",
"@types/glob": "^7.2.0",
"@types/lodash.merge": "^4.6.7",
"@types/lodash-es": "^4.17.12",
"@types/puppeteer": "^5.4.6",
"@types/vscode": "~1.51.0",
"@vscode/test-electron": "^2.3.9",
Expand All @@ -309,9 +322,9 @@
"esbuild": "^0.21.4",
"glob": "^8.0.3",
"puppeteer": "^22.11.0",
"rimraf": "^3.0.2",
"rimraf": "^6.0.0",
"svg-color-linter": "^1.3.0",
"svgo": "^2.8.0",
"typescript": "^4.7.2"
"typescript": "^5.5.3"
}
}
2 changes: 1 addition & 1 deletion package.nls.ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
"configuration.hidesExplorerArrows": "파일 탐색기의 폴더 화살표 숨기기.",
"configuration.opacity": "아이콘의 투명도 변경.",
"configuration.saturation": "아이콘의 채도 변경."
}
}
17 changes: 17 additions & 0 deletions sheriff.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type SheriffConfig } from '@softarc/sheriff-core';

export const sheriffConfig: SheriffConfig = {
entryFile: 'src/module/index.ts',
version: 1,
autoTagging: true,
tagging: {
'src/extension': 'extension',
'src/core': 'core',
'src/module': 'module',
},
depRules: {
root: ['core'],
extension: ['core'],
module: ['core'],
},
};
27 changes: 27 additions & 0 deletions src/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Architecture

The project is structured in a way that the core logic is separated from the extension logic. The core logic is used for the generation of the icon manifest, for the definition of the icon associations and for the translation logic. The extension logic is used for the interaction with the VS Code extension API (e.g. getting the user configuration, providing commands etc.).

```text
📦 src
┣ 📂 core <-- Logic for generating icon manifest, icon associations, translation logic, models, tests
┣ 📂 extension <-- Code which uses VS Code extension API (get user config, providing commands etc)
┣ 📂 module <-- Control which part of the core is exposed to the npm module
┗ 📂 scripts <-- Scripts which are executed during build time (in the package.json)
```

By using the [sheriff](https://github.com/softarc-consulting/sheriff) library dependencies between the modules can be verified. The command `bun run verify` checks if the imports between the modules are allowed. For instance it's not allowed, that any of the other modules imports something from the `extension` module because of it's dependency to `vscode`. But the `extension` module itself is allowed to import from `core`.

This is realized by using the dependency rules in the sheriff.config.ts file:

```ts
depRules: {
root: ['core'],
extension: ['core'],
module: ['core'],
}
```

## Npm module

The npm module exposes some of the functions so that the icon manifest can be generated programmatically. More information can be found in the [README.md](./module/README.md) of the module.
32 changes: 0 additions & 32 deletions src/commands/index.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/commands/restoreConfig.ts

This file was deleted.

Loading

0 comments on commit 528f950

Please sign in to comment.