Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge adapt into plugins #404

Merged
merged 6 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-planets-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@grogarden/gro': minor
---

rename some dir constants to prefix with GRO* instead of BUILD*
5 changes: 5 additions & 0 deletions .changeset/violet-parents-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@grogarden/gro': minor
---

merge adapt into plugins
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ It includes:
and other code outside of the SvelteKit frontend,
so you can use SvelteKit patterns everywhere
(these are best-effort shims, not perfect)
- [configurable plugins](/src/lib/docs/plugin.md) and [adapters](/src/lib/docs/adapt.md)
- [configurable plugins](/src/lib/docs/plugin.md)
to support SvelteKit, auto-restarting Node servers, and other external build processes
- see the [Gro config docs](/src/lib/docs/config.md) and
[the default config](https://github.com/grogarden/gro/blob/main/src/lib/gro.config.default.ts)
Expand Down
8 changes: 1 addition & 7 deletions gro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@ import type {GroConfig} from './src/lib/config.js';
*/
const config: GroConfig = {
plugins: async () => [
(await import('./src/lib/gro_plugin_library.js')).plugin(),
(await import('./src/lib/gro_plugin_sveltekit_frontend.js')).plugin(),
// TODO replace with an esbuild plugin, see the module for more
// (await import('./lib/gro_plugin_gen.js')).plugin(),
],
adapters: async () =>
Promise.all([
(await import('./src/lib/gro_adapter_sveltekit_frontend.js')).create_adapter({
host_target: 'github_pages',
}),
(await import('./src/lib/gro_adapter_library.js')).create_adapter(),
]),
};

export default config;
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./adapt.js": {
"default": "./dist/adapt.js",
"types": "./dist/adapt.d.ts"
},
"./args.js": {
"default": "./dist/args.js",
"types": "./dist/args.d.ts"
Expand Down Expand Up @@ -228,18 +224,14 @@
"default": "./dist/gen.js",
"types": "./dist/gen.d.ts"
},
"./gro_adapter_library.js": {
"default": "./dist/gro_adapter_library.js",
"types": "./dist/gro_adapter_library.d.ts"
},
"./gro_adapter_sveltekit_frontend.js": {
"default": "./dist/gro_adapter_sveltekit_frontend.js",
"types": "./dist/gro_adapter_sveltekit_frontend.d.ts"
},
"./gro_plugin_gen.js": {
"default": "./dist/gro_plugin_gen.js",
"types": "./dist/gro_plugin_gen.d.ts"
},
"./gro_plugin_library.js": {
"default": "./dist/gro_plugin_library.js",
"types": "./dist/gro_plugin_library.d.ts"
},
"./gro_plugin_server.js": {
"default": "./dist/gro_plugin_server.js",
"types": "./dist/gro_plugin_server.d.ts"
Expand Down
50 changes: 0 additions & 50 deletions src/lib/adapt.ts

This file was deleted.

8 changes: 1 addition & 7 deletions src/lib/build.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {z} from 'zod';
import {spawn} from '@grogarden/util/process.js';

import type {Task} from './task.js';
import {adapt} from './adapt.js';
import {Plugins} from './plugin.js';
import {clean_fs} from './clean.js';

Expand All @@ -24,7 +23,6 @@ export const task: Task<Args> = {
run: async (ctx): Promise<void> => {
const {
config,
log,
args: {install},
} = ctx;

Expand All @@ -38,12 +36,8 @@ export const task: Task<Args> = {
await clean_fs({build_dist: true});

const plugins = await Plugins.create({...ctx, config, dev: false, watch: false});

await plugins.setup();
await plugins.adapt();
await plugins.teardown();

// Adapt the build to final ouputs.
const adapters = await adapt(ctx);
if (!adapters.length) log.info('no adapters to `adapt`');
},
};
2 changes: 0 additions & 2 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {paths} from './paths.js';
import type {ToConfigAdapters} from './adapt.js';
import create_default_config from './gro.config.default.js';
import type {ToConfigPlugins} from './plugin.js';
import {exists} from './exists.js';
Expand All @@ -18,7 +17,6 @@ If none is provided, the fallback is located at `gro/src/lib/gro.config.default.

export interface GroConfig {
plugins: ToConfigPlugins;
adapters: ToConfigAdapters;
}

export interface GroConfigCreator {
Expand Down
1 change: 0 additions & 1 deletion src/lib/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

> <sub>[gro](/../..) / [lib](..) / lib/docs / README.md</sub>

- [adapt](adapt.md)
- [build](build.md)
- [config](config.md)
- [deploy](deploy.md)
Expand Down
103 changes: 0 additions & 103 deletions src/lib/docs/adapt.md

This file was deleted.

38 changes: 15 additions & 23 deletions src/lib/docs/build.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
# build

This document describes how to go from `gro build` to live websites and npm packages.
> these docs are for production builds, for development see [dev.md](dev.md)

> this is for production builds; for development, see [dev.md](dev.md)
## usage

For production, we use `gro build` to output builds to `.gro/prod/{build_name}`,
which then get _adapted_ — to use terminology of SvelteKit — to their final form.
Adapting can be as simple as copying the files to a different location,
or it may involve bundling or other arbitrary operations.
The Node library adapter internally uses
[`svelte-package`](https://kit.svelte.dev/docs/packaging).
The `gro build` task produces outputs for production:

## contents
```bash
gro build
```

- [plugin](#plugin)
- [adapt](#adapt)
- [deploying and publishing](#deploying-and-publishing)
Internally, it calls `vite build` and runs the configured Gro plugins.

## plugin
## plugins

`Plugin`s are objects that customize the behavior of `gro build` and `gro dev`.
They try to defer to underlying tools as much as possible, and exist to glue everything together.
For example, the library plugin internally uses
[`svelte-package`](https://kit.svelte.dev/docs/packaging).
See [plugin.md](plugin.md) to learn more.

## adapt

`Adapter`s are objects that output final build artifacts from production builds during `gro build`.
See [adapt.md](adapt.md) to learn more.

## deploying and publishing

Now that we can make builds and then adapt them, how do we, like, make them go?
You know, to the web or whatever?
Now that we can produce builds, how do we share them with the world?

The [`gro deploy`](deploy.md) task helps you output builds to a branch,
The [`gro deploy`](deploy.md) task outputs builds to a branch,
like for static publishing to GitHub pages.

The [`gro publish`](publish.md) task publishes packages to npm.

Both of these tasks call `gro build` internally
but you can always run it manually if you're curious.
Both of these tasks call `gro build` internally,
and you can always run it manually if you're curious.
22 changes: 1 addition & 21 deletions src/lib/docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ here's [the default config](/src/lib/gro.config.default.ts)
that's used for projects that do not define one at `gro.config.ts`.

The default export of a Gro config is `GroConfig | GroConfigCreator`.
Here's how to define a user config that overrides the default adapters and plugins:
Here's how to define a user config that overrides the default plugins:

```ts
import type {GroConfigCreator} from '@grogarden/gro';

const config: GroConfigCreator = async (default_config) => {
const final_config = {
...default_config,
adapters: () => {
const default_adapters = await default_config.adapters();
return default_adapters.concat(create_some_custom_adapter());
},
plugins: () => {
const default_plugins = await default_config.plugins();
return default_plugins.concat(create_some_custom_plugin());
Expand All @@ -49,7 +45,6 @@ export default config;
```ts
export interface GroConfig {
plugins: ToConfigPlugins;
adapters: ToConfigAdapters;
}

export interface GroConfigCreator {
Expand All @@ -72,18 +67,3 @@ export interface ToConfigPlugins<TPluginContext extends PluginContext = PluginCo
| Promise<Plugin<TPluginContext> | null | Array<Plugin<TPluginContext> | null>>;
}
```

## `adapters`

The `adapters` property is a function that returns any number of `Adapter` instances.
Read more about adapters and the `Adapter` in [adapt.md](adapt.md) and [build.md](build.md#adapt).

```ts
export interface ToConfigAdapters<TArgs = any> {
(
ctx: AdapterContext<TArgs>,
):
| (Adapter<TArgs> | null | Array<Adapter<TArgs> | null>)
| Promise<Adapter<TArgs> | null | Array<Adapter<TArgs> | null>>;
}
```
Loading
Loading