Skip to content

Commit 878f20f

Browse files
committed
ssg framework
1 parent 39e5358 commit 878f20f

33 files changed

Lines changed: 5011 additions & 0 deletions

build.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//stackpress
2+
import { terminalControls } from 'stackpress/terminal';
3+
import * as scripts from 'stackpress/scripts';
4+
//plugins
5+
import { bootstrap } from './config/build.js';
6+
7+
async function build() {
8+
const server = await bootstrap();
9+
const control = terminalControls('[EXAMPLE]');
10+
//make server, client and styles
11+
control.warning('Building pages, client and styles...');
12+
await scripts.build(server);
13+
};
14+
15+
build()
16+
.then(() => process.exit(0))
17+
.catch(e => {
18+
console.error(e);
19+
process.exit(1);
20+
});

config/build.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//node
2+
import path from 'node:path';
3+
//modules
4+
import unocss from 'unocss/vite';
5+
//stackpress
6+
import { server as http } from 'stackpress/http';
7+
//config
8+
import type { Config } from './common.js';
9+
import * as common from './common.js';
10+
11+
export const config: Config = {
12+
server: {
13+
...common.server,
14+
mode: 'production'
15+
},
16+
view: {
17+
...common.view,
18+
//reactus specific settings
19+
engine: {
20+
//path where to save assets (css, images, etc)
21+
assetPath: path.join(common.assets, 'assets'),
22+
//path where to save the client scripts (js)
23+
clientPath: path.join(common.assets, 'client'),
24+
//filepath to a global css file
25+
cssFiles: [
26+
'frui/frui.css',
27+
'stackpress/stackpress.css',
28+
'virtual:uno.css'
29+
],
30+
//vite plugins
31+
plugins: [ unocss() ],
32+
//original vite options (overrides other settings related to vite)
33+
vite: undefined
34+
}
35+
},
36+
brand: common.brand,
37+
cli: common.cli,
38+
cookie: common.cookie,
39+
language: common.language,
40+
session: common.session
41+
};
42+
43+
export async function bootstrap() {
44+
//make a server
45+
const server = http();
46+
//set config
47+
server.config.set(config);
48+
//load the plugins
49+
await server.bootstrap();
50+
//initialize the plugins
51+
await server.resolve('config');
52+
//add events
53+
await server.resolve('listen');
54+
//add routes
55+
await server.resolve('route');
56+
//return the server
57+
return server;
58+
};

config/common.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//node
2+
import path from 'node:path';
3+
4+
export type { Config } from 'stackpress/types';
5+
6+
export const cwd = process.cwd();
7+
export const build = path.join(cwd, '.build');
8+
export const assets = path.join(cwd, 'public');
9+
10+
export const brand = {
11+
name: 'Stackpress',
12+
logo: '/logo.png',
13+
icon: '/icon.png',
14+
favicon: '/favicon.ico'
15+
};
16+
17+
export const server = {
18+
port: 3000,
19+
cwd: cwd
20+
};
21+
22+
export const view = {
23+
//url flag (ie. ?json) used to disable template
24+
//rendering and show the raw json data instead
25+
noview: 'json',
26+
//used by vite and in development mode
27+
//to determine the root of the project
28+
base: '/',
29+
//frontend notification display settings
30+
notify: {
31+
position: 'bottom-center',
32+
autoClose: 5000,
33+
hideProgressBar: false,
34+
closeOnClick: true,
35+
pauseOnHover: true,
36+
draggable: true,
37+
theme: 'dark',
38+
}
39+
};
40+
41+
export const session = {
42+
//name of the session cookie
43+
key: 'session',
44+
//used to generate the session id
45+
seed: 'abc123',
46+
access: {
47+
GUEST: [
48+
//page routes
49+
{ method: 'ALL', route: '/' },
50+
{ method: 'GET', route: '/form' },
51+
{ method: 'ALL', route: '/auth/**' },
52+
{ method: 'ALL', route: '/api/**' }
53+
]
54+
}
55+
};
56+
57+
export const cookie = {
58+
//see: https://github.com/jshttp/cookie?tab=readme-ov-file#options-1
59+
path: '/'
60+
};
61+
62+
export const language = {
63+
//url flag (ie. ?json) used to change the user's locale
64+
//this is also the name of the cookie used to store the locale
65+
key: 'locale',
66+
//default locale
67+
locale: 'en_US',
68+
//languages and translations
69+
languages: {
70+
en_US: {
71+
label: 'EN',
72+
translations: {
73+
'Sign In': 'Signin',
74+
'Home Page': 'Home Page'
75+
}
76+
},
77+
th_TH: {
78+
label: 'TH',
79+
translations: {
80+
'Sign In': 'Signin',
81+
'Home Page': 'Home Pagesss'
82+
}
83+
}
84+
}
85+
};
86+
87+
export const cli = {
88+
label: '[WWW]',
89+
idea: path.join(cwd, 'schema.idea')
90+
};

config/develop.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//modules
2+
import unocss from 'unocss/vite';
3+
//stackpress
4+
import { server as http } from 'stackpress/http';
5+
//config
6+
import type { Config } from './common.js';
7+
import * as common from './common.js';
8+
9+
export const config: Config = {
10+
server: {
11+
...common.server,
12+
mode: 'development'
13+
},
14+
view: {
15+
...common.view,
16+
//reactus specific settings
17+
engine: {
18+
//base path (used in vite)
19+
basePath: '/',
20+
//client script route prefix used in the document markup
21+
//ie. /client/[id][extname]
22+
//<script type="module" src="/client/[id][extname]"></script>
23+
//<script type="module" src="/client/abc123.tsx"></script>
24+
clientRoute: '/client',
25+
//filepath to a global css file
26+
cssFiles: [
27+
'frui/frui.css',
28+
'stackpress/stackpress.css',
29+
'virtual:uno.css'
30+
],
31+
//vite plugins
32+
plugins: [ unocss() ]
33+
}
34+
},
35+
session: {
36+
...common.session,
37+
access: {
38+
GUEST: [
39+
...common.session.access.GUEST,
40+
//dev routes
41+
{ method: 'ALL', route: '/@vite/client' },
42+
{ method: 'ALL', route: '/@react-refresh' },
43+
{ method: 'ALL', route: '/@fs/**' },
44+
{ method: 'ALL', route: '/node_modules/**' },
45+
{ method: 'ALL', route: '/__uno.css' },
46+
{ method: 'ALL', route: '/plugins/**' },
47+
{ method: 'ALL', route: '/react.svg' },
48+
//public routes
49+
{ method: 'GET', route: '/assets/**' },
50+
{ method: 'GET', route: '/client/**' },
51+
{ method: 'GET', route: '/images/**' },
52+
{ method: 'GET', route: '/styles/**' },
53+
{ method: 'GET', route: '/favicon.ico' },
54+
{ method: 'GET', route: '/favicon.png' },
55+
]
56+
}
57+
},
58+
brand: common.brand,
59+
cli: common.cli,
60+
cookie: common.cookie,
61+
language: common.language
62+
};
63+
64+
export async function bootstrap() {
65+
//make a server
66+
const server = http();
67+
//set config
68+
server.config.set(config);
69+
//load the plugins
70+
await server.bootstrap();
71+
//initialize the plugins
72+
await server.resolve('config');
73+
//add events
74+
await server.resolve('listen');
75+
//add routes
76+
await server.resolve('route');
77+
//return the server
78+
return server;
79+
};

config/preview.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//node
2+
import path from 'node:path';
3+
//stackpress
4+
import type { Server } from 'stackpress/server';
5+
import { server as http } from 'stackpress/http';
6+
//plugin
7+
import assets from '../plugins/assets/plugin.js';
8+
//config
9+
import type { Config } from './common.js';
10+
import * as common from './common.js';
11+
12+
export const config: Config = {
13+
assets: common.assets,
14+
server: {
15+
...common.server,
16+
mode: 'production'
17+
},
18+
view: {
19+
...common.view,
20+
//reactus specific settings
21+
engine: {
22+
//client script route prefix used in the document markup
23+
//ie. /client/[id][extname]
24+
//<script type="module" src="/client/[id][extname]"></script>
25+
//<script type="module" src="/client/abc123.tsx"></script>
26+
clientRoute: '/client',
27+
//style route prefix used in the document markup
28+
//ie. /assets/[id][extname]
29+
//<link rel="stylesheet" type="text/css" href="/client/[id][extname]" />
30+
//<link rel="stylesheet" type="text/css" href="/assets/abc123.css" />
31+
cssRoute: '/assets',
32+
//path where to save and load (live) the server script (js)
33+
pagePath: path.join(common.cwd, '.build/views')
34+
}
35+
},
36+
brand: common.brand,
37+
cli: common.cli,
38+
cookie: common.cookie,
39+
language: common.language
40+
};
41+
42+
export async function bootstrap() {
43+
//make a server
44+
const server = http();
45+
//set config
46+
server.config.set(config);
47+
//load the plugins
48+
await server.bootstrap();
49+
//add the assets plugin
50+
assets(server as Server);
51+
//initialize the plugins
52+
await server.resolve('config');
53+
//add events
54+
await server.resolve('listen');
55+
//add routes
56+
await server.resolve('route');
57+
//return the server
58+
return server;
59+
};

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"type": "module",
3+
"name": "stackpress-with-unocss",
4+
"version": "1.0.0",
5+
"private": true,
6+
"plugins": [
7+
"./plugins/app/plugin",
8+
"stackpress"
9+
],
10+
"scripts": {
11+
"build": "tsx build.ts",
12+
"dev": "dotenv -e .env -- stackpress config/develop serve -v",
13+
"emit": "dotenv -e .env -- stackpress config/develop emit -v",
14+
"preview": "dotenv -e .env -- stackpress config/preview serve -v"
15+
},
16+
"dependencies": {
17+
"frui": "0.1.6",
18+
"react": "19.1.0",
19+
"react-dom": "19.1.0",
20+
"stackpress": "0.2.9"
21+
},
22+
"devDependencies": {
23+
"@stackpress/idea-transformer": "0.5.15",
24+
"@types/chai": "5.2.1",
25+
"@types/mocha": "10.0.10",
26+
"@types/node": "22.14.1",
27+
"@types/react": "19.1.2",
28+
"@types/react-dom": "19.1.2",
29+
"@vitejs/plugin-react": "4.4.1",
30+
"chai": "5.2.0",
31+
"dotenv-cli": "8.0.0",
32+
"fast-glob": "3.3.3",
33+
"mocha": "11.2.2",
34+
"nyc": "17.1.0",
35+
"prettier": "3.5.3",
36+
"ts-mocha": "11.1.0",
37+
"ts-morph": "25.0.1",
38+
"ts-node": "10.9.2",
39+
"tsx": "4.19.3",
40+
"typescript": "5.8.3",
41+
"unocss": "66.0.0",
42+
"vite": "6.3.2"
43+
}
44+
}

0 commit comments

Comments
 (0)