Skip to content

Commit 737d0cd

Browse files
committed
feat: client [wip]
1 parent d9a38a7 commit 737d0cd

File tree

16 files changed

+156
-9
lines changed

16 files changed

+156
-9
lines changed

client/app/app.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<template>
2-
<NuxtPage />
2+
<NuxtLayout>
3+
<NuxtPage />
4+
</NuxtLayout>
35
</template>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script setup lang="ts">
2+
import PKG from '../../../package.json'
3+
</script>
4+
5+
<template>
6+
<footer class="p-8 flex justify-between items-center">
7+
<a href="https://github.com/unplugin/unplugin-turbo-console" target="_blank" class="flex items-center gap-1 text-gray-400 hover:text-gray-500 transition-colors">
8+
<Icon name="uil:github" class="text-2xl" />
9+
Source Code
10+
</a>
11+
12+
<div class="text-gray-400">
13+
Version: {{ PKG.version }}
14+
</div>
15+
</footer>
16+
</template>

client/app/layouts/default.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<main>
3+
<slot />
4+
5+
<app-footer />
6+
</main>
7+
</template>

client/app/pages/index.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const launchEditorServerResponse = ref<LaunchEditorServerResponse>()
1919
async function init() {
2020
try {
2121
const position = window.location.hash.slice(1)
22+
if (!position) {
23+
throw new Error('No position provided')
24+
}
2225
const response = await $fetch<LaunchEditorServerResponse>(`/launchEditor?position=${(position)}`)
2326
if (response.status !== 'success') {
2427
throw new Error(response.message || 'Unknown error')
@@ -42,7 +45,7 @@ init()
4245
</script>
4346

4447
<template>
45-
<main class="h-screen w-screen p-8">
48+
<main class="w-screen p-8">
4649
<div v-if="requestState.status === 'pending'" class="flex h-full justify-center">
4750
<div class="flex flex-col items-center gap-2">
4851
<Icon name="uil:spinner" class="text-2xl animate-spin" />

examples/vite-vue3/src/jsLog.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
export function logJs() {
2-
console.log('from js') // turbo-console-disable-line
2+
console.info('from js')
3+
4+
console.warn('from js')
5+
6+
console.error('from js')
7+
8+
console.log('from js')
9+
10+
311
}
412

examples/vite-vue3/src/tsLog.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
export function logTs() {
2-
const a = '你好'
3-
console.log(a)
2+
const abc = '你4445jj5好'
3+
console.log(abc)
4+
5+
const def = '你4445jj5好'
6+
console.log(def)
7+
8+
// const ghi = '你4445jj5好'
9+
// console.log(ghi)
10+
11+
// const jkl = '你4445jj5好'
12+
// console.log(jkl)
13+
14+
const mno = '你4445jj5好'
15+
console.log(mno)
16+
17+
418
}

global.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33

44
export interface global {}
55

6+
interface ExpressionMeta {
7+
code: string
8+
method: string
9+
line: number
10+
column: number
11+
}
12+
613
declare global {
714
import type { Peer } from 'crossws'
815

916
var TurboConsoleFilePathMap: Map<string, string>
17+
var TurboConsoleExpressionsMap: Map<string, ExpressionMeta[]>
1018
var UNPLUGIN_TURBO_CONSOLE_LAUNCH_SERVER: boolean
1119
var UNPLUGIN_TURBO_CONSOLE_PEERS_SET: Set<Peer> | undefined
1220
}

src/core/server/filePathMap.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { version } from '../../../package.json'
44
export default defineEventHandler(async () => {
55
try {
66
const filePathMap = globalThis.TurboConsoleFilePathMap || new Map()
7+
const expressionsMap = globalThis.TurboConsoleExpressionsMap || new Map()
8+
79
return {
810
status: 'success',
911
filePathMap: Object.fromEntries(filePathMap),
12+
expressionsMap: Object.fromEntries(expressionsMap),
1013
version,
1114
}
1215
}

src/core/transform/compilers/sfc.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ export async function sfcCompiler(context: Context): Promise<CompileResult> {
55
try {
66
const { code } = context
77

8-
const scriptRegex = /<script(?:\s[^>]*?lang="([^"]*)")?\s*>([\s\S]*?)<\/script>/
8+
const scriptRegex = /<script\s*([^>]*)>([\s\S]*?)<\/script>/
99

1010
const match = scriptRegex.exec(code)
1111
if (match) {
12-
const lang = match[1] || 'js'
12+
const attrs = match[1] || ''
13+
const langMatch = attrs.match(/lang=["']([^"']*)["']/)
14+
const lang = langMatch ? langMatch[1] : 'js'
1315
const content = match[2]
1416
const offset = code.indexOf(content)
1517
const line = offset ? code.substring(0, offset).split('\n').length - 1 : 0

src/core/transform/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export async function transform(context: Context) {
7575
return false
7676
}
7777

78+
const consoleMethod = (node as any).callee.property.name
7879
const args = (node as any).arguments
7980

8081
const argsStart = calculateStart(compileResult.script, oxcMs.getLineColumnNumber(args[0].start))
@@ -90,6 +91,7 @@ export async function transform(context: Context) {
9091

9192
const { consoleString, _suffix } = genConsoleString({
9293
options,
94+
consoleMethod,
9395
originalLine,
9496
originalColumn,
9597
argType,

0 commit comments

Comments
 (0)