mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-22 23:10:40 +00:00
Initialize spyglass project and load vanilla-mcdoc
This commit is contained in:
931
package-lock.json
generated
931
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,8 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@giscus/react": "^2.2.3",
|
||||
"@spyglassmc/core": "^0.4.14",
|
||||
"@spyglassmc/mcdoc": "^0.3.17",
|
||||
"@zip.js/zip.js": "^2.4.5",
|
||||
"brace": "^0.11.1",
|
||||
"buffer": "^6.0.3",
|
||||
|
||||
@@ -7,6 +7,7 @@ import { DRAFT_PROJECT, useLocale, useProject, useVersion } from '../../contexts
|
||||
import { AsyncCancel, useActiveTimeout, useAsync, useSearchParam } from '../../hooks/index.js'
|
||||
import type { FileModel, VersionId } from '../../services/index.js'
|
||||
import { checkVersion, createMockFileModel, fetchPreset, fetchRegistries, getSnippet, shareSnippet } from '../../services/index.js'
|
||||
import { setupSpyglass } from '../../services/Spyglass.js'
|
||||
import { Store } from '../../Store.js'
|
||||
import { cleanUrl, deepEqual, genPath } from '../../Utils.js'
|
||||
import { Ad, Btn, BtnMenu, ErrorPanel, FileCreation, FileRenaming, Footer, HasPreview, Octicon, PreviewPanel, ProjectCreation, ProjectDeletion, ProjectPanel, SearchList, SourcePanel, TextInput, Tree, VersionSwitcher } from '../index.js'
|
||||
@@ -30,6 +31,10 @@ export function SchemaGenerator({ gen, allowedVersions }: Props) {
|
||||
|
||||
useEffect(() => Store.visitGenerator(gen.id), [gen.id])
|
||||
|
||||
useEffect(() => {
|
||||
setupSpyglass()
|
||||
}, [])
|
||||
|
||||
const [currentPreset, setCurrentPreset] = useSearchParam('preset')
|
||||
const [sharedSnippetId, setSharedSnippetId] = useSearchParam(SHARE_KEY)
|
||||
const backup = useMemo(() => Store.getBackup(gen.id), [gen.id])
|
||||
|
||||
@@ -16,6 +16,7 @@ const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes'
|
||||
const fixesUrl = 'https://raw.githubusercontent.com/misode/mcfixes'
|
||||
const versionDiffUrl = 'https://mcmeta-diff.misode.workers.dev'
|
||||
const whatsNewUrl = 'https://whats-new.misode.workers.dev'
|
||||
const vanillaMcdocUrl = 'https://proxy.misode.workers.dev/mcdoc'
|
||||
|
||||
type McmetaTypes = 'summary' | 'data' | 'data-json' | 'assets' | 'assets-json' | 'registries' | 'atlas'
|
||||
|
||||
@@ -39,6 +40,15 @@ async function validateCache(version: RefInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchVanillaMcdoc() {
|
||||
try {
|
||||
// TODO: enable refresh
|
||||
return cachedFetch(vanillaMcdocUrl, { decode: res => res.arrayBuffer(), refresh: false })
|
||||
} catch (e) {
|
||||
throw new Error(`Error occured while fetching vanilla-mcdoc: ${message(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchRegistries(versionId: VersionId) {
|
||||
console.debug(`[fetchRegistries] ${versionId}`)
|
||||
const version = config.versions.find(v => v.id === versionId)!
|
||||
@@ -51,7 +61,7 @@ export async function fetchRegistries(versionId: VersionId) {
|
||||
}
|
||||
return result
|
||||
} catch (e) {
|
||||
throw new Error(`Error occurred while fetching registries (2): ${message(e)}`)
|
||||
throw new Error(`Error occurred while fetching registries: ${message(e)}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
63
src/app/services/Spyglass.ts
Normal file
63
src/app/services/Spyglass.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import * as core from '@spyglassmc/core'
|
||||
import { BrowserExternals } from '@spyglassmc/core/lib/browser.js'
|
||||
import * as mcdoc from '@spyglassmc/mcdoc'
|
||||
import * as zip from '@zip.js/zip.js'
|
||||
import { fetchVanillaMcdoc } from './index.js'
|
||||
|
||||
const externals: core.Externals = {
|
||||
...BrowserExternals,
|
||||
archive: {
|
||||
...BrowserExternals.archive,
|
||||
async decompressBall(buffer, { stripLevel } = {}) {
|
||||
const reader = new zip.ZipReader(new zip.BlobReader(new Blob([buffer])))
|
||||
const entries = await reader.getEntries()
|
||||
return await Promise.all(entries.map(async e => {
|
||||
const data = await e.getData?.(new zip.Uint8ArrayWriter())
|
||||
const path = stripLevel === 1 ? e.filename.substring(e.filename.indexOf('/') + 1) : e.filename
|
||||
const type = e.directory ? 'dir' : 'file'
|
||||
return { data, path, mtime: '', type, mode: 0 }
|
||||
}))
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export async function setupSpyglass() {
|
||||
const logger: core.Logger = console
|
||||
const profilers = new core.ProfilerFactory(logger, [
|
||||
'project#init',
|
||||
'project#ready',
|
||||
'misode#setup',
|
||||
])
|
||||
const profiler = profilers.get('misode#setup')
|
||||
const service = new core.Service({
|
||||
logger,
|
||||
profilers,
|
||||
project: {
|
||||
cacheRoot: 'file:cache/',
|
||||
projectRoots: ['file:project/'],
|
||||
externals: externals,
|
||||
defaultConfig: core.ConfigService.merge(core.VanillaConfig, {
|
||||
env: { dependencies: ['@vanilla-mcdoc'] },
|
||||
}),
|
||||
initializers: [mcdoc.initialize, initialize],
|
||||
},
|
||||
})
|
||||
await service.project.ready()
|
||||
profiler.task('Project ready')
|
||||
await service.project.cacheService.save()
|
||||
profiler.task('Save cache')
|
||||
profiler.finalize()
|
||||
|
||||
service.logger.info(service.project.symbols.global)
|
||||
}
|
||||
|
||||
const initialize: core.ProjectInitializer = async (ctx) => {
|
||||
const { meta, externals, cacheRoot } = ctx
|
||||
|
||||
meta.registerDependencyProvider('@vanilla-mcdoc', async () => {
|
||||
const uri: string = new core.Uri('downloads/vanilla-mcdoc.tar.gz', cacheRoot).toString()
|
||||
const buffer = await fetchVanillaMcdoc()
|
||||
await core.fileUtil.writeFile(externals, uri, new Uint8Array(buffer))
|
||||
return { info: { startDepth: 1 }, uri }
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"target": "es2021",
|
||||
"module": "node16",
|
||||
"lib": ["dom","esnext"],
|
||||
"moduleResolution": "node16",
|
||||
|
||||
@@ -19,8 +19,14 @@ export default defineConfig({
|
||||
{ find: 'react/jsx-runtime', replacement: 'preact/jsx-runtime' },
|
||||
],
|
||||
},
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
target: 'es2021',
|
||||
},
|
||||
},
|
||||
build: {
|
||||
sourcemap: true,
|
||||
target: 'es2021',
|
||||
rollupOptions: {
|
||||
plugins: [
|
||||
html({
|
||||
|
||||
Reference in New Issue
Block a user