Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

epic: CLI + plugins #177

Merged
merged 101 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
1fcb2c0
feat: CLI
tpluscode Oct 2, 2024
cca64b6
test: update usage
tpluscode Oct 2, 2024
fd489b3
feat: express plugin, deploy plugin
tpluscode Oct 4, 2024
fc381a0
build(deps): include plugins by default
tpluscode Oct 4, 2024
c0c97f7
refactor: plugin config as object
tpluscode Oct 4, 2024
c047566
test: new config
tpluscode Oct 4, 2024
2708fd5
ci: ignore example from coverage
tpluscode Oct 4, 2024
554c1ec
wip: vite
tpluscode Oct 4, 2024
dac8666
Merge branch 'master' into plugin-vite
tpluscode Oct 7, 2024
3e30f38
wip: html+vite
tpluscode Oct 9, 2024
41fe9a7
feat(vite): default out dire relative to working dir
tpluscode Oct 9, 2024
968a961
Merge branch 'handler-chain' into plugins
tpluscode Oct 9, 2024
6a8f86f
Merge branch 'plugins' into plugin-vite
tpluscode Oct 9, 2024
a80a3be
docs(example): update readme
tpluscode Oct 9, 2024
6775ad1
chore: use mode
tpluscode Oct 9, 2024
55c8e84
style: lint
tpluscode Oct 9, 2024
5494e50
test: handler as factory
tpluscode Oct 9, 2024
ed72899
refactor: prevent vite pre-transform error
tpluscode Oct 9, 2024
730ecc2
feat: templates
tpluscode Oct 10, 2024
f1e03d9
build: fix deps
tpluscode Oct 10, 2024
01c02a4
spike: lit ssr
tpluscode Oct 12, 2024
ad7cd98
refactor: absolute src in script
tpluscode Oct 14, 2024
0e2588d
build: up oxigraph
tpluscode Oct 14, 2024
55ff114
Merge branch 'plugins' into plugin-vite
tpluscode Oct 14, 2024
7a699b4
Merge branch 'plugin-vite' into templates
tpluscode Oct 14, 2024
0ab9597
Merge branch 'templates' into ssr
tpluscode Oct 14, 2024
36ad33c
fix: use preferred import
tpluscode Oct 14, 2024
e545294
lint
tpluscode Oct 14, 2024
0af0958
chore: changeset
tpluscode Oct 14, 2024
8283580
refactor: render all nodes when multiple found by path
tpluscode Oct 16, 2024
e951514
Merge branch 'templates' into ssr
tpluscode Oct 16, 2024
6b605aa
ci: exclude example from coverage
tpluscode Oct 16, 2024
cc60b6c
refactor: merge express plugin with express host itself
tpluscode Oct 17, 2024
59f2990
test: middleware args
tpluscode Oct 17, 2024
be93e5a
test: deploy plugin
tpluscode Oct 17, 2024
8b3d8ba
lint: fixes
tpluscode Oct 17, 2024
5437284
test: cases for paths
tpluscode Oct 17, 2024
529759b
Merge branch 'plugins' into plugin-vite
tpluscode Oct 18, 2024
85cffe6
test: fix handler double
tpluscode Oct 18, 2024
255b485
refactor: better use of import.meta.url
tpluscode Oct 18, 2024
55e65a6
Update odd-hounds-float.md
tpluscode Oct 18, 2024
073dc7e
feat(serve-file): override content type
tpluscode Oct 18, 2024
4ebdc31
feat(serve-file): fallback content type
tpluscode Oct 18, 2024
9100b59
Merge branch 'plugins' into plugin-vite
tpluscode Oct 21, 2024
f390275
test: missing coverage
tpluscode Oct 21, 2024
8d750c5
test: vite config for tests
tpluscode Oct 21, 2024
cf7d302
test: more robust
tpluscode Oct 21, 2024
c5610d5
test(cli): config discovery
tpluscode Oct 21, 2024
57bb5dc
Merge branch 'plugin-vite' into ssr
tpluscode Oct 21, 2024
83d7204
build: package files
tpluscode Oct 21, 2024
2725e82
refactor: add types to CLI action
tpluscode Oct 22, 2024
fb65010
test: times out on node 18
tpluscode Oct 22, 2024
5173bb2
Merge branch 'plugin-vite' into templates
tpluscode Oct 22, 2024
269db4f
build(deps): missing dependency
tpluscode Oct 22, 2024
05e4d48
revert: keep default build dir
tpluscode Oct 22, 2024
a4b65c6
build+test: template packages
tpluscode Oct 22, 2024
e9f8281
chore: update lock
tpluscode Oct 22, 2024
bff0ebf
style: ignore lint errors
tpluscode Oct 22, 2024
33cf350
ci: no tests in handlebars yet
tpluscode Oct 22, 2024
ddd6de6
test: pointers passed to templates
tpluscode Oct 23, 2024
a4cc406
feat: parse and process any SPARQL path in template
tpluscode Oct 25, 2024
8616d42
refactor: make a plugin for shorthand terms
tpluscode Oct 18, 2024
df54f93
fix: update the other plugin
tpluscode Oct 18, 2024
f763de4
build(deps-dev): required for linting
tpluscode Oct 18, 2024
ed0d222
feat(express middleware): support named exports
tpluscode Oct 18, 2024
2ccaf78
chore: change ignore settings
tpluscode Oct 25, 2024
9405be5
build: tweaks
tpluscode Oct 25, 2024
cef50aa
style: ignore parser package
tpluscode Oct 25, 2024
710f80f
ci: ignore generated grammar from coverage
tpluscode Oct 25, 2024
0502e6a
Merge pull request #178 from zazuko/plugins
tpluscode Oct 25, 2024
06609ac
Merge remote-tracking branch 'origin/cli' into plugin-vite
tpluscode Oct 25, 2024
df878cc
Merge branch 'plugin-vite' into templates
tpluscode Oct 25, 2024
c41c2be
test: handlebars
tpluscode Oct 25, 2024
392c7ed
test: parsing all kinds of paths
tpluscode Oct 25, 2024
06a03be
test: fix mocha code
tpluscode Oct 25, 2024
d7f165a
feat: relative paths in templates
tpluscode Oct 25, 2024
996b55c
build(deps): use is-relative-url instead
tpluscode Oct 25, 2024
b93cf09
Merge branch 'templates' into ssr
tpluscode Oct 25, 2024
ca71671
build(deps): remove old plugin dependency
tpluscode Oct 25, 2024
84920d6
build(deps): remove old plugin dependency
tpluscode Oct 25, 2024
1c359bb
Merge branch 'cli' into plugin-vite
tpluscode Oct 25, 2024
e7cb076
Merge branch 'cli' into templates
tpluscode Oct 25, 2024
49a40d3
Merge branch 'templates' into ssr
tpluscode Oct 25, 2024
b4ca3dc
Merge branch 'plugin-vite' into templates
tpluscode Oct 25, 2024
fa059ba
build: ensure rollup optional packages
tpluscode Oct 25, 2024
72da30f
ci: run each package in separate job (#187)
tpluscode Oct 25, 2024
0eda9e4
Merge remote-tracking branch 'origin/cli' into plugin-vite
tpluscode Oct 25, 2024
a920e91
ci: test added packages
tpluscode Oct 25, 2024
4bc4541
Merge branch 'plugin-vite' into templates
tpluscode Oct 25, 2024
d85897d
ci: test added packages
tpluscode Oct 25, 2024
a388df0
Merge branch 'templates' into ssr
tpluscode Oct 25, 2024
91202c1
build: duplicate types failed test
tpluscode Oct 28, 2024
bba246c
build(deps): update express to v5
tpluscode Oct 28, 2024
192b5a4
test: default out dir
tpluscode Oct 28, 2024
28ba141
build(deps): remove middleware-async
tpluscode Oct 28, 2024
04cc067
Merge pull request #183 from zazuko/ssr
tpluscode Nov 6, 2024
f4d5f3e
test: increase timeout for GH
tpluscode Nov 6, 2024
fc2591e
Merge pull request #182 from zazuko/templates
tpluscode Nov 6, 2024
9e12ff4
Merge pull request #181 from zazuko/plugin-vite
tpluscode Nov 6, 2024
5ed0cda
Merge remote-tracking branch 'origin/master' into cli
tpluscode Nov 6, 2024
201b5df
build(deps): reinstall to fix rollup
tpluscode Nov 6, 2024
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
6 changes: 6 additions & 0 deletions .changeset/dirty-mugs-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kopflos-cms/plugin-deploy-resources": minor
"@kopflos-cms/plugin-express": minor
---

First version
6 changes: 6 additions & 0 deletions .changeset/dry-moose-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kopflos-cms/core": patch
---

Extracted logger to a new package `@kopflos-cms/core`

6 changes: 6 additions & 0 deletions .changeset/five-avocados-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kopflos-cms/core": patch
"@kopflos-cms/express": patch
---

Support for direct stream, using Web Streams
5 changes: 5 additions & 0 deletions .changeset/friendly-geese-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/core": patch
---

Revert dependency on `anylogger` to stable v1 branch
5 changes: 5 additions & 0 deletions .changeset/gentle-apes-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/vite": patch
---

Ensure the the `outDir` setting is also used for serving files in in production mode
30 changes: 30 additions & 0 deletions .changeset/odd-hounds-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@kopflos-cms/core": patch
---

Added support for templated resource shapes. Use `kl:regex` a pattern to match the request URL path.
Additionally, named capturing groups can be used to extract values from the URL path. They will be
accessible as `HandlerArgs#subjectVariables` and included when resolving `code:EcmaScriptTemplateLiteral`.

```turtle
<#WebPage>
a kl:ResourceShape ;
kl:api <> ;
sh:target
[
a kl:PatternedTarget ;
kl:regex "/(?<type>[^/]+).+\\.html$" ;
] ;
kl:handler
[
a kl:Handler ;
kl:method "GET" ;
code:implementedBy
[
a code:EcmaScriptModule ;
code:link <node:@kopflos-cms/serve-file#default> ;
code:arguments ( "pages/${type}.html"^^code:EcmaScriptTemplateLiteral ) ;
] ;
] ;
.
```
29 changes: 29 additions & 0 deletions .changeset/pink-eggs-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@kopflos-cms/core": minor
---

Handlers: Added support for `code:arguments`. Please refer to [rdf-loader-code](https://github.com/zazuko/rdf-loader-code?tab=readme-ov-file#loading-function-arguments) for more information.

```turtle
[
a kl:Handler ;
code:implementedBy [
a code:EcmaScriptModule ;
code:link <...> ;
code:arguments ("foo" "bar") ;
] ;
] .
```

Implementors must now return a factory function that returns the handler function.

```diff
import type { Handler } from "@kopflos-cms/core";

- export default function handler() {
+ export default function handler(foo, bar): Handler {
return async function handlerFunction() {
// ...
};
}
```
5 changes: 5 additions & 0 deletions .changeset/real-numbers-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/express": minor
---

The main export now returns `Promise<{ middleware: RequestHandler; instance: Kopflos }>`
5 changes: 5 additions & 0 deletions .changeset/red-bottles-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/serve-file": minor
---

First version: serve files directly, with an option to stream directly
5 changes: 5 additions & 0 deletions .changeset/shy-rivers-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kopflos": patch
---

Added `--variable <key=value>` option to override config variables
6 changes: 6 additions & 0 deletions .changeset/sixty-suns-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kopflos-labs/html-template": minor
"@kopflos-labs/handlebars": minor
---

First version
7 changes: 7 additions & 0 deletions .changeset/stupid-ads-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@kopflos-cms/express": patch
"@kopflos-cms/core": patch
"kopflos": patch
---

Added plugin with `onStart` hook
6 changes: 6 additions & 0 deletions .changeset/tame-cobras-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kopflos-cms/plugin-express": minor
"@kopflos-cms/express": minor
---

Added express-only middleware hooks
5 changes: 5 additions & 0 deletions .changeset/tender-countries-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sparql-path-parser": minor
---

First version
5 changes: 5 additions & 0 deletions .changeset/thick-socks-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-labs/lit": minor
---

First version - Server-Side rendering
5 changes: 5 additions & 0 deletions .changeset/thin-buses-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kopflos": minor
---

First version
5 changes: 5 additions & 0 deletions .changeset/thin-penguins-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/core": patch
---

Added `./env.js` to package exports
5 changes: 5 additions & 0 deletions .changeset/tiny-eels-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/express": patch
---

Ensure that middlewares from multiple plugins are registered in order
5 changes: 5 additions & 0 deletions .changeset/tough-peas-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/core": patch
---

Added support for `code:EcmaScriptTemplateLiteral`
5 changes: 5 additions & 0 deletions .changeset/wet-shirts-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/logger": minor
---

Extracted package from `@kopflos-cms/core`
5 changes: 5 additions & 0 deletions .changeset/wild-cooks-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kopflos": patch
---

Added `--mode (development|production)` option
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
},
"env": {
"mocha": true
}
},
"ignorePatterns": [
"packages/sparql-path-parser/"
]
}
21 changes: 20 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,38 @@ jobs:
unit-tests:
runs-on: [ ubuntu-latest ]
strategy:
fail-fast: false
matrix:
node: [ 18, 20, "lts/*" ]
package:
- name: "@kopflos-cms/core"
path: packages/core
- name: "@kopflos-cms/express"
path: packages/express
- name: "@kopflos-cms/plugin-deploy-resources"
path: packages/plugin-deploy-resources
- name: "@kopflos-cms/serve-file"
path: packages/serve-file
- name: "@kopflos-cms/vite"
path: packages/vite
- name: "@kopflos-labs/html-template"
path: labs/html-template
- name: "@kopflos-labs/handlebars"
path: labs/handlebars
- name: sparql-path-parser
path: packages/sparql-path-parser
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npx c8 --all --reporter lcovonly npm run --ws --if-present test
- run: npx c8 --all --src ${{ matrix.package.path }} --reporter lcovonly --reporter text npm run -w ${{ matrix.package.path }} test
- name: Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: ${{ matrix.package.name }}

lint:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage
node_modules
*.d.ts
*.js
*.js.map
3 changes: 2 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ignore:
- packages/mocha-chai-rdf
- example
- packages/sparql-path-parser/src/grammar
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
oxigraph/
dist/
35 changes: 35 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Kopflos example

API inspired by [Read the Plaque](https://readtheplaque.com/).

## Start

1. Start the database:
```bash
docker compose up -d
```
2. Start the server in development mode:
```bash
npx kopflos serve --mode development
```

The API is running on http://localhost:1429

## Details

When starting, `kopflos` automatically seeds the database wit resource from directories `resources` and
`resources.dev` (configured in `kopflos.config.ts`).

## Building for production

First run the build command which uses vite to transform and bundle HTML templates.

```bash
npx kopflos build
```

Then start the server in production mode:

```bash
npx kopflos serve
```
10 changes: 10 additions & 0 deletions example/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '2'
services:
oxigraph:
image: ghcr.io/oxigraph/oxigraph:0.4.1
user: root
command: serve --location /data --bind 0.0.0.0:7878
ports:
- 7878:7878
volumes:
- ./oxigraph:/data
32 changes: 32 additions & 0 deletions example/kopflos.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as url from 'node:url'
import type { KopflosConfig } from '@kopflos-cms/core'

export default <KopflosConfig> {
baseIri: 'http://localhost:1429',
apiGraphs: ['http://localhost:1429/api'],
sparql: {
default: {
endpointUrl: 'http://localhost:7878/query?union-default-graph',
updateUrl: 'http://localhost:7878/update',
},
},
variables: {
uiRoot: 'ui',
},
plugins: {
'@kopflos-cms/plugin-deploy-resources': {
paths: ['resources', 'resources.dev'],
},
'@kopflos-cms/express/middleware': {
before: [
'cors',
['compression', { level: 9 }],
url.fileURLToPath(new URL('lib/static.js', import.meta.url)),
],
},
'@kopflos-cms/vite': {
root: 'ui',
entrypoints: ['ui/*.html'],
},
},
}
5 changes: 5 additions & 0 deletions example/lib/static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import express from 'express'

export default (): express.RequestHandler => {
return express.static('public')
}
7 changes: 7 additions & 0 deletions example/lib/templateData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TemplateDataFunc } from '@kopflos-labs/html-template'

export const describe = (resourcePath: string): TemplateDataFunc => ({ env }) => {
return env.sparql.default.stream.query.construct(`
BASE <${env.kopflos.config.baseIri}>
DESCRIBE <${resourcePath}>`)
}
30 changes: 30 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "example",
"private": true,
"type": "module",
"scripts": {
"build": "kopflos build",
"start": "kopflos serve --mode development --trust-proxy",
"prestart:prod": "npm run build",
"start:prod": "kopflos serve --trust-proxy --variable uiRoot=dist"
},
"dependencies": {
"@kopflos-cms/vite": "*",
"@kopflos-cms/serve-file": "*",
"@kopflos-labs/html-template": "*",
"@kopflos-labs/handlebars": "*",
"@kopflos-labs/lit": "*",
"@openlayers-elements/core": "^0.3.0",
"@openlayers-elements/maps": "^0.3.0",
"@shoelace-style/shoelace": "^2.17.1",
"@webcomponents/template-shadowroot": "^0.2.1",
"express": "^5.0.1",
"kopflos": "*",
"lit-element": "^4.1.1",
"cors": "^2.8.5",
"compression": "^1.7.4"
},
"devDependencies": {
"@types/express": "^5"
}
}
1 change: 1 addition & 0 deletions example/public/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar
Loading