Skip to content

Commit

Permalink
Add to demo extension, label logs, use warn instead of fatal, remove …
Browse files Browse the repository at this point in the history
…build config
  • Loading branch information
aklinker1 committed Jul 25, 2024
1 parent b15999f commit 1f904b5
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 20 deletions.
5 changes: 0 additions & 5 deletions packages/module-auto-icons/build.config.ts

This file was deleted.

11 changes: 2 additions & 9 deletions packages/module-auto-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
"name": "@wxt-dev/module-auto-icons",
"version": "1.0.0",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"files": [
Expand Down
14 changes: 8 additions & 6 deletions packages/module-auto-icons/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'wxt';
import { defineWxtModule } from 'wxt/modules';
import { resolve } from 'path';
import { resolve, relative } from 'node:path';
import defu from 'defu';
import sharp from 'sharp';
import { ensureDir, exists } from 'fs-extra';
Expand All @@ -16,26 +16,28 @@ export default defineWxtModule<AutoIconsOptions>({
sizes: [128, 48, 32, 16],
});

if (!parsedOptions.enabled) return wxt.logger.warn(`${this.name} disabled`);
if (!parsedOptions.enabled)
return wxt.logger.warn(`\`[auto-icons]\` ${this.name} disabled`);

if (!(await exists(parsedOptions.baseIconsPath))) {
return wxt.logger.fatal(
`Cannot generate icons, no base icon found at ${parsedOptions.baseIconsPath}`,
const relativePath = relative(process.cwd(), parsedOptions.baseIconsPath);
return wxt.logger.warn(
`\`[auto-icons]\` Skipping icon generation, no base icon found at ${relativePath}`,
);
}

wxt.hooks.hook('build:manifestGenerated', async (wxt, manifest) => {
if (manifest.icons)
return wxt.logger.warn(
'icons property found in manifest, overwriting with auto-generated icons',
'`[auto-icons]` icons property found in manifest, overwriting with auto-generated icons',
);

manifest.icons = Object.fromEntries(
parsedOptions.sizes.map((size) => [size, `icons/${size}.png`]),
);
});

wxt.hooks.hook('build:done', async (wxt) => {
wxt.hooks.hook('build:done', async (wxt, output) => {
const image = sharp(parsedOptions.baseIconsPath).png();

if (
Expand Down
1 change: 1 addition & 0 deletions packages/wxt-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@wxt-dev/module-auto-icons": "workspace:*",
"sass": "^1.77.8",
"typescript": "^5.5.3",
"vitest": "^2.0.3",
Expand Down
File renamed without changes
3 changes: 3 additions & 0 deletions packages/wxt-demo/src/modules/auto-icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import autoIcons from '@wxt-dev/module-auto-icons';

export default autoIcons;
Binary file removed packages/wxt-demo/src/public/icon/16.png
Binary file not shown.
Binary file removed packages/wxt-demo/src/public/icon/32.png
Binary file not shown.
Binary file removed packages/wxt-demo/src/public/icon/48.png
Binary file not shown.
Binary file removed packages/wxt-demo/src/public/icon/96.png
Binary file not shown.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f904b5

Please sign in to comment.