Skip to content

Commit

Permalink
build: icons/associations integrity check
Browse files Browse the repository at this point in the history
  • Loading branch information
prazdevs committed Feb 25, 2024
1 parent a711f50 commit 96e7e24
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: Typecheck
run: pnpm typecheck

- name: Integrity
run: pnpm integrity

- name: Build extension
run: pnpm build

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: Typecheck
run: pnpm typecheck

- name: Integrity
run: pnpm integrity

- name: Build extension
run: pnpm build

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ We provide a set of npm scripts to make development and contribution easier:
| `build` | Builds the extension and themes to `dist`. |
| `catwalk` | Generates the main preview (requires `catwalk`). |
| `icons` | CLI to optimize/generate icons and icon previews. |
| `integrity` | Ensures all default associations refer to existing icons. |
| `pack` | Generates VSIX extension file. |

### Notes
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"build": "tsx scripts/build.ts",
"catwalk": "tsx scripts/catwalk.ts",
"icons": "tsx scripts/icons.ts",
"integrity": "tsx scripts/integrity.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"pack": "vsce package --no-dependencies",
Expand Down
4 changes: 4 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Build themes and extension.
*/

import { cp, readdir, writeFile } from 'node:fs/promises'
import { basename, join } from 'node:path'
import { exit } from 'node:process'
Expand Down
4 changes: 4 additions & 0 deletions scripts/catwalk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Generate main preview using Catwalk.
*/

import { exec } from 'node:child_process'
import { readdir, writeFile } from 'node:fs/promises'
import { join, resolve } from 'node:path'
Expand Down
4 changes: 4 additions & 0 deletions scripts/icons.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* CLI for icon SVG file manipulation.
*/

import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
import { readFile, readdir, writeFile } from 'node:fs/promises'
import { join, resolve } from 'node:path'
Expand Down
44 changes: 44 additions & 0 deletions scripts/integrity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Ensure all default associations refer to existing icons.
*/

import { readdir } from 'node:fs/promises'
import { basename, join, resolve } from 'node:path'
import { exit } from 'node:process'
import { consola } from 'consola'
import { fileIcons } from '~/defaults/fileIcons'
import { folderIcons } from '~/defaults/folderIcons'

let exitCode = 0

const ICONS = 'icons'
const flavors = await readdir(resolve(ICONS))

consola.info('Running integrity check...')

await Promise.all(flavors.map(async (f) => {
const icons = await readdir(resolve(join(ICONS, f)))

Object.keys(fileIcons).forEach((fi) => {
if (!icons.some(i => basename(i, '.svg') === fi)) {
consola.error(`Missing ${f} icon for ${fi}`)
exitCode++
}
})

Object.keys(folderIcons).forEach((fi) => {
if (!icons.some(i => basename(i, '.svg') === `folder_${fi}`)) {
consola.error(`Missing ${f} folder icon for ${fi}`)
exitCode++
}
if (!icons.some(i => basename(i, '.svg') === `folder_${fi}_open`)) {
consola.error(`Missing ${f} open folder icon for ${fi}`)
exitCode++
}
})
}))

if (exitCode === 0)
consola.success('Integrity check passed.')

exit(exitCode)
2 changes: 1 addition & 1 deletion src/defaults/fileIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2607,4 +2607,4 @@ const { languageIds, fileExtensions, fileNames } = Object.entries(fileIcons).red
},
)

export { languageIds, fileExtensions, fileNames }
export { languageIds, fileExtensions, fileNames, fileIcons }
2 changes: 1 addition & 1 deletion src/defaults/folderIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,4 @@ const { folderNames } = Object.entries(folderIcons).reduce(
},
)

export { folderNames }
export { folderNames, folderIcons }

0 comments on commit 96e7e24

Please sign in to comment.