-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add devtools and client build scripts (#48)
* feat: add devtools and client build scripts * fix: getMyModuleOptions * fix: lint issues * feat: update okuPergel devtools configuration * Update baseURL and package names
- Loading branch information
1 parent
fa91692
commit c1c97ec
Showing
18 changed files
with
2,435 additions
and
2,141 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ export default antfu( | |
'**/.DS_Store', | ||
'**/.vscode', | ||
'**/**.yml', | ||
'**/**.md', | ||
], | ||
}, | ||
{ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<NuxtLayout> | ||
<NuxtPage /> | ||
</NuxtLayout> | ||
</template> |
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,28 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
<NTip | ||
n="teal" | ||
class="py-4" | ||
> | ||
<p class="font-bold"> | ||
Note for module authors: | ||
</p> | ||
Nuxt DevTools is in early preview and the API is subject to change. | ||
Which means the setup in this template is only presenting the current state of the API. | ||
We suggest following closely to the changes in the <NLink | ||
href="https://github.com/nuxt/devtools" | ||
target="_blank" | ||
> | ||
nuxt/devtools | ||
</NLink> repository.<br> | ||
The UI components are coming from <NLink | ||
href="https://github.com/nuxt/devtools/tree/main/packages/devtools-ui-kit" | ||
target="_blank" | ||
> | ||
@nuxt/devtools-ui-kit | ||
</NLink>. | ||
</NTip> | ||
</template> |
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,83 @@ | ||
<script setup lang="ts"> | ||
import JsonEditorVue from 'json-editor-vue' | ||
const props = defineProps<{ | ||
name?: string | ||
open?: boolean | ||
state?: any | ||
readonly?: boolean | ||
}>() | ||
const emit = defineEmits<{ | ||
(e: 'update:open', value: boolean): void | ||
}>() | ||
const isOpen = useVModel(props, 'open', emit, { passive: true }) | ||
const colorMode = useColorMode() | ||
const proxy = ref() | ||
const state = useState(props.name) | ||
if (props.state) | ||
proxy.value = JSON.parse(JSON.stringify(props.state)) | ||
else if (typeof props.state === 'number' || typeof props.state !== 'string') | ||
proxy.value = props.state | ||
const watcher = watchPausable( | ||
proxy, | ||
(value) => { | ||
if (typeof value !== 'number' && typeof value !== 'string') | ||
deepSync(value, props.state) | ||
else | ||
state.value = value | ||
}, | ||
{ deep: true }, | ||
) | ||
function deepSync(from: any, to: any) { | ||
for (const key in from) { | ||
if (from[key] === null) | ||
to[key] = null | ||
else if (Array.isArray(from[key])) | ||
to[key] = from[key].slice() | ||
else if (typeof from[key] === 'object') | ||
deepSync(from[key], to[key]) | ||
else | ||
to[key] = from[key] | ||
} | ||
} | ||
async function refresh() { | ||
watcher.pause() | ||
proxy.value = JSON.parse(JSON.stringify(props.state)) | ||
await nextTick() | ||
watcher.resume() | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="state-editor-details" :open="!name ? true : isOpen"> | ||
<div flex="~ gap2" select-none items-center px4> | ||
<button v-if="name" flex="~" cursor-pointer items-center :class="isOpen ? '' : 'op50'" @click="isOpen = !isOpen"> | ||
<div i-carbon-chevron-right transition :class="isOpen ? 'rotate-90 op0' : ''" /> | ||
<code px3 py1 font-mono :class="isOpen ? 'bg-[#8881] rounded-t' : 'rounded hover:bg-active'">{{ name }}</code> | ||
</button> | ||
<slot name="actions" v-bind="{ isOpen, name, state }" /> | ||
<template v-if="isOpen"> | ||
<NButton | ||
v-tooltip.bottom="'Refresh View'" title="Refresh View" icon="carbon-renew" :border="false" | ||
@click="refresh" | ||
/> | ||
<DataSchemaButton v-if="proxy" :getter="() => ({ name, input: JSON.stringify(proxy) })" /> | ||
</template> | ||
</div> | ||
<template v-if="isOpen || !name"> | ||
<JsonEditorVue | ||
v-model="proxy" v-bind="$attrs" class="json-editor-vue" :class="[ | ||
colorMode.value === 'dark' ? 'jse-theme-dark' : '', | ||
name ? '' : '', | ||
]" :main-menu-bar="false" :navigation-bar="false" :status-bar="false" :read-only="readonly" :indentation="2" | ||
:tab-size="2" | ||
/> | ||
</template> | ||
</div> | ||
</template> |
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,16 @@ | ||
import { resolve } from 'pathe' | ||
|
||
export default defineNuxtConfig({ | ||
ssr: false, | ||
modules: [ | ||
'@nuxt/devtools-ui-kit', | ||
], | ||
nitro: { | ||
output: { | ||
publicDir: resolve(__dirname, '../dist/client'), | ||
}, | ||
}, | ||
app: { | ||
baseURL: '/__pergel', | ||
}, | ||
}) |
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,4 @@ | ||
{ | ||
"name": "pergel-client", | ||
"private": true | ||
} |
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,75 @@ | ||
<script setup lang="ts"> | ||
import { onDevtoolsClientConnected, useDevtoolsClient } from '@nuxt/devtools-kit/iframe-client' | ||
import type { ClientFunctions, ServerFunctions } from '../../src/rpc-types' | ||
const client = useDevtoolsClient() | ||
onDevtoolsClientConnected(async (client) => { | ||
const rpc = client.devtools.extendClientRpc<ServerFunctions, ClientFunctions>('pergel-rpc', { | ||
showNotification: (message) => { | ||
console.log('showNotification') | ||
Check warning on line 9 in packages/nuxt/client/pages/index.vue GitHub Actions / autofix
|
||
console.log('showNotification', message) | ||
Check warning on line 10 in packages/nuxt/client/pages/index.vue GitHub Actions / autofix
|
||
}, | ||
}) | ||
const dd = await rpc.getMyModuleOptions() | ||
console.log(dd) | ||
Check warning on line 14 in packages/nuxt/client/pages/index.vue GitHub Actions / autofix
|
||
}) | ||
</script> | ||
|
||
<template> | ||
<NSectionBlock | ||
icon="carbon-3d-mpr-toggle" | ||
text="Active Modules" | ||
container-class="grid grid-cols-minmax-400px gap3 px4" | ||
:padding="false" | ||
description="Total modules: " | ||
> | ||
asdasdas | ||
</NSectionBlock> | ||
<div class="relative p-10 n-bg-base flex flex-col h-screen"> | ||
<h1 class="text-3xl font-bold"> | ||
Pergel Module | ||
</h1> | ||
<div class="opacity-50 mb-4"> | ||
Powered by oku | ||
</div> | ||
<div | ||
v-if="client" | ||
class="flex flex-col gap-2" | ||
> | ||
<NTip | ||
n="green" | ||
icon="carbon-checkmark" | ||
> | ||
Nuxt DevTools is connected | ||
</NTip> | ||
<div> | ||
The current app is using | ||
<code class="text-green">vue@{{ client.host.nuxt.vueApp.version }}</code> | ||
</div> | ||
<div> | ||
<NButton | ||
n="green" | ||
class="mt-4" | ||
@click="client!.host.devtools.close()" | ||
> | ||
Close DevTools | ||
</NButton> | ||
</div> | ||
</div> | ||
<div v-else> | ||
<NTip n="yellow"> | ||
Failed to connect to the client. Did you open this page inside Nuxt DevTools? | ||
</NTip> | ||
</div> | ||
|
||
<NuxtLink | ||
to="/s3" | ||
class="absolute top-0 right-0 p-4" | ||
> | ||
Go to S3 | ||
</NuxtLink> | ||
|
||
<div class="flex-auto" /> | ||
<ModuleAuthorNote class="mt-5 " /> | ||
</div> | ||
</template> |
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,38 @@ | ||
<script setup lang="ts"> | ||
import { useDevtoolsClient } from '@nuxt/devtools-kit/iframe-client' | ||
const client = useDevtoolsClient() | ||
</script> | ||
|
||
<template> | ||
<div class="relative p-10 n-bg-base flex flex-col h-screen"> | ||
<h1 class="text-3xl font-bold"> | ||
My Module | ||
</h1> | ||
<div class="opacity-50 mb-4"> | ||
Nuxt DevTools Integration | ||
</div> | ||
<div v-if="client" class="flex flex-col gap-2"> | ||
<NTip n="green" icon="carbon-checkmark"> | ||
Nuxt DevTools is connected | ||
</NTip> | ||
<div> | ||
The current app is using | ||
<code class="text-green">vue@{{ client.host.nuxt.vueApp.version }}</code> | ||
</div> | ||
<div> | ||
<NButton n="green" class="mt-4" @click="client!.host.devtools.close()"> | ||
Close DevTools | ||
</NButton> | ||
</div> | ||
</div> | ||
<div v-else> | ||
<NTip n="yellow"> | ||
Failed to connect to the client. Did you open this page inside Nuxt DevTools? | ||
</NTip> | ||
</div> | ||
|
||
<div class="flex-auto" /> | ||
<ModuleAuthorNote class="mt-5 " /> | ||
</div> | ||
</template> |
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,3 @@ | ||
{ | ||
"extends": "./.nuxt/tsconfig.json" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,47 @@ | ||
import { resolve } from 'node:path' | ||
import { defineNuxtModule } from '@nuxt/kit' | ||
import { startSubprocess } from '@nuxt/devtools-kit' | ||
|
||
export default defineNuxtConfig({ | ||
modules: ['../src/module'], | ||
myModule: {}, | ||
devtools: { enabled: true }, | ||
modules: [ | ||
'@nuxt/devtools', | ||
/** | ||
* My module | ||
*/ | ||
'../src/module', | ||
/** | ||
* Start a sub Nuxt Server for developing the client | ||
* | ||
* The terminal output can be found in the Terminals tab of the devtools. | ||
*/ | ||
defineNuxtModule({ | ||
setup(_, nuxt) { | ||
if (!nuxt.options.dev) | ||
return | ||
|
||
const subprocess = startSubprocess( | ||
{ | ||
command: 'npx', | ||
args: ['nuxi', 'dev', '--port', '3300'], | ||
cwd: resolve(__dirname, '../client'), | ||
}, | ||
{ | ||
id: 'pergel:client', | ||
name: 'My Module Client Dev', | ||
}, | ||
) | ||
|
||
subprocess.getProcess().stdout?.on('data', (data) => { | ||
console.log(` sub: ${data.toString()}`) | ||
Check warning on line 35 in packages/nuxt/playground/nuxt.config.ts GitHub Actions / autofix
|
||
}) | ||
|
||
process.on('exit', () => { | ||
subprocess.terminate() | ||
}) | ||
}, | ||
}), | ||
], | ||
pergel: { | ||
devtools: true, | ||
}, | ||
}) |
Oops, something went wrong.