Skip to content

Commit

Permalink
switch to pnpm and move docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrider-05 committed Oct 31, 2023
1 parent fc339a6 commit a2f8de3
Show file tree
Hide file tree
Showing 144 changed files with 8,476 additions and 12,396 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Process for contributing to this package:
1. Find [an issue][issues] or [feature request][features] to work on
1. Fork & clone the repository
1. Create a new branch and make the changes on this branch
1. Run `npm run format` and commit your changes.
1. Run `pnpm format` and commit your changes.
1. [Create a new pull request][compare] and address any feedback

[issues]: https://github.com/ghostrider-05/kismet.ts/issues
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install node.js v16
- uses: pnpm/action-setup@v2
with:
version: 8

- name: Install node.js v18
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: npm ci
run: pnpm install

- name: Compile
run: npm run prestart
run: pnpm prestart

- name: ESLint & Prettier
run: npm run lint
run: pnpm lint

- name: Tests
run: npm run test
run: pnpm test

# TODO: write
# - name: Tests
Expand Down
19 changes: 10 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ git-*
*.cs
*.txt
*.py
extract.bat

# Docs
docs/core/
docs/items/
docs/kismet.ts/
docs/parsers/
docs/parsers-node/
docs/shared/
docs/util/
docs/.vuepress/example.ts
docs/.vuepress/packages/
apps/docs/src/core/
apps/docs/src/items/
apps/docs/src/kismet.ts/
apps/docs/src/parsers/
apps/docs/src/parsers-node/
apps/docs/src/shared/
apps/docs/src/util/
apps/docs/src/.vuepress/example.ts
apps/docs/src/.vuepress/packages/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use-node-version=18.18.2
9 changes: 9 additions & 0 deletions apps/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Guide changelog

## 10-05-2023

- add section about comparing local classes

## 23-01-2023

- initial documentation release
23 changes: 23 additions & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@kismet.ts/docs",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"docs:dev": "vuepress dev src",
"docs:ref": "cd ../.. && pnpm prestart && node ./dist/typedoc.js --out apps/docs/src/ && cd apps/docs/",
"docs:build": "pnpm docs:ref && vuepress build src"
},
"keywords": [],
"author": "ghostrider-05",
"license": "ISC",
"dependencies": {
"@kismet.ts/core": "link:packages\\core",
"@kismet.ts/items": "link:packages\\items"
},
"devDependencies": {
"@vuepress/client": "2.0.0-beta.67",
"vue": "^3.3.7",
"vuepress": "2.0.0-beta.67"
}
}
File renamed without changes.
51 changes: 15 additions & 36 deletions docs/.vuepress/config.ts → apps/docs/src/.vuepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { defaultTheme, defineUserConfig, SidebarGroup } from 'vuepress'
import fetch from 'node-fetch'
import { existsSync, readdirSync, writeFileSync } from 'fs'
import { join, resolve } from 'path'
import { mkdir, rename } from 'fs/promises'

const packages = readdirSync(resolve('.', './packages/'))
.filter(name => existsSync(resolve('.', `./packages/${name}/docs/`)))
import { defaultTheme, defineUserConfig, type SidebarGroup } from 'vuepress'

const packageFolder = resolve('.', '../../packages')

const packages = readdirSync(packageFolder)
.filter(name => existsSync(join(packageFolder, name, 'docs')))

const items: SidebarGroup[] = []

await fetch('https://raw.githubusercontent.com/ghostrider-05/kismet.ts-template/main/src/index.ts')
.then(res => res.text())
.then(text => writeFileSync(join('docs', '.vuepress', 'example.ts'), text))
.then(text => writeFileSync(join('src', '.vuepress', 'example.ts'), text))

export default defineUserConfig({
title: 'Kismet.ts',
Expand All @@ -21,12 +23,14 @@ export default defineUserConfig({
],
pagePatterns: [
'**/*.md',
'../packages/**/docs/*.md',
'../packages/**/docs/**/*.md',
'!../packages/**/node_modules/**/*.md',
'!.vuepress',
'!node_modules'
],
extendsPage(page, app) {
//@ts-ignore
page.data.packages = packages
},
theme: defaultTheme({
repo: 'ghostrider-05/kismet.ts',
contributors: false,
Expand All @@ -45,12 +49,7 @@ export default defineUserConfig({
}), {})
},
}),
async onInitialized(app) {
app.pages.forEach((page, i) => {
if (page.path.startsWith('/../packages/'))
app.pages[i] = { ...page, path: '/' + page.path.slice('/../packages/'.length).replace('docs/', '') }
})

async onInitialized() {
for (const pkg of packages) {
const packageName = pkg === 'kismet.ts' ? pkg : `@kismet.ts/${pkg}`

Expand All @@ -59,8 +58,7 @@ export default defineUserConfig({
link: `/${pkg}/reference/`
}]})


const files = readdirSync(resolve('.', `./packages/${pkg}/docs/`))
const files = readdirSync(join(packageFolder, pkg, 'docs'))

if (files.some(file => file === 'index.md')) {
items.at(-1)!.children.push({ text: 'Getting started', link: `/${pkg}/index.html`, children: [] })
Expand All @@ -72,7 +70,7 @@ export default defineUserConfig({
} else if (!item.includes('.')) {
items.at(-1)?.children.push({ text: item, children: [] })

const children = readdirSync(resolve('.', `./packages/${pkg}/docs/${item}`))
const children = readdirSync(join(packageFolder, pkg, 'docs', item))
.filter(child => child.endsWith('.md'))

for (const subitem of children) {
Expand All @@ -82,23 +80,4 @@ export default defineUserConfig({
}
}
},
async onGenerated () {
const folder = join('docs', '.vuepress', 'packages')
const dist = join('docs', '.vuepress', 'dist')

for (const pkg of readdirSync(resolve('.', folder))) {
if (!existsSync(join(dist, pkg))) await mkdir(join(dist, pkg))

for (const name of readdirSync(resolve('.', join(folder, pkg, 'docs')))) {
if (name.endsWith('.html')) {
await rename(join(folder, pkg, 'docs', name), join(dist, pkg, name))
} else {
await mkdir(join(dist, pkg, name))
for (const child of readdirSync(resolve('.', join(folder, pkg, 'docs', name)))) {
await rename(join(folder, pkg, 'docs', name, child), join(dist, pkg, name, child))
}
}
}
}
}
})
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions apps/workers/assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "kismet-cdn",
"version": "0.1.0",
"description": "A CF worker for kismet assets",
"devDependencies": {},
"private": true,
"scripts": {
"publish": "wrangler publish -c ./wrangler.toml"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ghostrider-05/kismet.ts.git"
},
"author": "ghostrider-05",
"license": "ISC",
"bugs": {
"url": "https://github.com/ghostrider-05/kismet.ts/issues"
},
"homepage": "https://github.com/ghostrider-05/kismet.ts#readme"
}
67 changes: 67 additions & 0 deletions apps/workers/assets/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { R2AssetHandlerItem, handleR2AssetReq } from '../../shared/r2.js'

interface Env {
KISMET_ASSETS: R2Bucket
KISMET_KV: KVNamespace
TAGS: string
AUTH: string
CACHE_DISABLED_MODE: string
}

export default<ExportedHandler<Env>> {
async fetch (request, env, ctx) {
const LATEST_KV_KEY = 'latest_version'
const { pathname, searchParams } = new URL(request.url)

const handleR2Req = (item: R2AssetHandlerItem) => handleR2AssetReq({
bucket: env.KISMET_ASSETS,
auth: env.AUTH,
ctx,
cacheOptions: {
use: searchParams.get('mode') !== env.CACHE_DISABLED_MODE,
versionedControl: 'max-age=31536000, immutable',
control: 'max-age=604800',
},
req: request,
}, item)

if (pathname.startsWith('/assets')) {
let version = searchParams.get('version')
const tag = searchParams.get('tag'),
useLatestVersion = version === 'latest'

if (!version || !tag || !env.TAGS.split(',').includes(tag)) {
return new Response(null, { status: 400 })
}

const latest = await env.KISMET_KV.get(LATEST_KV_KEY, { type: 'text', cacheTtl: 604800 })
if (!latest) return new Response(null, { status: 500 })

if (useLatestVersion) {
version = latest
}

const key = `versions/${version}/${tag}`

return await handleR2Req({ key,
messages: { error: 'Asset not found for version ' + version },
versioned: !useLatestVersion,
view: ['true', '1'].includes(searchParams.get('view')),
headersToAppend: [
['x-kismet-latest-version', latest],
],
})
} else if (pathname.startsWith('/images')) {
const name = searchParams.get('name')

if (!name) return new Response(null, { status: 400 })

return await handleR2Req({
key: `images/${name}`,
messages: { error: 'Image not found for this class...' },
})
}

return new Response(null, { status: 404 });
},
};
15 changes: 15 additions & 0 deletions apps/workers/assets/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name="kismet-cdn"
main="./src/index.ts"
compatibility_date="2023-05-14"

kv_namespaces = [
{ binding = "KISMET_KV", id = "89f9e0f8f12042469151882e25cb57c8" }
]

r2_buckets = [
{ binding = "KISMET_ASSETS", bucket_name = "assets" }
]

[vars]
TAGS="itemdb,blender,classes,compact_tree,nodes,tree,history,nodes_automated"
CACHE_DISABLED_MODE="dev"
3 changes: 3 additions & 0 deletions apps/workers/shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @workers/shared

A collection of shared utilities for Cloudflare workers
Loading

0 comments on commit a2f8de3

Please sign in to comment.