Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wrnrlr committed Nov 4, 2024
1 parent 1455561 commit ad0d0aa
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
dist/
www/dist/
www/docs
www/public/bundle.js
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"@std/testing": "jsr:@std/testing@^0.225.3",
"jsdom": "npm:jsdom",
"typedoc": "npm:typedoc@^0.26.6",
"vite": "npm:vite@^5.4.9"
"vite": "npm:vite@^5.4.9",
"esbuild": "npm:esbuild@^0.24.0"
},
"tasks": {
"dev": "deno run -A npm:vite --config www/vite.config.js",
Expand Down
4 changes: 2 additions & 2 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<span class="prelude text-6xl">Prelude</span>
<span class="text-3xl">A signal-based web library that lets you <br> develop in a familiar functional style</span>
<div class="flex gap-4">
<a class="px-3 py-2 rounded-md bg-neutral-200 text-xl font-weight-500" href="prelude/docs/index.html">Get Started</a>
<a class="px-3 py-2 rounded-md bg-green-600 text-xl text-white font-weight-500 shadow" href="prelude/playground">Open Playground</a>
<a class="px-3 py-2 rounded-md bg-neutral-200 text-xl font-weight-500" href="/prelude/docs/index.html">Get Started</a>
<a class="px-3 py-2 rounded-md bg-green-600 text-xl text-white font-weight-500 shadow" href="/prelude/playground">Open Playground</a>
</div>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion www/public/example/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<script type="module">

import {h,signal,effect,render,resource,memo,Router,List,Show} from '../src/mod.ts'
import {h,signal,effect,render,resource,memo,Router,List,Show} from '/prelude/prelude.js'

function makeApi(base,method='GET') {
return async (s='') => await (await fetch('https://dummyjson.com/'+base+s,{method})).json()
Expand Down
2 changes: 1 addition & 1 deletion www/public/example/counter.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<script type="module">

import {h,signal,render} from '../src/mod.ts'
import {h,signal,render} from '/prelude/bundle.js'

function Input(props) {
const onInput = e => props.value(parseInt(e.target.value))
Expand Down
2 changes: 1 addition & 1 deletion www/public/example/greeting.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<script type="module">

import {h,signal,effect,render} from '../src/mod.ts'
import {h,signal,effect,render} from '/prelude/bundle.js'

function Input(props) {
const onInput = e => props.value(e.target.value)
Expand Down
22 changes: 0 additions & 22 deletions www/public/example/paint.html

This file was deleted.

2 changes: 1 addition & 1 deletion www/public/example/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<script type="module">

import {h,signal,render,Show} from '../src/mod.ts'
import {h,signal,render,Show} from '/prelude/bundle.js'

function App(props) {
const toggle = signal(true)
Expand Down
2 changes: 1 addition & 1 deletion www/public/example/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<script type="module">

import {h,signal,effect,batch,wrap,render,List} from '../src/mod.ts'
import {h,signal,effect,batch,wrap,render,List} from '/prelude/bundle.js'

const data = [
{description:'Buy groceries',done:false},
Expand Down
99 changes: 65 additions & 34 deletions www/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,9 @@
import * as path from '@std/path'
import * as fs from '@std/fs'
import {defineConfig} from 'vite'
import * as esbuild from 'esbuild'
import { Application, TSConfigReader, TypeDocReader } from 'typedoc'

function typedocPlugin() {
let _config
return {
name: 'typedoc-plugin',
apply: 'build',
configResolved(config) { _config = config },
async writeBundle() {
const name = path.join(__dirname, 'typedoc.json')
console.log('NAME',name)
const config = JSON.parse(await Deno.readTextFile(name))
console.log('CONFIG',config)
config.hostedBaseUrl = 'https://wrnrlr.github.io/prelude/docs'
config.useHostedBaseUrlForAbsoluteLinks = true
config.out = path.join(__dirname, './dist/docs')
config.entryPoints = [path.join(__dirname, '../src/mod.ts')]
console.log('CONFIG',config)
const app = await Application.bootstrap(config)
// console.log(app)
if (!app) Deno.exit()
const project = await app.convert()
if (!project) Deno.exit()
console.log('PROJECT', project)
try {
await app.generateDocs(project, config.out)
} catch (e) {
console.error(e)
}
}
}
}

export default defineConfig(({ command, mode }) => {
const root = path.join(__dirname, '')

Expand All @@ -55,9 +25,20 @@ export default defineConfig(({ command, mode }) => {
// console.log('docs',input.docs)

build = {
// lib: { entry: 'src/mod.ts', formats: ['es'] },
lib: {
entry: path.join(root, '../src/mod.ts'),
formats: ['es'],
name: 'mod',
fileName: (name) => 'prelude.js'
},
rollupOptions: {
input
input,
exports: 'named',
output: {
manualChunks(id) {
// if (id.endsWith('src/mod.ts')) return 'prelude'
}
}
}
}

Expand All @@ -69,7 +50,57 @@ export default defineConfig(({ command, mode }) => {
assetsInclude,
base: '/prelude',
plugins: [
typedocPlugin()
esbuildPlugin(), typedocPlugin()
]
}
})

function esbuildPlugin() {
let ctx
return {
name: 'typedoc-plugin',
async buildStart() {
const entry = path.join(__dirname, '../src/mod.ts')
const options = {
entryPoints: [entry],
outfile: path.join(__dirname, './public/bundle.js'),
bundle: true,
format:'esm',
// minify: true,
// sourcemap: true,
target: ["es2020"],
}
ctx = await esbuild.context(options)
await ctx.watch()
},
async buildEnd() {
await ctx.dispose()
}
}
}

function typedocPlugin() {
let _config
return {
name: 'typedoc-plugin',
apply: 'build',
configResolved(config) { _config = config },
async writeBundle() {
const name = path.join(__dirname, 'typedoc.json')
const config = JSON.parse(await Deno.readTextFile(name))
config.hostedBaseUrl = 'https://wrnrlr.github.io/prelude/docs'
config.useHostedBaseUrlForAbsoluteLinks = true
config.out = path.join(__dirname, './dist/docs')
config.entryPoints = [path.join(__dirname, '../src/mod.ts')]
const app = await Application.bootstrap(config)
if (!app) Deno.exit()
const project = await app.convert()
if (!project) Deno.exit()
try {
await app.generateDocs(project, config.out)
} catch (e) {
console.error(e)
}
}
}
}

0 comments on commit ad0d0aa

Please sign in to comment.