1- import type { InkEvent , DocumentBuilder } from '@stackpress/ink/compiler' ;
2-
3- import path from 'path' ;
1+ //modules
2+ import fs from 'node:fs' ;
3+ import path from 'node: path' ;
44import { globSync as glob } from 'fast-glob' ;
5+ //ink
6+ import type { InkEvent , DocumentBuilder } from '@stackpress/ink/compiler' ;
57import ink , { cache } from '@stackpress/ink/compiler' ;
68import { plugin } from '@stackpress/ink-css' ;
79
8- const docs = path . resolve ( __dirname , '../../../docs' ) ;
10+ const docs = path . resolve (
11+ __dirname ,
12+ '../../../docs'
13+ ) ;
14+
915//create ink compiler
1016const compiler = ink ( {
1117 brand : '' ,
@@ -45,37 +51,51 @@ compiler.emitter.on('rendered', (event: InkEvent<string>) => {
4551 }
4652} ) ;
4753
48- // first build all the templates
49- glob (
50- 'pages/**/*.ink' ,
51- { cwd : __dirname }
52- ) . forEach ( async file => {
53- //default props
54- const props = { title : 'Ink Documentation' } ;
55- //ex. pages/index.ink
56- const template = path . join ( __dirname , file ) ;
57- //get builder
58- const builder = compiler . fromSource ( template ) ;
59- //update manifest in memory
60- compiler . manifest . set (
61- builder . document . id ,
62- builder . document . absolute
63- ) ;
64- //get the build object
65- const build = await builder . build ( ) ;
66- //emit view render event
67- const pre = await compiler . emitter . waitFor < string > (
68- 'render' ,
69- { builder, build, props }
70- ) ;
71- //render the document
72- const html = pre . data || build . document . render ( props ) ;
73- //emit view rendered event
74- await compiler . emitter . waitFor < string > (
75- 'rendered' ,
76- { builder, build, props, html }
54+ //get all the templates
55+ const templates = glob ( 'pages/**/*.ink' , { cwd : __dirname } ) ;
56+
57+ async function build ( ) {
58+ //loop through the templates
59+ for ( const file of templates ) {
60+ //default props
61+ const props = { title : 'Ink Documentation' } ;
62+ //ex. pages/index.ink
63+ const template = path . join ( __dirname , file ) ;
64+ //get builder
65+ const builder = compiler . fromSource ( template ) ;
66+ //update manifest in memory
67+ compiler . manifest . set (
68+ builder . document . id ,
69+ builder . document . relative
70+ ) ;
71+ //get the build object
72+ const build = await builder . build ( ) ;
73+ //emit view render event
74+ const pre = await compiler . emitter . waitFor < string > (
75+ 'render' ,
76+ { builder, build, props }
77+ ) ;
78+ //render the document
79+ const html = pre . data || build . document . render ( props ) ;
80+ //emit view rendered event
81+ await compiler . emitter . waitFor < string > (
82+ 'rendered' ,
83+ { builder, build, props, html }
84+ ) ;
85+ await builder . client ( ) ;
86+ await builder . styles ( ) ;
87+ await builder . markup ( ) ;
88+ }
89+
90+ fs . writeFileSync (
91+ path . join ( docs , 'build' , 'manifest.json' ) ,
92+ compiler . manifest . toJson ( )
7793 ) ;
78- await builder . client ( ) ;
79- await builder . styles ( ) ;
80- await builder . markup ( ) ;
94+ }
95+
96+ build ( ) . then ( ( ) => {
97+ process . exit ( 0 ) ;
98+ } ) . catch ( e => {
99+ console . error ( e ) ;
100+ process . exit ( 1 ) ;
81101} ) ;
0 commit comments