Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions language/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"editor.insertSpaces": false,
"editor.insertSpaces": true,
"typescript.tsc.autoDetect": "off",
"typescript.preferences.quoteStyle": "single",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
},
"editor.tabSize": 2,
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build:transformer": "yarn --cwd packages/idea-transformer build",
"build:idea": "yarn --cwd packages/idea build",
"build:example": "yarn --cwd example build",
"dev": "yarn --cwd packages/www dev",
"report": "yarn report:env nyc yarn test && nyc report -r lcov",
"report:env": "NODE_OPTIONS=\"--disable-warning=ExperimentalWarning --experimental-loader @istanbuljs/esm-loader-hook\"",
"transform": "yarn --cwd example transform",
Expand Down
137 changes: 137 additions & 0 deletions packages/www/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

archives
.ink
.DS_Store
.build

archives
93 changes: 93 additions & 0 deletions packages/www/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//node
import fs from 'node:fs/promises';
import path from 'node:path';
//stackpress
import { Terminal } from 'stackpress/terminal';
import * as scripts from 'stackpress/scripts';
//plugins
import { docs } from './config/common.js';
import bootstrap from './config/build.js';

async function build() {
const server = await bootstrap();
const cli = new Terminal(['build'], server);

cli.control.system('Copying public to docs...');
await fsCopyFolder(path.join(cli.cwd, 'public'), docs);

cli.control.system('Building pages, client and styles...');
await scripts.build(server);

cli.control.system('Generating markup in docs...');
const ignore = Array.from(server.action.expressions.keys());
const routes = Array.from(server.routes.entries()).filter(
([event]) => !ignore.includes(event)
);

for (const [event, route] of routes) {
const request = server.request({
url: new URL(`https://www.stackpress.io${route.path}`),
});
const response = await server.resolve(event, request);
cli.control.system(`Generating ${request.url.href} ...`);
if (response.results) {
const routepath = route.path.replace(/^\//, '');
const filepath = routepath === '' ? 'index.html' : `${routepath}.html`;
await fsWriteFile(
path.join(docs, filepath),
response.results as string
)
}
}
};

async function fsWriteFile(file: string, data: string) {
const dirname = path.dirname(file);
if (!await fsExists(dirname)) {
await fs.mkdir(dirname, { recursive: true });
}
await fs.writeFile(file, data, 'utf-8');
}

async function fsCopyFile(source: string, destination: string) {
if (await fsExists(source)) {
const dirname = path.dirname(destination);
if (!await fsExists(dirname)) {
await fs.mkdir(dirname, { recursive: true });
}
await fs.copyFile(source, destination);
}
};

async function fsCopyFolder(source: string, destination: string) {
//find all the files from source
const files = await fs.readdir(source);
for (const file of files) {
//ignore . and ..
if (file === '.' || file === '..') continue;
//make an absolute source path
const absolute = path.join(source, file);
const stat = await fs.stat(absolute);
//if file is a directory, recurse
if (stat.isDirectory()) {
fsCopyFolder(
path.join(source, file),
path.join(destination, file)
);
continue;
}
await fsCopyFile(absolute, path.join(destination, file));
}
};

async function fsExists(path: string) {
return await fs.access(path).then(() => true).catch(() => false);
}

build().then(() => {
console.log('Build completed successfully.');
process.exit(0);
}).catch((error) => {
console.error('Build failed:', error);
process.exit(1);
});
60 changes: 60 additions & 0 deletions packages/www/config/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//node
import path from 'node:path';
//modules
import unocss from 'unocss/vite';
//stackpress
import { server as http } from 'stackpress/http';
//config
import type { Config } from './common.js';
import * as common from './common.js';

export const config: Config = {
server: {
...common.server,
mode: 'production'
},
view: {
...common.view,
//reactus specific settings
engine: {
//path where to save assets (css, images, etc)
assetPath: path.join(common.docs, 'assets'),
//path where to save the client scripts (js)
clientPath: path.join(common.docs, 'client'),
//path where to save the server scripts (js)
pagePath: path.join(common.build, 'pages'),
//filepath to a global css file
cssFiles: [
'frui/frui.css',
'stackpress/stackpress.css',
'virtual:uno.css'
],
//vite plugins
plugins: [ unocss() ],
//original vite options (overrides other settings related to vite)
vite: undefined
}
},
brand: common.brand,
cli: common.cli,
cookie: common.cookie,
language: common.language,
session: common.session
};

export default async function bootstrap() {
//make a server
const server = http();
//set config
server.config.set(config);
//load the plugins
await server.bootstrap();
//initialize the plugins
await server.resolve('config');
//add events
await server.resolve('listen');
//add routes
await server.resolve('route');
//return the server
return server;
};
Loading