Skip to content

Commit

Permalink
create note
Browse files Browse the repository at this point in the history
  • Loading branch information
nakasyou committed Feb 19, 2024
1 parent d44aed5 commit fa242e4
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 53 deletions.
117 changes: 69 additions & 48 deletions src/integrations/cloudflare/index.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,94 @@
import { type AstroConfig, type AstroIntegration } from "astro"
import { fileURLToPath } from "url"
import { build } from 'esbuild'
import { type AstroConfig, type AstroIntegration } from 'astro'
import * as fs from 'fs/promises'
import fg from 'fast-glob'
import path from 'path'
import { getParsedCommandLineOfConfigFile } from "typescript"

export default (): AstroIntegration => {
let buildConfig: AstroConfig['build']

return {
name: "cloudflare-adapter",
name: 'cloudflare-adapter',
hooks: {
"astro:config:setup": ({ config }) => {
config.vite.plugins = [
{
name: 'qwik-resolve',
resolveId(source, importer, options) {
if (source === '@qwik-client-manifest') {
return source
}
'astro:config:setup': ({ config, command }) => {
if (command === 'build') {
config.vite.plugins = [
{
name: 'qwik-resolve',
resolveId(source, importer, options) {
if (source === '@qwik-client-manifest') {
return source
}
},
async load(id, options) {
if (id.startsWith('@qwik-client-manifest')) {
const manifestPath = (await fg('.tmp-*/q-manifest.json'))[0]!
const manifestJson = await fs.readFile(manifestPath, {
encoding: 'utf-8'
})
return `export const manifest = (${manifestJson})`
}
},
enforce: 'pre'
},
async load(id, options) {
if (id.startsWith('@qwik-client-manifest')) {
const manifestPath = (await fg('.tmp-*/q-manifest.json'))[0]!
const manifestJson = await fs.readFile(manifestPath, { encoding: 'utf-8' })
return `export const manifest = (${manifestJson})`
}
},
enforce: 'pre'
},
...(config.vite.plugins ?? [])
]
...(config.vite.plugins ?? [])
]
}
},
"astro:config:done": ({ setAdapter, config }) => {
'astro:config:done': ({ setAdapter, config }) => {
buildConfig = config.build
setAdapter({
name: "cloudflare-adapter",
serverEntrypoint: "./src/integrations/cloudflare/server/server.ts",
name: 'cloudflare-adapter',
serverEntrypoint: './src/integrations/cloudflare/server/server.ts',
supportedAstroFeatures: {
staticOutput: "stable",
serverOutput: "stable",
assets: {

}
staticOutput: 'stable',
serverOutput: 'stable',
assets: {}
},
exports: ["fetch"]
exports: ['fetch']
})
},
"astro:build:done": async () => {
await fs.writeFile('dist/_worker.js', 'import { fetch } from "./server/entry.mjs"\nglobalThis.process={env:{}};\nexport default { fetch }')
'astro:build:done': async () => {
await fs.writeFile(
'dist/_worker.js',
'import { fetch } from "./server/entry.mjs"\nglobalThis.process={env:{}};\nexport default { fetch }'
)
const clientFiles = await fg('./dist/client/**/*')

await fs.writeFile('dist/_routes.json', JSON.stringify({
version: 1,
exclude: [...new Set([
...clientFiles.map(path => path.replace('./dist/client', '')),
...clientFiles.map(path => path.replace('./dist/client', '').replace(/index\.html$/, ''))
])],
include: ['/*']
}, null, 2))
await fs.writeFile(
'dist/_routes.json',
JSON.stringify(
{
version: 1,
exclude: [
...new Set([
...clientFiles.map((path) =>
path.replace('./dist/client', '')
),
...clientFiles.map((path) =>
path
.replace('./dist/client', '')
.replace(/index\.html$/, '')
)
])
],
include: ['/*']
},
null,
2
)
)

for (const file of clientFiles) {
const content = await Bun.file(file).arrayBuffer()
await Bun.write(path.join('dist', file.replace('./dist/client/', '')), content, {
createPath: true
})
await Bun.write(
path.join('dist', file.replace('./dist/client/', '')),
content,
{
createPath: true
}
)
}
}
},
}
}
}
}
28 changes: 24 additions & 4 deletions src/islands/app/qwik/CreateNote.qwik.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$ } from '@builder.io/qwik'
import { component$, useSignal } from '@builder.io/qwik'

/*
<div id="create-note-dialog" hidden>
Expand All @@ -24,8 +24,28 @@ import { component$ } from '@builder.io/qwik'
</div>
</div>*/
export const CreateNote = component$(() => {

return <div onClick$={() => console.log('a')}>
aaa
const isOpenedCreateNoteDialog = useSignal(false)
return <div>
<div>
{
isOpenedCreateNoteDialog.value && <div class="fixed top-0 left-0 w-full h-[100dvh] bg-[#000a] p-5">
<div class="rounded-lg border bg-background">
<div class="text-2xl">新しいノートを作成</div>
<div class="flex flex-col gap-2">
</div>
</div>
</div>
}
</div>
<div class="fixed right-0 bottom-0 m-5">
<button onClick$={() => {
isOpenedCreateNoteDialog.value = true
}}>
<div class="flex items-center filled-tonal-button gap-2">
<div class="text-xl">+</div>
<div class="hidden md:block">新しいノート</div>
</div>
</button>
</div>
</div>
})
2 changes: 1 addition & 1 deletion src/pages/app/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { CreateNote } from '../../islands/app/qwik/CreateNote.qwik'
<div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-0">
<div class="text-2xl">すべてのノート</div>
<CreateNote />
</div>
</div>
</div>
<CreateNote />
</App>
<script>
/*import { NotesDB } from '../../islands/note/notes-schema'
Expand Down

0 comments on commit fa242e4

Please sign in to comment.