Skip to content

Commit

Permalink
Merge pull request #1 from ItinerisLtd/add-set-config-function
Browse files Browse the repository at this point in the history
Added default configuration
  • Loading branch information
danlapteacru authored Sep 3, 2024
2 parents 3e138ce + 2a2a500 commit 01013a0
Show file tree
Hide file tree
Showing 7 changed files with 751 additions and 697 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,41 @@ npm install bud-favicons --save-dev
**bud-favicons** works with zero configuration. But there is a robust and developer friendly configuration API should you need to make a modification to the provided defaults.
You can see the full list of options in the [favicons documentation](https://github.com/itgalaxy/favicons#usage).

## Configuration with `bud.favicons`
## Default configuration

```ts
const options = {
logo: bud.path('resources/images/favicon.svg'),
mode: 'webapp',
devMode: 'webapp',
outputPath: bud.path('public'),
favicons: {
icons: {
android: true,
appleIcon: true,
appleStartup: true,
favicons: true,
windows: true,
yandex: false,
},
},
};
```

## Configuration with `bud.favicons.config`

You can configure `favicons` with the `bud.favicons` method:

```ts title=bud.config.ts
bud.favicons({
bud.favicons.setup({
logo: bud.path('resources/images/favicon.svg'),
});
```

OR

```ts title=bud.config.ts
bud.favicons({
bud.favicons.setup({
logo: bud.path('resources/images/favicon.svg'),
mode: 'webapp',
devMode: 'webapp',
Expand Down
49 changes: 23 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
{
"name": "bud-favicons",
"version": "0.0.0",
"version": "0.0.15",
"description": "Bud.js extension to automatically generate favicons.",
"engines": {
"node": ">=16"
},
"contributors": [
{
"email": "[email protected]",
"name": "Dan Lapteacru",
"url": "https://github.com/danlapteacru"
}
],
"main": "index.js",
"license": "MIT",
"homepage": "https://github.com/ItinerisLtd/bud-favicons",
"repository": {
Expand All @@ -27,38 +18,44 @@
"webpack-favicons",
"favicons-webpack-plugin"
],
"files": [
"docs",
"lib",
"src"
"contributors": [
{
"email": "[email protected]",
"name": "Dan Lapteacru",
"url": "https://github.com/danlapteacru"
}
],
"type": "module",
"exports": {
".": "./lib/index.js"
".": "./lib/index.js",
"./types": "./lib/types.js"
},
"typesVersions": {
"*": {
".": [
"./lib/types/index.d.ts",
"./lib/index.d.ts"
"./lib/index.js"
],
"types": [
"./lib/types.js"
]
}
},
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"files": [
"lib",
"src"
],
"devDependencies": {
"@types/node": "20.14.12"
},
"dependencies": {
"@roots/bud": "^6.23.3",
"@roots/bud-framework": "^6.23.3",
"@roots/bud-support": "^6.23.3",
"@roots/bud-typescript": "^6.23.3",
"favicons": "^7.2.0",
"favicons-webpack-plugin": "^6.0.1",
"tslib": "2.6.3"
"@types/node": "18.17.9",
"tslib": "2.6.2"
},
"volta": {
"extends": "../../../package.json"
"dependencies": {
"favicons": "^7.1.4",
"favicons-webpack-plugin": "^6.0.1"
}
}
75 changes: 58 additions & 17 deletions src/extension/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,73 @@
import {type Bud, type WebpackPluginInstance} from '@roots/bud-framework'
import {Bud} from "@roots/bud-framework";
import {Extension} from '@roots/bud-framework/extension'
import {
bind,
dependsOn,
expose,
label,
} from '@roots/bud-framework/extension/decorators'

import {type BudFaviconsPublicOptions} from './types.js'
import FaviconsWebpackPlugin from "favicons-webpack-plugin";
import {bind, label, expose} from '@roots/bud-framework/extension/decorators'
import FaviconsWebpackPlugin from 'favicons-webpack-plugin'
import merge from '@roots/bud-support/merge'
import type {WebpackPluginInstance} from '@roots/bud-framework/config'
import type {BudFaviconsPublicOptions} from "./types.js";

/**
* Favicons extension
* BudFavicons extension for handling favicons in the Bud framework.
*
* @label `bud-favicons`
* @expose `favicons`
*/
@label(`bud-favicons`)
@dependsOn(['favicons-webpack-plugin'])
@expose(`favicons`)
export default class BudFavicons extends Extension<
BudFaviconsPublicOptions,
WebpackPluginInstance
> {
/**
* {@link Extension.register}
* Options for the favicons.
* @private
*/
private faviconOptions: {}|BudFaviconsPublicOptions = {};

/**
* Creates an instance of FaviconsWebpackPlugin with merged options.
*
* @param {Bud} app - The Bud application instance.
* @returns {Promise<WebpackPluginInstance>} - The FaviconsWebpackPlugin instance.
*/
@bind
public override async make(app: Bud): Promise<WebpackPluginInstance> {
return new FaviconsWebpackPlugin(merge({}, this.defaultOptions(app), this.faviconOptions));
}

/**
* Sets up the favicon options.
*
* @param {BudFaviconsPublicOptions} options - The options for the favicons.
*/
@bind
public override async configAfter(bud : Bud) : Promise<void> {
new FaviconsWebpackPlugin(this.options);
public setup(options: BudFaviconsPublicOptions): void {
this.faviconOptions = options;
}
}

export type * from './types.js'
/**
* Provides the default options for the favicons.
*
* @param {Bud} app - The Bud application instance.
* @returns {BudFaviconsPublicOptions} - The default options for the favicons.
* @private
*/
private defaultOptions(app: Bud): BudFaviconsPublicOptions {
return {
logo: app.path('resources/images/favicon.svg'),
mode: 'webapp',
devMode: 'webapp',
outputPath: app.path('public'),
favicons: {
icons: {
android: true,
appleIcon: true,
appleStartup: true,
favicons: true,
windows: true,
yandex: false,
},
},
};
}
}
25 changes: 10 additions & 15 deletions src/extension/types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import type BudFavicons from './index.js'

import type {FaviconWebpackPlugionOptions} from "favicons-webpack-plugin/src/options.js";
import BudFavicons from "./index.js";
import type {Rule} from "@roots/bud-framework";

declare module '@roots/bud-framework' {
interface Bud {
favicons: BudFavicons,
}
interface BudFaviconsPublicOptions extends FaviconWebpackPlugionOptions {}

export {type BudFaviconsPublicOptions}

declare module '@roots/bud-framework' {
interface Modules {
'bud-favicons': BudFavicons,
'bud-favicons': BudFavicons
}

interface Rules {
js: Rule,
ts: Rule,
interface Bud {
favicons: BudFavicons
}
}

interface BudFaviconsPublicOptions extends FaviconWebpackPlugionOptions {}

export {type BudFaviconsPublicOptions}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* bud-favicons
*
* @see https://bud.js.org
* @see https://github.com/roots/bud
* @see https://github.com/ItinerisLtd/bud-favicons
*/

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"@roots/bud-build",
"@roots/bud-extensions",
"@roots/bud-support",
"favicons-webpack-plugin",
"@roots/bud-api"
]
},
"include": ["./src"],
"include": ["./src/**/*"],
"exclude": ["test", "node_modules", "dist"]
}
Loading

0 comments on commit 01013a0

Please sign in to comment.