Skip to content

Commit 4ee7256

Browse files
committed
updating sample build script
1 parent a796e70 commit 4ee7256

2 files changed

Lines changed: 57 additions & 36 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"test": "yarn test:ink && yarn test:css",
2020
"test:ink":"yarn --cwd packages/ink test",
2121
"test:css": "yarn --cwd packages/ink-css test",
22+
"test:web": "yarn --cwd packages/ink-web test",
2223
"dev:http": "yarn --cwd examples/with-http dev",
2324
"dev:express": "yarn --cwd examples/with-express dev",
2425
"dev:fastify": "yarn --cwd examples/with-fastify dev",

packages/ink-web/src/build.ts

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
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';
44
import { globSync as glob } from 'fast-glob';
5+
//ink
6+
import type { InkEvent, DocumentBuilder } from '@stackpress/ink/compiler';
57
import ink, { cache } from '@stackpress/ink/compiler';
68
import { 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
1016
const 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

Comments
 (0)