Skip to content

Commit 5dd84db

Browse files
committed
building docs
1 parent d986177 commit 5dd84db

File tree

247 files changed

+1415
-823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+1415
-823
lines changed

build.ts

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,94 @@
1+
//node
2+
import fs from 'node:fs/promises';
3+
import path from 'node:path';
14
//stackpress
25
import { terminalControls } from 'stackpress/terminal';
36
import * as scripts from 'stackpress/scripts';
47
//plugins
5-
import { bootstrap } from './config/build.js';
8+
import { docs } from './config/common.js';
9+
import bootstrap from './config/build.js';
610

711
async function build() {
812
const server = await bootstrap();
9-
const control = terminalControls('[EXAMPLE]');
10-
//make server, client and styles
11-
control.warning('Building pages, client and styles...');
13+
const cwd = server.config.path('server.cwd', process.cwd());
14+
const label = server.config.path('terminal.label', '[SP]');
15+
const control = terminalControls(label);
16+
17+
control.system('Copying public to docs...');
18+
await fsCopyFolder(path.join(cwd, 'public'), docs);
19+
20+
control.system('Building pages, client and styles...');
1221
await scripts.build(server);
22+
23+
control.system('Generating markup in docs...');
24+
const ignore = Array.from(server.action.expressions.keys());
25+
const routes = Array.from(server.routes.entries()).filter(
26+
([ event ]) => !ignore.includes(event)
27+
);
28+
for (const [ event, route ] of routes) {
29+
const response = await server.resolve(event);
30+
if (response.results) {
31+
const routepath = route.path.replace(/^\//, '');
32+
const filepath = routepath === '' ? 'index.html' : `${routepath}.html`;
33+
await fsWriteFile(
34+
path.join(docs, filepath),
35+
response.results as string
36+
)
37+
}
38+
}
39+
};
40+
41+
async function fsWriteFile(file: string, data: string) {
42+
const dirname = path.dirname(file);
43+
if (!await fsExists(dirname)) {
44+
await fs.mkdir(dirname, { recursive: true });
45+
}
46+
await fs.writeFile(file, data, 'utf-8');
47+
}
48+
49+
async function fsCopyFile(source: string, destination: string) {
50+
if (await fsExists(source)) {
51+
const dirname = path.dirname(destination);
52+
if (!await fsExists(dirname)) {
53+
await fs.mkdir(dirname, { recursive: true });
54+
}
55+
await fs.copyFile(source, destination);
56+
}
1357
};
1458

59+
async function fsCopyFolder(source: string, destination: string) {
60+
//find all the files from source
61+
const files = await fs.readdir(source);
62+
for (const file of files) {
63+
//ignore . and ..
64+
if (file === '.' || file === '..') continue;
65+
//make an absolute source path
66+
const absolute = path.join(source, file);
67+
const stat = await fs.stat(absolute);
68+
//if file is a directory, recurse
69+
if (stat.isDirectory()) {
70+
fsCopyFolder(
71+
path.join(source, file),
72+
path.join(destination, file)
73+
);
74+
continue;
75+
}
76+
await fsCopyFile(absolute, path.join(destination, file));
77+
}
78+
};
79+
80+
async function fsExists(path: string) {
81+
return await fs.access(path).then(() => true).catch(() => false);
82+
}
83+
84+
build().then(() => {
85+
console.log('Build completed successfully.');
86+
process.exit(0);
87+
}).catch((error) => {
88+
console.error('Build failed:', error);
89+
process.exit(1);
90+
});
91+
1592
build()
1693
.then(() => process.exit(0))
1794
.catch(e => {
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/2-plugin-architecture-bO-Z_G-l.css renamed to docs/assets/2-plugin-architecture-C9-SlId4.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/3-database-engine-C9-SlId4.css

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

docs/assets/3-database-engine-bO-Z_G-l.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/assets/3-server-routes-C9-SlId4.css

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

docs/assets/3-server-routes-bO-Z_G-l.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/assets/4-context-provider-C9-SlId4.css

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

0 commit comments

Comments
 (0)