-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
126 additions
and
29 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/pintora-target-wintercg/build/ESBuildPintoraRuntimePlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as path from 'path' | ||
import * as fs from 'fs' | ||
import { Plugin } from 'esbuild' | ||
|
||
const packageDir = path.resolve(__dirname, '../node_modules') | ||
|
||
const RUNTIME_CODE_NS = 'pintora-runtime-code' | ||
|
||
export function makeESBuildNodePolyfillsPlugin(opts: { runtimeLibPath: string }) { | ||
return { | ||
name: 'ESBuildNodePolyfillsPlugin', | ||
setup(build) { | ||
build.onResolve({ filter: /virtual:pintora/ }, args => { | ||
return { namespace: RUNTIME_CODE_NS, path: opts.runtimeLibPath } | ||
}) | ||
build.onLoad({ filter: /.*/, namespace: RUNTIME_CODE_NS }, args => { | ||
const contents = fs.readFileSync(opts.runtimeLibPath) | ||
return { | ||
contents, | ||
} | ||
}) | ||
}, | ||
} as Plugin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/pintora-target-wintercg/src/edge-runtime-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { EdgeRuntime, runServer } from 'edge-runtime' | ||
import { onExit } from 'signal-exit' | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
|
||
const dir = __dirname | ||
|
||
async function main() { | ||
const initialCode = fs.readFileSync(path.join(dir, '../dist/platforms/edge-handler.js'), 'utf-8').toString() | ||
|
||
const edgeRuntime = new EdgeRuntime({ initialCode }) | ||
|
||
const server = await runServer({ runtime: edgeRuntime, port: 9000 }) | ||
console.log(`> Edge server running at ${server.url}`) | ||
onExit(() => { | ||
server.close() | ||
return | ||
}) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/pintora-target-wintercg/src/platforms/edge-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// this module runs inside edge runtime, and pintoraTarget will be prepended by bundler | ||
/* eslint-disable @typescript-eslint/triple-slash-reference */ | ||
/// <reference path="../../types/index.d.ts" /> | ||
|
||
const target = pintoraTarget | ||
|
||
addEventListener('fetch', async event => { | ||
const requestText = await event.request.text() | ||
|
||
const code = | ||
requestText || | ||
` | ||
sequenceDiagram | ||
title: Sequence Diagram Example | ||
autonumber | ||
User->>Pintora: render this | ||
` | ||
const result = await target.pintoraMain({ | ||
code, | ||
}) | ||
const response = new Response(result.data, { | ||
headers: { | ||
'Content-Type': 'image/svg+xml', | ||
}, | ||
}) | ||
return event.respondWith(response) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.