Skip to content

Commit

Permalink
Add missing actions docs (#945)
Browse files Browse the repository at this point in the history
* docs: remove old deprecated docs - add actions

* docs: add actions

* docs: tweak

Co-authored-by: Kawika Bader <[email protected]>

* docs: tweak

Co-authored-by: Kawika Bader <[email protected]>

---------

Co-authored-by: Kawika Bader <[email protected]>
  • Loading branch information
agerard-godaddy and kbader-godaddy authored Oct 15, 2024
1 parent d1bc504 commit 821999b
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 134 deletions.
8 changes: 8 additions & 0 deletions packages/gasket-plugin-express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ export default makeGasket({

## Actions

### getExpressApp

Get the Express app instance.

```js
const app = actions.gasket.getExpressApp();
```

Each Gasket creates a single shared Express instance, ensuring consistent access to the same app instance wherever it's needed.

## Lifecycles

Expand Down
12 changes: 12 additions & 0 deletions packages/gasket-plugin-fastify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ export default makeGasket({
});
```

## Actions

### getFastifyApp

Get the Fastify app instance.

```js
const app = actions.gasket.getFastifyApp();
```

Each Gasket creates a single shared Fastify instance, ensuring consistent access to the same app instance wherever it's needed.

## Lifecycles

### fastify
Expand Down
1 change: 0 additions & 1 deletion packages/gasket-plugin-happyfeet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ This action is used to configure and get a [Happy Feet](https://github.com/asilv
You can specify the various [happy-feet](https://github.com/asilvas/happy-feet#usage) config options in the gasketConfig
or pass the config object directly to the action.


#### gasketConfig example

```js
Expand Down
25 changes: 21 additions & 4 deletions packages/gasket-plugin-https/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,29 @@ export default makeGasket({
});
```

## Actions

### startServer

This action kicks off the machinery to get your Gasket app running.
Typically placed in a `server.js` file, it can be executed with `node` or your preferred runner.

```js
import gasket from './gasket.js';
gasket.actions.startServer();
```

This action will execute several of the lifecycles mentioned next, allowing apps
and plugins to further set the server up.

## Lifecycles

### devProxy

Adjust and configure `devProxy` options for a proxy server during local development. This is useful if `https` is needed in local development. The options for `http-proxy` can be found [here](https://www.npmjs.com/package/http-proxy#options). The `devProxy` configuration must be defined in some capacity on the gasket config for this lifecycle to execute.
Adjust and configure `devProxy` options for a proxy server during local development.
This is useful if `https` is needed in local development.
The options for `http-proxy` can be found [here](https://www.npmjs.com/package/http-proxy#options).
The `devProxy` configuration must be defined in some capacity on the gasket config for this lifecycle to execute.

```js
/**
Expand All @@ -119,12 +137,12 @@ devProxy: async function devProxy(gasket, devProxyConfig) {
port: 8443
}
}

```

### serverConfig

Allows for server options to be added before `createServers` is called. Example use-case would be adding `sni` configurations when using `https` for local development.
Allows for server options to be added before `createServers` is called.
Example use-case would be adding `sni` configurations when using `https` for local development.

```js
/**
Expand All @@ -142,7 +160,6 @@ serverConfig: async function serverConfig(gasket, rawConfig) {

return rawConfig;
}

```

### createServers
Expand Down
10 changes: 10 additions & 0 deletions packages/gasket-plugin-logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ custom logger: `@gasket/plugin-winston`.

This plugin is only used by presets for `create-gasket-app` and is not installed for apps.

## Actions

### getLogger

Get the logger instance using the Actions API.

```js
const logger = gasket.actions.getLogger();
```

## Lifecycles

### createLogger
Expand Down
10 changes: 10 additions & 0 deletions packages/gasket-plugin-metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ notably the [@gasket/plugin-docs] which uses it to collate docs for an app.

This is a default plugin in the Gasket CLI and is always available for use.

## Actions

### getMetadata

Get all the metadata for the configured plugins and modules.

```js
const metadata = await gasket.actions.getMetadata();
```

## Lifecycles

### metadata
Expand Down
68 changes: 45 additions & 23 deletions packages/gasket-plugin-nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,51 @@ Also note when using [@gasket/plugin-intl] to determine the locale, that the
`NEXT_LOCALE` cookie will have no effect. You can, of course, hook the [intlLocale]
lifecycle in an app to enable that behavior if desired.

## Actions

### getNextConfig

This action returns the current `nextConfig` object
which allows plugins to configure the Next.js application.

Place this in a `next.config.js` file which Next.js will load.

```js
// next.config.js

import gasket from './gasket.js';
export default gasket.actions.getNextConfig();
```

### getNextRoute

This action is intended for use in server contexts where you need to know how a
request will route to a Next.js page.
This async function returns null if the manifest could not be parsed or if the
requested URL does not match a route.
If a match _is_ found, an object with these properties is returned:

| Property | Type | Description |
|----------|------|-------------|
| `page` | `String` | The page name/path used to identify a page within next.js |
| `regex` | `RegExp` | The regular expression that matches URLs to the page |
| `routeKeys` | `Object` | For dynamic routes the mapping of URL placeholders to parsed route parameters |
| `namedRegex` | `RegExp` | Like `regex`, but [named capturing groups] are included to populate dynamic routing parameters |

```javascript
import gasket from '../gasket.js';

async function someMiddleware(req, res, next) {
const route = await gasket.actions.getNextRoute();
if (route) {
const { groups } = req.url.match(route.namedRegex);
console.log(`Matched ${route.page} with parameters`, groups);
}

next();
}
```

## Lifecycles

### next
Expand Down Expand Up @@ -227,29 +272,6 @@ export default {
};
```

## Utilities

This plugin hooks the `actions` lifecycle creates a `getNextRoute` action. It is intended for use in server contexts where you need to know how a request will route to a next.js page. This async function returns null if the manifest could not be parsed or if the requested URL does not match a route. If a match _is_ found, an object with these properties is returned:

| Property | Type | Description |
|----------|------|-------------|
| `page` | `String` | The page name/path used to identify a page within next.js |
| `regex` | `RegExp` | The regular expression that matches URLs to the page |
| `routeKeys` | `Object` | For dynamic routes the mapping of URL placeholders to parsed route parameters |
| `namedRegex` | `RegExp` | Like `regex`, but [named capturing groups] are included to populate dynamic routing parameters |

```javascript
async function someMiddleware(req, res, next) {
const route = await req.getNextRoute();
if (route) {
const { groups } = req.url.match(route.namedRegex);
console.log(`Matched ${route.page} with parameters`, groups);
}

next();
}
```

## License

[MIT](./LICENSE.md)
Expand Down
121 changes: 15 additions & 106 deletions packages/gasket-plugin-webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,43 @@ If your app was previously using the `webpack` property in the
`gasket.js`, then you should take steps [migrating to webpackConfig]
lifecycle.

## API
## Actions

The package exposes an init function called `initWebpack` which can be used by
plugins that need to gather Webpack configuration.
### getWebpackConfig

### initWebpack

Use this to initialize the Webpack lifecycles in a consuming plugin.
This action can be used by plugins that need to gather Webpack configuration.

```js
import { initWebpack } from '@gasket/plugin-webpack';

/**
* Creates the webpack config
* @param {Gasket} gasket The Gasket API
* @param {Object} webpackConfig Initial webpack config
* @param {Object} data Additional info
* @returns {Object} Final webpack config
*/
const config = initWebpack(gasket, webpackConfig, data);
// Any starting Webpack configuration
const initialConfig = { };

// Any additional context such as isServer or not
const context = { isServer: true };

const webpackConfig = actions.gasket.getWebpackConfig(initialConfig, context);
```

This action will execute the `webpackConfig` lifecycle and return the final
Webpack configuration object.

## Lifecycles

### webpackConfig

Executed by [initWebpack](#initwebpack), it receives three parameters:
Executed by [getWebpackConfig](#getwebpackconfig) action,
it receives three parameters:

1. The Gasket API
2. A Webpack config object
3. A context object with the following properties:
* `webpack` - The Webpack API.
* `webpackMerge` - _DEPRECATED - Use `require('webpack-merge')`._
Getter returns [webpack-merge v4] API.
* `...additionalContext` - Additional context may be exposed. For example, in next.js apps, the [next.js webpack config options](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config) are included.

A hook should return a new Webpack config object derived from the original. The
usage of [webpack-merge] is recommended when doing so since it can properly
handle the overloaded types within Webpack config properties, which can be
tricky.

We recommend requiring [webpack-merge] as a dependency in your lifecycles,
instead of using the instance on context which will be removed in a future
version.

```js
import webpackMerge from 'webpack-merge';

Expand All @@ -108,93 +100,10 @@ export default {
};
```

### webpackChain

_DEPRECATED - Use [`webpackConfig`](#webpackConfig) lifecycle instead._

Executed before the `webpack` lifecycle, allows you to easily create the initial
Webpack configuration using a chaining syntax that is provided by the
`webpack-chain` library. The resulting configuration is then merged with:

- WebPack configuration that is specified in the `gasket.js` as `webpack`
object.

The result of this will be passed into the `webpack` hook as base configuration.

### webpack

_DEPRECATED - Use [`webpackConfig`](#webpackConfig) lifecycle instead._

Executed after `webpack-chain` lifecycle. It receives the full Webpack config as
first argument. It can be used to add additional configurations to Webpack.

## Migrating to webpackConfig

### From Gasket config

If your app previously added Webpack configuration in the `gasket.js`,
this feature is deprecated and you should migrate to using
the [`webpackConfig`](#webpackConfig) lifecycle.

For background, the `webpack` config is merged using an old deprecated "smart"
method from [webpack-merge]. It is now recommended for apps and plugins to
handle any merge strategies themselves in the `webpackConfig` lifecycle.

So move from this setting `webpack` in the `gasket.js`:

```diff
// gasket.js
export default makeGasket({
plugins: {
pluginWebpack
},
- webpack: {
- performance: {
- maxAssetSize: 20000
- }
- }
});
```

to using the webpackConfig lifecycle to merge any custom Webpack config:

```javascript
// sample-plugin.js
import webpackMerge from 'webpack-merge';

export default {
name: 'sample-plugin',
hooks: {
webpackConfig: function (gasket, webpackConfig, context) {
return webpackMerge.merge(webpackConfig, {
performance: {
maxAssetSize: 20000
}
})
}
}
};
```

This gives apps the freedom to use whatever [merge strategies] makes sense
for the custom webpack they want to configure.

### From other lifecycles

If you have plugins that were using either [webpackChain](#webpackchain)
or [webpack](#webpack) lifecycles, these are now deprecated and will be removed
in the next major release. Both of these lifecycles depended on the same
deprecated "smart" method from [webpack-merge].

Instead, handle any merging in the [webpackConfig](#webpackconfig), using
whatever [merge strategies] are useful for the particular config being added.

## License

[MIT](./LICENSE.md)

<!-- LINKS -->

[webpack-merge v4]:https://github.com/survivejs/webpack-merge/tree/v4.2.2
[webpack-merge]: https://github.com/survivejs/webpack-merge
[merge strategies]: https://github.com/survivejs/webpack-merge#customizearray-and-customizeobject

0 comments on commit 821999b

Please sign in to comment.