Skip to content

Commit 1579977

Browse files
committed
fix: Blueprint types
1 parent f09f8f8 commit 1579977

File tree

8 files changed

+91
-27
lines changed

8 files changed

+91
-27
lines changed

examples/blueprint.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { writeFile } from 'node:fs/promises'
2+
import { dirname, join } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
5+
import layouts from '@metalsmith/layouts'
6+
import * as types from '@seamapi/types/connect'
7+
import type { Builder, Command, Describe, Handler } from 'landlubber'
8+
import Metalsmith from 'metalsmith'
9+
import { mkdirp } from 'mkdirp'
10+
11+
import {
12+
blueprint,
13+
getHandlebarsPartials,
14+
handlebarsHelpers,
15+
} from '@seamapi/smith'
16+
17+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
18+
interface Options {}
19+
20+
export const command: Command = 'blueprint'
21+
22+
export const describe: Describe = 'Generate content from blueprint'
23+
24+
export const builder: Builder = {
25+
root: {
26+
type: 'string',
27+
default: 'test/fixtures/handlebars/partials',
28+
describe: 'TODO',
29+
},
30+
}
31+
32+
export const handler: Handler<Options> = async ({ logger }) => {
33+
const rootDir = dirname(fileURLToPath(import.meta.url))
34+
35+
await mkdirp('tmp')
36+
await writeFile(join('tmp', 'README.md'), Buffer.from(''))
37+
38+
const partials = await getHandlebarsPartials('examples/layouts/partials')
39+
40+
logger.info('Generating from blueprint')
41+
42+
Metalsmith(rootDir)
43+
.source('../tmp')
44+
.destination('../tmp/dist')
45+
.clean(true)
46+
.use(blueprint({ types }))
47+
.use(
48+
layouts({
49+
default: 'default.hbs',
50+
engineOptions: {
51+
noEscape: true,
52+
helpers: handlebarsHelpers,
53+
partials,
54+
},
55+
}),
56+
)
57+
.use((files: Metalsmith.Files, metalsmith: Metalsmith): void => {
58+
files['metadata.json'] = {
59+
contents: Buffer.from(JSON.stringify(metalsmith.metadata())),
60+
layout: 'default.hbs',
61+
}
62+
})
63+
.build((err) => {
64+
if (err != null) throw err
65+
})
66+
}

examples/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import landlubber from 'landlubber'
44

5-
import * as todo from './todo.js'
5+
import * as blueprint from './blueprint.js'
66

7-
const commands = [todo]
7+
const commands = [blueprint]
88

99
await landlubber(commands).parse()

examples/layouts/default.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{content}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# {{content}}

examples/todo.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"eslint": "^8.9.0",
8888
"jstransformer-handlebars": "^1.2.0",
8989
"metalsmith": "^2.6.3",
90+
"mkdirp": "^3.0.1",
9091
"prettier": "^3.0.0",
9192
"tsx": "^4.6.2",
9293
"typescript": "~5.3.3"
@@ -104,6 +105,7 @@
104105
"devDependencies": {
105106
"@metalsmith/layouts": "^2.7.0",
106107
"@seamapi/blueprint": "^0.43.1",
108+
"@seamapi/types": "^1.402.0",
107109
"@swc/core": "^1.11.29",
108110
"@types/debug": "^4.1.12",
109111
"@types/micromatch": "^4.0.9",
@@ -116,6 +118,7 @@
116118
"jstransformer-handlebars": "^1.2.0",
117119
"landlubber": "^2.0.0",
118120
"metalsmith": "^2.6.3",
121+
"mkdirp": "^3.0.1",
119122
"prettier": "^3.0.0",
120123
"tsc-alias": "^1.8.2",
121124
"tsup": "^8.0.1",

src/lib/blueprint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export const blueprint =
1212
skipCodeFormat = false,
1313
}: {
1414
types: unknown
15-
formatCode: BlueprintOptions['formatCode']
16-
skipCodeFormat: boolean
15+
formatCode?: BlueprintOptions['formatCode']
16+
skipCodeFormat?: boolean
1717
}) =>
1818
async (_files: Metalsmith.Files, metalsmith: Metalsmith): Promise<void> => {
1919
const metadata = metalsmith.metadata()

0 commit comments

Comments
 (0)