Skip to content

Commit

Permalink
Revision 0.8.9 (#32)
Browse files Browse the repository at this point in the history
* Revision 0.8.9

* Version
  • Loading branch information
sinclairzx81 authored Dec 18, 2024
1 parent dfd163d commit bdb75c3
Show file tree
Hide file tree
Showing 22 changed files with 1,608 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
timeout-minutes: 2
strategy:
matrix:
node: [20.x]
node: [22.x]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
Expand Down
14 changes: 13 additions & 1 deletion example/index.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Network, FileSystem } from '@sinclair/smoke'
import { Network, FileSystem, Proxy } from '@sinclair/smoke'

// ------------------------------------------------------------------
// Store Static Files
Expand Down Expand Up @@ -27,3 +27,15 @@ Http.listen({ port: 5000 }, (request) => {
const html = await Http.fetch('http://localhost:5000/index.html').then((x) => x.text())

console.log(html)

// ------------------------------------------------------------------
// Proxy Intecept
// ------------------------------------------------------------------

await Proxy.listen({ path: '/proxy' }, (request) => {
return new Response('hello from proxy')
})

const result = await fetch('/proxy').then((res) => res.text())

console.log(result)
33 changes: 30 additions & 3 deletions hammer.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Http from 'node:http'
import * as Path from 'node:path'
import * as Fs from 'node:fs'

// -------------------------------------------------------------------------------
Expand All @@ -16,19 +18,43 @@ export async function format() {
// Start
// -------------------------------------------------------------------------------
export async function start(target = 'target/example') {
const worker = shell(`hammer watch src/proxy/service/worker.mts --dist ${target}`)
const start = shell(`hammer serve example/index.html --dist ${target}`)
const drift = shell(`drift wait 100 url http://localhost:5000`)
await Promise.all([start, drift])
await Promise.all([worker, start, drift])
}
// -------------------------------------------------------------------------------
// Chrome
// -------------------------------------------------------------------------------
async function chrome_warmup() {
// Chrome will not have been run in CI environment due to fresh install. It's been
// noted that initialization of Chrome seems to involve running a latent optimization
// process on the user directory which takes some time to complete. The following just
// runs chrome, waits 8 seconds and exits.
await shell(`drift wait 8000 close`)
}
// -------------------------------------------------------------------------------
// Test
// -------------------------------------------------------------------------------
export async function test_serve(target = 'target/test') {
await shell(`hammer serve test/index.html --dist ${target}`)
}
function test_server(target = 'target/test', port = 5010) {
return Http.createServer((req, res) => {
const [path, extname] = [Path.join(target, req.url), Path.extname(req.url)]
if(Fs.existsSync(path) && Fs.statSync(path).isFile()) {
if(extname === '.js') res.writeHead(200, { 'Content-Type': 'application/javascript' })
res.end(Fs.readFileSync(path))
} else {
res.end('<html><head>NotFound</head></html>')
}
}).listen(port)
}
export async function test(filter = '', target = 'target/test') {
await chrome_warmup()
const server = test_server(target, 5010)
await shell(`hammer build src/proxy/service/worker.mts --dist ${target}`)
await shell(`hammer build test/index.mts --dist ${target} --platform node`)
const server = require('http').createServer((_, res) => res.end('<html><head></head></html>')).listen(5010)
await shell(`drift url http://localhost:5010 wait 1000 run ./${target}/index.mjs args "${filter}"`)
server.close()
}
Expand All @@ -38,6 +64,7 @@ export async function test(filter = '', target = 'target/test') {
export async function build(target = 'target/build') {
await clean()
await shell(`tsc -p src/tsconfig.json --outDir ${target} --declaration`)
await shell(`hammer build src/proxy/service/worker.mts --dist ${target}`)
await folder(target).add('package.json')
await folder(target).add('readme.md')
await folder(target).add('license')
Expand All @@ -52,4 +79,4 @@ export async function publish(otp, target = 'target/build') {
await shell(`cd ${target} && npm publish sinclair-smoke-${version}.tgz --access=public --otp ${otp}`)
await shell(`git tag ${version}`)
await shell(`git push origin ${version}`)
}
}
Loading

0 comments on commit bdb75c3

Please sign in to comment.