Skip to content

Commit bafe970

Browse files
committed
remove code-group from examples
1 parent 637785b commit bafe970

8 files changed

Lines changed: 4 additions & 54 deletions

File tree

content/pinion/docs/composability.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ This chapter shows how to test generators, use them programmatically in CLI tool
1010

1111
Another generator can be directly imported and run like any other tasks:
1212

13-
::: code-group
14-
1513
```ts [generators/app.tpl.ts]
1614
import { PinionContext, exec } from '@featherscloud/pinion'
1715
import { generate as generateReadme } from './readme.tpl'
@@ -48,16 +46,12 @@ export function generate(init: Context) {
4846
}
4947
```
5048

51-
:::
52-
5349
```sh
5450
npx pinion generators/app.tpl.ts
5551
```
5652

5753
The [runGenerators](./api.md#rungenerators) tasks also allows to run all `.tpl.ts` generators in a folder in alphabetical order using the current context.
5854

59-
::: code-group
60-
6155
```ts [generators/app.tpl.ts]
6256
// Get current file and directory in an ES module
6357
import { fileURLToPath } from 'node:url'
@@ -108,8 +102,6 @@ export function generate(init: Context) {
108102
}
109103
```
110104

111-
:::
112-
113105
## Embedability
114106

115107
Since a generator is just a function that can be called anywhere, Pinion generators can be composed, tested or used programatically e.g. in your own CLI tools just by importing the file, initialising a context and calling the generator:
@@ -137,8 +129,6 @@ npx pinion generators/app.tpl.ts
137129

138130
Similar to an embedded generator, automated tests can be written by initializing the context - usually with a temporary path - and passing all context variables necessary to [skip user prompts](./user-input.md#prompting):
139131

140-
::: code-group
141-
142132
```ts [tests/readme.tpl.test.ts]
143133
import { describe, it } from 'node:test'
144134
import assert from 'node:assert'
@@ -221,8 +211,6 @@ export function generate(init: Context) {
221211
}
222212
```
223213

224-
:::
225-
226214
```sh
227215
node --import tsx --test test/readme.tpl.test.ts
228216
```

content/pinion/docs/generators.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ outline: deep
66

77
A Pinion generator is any file that has a `generate` export which takes a context and returns a Promise with that context. In its most basic form a Pinion generator looks like this:
88

9-
::: code-group
10-
119
```ts [generators/empty.tpl.ts]
1210
import { PinionContext } from '@featherscloud/pinion'
1311

@@ -18,8 +16,6 @@ interface Context extends PinionContext {}
1816
export const generate = (init: Context) => Promise.resolve(init)
1917
```
2018

21-
:::
22-
2319
```sh
2420
npx pinion generators/empty.tpl.ts
2521
```
@@ -92,6 +88,8 @@ Let's review key lines to see how to further define `Context`:
9288

9389
<!--@include: ./shared/context-extending-1.md-->
9490

91+
:embed-markdown{collection="pinionShared" path="pinion/shared/context-extending-1"}
92+
9593
The above example is a bit contrived because we can use TypeScript functions directly in templates. It's not necessary to define variables outside of templates like it is with other generator tools.
9694

9795
The concept to be learned is that you can add properties to `context` in the promise and they will be available in the template. This would be more useful if we extracted the function into its own module and reused it in multiple generators.
@@ -102,8 +100,6 @@ What's really cool is that there's no special magic to learn. To make a reusable
102100

103101
A task is any step within the `generate` function. Pinion tasks rely on functional programming through `Promise.then` chains. You can follow each step in the generator and they are still bundled as a testable and embedable plain function.
104102

105-
::: code-group
106-
107103
```ts [generators/tasks.tpl.ts]
108104
import { PinionContext, prompt } from '@featherscloud/pinion'
109105

@@ -151,8 +147,6 @@ export function generate(init: Context) {
151147
}
152148
```
153149

154-
:::
155-
156150
```sh
157151
npx pinion generators/tasks.tpl.ts
158152
```

content/pinion/docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ A Pinion generator has two ingredients:
3131

3232
The following file generates a basic `readme.md` from a TypeScript template string:
3333

34-
<!--@include: ./shared/quick-start-1-basics.md-->
34+
:embed-markdown{collection="pinionShared" path="pinion/shared/quick-start-1-basics"}
3535

3636
Once you ran the command, you can find your `readme.md` file in the current directory.
3737

@@ -41,7 +41,7 @@ Pinion comes with a `prompt` utility that works with your typed context. Let's g
4141

4242
You can ask questions from the command line with the [prompt](./generators.md#prompt) task:
4343

44-
<!--@include: ./shared/quick-start-2-user-input.md-->
44+
:embed-markdown{collection="pinionShared" path="pinion/shared/quick-start-2-user-input"}
4545

4646
Pinion uses [Inquirer](https://www.npmjs.com/package/inquirer) under the hood to ask questions. The `prompt` task takes an array or object of [Inquirer questions](https://www.npmjs.com/package/inquirer#question) and returns a function that takes a context and returns a promise with the updated context. We can then use this context in the next step to render our template with the answers.
4747

content/pinion/docs/templates.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ There are three main helpers for working with file pointers:
1616

1717
The following example asks for the path the `readme.md` file should be generated in and then puts the path together dynamically based on the context:
1818

19-
::: code-group
20-
2119
```ts [generators/readme.tpl.ts]
2220
import {
2321
PinionContext,
@@ -74,8 +72,6 @@ export function generate(init: Context) {
7472
}
7573
```
7674

77-
:::
78-
7975
```sh
8076
npx pinion generators/readme.tpl.ts
8177
```
@@ -91,8 +87,6 @@ While you could use them in your own tasks, Pinion tries to avoid difficult-to-d
9187

9288
It also allows composing templates by splitting them up into separate functions, and you have the entire JavaScript ecosystem (like [Lodash](https://lodash.com/)) available as helpers:
9389

94-
::: code-group
95-
9690
```ts [generators/readme.tpl.ts]
9791
import { upperFirst } from 'lodash'
9892
import { PinionContext, renderTemplate, toFile } from '@featherscloud/pinion'
@@ -128,8 +122,6 @@ export function generate(init: Context) {
128122
}
129123
```
130124

131-
:::
132-
133125
```sh
134126
npx pinion generators/readme.tpl.ts
135127
```
@@ -153,8 +145,6 @@ This is done by passing a template and an injection point to the `inject` task.
153145

154146
The following example generates a TypeScript Express middleware and imports and registers it in `src/app.ts`:
155147

156-
::: code-group
157-
158148
```ts [generators/middleware.tpl.ts]
159149
import {
160150
PinionContext,
@@ -221,8 +211,6 @@ const app = express()
221211
export { app }
222212
```
223213

224-
:::
225-
226214
```sh
227215
npx pinion generators/middleware.tpl.ts
228216
```

content/pinion/docs/user-input.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ This section shows how to handle user input through prompts and CLI arguments.
1010

1111
As [we have seen before](./index.md#asking-questions), the [prompt](./api.md#prompt) task allows to ask questions from the command line using the [Inquirer](https://www.npmjs.com/package/inquirer) library. It gets passed a [list of Inquirer questions](https://www.npmjs.com/package/inquirer#question) that can also be put together based on the current context. This can be used to e.g. ask questions conditionally or skip them if the value is already passed (e.g. in an automated test):
1212

13-
::: code-group
14-
1513
```ts [generators/readme.tpl.ts]
1614
import {
1715
PinionContext,
@@ -63,8 +61,6 @@ export function generate(init: Context) {
6361
}
6462
```
6563

66-
:::
67-
6864
```sh
6965
npx pinion generators/readme.tpl.ts
7066
```
@@ -79,8 +75,6 @@ npx pinion generators/readme.ts --description hello something
7975

8076
`context.argv` would be `['--description', 'hello', 'something']`. You can parse the list yourself and Pinion also ships with a [commander task](./api.md#commander) that uses the `commander` module to create command-line interfaces. The following example adds `--name` and `--description` command line arguments and skips prompting the user if it is passed.
8177

82-
::: code-group
83-
8478
```ts [generators/readme.tpl.ts]
8579
import {
8680
Command,
@@ -141,8 +135,6 @@ export function generate(init: Context) {
141135
}
142136
```
143137

144-
:::
145-
146138
```sh
147139
npx pinion generators/readme.tpl.ts --name Test --description "The description from the command line"
148140
```

content/pinion/shared/context-extending-1.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
::: code-group
2-
31
```ts:line-numbers {5,9,14,22} [generators/readme.tpl.ts]
42
import { PinionContext, toFile, renderTemplate } from '@featherscloud/pinion'
53
@@ -28,8 +26,6 @@ export const generate = (init: Context) => Promise.resolve(init)
2826
.then(renderTemplate(readme, toFile('readme.md')))
2927
```
3028

31-
:::
32-
3329
```sh
3430
npx pinion generators/readme.tpl.ts
3531
```

content/pinion/shared/quick-start-1-basics.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
::: code-group
2-
31
```ts [generators/readme.tpl.ts]
42
import { PinionContext, renderTemplate, toFile } from '@featherscloud/pinion'
53

@@ -22,8 +20,6 @@ export function generate(init: Context) {
2220
}
2321
```
2422

25-
:::
26-
2723
```sh
2824
npx pinion generators/readme.tpl.ts
2925
```

content/pinion/shared/quick-start-2-user-input.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
::: code-group
2-
31
```ts{7-8,25-34} [generators/readme.tpl.ts]
42
import {
53
PinionContext, renderTemplate, toFile, prompt
@@ -40,8 +38,6 @@ export const generate = (init: Context) => Promise.resolve(init)
4038
.then(renderTemplate(readme, toFile('readme.md')))
4139
```
4240

43-
:::
44-
4541
```sh
4642
npx pinion generators/readme.tpl.ts
4743
```

0 commit comments

Comments
 (0)