From 08c2497fab6d6efb8462a689e94e52ec17b91ff9 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 25 May 2026 22:43:15 +0200 Subject: [PATCH 01/10] feat: use fastify as server - remove nitropack - new @mcflyjs/fastify package - test-core workspace for testing the new setup --- .vscode/settings.json | 1 - mcfly.config.mjs | 3 + packages/config/package.json | 6 +- ...efine-mcfly-config.ts => define-config.ts} | 10 +- packages/config/src/index.ts | 2 +- packages/core/package.json | 10 +- packages/core/src/cli/commands/serve.ts | 129 --------- packages/core/src/{cli => }/commands/build.ts | 33 +-- .../core/src/{cli => }/commands/generate.ts | 0 packages/core/src/{cli => }/commands/new.ts | 0 .../core/src/{cli => }/commands/prepare.ts | 7 +- packages/core/src/commands/serve.ts | 57 ++++ packages/core/src/get-config.js | 23 -- packages/core/src/{cli => }/index.ts | 0 packages/core/src/mcfly-nitro-config.ts | 35 --- packages/core/src/route-middleware.js | 161 ----------- packages/core/src/runtime/index.ts | 1 - packages/core/test/build.test.ts | 2 +- packages/core/test/prepare.test.ts | 16 +- packages/fastify/index.js | 7 + packages/fastify/package.json | 16 ++ packages/fastify/serve.js | 17 ++ pnpm-lock.yaml | 270 ++++-------------- pnpm-workspace.yaml | 8 +- site/mcfly.config.mjs | 43 +-- test-core/mcfly.config.mjs | 6 + test-core/package.json | 17 ++ test-core/src/api/README.md | 29 ++ test-core/src/api/example/index.js | 6 + test-core/src/api/root.js | 6 + test-core/src/pages/index.html | 0 31 files changed, 270 insertions(+), 651 deletions(-) create mode 100644 mcfly.config.mjs rename packages/config/src/{define-mcfly-config.ts => define-config.ts} (64%) delete mode 100644 packages/core/src/cli/commands/serve.ts rename packages/core/src/{cli => }/commands/build.ts (68%) rename packages/core/src/{cli => }/commands/generate.ts (100%) rename packages/core/src/{cli => }/commands/new.ts (100%) rename packages/core/src/{cli => }/commands/prepare.ts (76%) create mode 100644 packages/core/src/commands/serve.ts rename packages/core/src/{cli => }/index.ts (100%) delete mode 100644 packages/core/src/mcfly-nitro-config.ts delete mode 100644 packages/core/src/route-middleware.js create mode 100644 packages/fastify/index.js create mode 100644 packages/fastify/package.json create mode 100644 packages/fastify/serve.js create mode 100644 test-core/mcfly.config.mjs create mode 100644 test-core/package.json create mode 100644 test-core/src/api/README.md create mode 100644 test-core/src/api/example/index.js create mode 100644 test-core/src/api/root.js create mode 100644 test-core/src/pages/index.html diff --git a/.vscode/settings.json b/.vscode/settings.json index c64e200..80cc44e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,7 +8,6 @@ "hookable", "mcfly", "mcflyjs", - "nitropack", "ultrahtml", "unstorage" ], diff --git a/mcfly.config.mjs b/mcfly.config.mjs new file mode 100644 index 0000000..7a4165f --- /dev/null +++ b/mcfly.config.mjs @@ -0,0 +1,3 @@ +export default { + from: 'root', +} diff --git a/packages/config/package.json b/packages/config/package.json index c4e71d8..2361018 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -9,8 +9,7 @@ "types": "./dist/index.d.ts", "default": "./dist/index.js" }, - "./define-mcfly-config": "./dist/define-mcfly-config.js", - "./nitro-config": "./dist/nitro-config.js" + "./define-config": "./dist/define-config.js" }, "scripts": { "build": "tsc --erasableSyntaxOnly", @@ -32,8 +31,5 @@ "dependencies": { "h3": "^1.15.1", "web-component-base": "^4.0.0" - }, - "devDependencies": { - "nitropack": "~2.11.7" } } diff --git a/packages/config/src/define-mcfly-config.ts b/packages/config/src/define-config.ts similarity index 64% rename from packages/config/src/define-mcfly-config.ts rename to packages/config/src/define-config.ts index d3c638a..d765cf5 100644 --- a/packages/config/src/define-mcfly-config.ts +++ b/packages/config/src/define-config.ts @@ -1,8 +1,6 @@ -import type { NitroConfig } from 'nitropack' - export type McFlyConfig = { - components: 'js' | 'lit' - nitro?: NitroConfig + server: McFlyServer + components?: 'js' | 'lit' plugins?: McFlyPlugin[] } @@ -11,7 +9,7 @@ export type McFlyConfig = { * @param {McFlyConfig} config * @returns {function(): McFlyConfig}e */ -export function defineMcFlyConfig(config: McFlyConfig) { +export function defineConfig(config: McFlyConfig) { return () => config } @@ -19,3 +17,5 @@ export function defineMcFlyConfig(config: McFlyConfig) { * TODO: finalize Plugin type */ export type McFlyPlugin = {} + +export type McFlyServer = any diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 6ea9e33..5784af5 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -1 +1 @@ -export { type McFlyConfig, defineMcFlyConfig } from './define-mcfly-config.js' +export { type McFlyConfig, defineConfig } from './define-config.js' diff --git a/packages/core/package.json b/packages/core/package.json index 2dc351e..3f8d7bd 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -3,17 +3,16 @@ "version": "0.8.8", "description": "McFly core package", "type": "module", - "main": "./dist/cli/index.js", + "main": "./dist/index.js", "bin": { - "mcfly": "./dist/cli/index.js" + "mcfly": "./dist/index.js" }, "exports": { ".": { - "types": "./dist/cli/index.d.ts", - "default": "./dist/cli/index.js" + "types": "./dist/index.d.ts", + "default": "./dist/index.js" }, "./runtime": "./dist/runtime/index.js", - "./cli": "./dist/cli/index.js", "./package.json": "./package.json" }, "files": [ @@ -43,7 +42,6 @@ "devalue": "^5.1.1", "esprima": "^4.0.1", "h3": "^1.15.1", - "nitropack": "^2.11.7", "pathe": "^2.0.3", "ultrahtml": "^1.5.3" }, diff --git a/packages/core/src/cli/commands/serve.ts b/packages/core/src/cli/commands/serve.ts deleted file mode 100644 index 18fd562..0000000 --- a/packages/core/src/cli/commands/serve.ts +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env node - -import { consola } from 'consola' -import { colorize } from 'consola/utils' -import { defineCommand, type ParsedArgs } from 'citty' -import { createRequire } from 'node:module' -import { - type Nitro, - build, - createDevServer, - createNitro, - prepare, - prerender, -} from 'nitropack' -import { resolve } from 'pathe' -import { fileURLToPath } from 'node:url' -import { dirname } from 'pathe' -import { getMcFlyConfig, getNitroConfig } from '../../get-config.js' - -const hmrKeyRe = /^runtimeConfig\.|routeRules\./ -const __filename = fileURLToPath(import.meta.url) -const __dirname = dirname(__filename) - -async function printInfo() { - try { - const _require = createRequire(import.meta.url) - const mcflyPkg = await _require('@mcflyjs/core/package.json') - const mcflyPkgVersion = `McFly ${colorize('bold', mcflyPkg.version)}` - const nitroPkg = await _require('nitropack/package.json') - const nitroPkgVersion = `Nitro ${nitroPkg.version}` - consola.log( - `${colorize('blue', mcflyPkgVersion)} ${colorize('dim', nitroPkgVersion)}` - ) - } catch (e) { - consola.error(e) - } -} - -async function serve(args: ParsedArgs) { - try { - // TODO: check for dir type (should be string) - const dir = args.dir?.toString() || args._dir?.toString() - const rootDir: string = resolve(dir || '.') - - let nitro: Nitro - const reload = async () => { - // close existing nitro - if (nitro) { - consola.info('Restarting dev server...') - if ('unwatch' in nitro.options._c12) { - await nitro.options._c12.unwatch() - } - await nitro.close() - } - - const { mcflyConfig, configFile } = await getMcFlyConfig() - const nitroConfig = await getNitroConfig(mcflyConfig) - - // create new nitro - nitro = await createNitro( - { - rootDir, - dev: true, - preset: 'nitro-dev', - _cli: { command: 'dev' }, - ...nitroConfig, - }, - { - watch: true, - c12: { - async onUpdate({ getDiff, newConfig }: any) { - const diff = getDiff() - - if (diff.length === 0) { - return // No changes - } - - consola.info( - 'Nitro config updated:\n' + - diff - .map((entry: unknown) => ` ${entry?.toString()}`) - .join('\n') - ) - - // TODO: get types for c12 config & remove unknown - // @ts-ignore - await (diff.every((e: unknown) => hmrKeyRe.test(e.key)) - ? nitro.updateConfig(newConfig.config || {}) // Hot reload - : reload()) // Full reload - }, - }, - } - ) - nitro.hooks.hookOnce('restart', reload) - nitro.options.runtimeConfig.appConfigFile = configFile - - nitro.options.handlers.push({ - middleware: true, - handler: resolve(__dirname, '../../route-middleware.js'), - }) - const server = createDevServer(nitro) - - // const listenOptions = parseArgs(args) - await server.listen(1234) - await prepare(nitro) - await prerender(nitro) - await build(nitro) - } - await reload() - } catch (e) { - consola.error(e) - } -} - -export default defineCommand({ - meta: { - name: 'serve', - description: 'Runs the dev server.', - }, - async run({ args }) { - await printInfo() - await serve(args) - }, -}) - -export const exportedForTest = { - serve, - printInfo, -} diff --git a/packages/core/src/cli/commands/build.ts b/packages/core/src/commands/build.ts similarity index 68% rename from packages/core/src/cli/commands/build.ts rename to packages/core/src/commands/build.ts index e088e73..c6b30fc 100644 --- a/packages/core/src/cli/commands/build.ts +++ b/packages/core/src/commands/build.ts @@ -3,15 +3,8 @@ import { consola } from 'consola' import { defineCommand, type ParsedArgs } from 'citty' import { dirname, resolve } from 'pathe' -import { - build, - copyPublicAssets, - createNitro, - prepare, - prerender, -} from 'nitropack' import { fileURLToPath } from 'node:url' -import { getMcFlyConfig, getNitroConfig } from '../../get-config.js' +import { getMcFlyConfig } from '../get-config.js' async function _build(args: ParsedArgs) { consola.start('Building project...') @@ -21,33 +14,11 @@ async function _build(args: ParsedArgs) { const rootDir = resolve(dir) const { mcflyConfig, configFile } = await getMcFlyConfig() - const nitroConfig = await getNitroConfig(mcflyConfig) - - const nitro = await createNitro({ - rootDir, - dev: false, - - ...nitroConfig, - - minify: args.minify ?? nitroConfig.minify, - preset: args.preset ?? nitroConfig.preset, - }) const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) - nitro.options.handlers.push({ - middleware: true, - handler: resolve(__dirname, '../../route-middleware.js'), - }) - - nitro.options.runtimeConfig.appConfigFile = configFile - - await prepare(nitro) - await copyPublicAssets(nitro) - await prerender(nitro) - await build(nitro) - await nitro.close() + consola.info('dir', __dirname) } catch (err) { consola.error(err) } diff --git a/packages/core/src/cli/commands/generate.ts b/packages/core/src/commands/generate.ts similarity index 100% rename from packages/core/src/cli/commands/generate.ts rename to packages/core/src/commands/generate.ts diff --git a/packages/core/src/cli/commands/new.ts b/packages/core/src/commands/new.ts similarity index 100% rename from packages/core/src/cli/commands/new.ts rename to packages/core/src/commands/new.ts diff --git a/packages/core/src/cli/commands/prepare.ts b/packages/core/src/commands/prepare.ts similarity index 76% rename from packages/core/src/cli/commands/prepare.ts rename to packages/core/src/commands/prepare.ts index 7ec9558..7e20c13 100755 --- a/packages/core/src/cli/commands/prepare.ts +++ b/packages/core/src/commands/prepare.ts @@ -3,8 +3,7 @@ import { consola } from 'consola' import { defineCommand, type ParsedArgs } from 'citty' import { resolve } from 'pathe' -import { createNitro, writeTypes } from 'nitropack' -import { getMcFlyConfig, getNitroConfig } from '../../get-config.js' +import { getMcFlyConfig } from '../get-config.js' async function prepare(args: ParsedArgs) { consola.start('Preparing McFly workspace...') @@ -16,10 +15,8 @@ async function prepare(args: ParsedArgs) { const dir: string = args.dir?.toString() || args._dir?.toString() || '.' const rootDir = resolve(dir) const { mcflyConfig } = await getMcFlyConfig() - const nitroConfig = await getNitroConfig(mcflyConfig) - const nitro = await createNitro({ rootDir, ...nitroConfig }) - await writeTypes(nitro) + consola.info({ mcflyConfig, rootDir }) } catch (e) { consola.error(e) err = e diff --git a/packages/core/src/commands/serve.ts b/packages/core/src/commands/serve.ts new file mode 100644 index 0000000..3ac8c43 --- /dev/null +++ b/packages/core/src/commands/serve.ts @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +import { consola } from 'consola' +import { colorize } from 'consola/utils' +import { defineCommand, type ParsedArgs } from 'citty' +import { createRequire } from 'node:module' +import { resolve } from 'pathe' +// import { fileURLToPath } from 'node:url' +// import { dirname } from 'pathe' +import { getMcFlyConfig } from '../get-config.js' + +// const __filename = fileURLToPath(import.meta.url) +// const __dirname = dirname(__filename) + +async function printInfo() { + try { + const _require = createRequire(import.meta.url) + const mcflyPkg = await _require('@mcflyjs/core/package.json') + const mcflyPkgVersion = `McFly ${colorize('bold', mcflyPkg.version)}` + consola.log(`${colorize('blue', mcflyPkgVersion)}`) + } catch (e) { + consola.error(e) + } +} + +async function serve(args: ParsedArgs) { + try { + // TODO: check for dir type (should be string) + const dir = args.dir?.toString() || args._dir?.toString() + const rootDir: string = resolve(dir || '.') + + const { mcflyConfig } = await getMcFlyConfig() + + /** + * TODO: config for srcDir + */ + mcflyConfig.server.serve({ rootDir: rootDir + '/src', apiDir: '/api' }) + } catch (e) { + consola.error(e) + } +} + +export default defineCommand({ + meta: { + name: 'serve', + description: 'Runs the dev server.', + }, + async run({ args }) { + await printInfo() + await serve(args) + }, +}) + +export const exportedForTest = { + serve, + printInfo, +} diff --git a/packages/core/src/get-config.js b/packages/core/src/get-config.js index 28fc84a..11e3acd 100644 --- a/packages/core/src/get-config.js +++ b/packages/core/src/get-config.js @@ -1,27 +1,4 @@ import { loadConfig } from 'c12' -import { mcflyNitroConfig } from './mcfly-nitro-config.js' - -/** - * @typedef {import('nitropack').NitroConfig} NitroConfig - */ - -/** - * Create a valid Nitro configuration given a McFly config object - * @returns {Promise} - */ -export async function getNitroConfig(mcflyConfig = {}) { - const { config: nitroConfig } = await loadConfig({ name: 'nitro' }) - return { - // nitro config in mcfly config - ...mcflyConfig.nitro, - - // nitro config from nitro config - ...(nitroConfig ?? {}), - - // McFly standard nitro config - ...mcflyNitroConfig, - } -} export async function getMcFlyConfig() { const { config: mcflyConfig, configFile } = await loadConfig({ diff --git a/packages/core/src/cli/index.ts b/packages/core/src/index.ts similarity index 100% rename from packages/core/src/cli/index.ts rename to packages/core/src/index.ts diff --git a/packages/core/src/mcfly-nitro-config.ts b/packages/core/src/mcfly-nitro-config.ts deleted file mode 100644 index 4220983..0000000 --- a/packages/core/src/mcfly-nitro-config.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { type NitroConfig } from 'nitropack' - -/** - * @typedef {import('nitropack').NitroConfig} NitroConfig - * @type {NitroConfig} - */ -export const mcflyNitroConfig: NitroConfig = { - framework: { - name: 'McFly', - }, - compatibilityDate: '2024-12-08', - srcDir: 'src', - apiDir: 'api', - devServer: { - watch: ['./pages', './components', './api'], - }, - serverAssets: [ - { - baseName: 'pages', - dir: './pages', - }, - { - baseName: 'components', - dir: './components', - }, - ], - imports: { - presets: [ - { - from: 'web-component-base', - imports: ['WebComponent', 'html', 'attachEffect'], - }, - ], - }, -} diff --git a/packages/core/src/route-middleware.js b/packages/core/src/route-middleware.js deleted file mode 100644 index b0c3d07..0000000 --- a/packages/core/src/route-middleware.js +++ /dev/null @@ -1,161 +0,0 @@ -import { eventHandler } from 'h3' -import { useStorage } from 'nitropack/runtime' -import { createHooks } from 'hookable' -import { consola } from 'consola' -import { colorize } from 'consola/utils' -import { useRuntimeConfig } from 'nitropack/runtime' -import { dirname, relative } from 'pathe' -import { fileURLToPath } from 'node:url' - -import { - hooks as mcflyHooks, - defaultMcflyConfig, - evaluateServerScripts, - injectHtmlFragments, - injectCustomElements, -} from '@mcflyjs/core/runtime' // important to import from installed node_module because this script is passed to another context - -/** - * @typedef {import('../config').McFlyConfig} Config - * @typedef {import('unstorage').Storage} Storage - * @typedef {import('unstorage').StorageValue} StorageValue - * @typedef {import('h3').EventHandler} EventHandler - */ - -/** - * McFly middleware event handler - */ -export default eventHandler(async (event) => { - const timeStart = performance.now() - const hooks = createHooks() - Object.keys(mcflyHooks).forEach((hookName) => hooks.addHooks(hookName)) - const { path } = event - const storage = useStorage() - - const { appConfigFile } = useRuntimeConfig() - const __filename = fileURLToPath(import.meta.url) - const __dirname = dirname(__filename) - let relativePath = relative(__dirname, appConfigFile) - - let config - // TODO: this still doesn't work on Netlify - try { - const { default: configFn } = await import(relativePath) - config = configFn() - } catch (err) { - consola.error(err) - } - - // if not page, don't render - if (event.path.startsWith('/api')) { - return - } - - if (!config || Object.keys(config).length === 0) { - config = defaultMcflyConfig - consola.warn( - `[WARN]: McFly configuration not found, using defaults...`, - defaultMcflyConfig - ) - } - - const plugins = config.plugins ?? [] - - plugins.forEach((plugin) => { - const pluginHooks = Object.keys(plugin) - pluginHooks.forEach((pluginHook) => { - hooks.hook(pluginHook, plugin[pluginHook]) - }) - }) - - const { components: componentType } = config - let html = await getHtml(path, storage) - - if (html) { - const transforms = [ - { - fn: evaluateServerScripts, - args: [event], - hook: mcflyHooks.serverScriptsEvaluated, - }, - { - fn: injectHtmlFragments, - args: [storage], - hook: mcflyHooks.fragmentsInjected, - }, - { - fn: injectCustomElements, - args: [componentType, storage], - hook: mcflyHooks.customElementsInjected, - }, - ] - - if (!!componentType && !!html) { - for (const transform of transforms) { - html = await transform.fn(html.toString(), ...transform.args) - - // call hook - if (transform.hook) { - // not sure if we want to await, for now it makes the outcome predictable - await hooks.callHook(transform.hook) - } - } - } else { - consola.error('[ERR]: Failed to insert registry', { - componentType: !componentType ? 'missing' : 'okay', - html: !html ? 'missing' : 'okay', - }) - } - } - - if (html) { - await hooks.callHook(mcflyHooks.pageRendered) - } - - const timeEnd = performance.now() - consola.info( - colorize('green', event.path), - 'rendered in', - Math.round(timeEnd - timeStart), - 'ms' - ) - return ( - html ?? - new Response( - '😱 ERROR 404: Not found. You can put a 404.html on the ./src/pages directory to customize this error page.', - { status: 404 } - ) - ) -}) -/** - * Gets the storage path for a file - * @param {string} filename - * @returns {string} - */ -function getPath(filename) { - return `assets:pages${filename}` -} - -function getPurePath(path) { - return path.split('?')[0] -} - -/** - * Gets the correct HTML depending on the path requested - * @param {string} path - * @param {Storage} storage - * @returns {Promise} - */ -async function getHtml(path, storage) { - const purePath = getPurePath(path) - const rawPath = - purePath[purePath.length - 1] === '/' ? purePath.slice(0, -1) : purePath - const filename = rawPath === '' ? '/index.html' : `${rawPath}.html` - const fallback = getPath(rawPath + '/index.html') - const filePath = getPath(filename) - let html = await storage.getItem(filePath) - if (!html) html = await storage.getItem(fallback) - if (!html) html = await storage.getItem(getPath('/404.html')) - - return html -} diff --git a/packages/core/src/runtime/index.ts b/packages/core/src/runtime/index.ts index 99f860a..754f274 100644 --- a/packages/core/src/runtime/index.ts +++ b/packages/core/src/runtime/index.ts @@ -4,4 +4,3 @@ export { getFiles } from './get-files.js' export { hooks } from './hooks.mjs' export { injectCustomElements } from './inject-elements.js' export { injectHtmlFragments } from './inject-fragments.mjs' -export { mcflyNitroConfig as nitroConfig } from '../mcfly-nitro-config.js' diff --git a/packages/core/test/build.test.ts b/packages/core/test/build.test.ts index 9cd30cb..df74e88 100644 --- a/packages/core/test/build.test.ts +++ b/packages/core/test/build.test.ts @@ -1,7 +1,7 @@ import type { ParsedArgs } from 'citty' import consola from 'consola' import { expect, it, vi } from 'vitest' -import { exportedForTest } from '../src/cli/commands/build.js' +import { exportedForTest } from '../src/commands/build' const build = exportedForTest.build diff --git a/packages/core/test/prepare.test.ts b/packages/core/test/prepare.test.ts index 4a2e160..3bc53fb 100644 --- a/packages/core/test/prepare.test.ts +++ b/packages/core/test/prepare.test.ts @@ -1,6 +1,6 @@ import { consola } from 'consola' import { it, expect, vi } from 'vitest' -import { exportedForTest } from '../src/cli/commands/prepare.js' +import { exportedForTest } from '../src/commands/prepare' const prepare = exportedForTest.prepare const mocks = vi.hoisted(() => { @@ -9,12 +9,6 @@ const mocks = vi.hoisted(() => { } }) -vi.mock('nitropack', () => { - return { - createNitro: mocks.createNitro, - } -}) - it('start prepare script', () => { const spy = vi.spyOn(consola, 'start') @@ -23,14 +17,6 @@ it('start prepare script', () => { expect(spy).toHaveBeenCalled() }) -it.skip('execute nitropack prepare', () => { - const successSpy = vi.spyOn(consola, 'success') - - prepare({ dir: 'fakeDir', _: [] }) - - expect(successSpy).toHaveBeenCalled() -}) - it.skip('catch error', () => { const dir = 'fake-dir' const errSpy = vi.spyOn(consola, 'error') diff --git a/packages/fastify/index.js b/packages/fastify/index.js new file mode 100644 index 0000000..bf6b592 --- /dev/null +++ b/packages/fastify/index.js @@ -0,0 +1,7 @@ +import serve from './serve' + +export default () => { + return { + serve, + } +} diff --git a/packages/fastify/package.json b/packages/fastify/package.json new file mode 100644 index 0000000..44dc408 --- /dev/null +++ b/packages/fastify/package.json @@ -0,0 +1,16 @@ +{ + "name": "@mcflyjs/fastify", + "version": "0.0.1", + "type": "module", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@fastify/autoload": "6.3.1", + "fastify": "5.8.5" + } +} diff --git a/packages/fastify/serve.js b/packages/fastify/serve.js new file mode 100644 index 0000000..83bb28e --- /dev/null +++ b/packages/fastify/serve.js @@ -0,0 +1,17 @@ +import Fastify from 'fastify' +import AutoLoad from '@fastify/autoload' +import path from 'node:path' + +export default ({ rootDir, apiDir }) => { + const server = Fastify({ logger: true }) + + server.register(AutoLoad, { + dir: path.join(rootDir, apiDir), + options: { + prefix: apiDir, + }, + }) + + console.log('Watching for file changes in', rootDir) + server.listen({ port: 3000 }) +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec2ec01..145055f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,7 +37,7 @@ importers: version: 9.1.7 netlify-cli: specifier: ^25.6.0 - version: 25.6.2(@types/node@25.6.2)(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1)(picomatch@4.0.4) + version: 25.6.2(@types/node@25.6.2)(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1)(picomatch@4.0.4)(rollup@4.60.3) prettier: specifier: ^3.8.3 version: 3.8.3 @@ -59,10 +59,6 @@ importers: web-component-base: specifier: ^4.0.0 version: 4.1.2 - devDependencies: - nitropack: - specifier: ~2.11.7 - version: 2.11.13(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.4) packages/core: dependencies: @@ -84,9 +80,6 @@ importers: h3: specifier: ^1.15.1 version: 1.15.11 - nitropack: - specifier: ^2.11.7 - version: 2.11.13(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.4) pathe: specifier: ^2.0.3 version: 2.0.3 @@ -148,6 +141,15 @@ importers: specifier: ^22.13.11 version: 22.19.18 + packages/fastify: + dependencies: + '@fastify/autoload': + specifier: 6.3.1 + version: 6.3.1 + fastify: + specifier: 5.8.5 + version: 5.8.5 + site: dependencies: '@mcflyjs/config': @@ -164,7 +166,19 @@ importers: version: 0.2.9 '@mcflyjs/core': specifier: ^0.8.8 - version: 0.8.8(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.0)(magicast@0.3.5) + version: 0.8.8(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.4)(magicast@0.3.5) + + test-core: + dependencies: + '@mcflyjs/config': + specifier: workspace:* + version: link:../packages/config + '@mcflyjs/core': + specifier: workspace:* + version: link:../packages/core + '@mcflyjs/fastify': + specifier: workspace:* + version: link:../packages/fastify packages: @@ -966,6 +980,9 @@ packages: '@fastify/ajv-compiler@4.0.5': resolution: {integrity: sha512-KoWKW+MhvfTRWL4qrhUwAAZoaChluo0m0vbiJlGMt2GXvL4LVPQEjt8kSpHI3IBq5Rez8fg+XeH3cneztq+C7A==} + '@fastify/autoload@6.3.1': + resolution: {integrity: sha512-0fsG+lO3m5yEZVjXKpltCe+2eHhM6rfAPQhvlGUgLUFTw/N2wA9WqPTObMtrF3oUCUrxbSDv60HlUIoh+aFM1A==} + '@fastify/busboy@3.2.0': resolution: {integrity: sha512-m9FVDXU3GT2ITSe0UaMA5rU3QkfC/UXtCU8y0gSN/GugTqtVldOBWIB5V6V3sbmenVZUIpU6f+mPEO2+m5iTaA==} @@ -6853,6 +6870,8 @@ snapshots: ajv-formats: 3.0.1(ajv@8.20.0) fast-uri: 3.1.2 + '@fastify/autoload@6.3.1': {} + '@fastify/busboy@3.2.0': {} '@fastify/error@4.2.0': {} @@ -7080,7 +7099,7 @@ snapshots: h3: 1.15.11 web-component-base: 4.1.2 - '@mcflyjs/core@0.8.8(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.0)(magicast@0.3.5)': + '@mcflyjs/core@0.8.8(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.4)(magicast@0.3.5)': dependencies: c12: 3.3.4(magicast@0.3.5) citty: 0.1.6 @@ -7088,7 +7107,7 @@ snapshots: devalue: 5.8.0 esprima: 4.0.1 h3: 1.15.11 - nitropack: 2.11.13(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.0) + nitropack: 2.11.13(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.4) pathe: 2.0.3 ultrahtml: 1.6.0 transitivePeerDependencies: @@ -7166,23 +7185,23 @@ snapshots: find-up: 7.0.0 minimatch: 10.2.5 read-pkg: 9.0.1 - semver: 7.7.2 + semver: 7.8.0 yaml: 2.8.4 yargs: 17.7.2 - '@netlify/build@35.13.4(@opentelemetry/api@1.8.0)(@types/node@25.6.2)(picomatch@4.0.4)': + '@netlify/build@35.13.4(@opentelemetry/api@1.8.0)(@types/node@25.6.2)(picomatch@4.0.4)(rollup@4.60.3)': dependencies: '@bugsnag/js': 8.9.0 '@netlify/blobs': 10.7.0(supports-color@10.2.2) '@netlify/cache-utils': 6.0.5 '@netlify/config': 24.5.0 '@netlify/edge-bundler': 14.10.1 - '@netlify/functions-utils': 6.2.30(supports-color@10.2.2) + '@netlify/functions-utils': 6.2.30(rollup@4.60.3)(supports-color@10.2.2) '@netlify/git-utils': 6.0.4 '@netlify/opentelemetry-utils': 2.0.2(@opentelemetry/api@1.8.0) '@netlify/plugins-list': 6.81.6 '@netlify/run-utils': 6.0.3 - '@netlify/zip-it-and-ship-it': 14.5.4(supports-color@10.2.2) + '@netlify/zip-it-and-ship-it': 14.5.4(rollup@4.60.3)(supports-color@10.2.2) '@opentelemetry/api': 1.8.0 '@sindresorhus/slugify': 2.2.1 ansi-escapes: 7.3.0 @@ -7215,7 +7234,7 @@ snapshots: resolve: 2.0.0-next.6 rfdc: 1.4.1 safe-json-stringify: 1.2.0 - semver: 7.7.2 + semver: 7.8.0 string-width: 7.2.0 supports-color: 10.2.2 terminal-link: 4.0.0 @@ -7310,7 +7329,7 @@ snapshots: image-size: 2.0.2 js-image-generator: 1.0.4 parse-gitignore: 2.0.0 - semver: 7.7.2 + semver: 7.8.0 tmp-promise: 3.0.3 uuid: 13.0.0 write-file-atomic: 5.0.1 @@ -7328,12 +7347,12 @@ snapshots: image-size: 2.0.2 js-image-generator: 1.0.4 parse-gitignore: 2.0.0 - semver: 7.7.2 + semver: 7.8.0 tmp-promise: 3.0.3 uuid: 13.0.0 write-file-atomic: 5.0.1 - '@netlify/dev@4.17.3(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1)': + '@netlify/dev@4.17.3(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1)(rollup@4.60.3)': dependencies: '@netlify/ai': 0.4.1 '@netlify/blobs': 10.7.4 @@ -7341,7 +7360,7 @@ snapshots: '@netlify/database-dev': 0.10.0 '@netlify/dev-utils': 4.4.3 '@netlify/edge-functions-dev': 1.0.16 - '@netlify/functions-dev': 1.2.6 + '@netlify/functions-dev': 1.2.6(rollup@4.60.3) '@netlify/headers': 2.1.8 '@netlify/images': 1.3.7(@netlify/blobs@10.7.4)(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1) '@netlify/redirects': 3.1.10 @@ -7393,7 +7412,7 @@ snapshots: p-wait-for: 5.0.2 parse-imports: 2.2.1 path-key: 4.0.0 - semver: 7.7.2 + semver: 7.8.0 tar: 7.5.15 tmp-promise: 3.0.3 urlpattern-polyfill: 8.0.2 @@ -7416,12 +7435,12 @@ snapshots: dependencies: '@netlify/types': 2.6.0 - '@netlify/functions-dev@1.2.6': + '@netlify/functions-dev@1.2.6(rollup@4.60.3)': dependencies: '@netlify/blobs': 10.7.4 '@netlify/dev-utils': 4.4.3 '@netlify/functions': 5.2.0 - '@netlify/zip-it-and-ship-it': 14.5.4 + '@netlify/zip-it-and-ship-it': 14.5.4(rollup@4.60.3)(supports-color@10.2.2) cron-parser: 4.9.0 decache: 4.6.2 extract-zip: 2.0.1 @@ -7429,7 +7448,7 @@ snapshots: jwt-decode: 4.0.0 lambda-local: 2.2.0 read-package-up: 11.0.0 - semver: 7.7.2 + semver: 7.8.0 source-map-support: 0.5.21 transitivePeerDependencies: - bare-abort-controller @@ -7439,9 +7458,9 @@ snapshots: - rollup - supports-color - '@netlify/functions-utils@6.2.30(supports-color@10.2.2)': + '@netlify/functions-utils@6.2.30(rollup@4.60.3)(supports-color@10.2.2)': dependencies: - '@netlify/zip-it-and-ship-it': 14.5.4(supports-color@10.2.2) + '@netlify/zip-it-and-ship-it': 14.5.4(rollup@4.60.3)(supports-color@10.2.2) cpy: 11.1.0 path-exists: 5.0.0 transitivePeerDependencies: @@ -7669,7 +7688,7 @@ snapshots: '@babel/types': 7.28.0 '@netlify/binary-info': 1.0.0 '@netlify/serverless-functions-api': 2.15.1 - '@vercel/nft': 0.29.4(rollup@4.60.3) + '@vercel/nft': 0.29.4(rollup@4.60.3)(supports-color@10.2.2) archiver: 7.0.1 common-path-prefix: 3.0.0 copy-file: 11.1.0 @@ -7706,13 +7725,13 @@ snapshots: - rollup - supports-color - '@netlify/zip-it-and-ship-it@14.5.4': + '@netlify/zip-it-and-ship-it@14.5.4(rollup@4.60.3)(supports-color@10.2.2)': dependencies: '@babel/parser': 7.29.3 '@babel/types': 7.29.0 '@netlify/binary-info': 1.0.0 '@netlify/serverless-functions-api': 2.15.0 - '@vercel/nft': 0.29.4(rollup@4.60.3) + '@vercel/nft': 0.29.4(rollup@4.60.3)(supports-color@10.2.2) archiver: 7.0.1 common-path-prefix: 3.0.0 copy-file: 11.1.0 @@ -7733,49 +7752,7 @@ snapshots: precinct: 12.3.2(supports-color@10.2.2) require-package-name: 2.0.1 resolve: 2.0.0-next.6 - semver: 7.7.2 - tmp-promise: 3.0.3 - toml: 3.0.0 - unixify: 1.0.0 - urlpattern-polyfill: 8.0.2 - yargs: 17.7.2 - zod: 3.25.76 - transitivePeerDependencies: - - bare-abort-controller - - bare-buffer - - encoding - - react-native-b4a - - rollup - - supports-color - - '@netlify/zip-it-and-ship-it@14.5.4(supports-color@10.2.2)': - dependencies: - '@babel/parser': 7.29.3 - '@babel/types': 7.29.0 - '@netlify/binary-info': 1.0.0 - '@netlify/serverless-functions-api': 2.15.0 - '@vercel/nft': 0.29.4(supports-color@10.2.2) - archiver: 7.0.1 - common-path-prefix: 3.0.0 - copy-file: 11.1.0 - es-module-lexer: 1.7.0 - esbuild: 0.27.3 - execa: 8.0.1 - fast-glob: 3.3.3 - filter-obj: 6.1.0 - find-up: 7.0.0 - is-path-inside: 4.0.0 - junk: 4.0.1 - locate-path: 7.2.0 - merge-options: 3.0.4 - minimatch: 10.2.5 - normalize-path: 3.0.0 - p-map: 7.0.3 - path-exists: 5.0.0 - precinct: 12.3.2(supports-color@10.2.2) - require-package-name: 2.0.1 - resolve: 2.0.0-next.6 - semver: 7.7.2 + semver: 7.8.0 tmp-promise: 3.0.3 toml: 3.0.0 unixify: 1.0.0 @@ -7928,7 +7905,7 @@ snapshots: '@opentelemetry/propagator-b3': 1.30.1(@opentelemetry/api@1.9.0) '@opentelemetry/propagator-jaeger': 1.30.1(@opentelemetry/api@1.9.0) '@opentelemetry/sdk-trace-base': 1.30.1(@opentelemetry/api@1.9.0) - semver: 7.7.2 + semver: 7.8.0 '@opentelemetry/semantic-conventions@1.28.0': {} @@ -8292,26 +8269,7 @@ snapshots: '@typescript-eslint/types': 8.59.2 eslint-visitor-keys: 5.0.1 - '@vercel/nft@0.29.4(rollup@4.60.3)': - dependencies: - '@mapbox/node-pre-gyp': 2.0.3(supports-color@10.2.2) - '@rollup/pluginutils': 5.3.0(rollup@4.60.3) - acorn: 8.16.0 - acorn-import-attributes: 1.9.5(acorn@8.16.0) - async-sema: 3.1.1 - bindings: 1.5.0 - estree-walker: 2.0.2 - glob: 10.5.0 - graceful-fs: 4.2.11 - node-gyp-build: 4.8.4 - picomatch: 4.0.4 - resolve-from: 5.0.0 - transitivePeerDependencies: - - encoding - - rollup - - supports-color - - '@vercel/nft@0.29.4(supports-color@10.2.2)': + '@vercel/nft@0.29.4(rollup@4.60.3)(supports-color@10.2.2)': dependencies: '@mapbox/node-pre-gyp': 2.0.3(supports-color@10.2.2) '@rollup/pluginutils': 5.3.0(rollup@4.60.3) @@ -9849,7 +9807,7 @@ snapshots: process-warning: 5.0.0 rfdc: 1.4.1 secure-json-parse: 4.1.0 - semver: 7.7.2 + semver: 7.8.0 toad-cache: 3.7.0 fastq@1.20.1: @@ -10689,7 +10647,7 @@ snapshots: lodash.isstring: 4.0.1 lodash.once: 4.1.1 ms: 2.1.3 - semver: 7.7.2 + semver: 7.8.0 junk@4.0.1: {} @@ -11017,16 +10975,16 @@ snapshots: negotiator@1.0.0: {} - netlify-cli@25.6.2(@types/node@25.6.2)(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1)(picomatch@4.0.4): + netlify-cli@25.6.2(@types/node@25.6.2)(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1)(picomatch@4.0.4)(rollup@4.60.3): dependencies: '@fastify/static': 9.0.0 '@netlify/ai': 0.4.1 '@netlify/api': 14.0.18 '@netlify/blobs': 10.7.0(supports-color@10.2.2) - '@netlify/build': 35.13.4(@opentelemetry/api@1.8.0)(@types/node@25.6.2)(picomatch@4.0.4) + '@netlify/build': 35.13.4(@opentelemetry/api@1.8.0)(@types/node@25.6.2)(picomatch@4.0.4)(rollup@4.60.3) '@netlify/build-info': 10.5.1 '@netlify/config': 24.5.0 - '@netlify/dev': 4.17.3(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1) + '@netlify/dev': 4.17.3(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1)(rollup@4.60.3) '@netlify/dev-utils': 4.4.3 '@netlify/edge-bundler': 14.10.1 '@netlify/edge-functions': 3.0.6 @@ -11035,7 +10993,7 @@ snapshots: '@netlify/images': 1.3.7(@netlify/blobs@10.7.0)(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1) '@netlify/local-functions-proxy': 2.0.3 '@netlify/redirect-parser': 15.0.4 - '@netlify/zip-it-and-ship-it': 14.5.4 + '@netlify/zip-it-and-ship-it': 14.5.4(rollup@4.60.3)(supports-color@10.2.2) '@octokit/rest': 22.0.0 '@opentelemetry/api': 1.8.0 '@pnpm/tabtab': 0.5.4 @@ -11162,110 +11120,6 @@ snapshots: p-wait-for: 5.0.2 qs: 6.15.1 - nitropack@2.11.13(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.0): - dependencies: - '@cloudflare/kv-asset-handler': 0.4.2 - '@netlify/functions': 3.1.10(rollup@4.60.3) - '@rollup/plugin-alias': 5.1.1(rollup@4.60.3) - '@rollup/plugin-commonjs': 28.0.9(rollup@4.60.3) - '@rollup/plugin-inject': 5.0.5(rollup@4.60.3) - '@rollup/plugin-json': 6.1.0(rollup@4.60.3) - '@rollup/plugin-node-resolve': 16.0.3(rollup@4.60.3) - '@rollup/plugin-replace': 6.0.3(rollup@4.60.3) - '@rollup/plugin-terser': 0.4.4(rollup@4.60.3) - '@vercel/nft': 0.29.4(rollup@4.60.3) - archiver: 7.0.1 - c12: 3.3.4(magicast@0.3.5) - chokidar: 4.0.3 - citty: 0.1.6 - compatx: 0.2.0 - confbox: 0.2.4 - consola: 3.4.2 - cookie-es: 2.0.1 - croner: 9.1.0 - crossws: 0.3.5 - db0: 0.3.4(@electric-sql/pglite@0.3.16) - defu: 6.1.7 - destr: 2.0.5 - dot-prop: 9.0.0 - esbuild: 0.25.12 - escape-string-regexp: 5.0.0 - etag: 1.8.1 - exsolve: 1.0.8 - globby: 14.1.0 - gzip-size: 7.0.0 - h3: 1.15.11 - hookable: 5.5.3 - httpxy: 0.1.7 - ioredis: 5.10.1 - jiti: 2.7.0 - klona: 2.0.6 - knitwork: 1.3.0 - listhen: 1.10.0 - magic-string: 0.30.21 - magicast: 0.3.5 - mime: 4.1.0 - mlly: 1.8.2 - node-fetch-native: 1.6.7 - node-mock-http: 1.0.4 - ofetch: 1.5.1 - ohash: 2.0.11 - pathe: 2.0.3 - perfect-debounce: 1.0.0 - pkg-types: 2.3.1 - pretty-bytes: 6.1.1 - radix3: 1.1.2 - rollup: 4.60.3 - rollup-plugin-visualizer: 6.0.11(rollup@4.60.3) - scule: 1.3.0 - semver: 7.8.0 - serve-placeholder: 2.0.2 - serve-static: 2.2.1 - source-map: 0.7.6 - std-env: 3.10.0 - ufo: 1.6.4 - ultrahtml: 1.6.0 - uncrypto: 0.1.3 - unctx: 2.5.0 - unenv: 2.0.0-rc.24 - unimport: 5.7.0 - unplugin-utils: 0.2.5 - unstorage: 1.17.5(@netlify/blobs@10.7.0)(db0@0.3.4(@electric-sql/pglite@0.3.16))(ioredis@5.10.1) - untyped: 2.0.0 - unwasm: 0.3.11 - youch: 4.1.0-beta.8 - youch-core: 0.3.3 - transitivePeerDependencies: - - '@azure/app-configuration' - - '@azure/cosmos' - - '@azure/data-tables' - - '@azure/identity' - - '@azure/keyvault-secrets' - - '@azure/storage-blob' - - '@capacitor/preferences' - - '@deno/kv' - - '@electric-sql/pglite' - - '@libsql/client' - - '@netlify/blobs' - - '@planetscale/database' - - '@upstash/redis' - - '@vercel/blob' - - '@vercel/functions' - - '@vercel/kv' - - aws4fetch - - bare-abort-controller - - bare-buffer - - better-sqlite3 - - drizzle-orm - - encoding - - idb-keyval - - mysql2 - - react-native-b4a - - rolldown - - sqlite3 - - supports-color - - uploadthing - nitropack@2.11.13(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.4): dependencies: '@cloudflare/kv-asset-handler': 0.4.2 @@ -11277,7 +11131,7 @@ snapshots: '@rollup/plugin-node-resolve': 16.0.3(rollup@4.60.3) '@rollup/plugin-replace': 6.0.3(rollup@4.60.3) '@rollup/plugin-terser': 0.4.4(rollup@4.60.3) - '@vercel/nft': 0.29.4(rollup@4.60.3) + '@vercel/nft': 0.29.4(rollup@4.60.3)(supports-color@10.2.2) archiver: 7.0.1 c12: 3.3.4(magicast@0.3.5) chokidar: 4.0.3 @@ -11425,13 +11279,13 @@ snapshots: normalize-package-data@7.0.1: dependencies: hosted-git-info: 8.1.0 - semver: 7.7.2 + semver: 7.8.0 validate-npm-package-license: 3.0.4 normalize-package-data@8.0.0: dependencies: hosted-git-info: 9.0.3 - semver: 7.7.2 + semver: 7.8.0 validate-npm-package-license: 3.0.4 normalize-path@2.1.1: @@ -11622,7 +11476,7 @@ snapshots: ky: 1.14.3 registry-auth-token: 5.1.1 registry-url: 6.0.1 - semver: 7.7.2 + semver: 7.8.0 parallel-transform@1.2.0: dependencies: @@ -12916,7 +12770,7 @@ snapshots: is-npm: 6.1.0 latest-version: 9.0.0 pupa: 3.3.0 - semver: 7.7.2 + semver: 7.8.0 xdg-basedir: 5.1.0 uqr@0.1.3: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index e83b6f6..5d20dc5 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,7 +1,9 @@ packages: - - "packages/**" - - "templates/**" - - "site/**" + - 'packages/**' + - 'templates/**' + - 'site' + - 'test-fastify' + - 'test-core' allowBuilds: '@parcel/watcher': false esbuild: true diff --git a/site/mcfly.config.mjs b/site/mcfly.config.mjs index e742909..2d065a8 100644 --- a/site/mcfly.config.mjs +++ b/site/mcfly.config.mjs @@ -1,27 +1,28 @@ // @ts-check -import { defineMcFlyConfig } from '@mcflyjs/config' +import { defineConfig } from '@mcflyjs/config' // import testPlugin from './test-plugin.mjs' -export default defineMcFlyConfig({ +export default defineConfig({ + server: {}, components: 'js', // plugins: [testPlugin()], - nitro: { - preset: 'netlify', - devServer: { - watch: ['../packages'], - }, - routeRules: { - '/chat': { - redirect: { - to: 'https://matrix.to/#/#mcfly:matrix.org', - statusCode: 302, - }, - }, - }, - compressPublicAssets: { - gzip: true, - brotli: true, - }, - compatibilityDate: '2024-12-08', - }, + // nitro: { + // preset: 'netlify', + // devServer: { + // watch: ['../packages'], + // }, + // routeRules: { + // '/chat': { + // redirect: { + // to: 'https://matrix.to/#/#mcfly:matrix.org', + // statusCode: 302, + // }, + // }, + // }, + // compressPublicAssets: { + // gzip: true, + // brotli: true, + // }, + // compatibilityDate: '2024-12-08', + // }, }) diff --git a/test-core/mcfly.config.mjs b/test-core/mcfly.config.mjs new file mode 100644 index 0000000..5d1a114 --- /dev/null +++ b/test-core/mcfly.config.mjs @@ -0,0 +1,6 @@ +import { defineConfig } from '@mcflyjs/config' +import fastify from '@mcflyjs/fastify' + +export default defineConfig({ + server: fastify(), +}) diff --git a/test-core/package.json b/test-core/package.json new file mode 100644 index 0000000..f6c6c0d --- /dev/null +++ b/test-core/package.json @@ -0,0 +1,17 @@ +{ + "name": "test-core", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "mcfly serve" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@mcflyjs/core": "workspace:*", + "@mcflyjs/config": "workspace:*", + "@mcflyjs/fastify": "workspace:*" + } +} diff --git a/test-core/src/api/README.md b/test-core/src/api/README.md new file mode 100644 index 0000000..75b5658 --- /dev/null +++ b/test-core/src/api/README.md @@ -0,0 +1,29 @@ +# Routes Folder + +Routes define the pathways within your application. +Fastify's structure supports the modular monolith approach, where your +application is organized into distinct, self-contained modules. +This facilitates easier scaling and future transition to a microservice architecture. +In the future you might want to independently deploy some of those. + +In this folder you should define all the routes that define the endpoints +of your web application. +Each service is a [Fastify +plugin](https://fastify.dev/docs/latest/Reference/Plugins/), it is +encapsulated (it can have its own independent plugins) and it is +typically stored in a file; be careful to group your routes logically, +e.g. all `/users` routes in a `users.js` file. We have added +a `root.js` file for you with a '/' root added. + +If a single file becomes too large, create a folder and add a `index.js` file there: +this file must be a Fastify plugin, and it will be loaded automatically +by the application. You can now add as many files as you want inside that folder. +In this way you can create complex routes within a single monolith, +and eventually extract them. + +If you need to share functionality between routes, place that +functionality into the `plugins` folder, and share it via +[decorators](https://fastify.dev/docs/latest/Reference/Decorators/). + +If you're a bit confused about using `async/await` to write routes, you would +better take a look at [Promise resolution](https://fastify.dev/docs/latest/Reference/Routes/#promise-resolution) for more details. diff --git a/test-core/src/api/example/index.js b/test-core/src/api/example/index.js new file mode 100644 index 0000000..f0a706f --- /dev/null +++ b/test-core/src/api/example/index.js @@ -0,0 +1,6 @@ +export default async (fastify) => { + fastify.get('/', async function (request, reply) { + console.log({ request, reply }) + return 'This is an example' + }) +} diff --git a/test-core/src/api/root.js b/test-core/src/api/root.js new file mode 100644 index 0000000..144eba9 --- /dev/null +++ b/test-core/src/api/root.js @@ -0,0 +1,6 @@ +export default async function (fastify, opts) { + fastify.get('/', async function (request, reply) { + console.log({ opts, request, reply }) + return { root: true } + }) +} diff --git a/test-core/src/pages/index.html b/test-core/src/pages/index.html new file mode 100644 index 0000000..e69de29 -- 2.45.2 From 185c274621ddb709484f8133f852144d2bd46395 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 25 May 2026 22:55:25 +0200 Subject: [PATCH 02/10] chore: remove create-component package --- packages/create-component/LICENSE | 21 --- packages/create-component/README.md | 12 -- packages/create-component/package.json | 35 ---- packages/create-component/pnpm-lock.yaml | 48 ------ packages/create-component/src/index.ts | 197 ----------------------- packages/create-component/tsconfig.json | 10 -- 6 files changed, 323 deletions(-) delete mode 100644 packages/create-component/LICENSE delete mode 100644 packages/create-component/README.md delete mode 100644 packages/create-component/package.json delete mode 100644 packages/create-component/pnpm-lock.yaml delete mode 100755 packages/create-component/src/index.ts delete mode 100644 packages/create-component/tsconfig.json diff --git a/packages/create-component/LICENSE b/packages/create-component/LICENSE deleted file mode 100644 index 009a8d8..0000000 --- a/packages/create-component/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2026 Ayo Ayco - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/create-component/README.md b/packages/create-component/README.md deleted file mode 100644 index ef592d9..0000000 --- a/packages/create-component/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Create Component - -``` -npm create @mcflyjs/component@latest -``` - -Create a new web component powered by [webcomponent.io](https://webcomponent.io) - ---- - -_Just keep building._
-_A project by [Ayo](https://ayo.ayco.io)_ diff --git a/packages/create-component/package.json b/packages/create-component/package.json deleted file mode 100644 index c3164ef..0000000 --- a/packages/create-component/package.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "@mcflyjs/create-component", - "version": "0.0.1", - "description": "Create a new web component", - "type": "module", - "bin": { - "create-component": "./dist/index.js" - }, - "main": "./dist/index.js", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - } - }, - "scripts": { - "build": "tsc --erasableSyntaxOnly", - "dev": "npx jiti ./src/index.ts", - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "https://git.ayo.run/ayo/mcfly", - "directory": "packages/create-component" - }, - "author": "Ayo Ayco", - "license": "MIT", - "dependencies": { - "consola": "^3.4.2", - "giget": "^3.2.0" - }, - "devDependencies": { - "@types/node": "^25.6.0" - } -} diff --git a/packages/create-component/pnpm-lock.yaml b/packages/create-component/pnpm-lock.yaml deleted file mode 100644 index fae6010..0000000 --- a/packages/create-component/pnpm-lock.yaml +++ /dev/null @@ -1,48 +0,0 @@ -lockfileVersion: '9.0' - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - -importers: - - .: - dependencies: - consola: - specifier: ^3.4.2 - version: 3.4.2 - giget: - specifier: ^3.2.0 - version: 3.2.0 - devDependencies: - '@types/node': - specifier: ^25.6.0 - version: 25.6.2 - -packages: - - '@types/node@25.6.2': - resolution: {integrity: sha512-sokuT28dxf9JT5Kady1fsXOvI4HVpjZa95NKT5y9PNTIrs2AsobR4GFAA90ZG8M+nxVRLysCXsVj6eGC7Vbrlw==} - - consola@3.4.2: - resolution: {integrity: sha512-5IKcdX0nnYavi6G7TtOhwkYzyjfJlatbjMjuLSfE2kYT5pMDOilZ4OvMhi637CcDICTmz3wARPoyhqyX1Y+XvA==} - engines: {node: ^14.18.0 || >=16.10.0} - - giget@3.2.0: - resolution: {integrity: sha512-GvHTWcykIR/fP8cj8dMpuMMkvaeJfPvYnhq0oW+chSeIr+ldX21ifU2Ms6KBoyKZQZmVaUAAhQ2EZ68KJF8a7A==} - hasBin: true - - undici-types@7.19.2: - resolution: {integrity: sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==} - -snapshots: - - '@types/node@25.6.2': - dependencies: - undici-types: 7.19.2 - - consola@3.4.2: {} - - giget@3.2.0: {} - - undici-types@7.19.2: {} diff --git a/packages/create-component/src/index.ts b/packages/create-component/src/index.ts deleted file mode 100755 index 6f56480..0000000 --- a/packages/create-component/src/index.ts +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/env node - -import { consola } from 'consola' -import { colorize } from 'consola/utils' -import { downloadTemplate } from 'giget' -import { spawnSync } from 'node:child_process' -import * as path from 'node:path' - -const [, , directoryArg] = process.argv - -type PromptAction = { - prompt: string - info?: string - startMessage: string - command: string - subCommand: string - error: string -} - -/** - * Create Web Component - */ -async function create() { - const defaultDirectory = 'hello-world' - consola.box(`Hello! Let's build a new ${colorize('bold', 'Web Component')}!`) - let directory = directoryArg - - if (!directory) { - directory = - (await consola.prompt('Give your new project a name:', { - placeholder: defaultDirectory, - })) ?? defaultDirectory - } else { - consola.success(`Using ${directory} as name.`) - } - - if (typeof directory !== 'string') { - return - } - - directory = getSafeDirectory(directory) - const hasErrors = await downloadTemplateToDirectory(directory) - - if (!hasErrors) { - const prompts: PromptAction[] = [ - { - prompt: `Would you like to install the dependencies to ${colorize( - 'bold', - directory - )}?`, - info: 'This might take some time depending on your connectivity.', - startMessage: 'Installing dependencies using npm...', - command: `npm`, - subCommand: 'install', - error: `Install dependencies later with ${colorize( - 'yellow', - 'npm install' - )}`, - }, - { - prompt: 'Would you like to initialize your git repository?', - startMessage: 'Initializing git repository...', - command: `git`, - subCommand: 'init', - error: `Initialize git repository later with ${colorize( - 'yellow', - 'git init' - )}`, - }, - ] - - const intentions = await askPrompts(prompts, directory) - if (!!intentions && intentions.length > 0) - showResults(directory, intentions[0]) - } -} - -/** - * Returns string that is safe for commands - * @param {string} directory - * @returns string - */ -function getSafeDirectory(directory: string): string { - const { platform } = process - const locale = path[platform === `win32` ? `win32` : `posix`] - const localePath = directory.split(path.sep).join(locale.sep) - return path.normalize(localePath) -} - -/** - * Tries to download the template to the directory and returns a Promise whether the operation resulted to errors - * @param {string} directory - * @returns Promise hasErrors - */ -async function downloadTemplateToDirectory( - directory: string -): Promise { - let hasErrors = false - - try { - consola.start( - `Copying template to ${colorize('bold', getSafeDirectory(directory))}...` - ) - await downloadTemplate('github:ayo-run/web-component', { - dir: directory, - }) - } catch (ㆆ_ㆆ) { - if (ㆆ_ㆆ instanceof Error) { - consola.error(ㆆ_ㆆ.message) - } else { - consola.error(ㆆ_ㆆ) - } - consola.info('Try a different name.\n') - hasErrors = true - } - - return hasErrors -} - -/** - * Iterate over an array of prompts and ask for user intention - * @param {Array} prompts - * @param {string} cwd - * @returns Promise | undefined> - */ -async function askPrompts( - prompts: PromptAction[], - cwd: string -): Promise { - const results: boolean[] = [] - - for (const p of prompts) { - const userIntends = await consola.prompt(p.prompt, { - type: 'confirm', - }) - - if (typeof userIntends !== 'boolean') { - return - } - - if (userIntends) { - p.info && consola.info(p.info) - consola.start(p.startMessage) - try { - spawnSync(p.command, [p.subCommand], { - cwd, - shell: true, - timeout: 100_000, - stdio: 'inherit', - }) - consola.success('Done!') - } catch (ㆆ_ㆆ) { - if (ㆆ_ㆆ instanceof Error) { - consola.error(ㆆ_ㆆ.message) - } else { - consola.error(ㆆ_ㆆ) - } - consola.info(p.error + '\n') - } - } - results.push(userIntends) - } - - return results -} - -/** - * Displays the success result string based on directory and choices - * @param {string} directory - * @param {boolean} installDeps - */ -function showResults(directory: string, installDeps: boolean) { - let nextActions = [ - `Go to your project by running ${colorize('yellow', `cd ${directory}`)}`, - ] - - if (!installDeps) { - nextActions.push( - `Install the dependencies with ${colorize('yellow', 'npm install')}` - ) - } - - nextActions = nextActions.concat([ - `Start the dev server with ${colorize('yellow', 'npm start')}`, - ]) - - const result = `πŸŽ‰ Your new ${colorize( - 'bold', - 'Web Commponent' - )} app is ready: ${directory}\n\nNext actions: ${nextActions - .map((action, index) => `\n${++index}. ${action}`) - .join('')}` - - consola.box(result) -} - -create() diff --git a/packages/create-component/tsconfig.json b/packages/create-component/tsconfig.json deleted file mode 100644 index ab2dec0..0000000 --- a/packages/create-component/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["src"], - "compilerOptions": { - "allowJs": true, - "emitDeclarationOnly": false, - "declarationDir": "./dist", - "outDir": "./dist" - } -} -- 2.45.2 From 8a55ca61de4ca7c72bbf29aad9f7f7d0ee7d4212 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 25 May 2026 22:55:57 +0200 Subject: [PATCH 03/10] feat: new demo workspace --- {test-core => demo}/mcfly.config.mjs | 0 {test-core => demo}/package.json | 2 +- {test-core => demo}/src/api/README.md | 0 {test-core => demo}/src/api/example/index.js | 0 {test-core => demo}/src/api/root.js | 0 {test-core => demo}/src/pages/index.html | 0 package.json | 4 ++- packages/create-mcfly/src/index.ts | 2 +- packages/fastify/serve.js | 2 +- pnpm-lock.yaml | 37 +++++++------------- pnpm-workspace.yaml | 3 +- 11 files changed, 19 insertions(+), 31 deletions(-) rename {test-core => demo}/mcfly.config.mjs (100%) rename {test-core => demo}/package.json (93%) rename {test-core => demo}/src/api/README.md (100%) rename {test-core => demo}/src/api/example/index.js (100%) rename {test-core => demo}/src/api/root.js (100%) rename {test-core => demo}/src/pages/index.html (100%) diff --git a/test-core/mcfly.config.mjs b/demo/mcfly.config.mjs similarity index 100% rename from test-core/mcfly.config.mjs rename to demo/mcfly.config.mjs diff --git a/test-core/package.json b/demo/package.json similarity index 93% rename from test-core/package.json rename to demo/package.json index f6c6c0d..a41b156 100644 --- a/test-core/package.json +++ b/demo/package.json @@ -1,5 +1,5 @@ { - "name": "test-core", + "name": "demo", "version": "1.0.0", "description": "", "main": "index.js", diff --git a/test-core/src/api/README.md b/demo/src/api/README.md similarity index 100% rename from test-core/src/api/README.md rename to demo/src/api/README.md diff --git a/test-core/src/api/example/index.js b/demo/src/api/example/index.js similarity index 100% rename from test-core/src/api/example/index.js rename to demo/src/api/example/index.js diff --git a/test-core/src/api/root.js b/demo/src/api/root.js similarity index 100% rename from test-core/src/api/root.js rename to demo/src/api/root.js diff --git a/test-core/src/pages/index.html b/demo/src/pages/index.html similarity index 100% rename from test-core/src/pages/index.html rename to demo/src/pages/index.html diff --git a/package.json b/package.json index 6019ff4..dc9b539 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ "postinstall": "pnpm -F @mcflyjs/core build && pnpm -F @mcflyjs/config build", "start": "pnpm run site", "dev": "pnpm run site", - "site": "pnpm -F @mcflyjs/core run build && pnpm -F @mcflyjs/config run build && pnpm --filter site start", + "demo": "pnpm run build:deps && pnpm -F demo start", + "site": "pnpm run build:deps && pnpm -F site start", "build": "pnpm -F './packages/**' build", + "build:deps": "pnpm -F @mcflyjs/core build && pnpm -F @mcflyjs/config build", "build:site": "pnpm -F site build", "build:site:preview": "pnpm -F site build:preview", "template:basic": "pnpm run build && pnpm -F basic-template start", diff --git a/packages/create-mcfly/src/index.ts b/packages/create-mcfly/src/index.ts index 5ec8d01..95f6eb8 100755 --- a/packages/create-mcfly/src/index.ts +++ b/packages/create-mcfly/src/index.ts @@ -4,7 +4,7 @@ import { consola } from 'consola' import { colorize } from 'consola/utils' import { downloadTemplate } from 'giget' import { spawnSync } from 'node:child_process' -import * as path from 'node:path' +import path from 'node:path' const [, , directoryArg] = process.argv diff --git a/packages/fastify/serve.js b/packages/fastify/serve.js index 83bb28e..a55ad4b 100644 --- a/packages/fastify/serve.js +++ b/packages/fastify/serve.js @@ -12,6 +12,6 @@ export default ({ rootDir, apiDir }) => { }, }) - console.log('Watching for file changes in', rootDir) + console.log('[INFO]: Watching for file changes in', rootDir) server.listen({ port: 3000 }) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 145055f..9e60029 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,18 @@ importers: specifier: ^4.1.5 version: 4.1.5(@opentelemetry/api@1.8.0)(@types/node@25.6.2)(vite@7.3.3(@types/node@25.6.2)(jiti@2.7.0)(terser@5.47.1)(yaml@2.8.4)) + demo: + dependencies: + '@mcflyjs/config': + specifier: workspace:* + version: link:../packages/config + '@mcflyjs/core': + specifier: workspace:* + version: link:../packages/core + '@mcflyjs/fastify': + specifier: workspace:* + version: link:../packages/fastify + packages/config: dependencies: h3: @@ -115,19 +127,6 @@ importers: specifier: ^3.0.9 version: 3.2.4(@types/node@25.6.2)(@vitest/ui@3.0.9)(jiti@2.7.0)(terser@5.47.1)(yaml@2.8.4) - packages/create-component: - dependencies: - consola: - specifier: ^3.4.2 - version: 3.4.2 - giget: - specifier: ^3.2.0 - version: 3.2.0 - devDependencies: - '@types/node': - specifier: ^25.6.0 - version: 25.6.2 - packages/create-mcfly: dependencies: consola: @@ -168,18 +167,6 @@ importers: specifier: ^0.8.8 version: 0.8.8(@electric-sql/pglite@0.3.16)(@netlify/blobs@10.7.4)(magicast@0.3.5) - test-core: - dependencies: - '@mcflyjs/config': - specifier: workspace:* - version: link:../packages/config - '@mcflyjs/core': - specifier: workspace:* - version: link:../packages/core - '@mcflyjs/fastify': - specifier: workspace:* - version: link:../packages/fastify - packages: '@ampproject/remapping@2.3.0': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 5d20dc5..e773a5f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -2,8 +2,7 @@ packages: - 'packages/**' - 'templates/**' - 'site' - - 'test-fastify' - - 'test-core' + - 'demo' allowBuilds: '@parcel/watcher': false esbuild: true -- 2.45.2 From 7c0949c51873107d8dcd81e671d0fc4d39fdf59b Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 25 May 2026 22:57:42 +0200 Subject: [PATCH 04/10] chore: comment todo --- packages/core/src/commands/serve.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/commands/serve.ts b/packages/core/src/commands/serve.ts index 3ac8c43..fb40e65 100644 --- a/packages/core/src/commands/serve.ts +++ b/packages/core/src/commands/serve.ts @@ -32,7 +32,10 @@ async function serve(args: ParsedArgs) { const { mcflyConfig } = await getMcFlyConfig() /** - * TODO: config for srcDir + * TODO: config + * - srcDir, apiDir ? + * - autoLoad config + * - fastify config */ mcflyConfig.server.serve({ rootDir: rootDir + '/src', apiDir: '/api' }) } catch (e) { -- 2.45.2 From b285e0a73b0031491c7c72d5a84d04c2b7592c9e Mon Sep 17 00:00:00 2001 From: Ayo Date: Wed, 3 Jun 2026 22:17:05 +0200 Subject: [PATCH 05/10] feat: expose mcfly logger to server framework; log api URL --- demo/src/api/index.js | 5 +++++ eslint.config.mjs | 2 +- packages/core/src/commands/serve.ts | 9 ++++++++- packages/fastify/serve.js | 13 +++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 demo/src/api/index.js diff --git a/demo/src/api/index.js b/demo/src/api/index.js new file mode 100644 index 0000000..ab7329b --- /dev/null +++ b/demo/src/api/index.js @@ -0,0 +1,5 @@ +export default async (fastify) => { + fastify.get('/', async function (request, reply) { + return 'This is the API Index' + }) +} diff --git a/eslint.config.mjs b/eslint.config.mjs index c8760e1..0490e0e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -16,7 +16,7 @@ export default [ eslintPluginPrettierRecommended, includeIgnoreFile(gitignorePath), { - ignores: ['site/*', 'templates/*', '**/public/*'], + ignores: ['site/*', 'templates/*', '**/public/*', 'demo/*'], }, { rules: { diff --git a/packages/core/src/commands/serve.ts b/packages/core/src/commands/serve.ts index fb40e65..74f13cc 100644 --- a/packages/core/src/commands/serve.ts +++ b/packages/core/src/commands/serve.ts @@ -8,6 +8,7 @@ import { resolve } from 'pathe' // import { fileURLToPath } from 'node:url' // import { dirname } from 'pathe' import { getMcFlyConfig } from '../get-config.js' +import type { McFlyConfig } from '../../../config/dist/define-config.js' // const __filename = fileURLToPath(import.meta.url) // const __dirname = dirname(__filename) @@ -37,7 +38,13 @@ async function serve(args: ParsedArgs) { * - autoLoad config * - fastify config */ - mcflyConfig.server.serve({ rootDir: rootDir + '/src', apiDir: '/api' }) + if (mcflyConfig.server) + mcflyConfig.server.serve({ + rootDir: rootDir + '/src', + apiDir: '/api', + logger: consola, + }) + else consola.error('[McFly]: `server` configuration required') } catch (e) { consola.error(e) } diff --git a/packages/fastify/serve.js b/packages/fastify/serve.js index a55ad4b..4fdcbae 100644 --- a/packages/fastify/serve.js +++ b/packages/fastify/serve.js @@ -2,8 +2,9 @@ import Fastify from 'fastify' import AutoLoad from '@fastify/autoload' import path from 'node:path' -export default ({ rootDir, apiDir }) => { - const server = Fastify({ logger: true }) +export default ({ rootDir, apiDir, logger, port }) => { + const server = Fastify() + const portNumber = port ?? 3000 server.register(AutoLoad, { dir: path.join(rootDir, apiDir), @@ -12,6 +13,10 @@ export default ({ rootDir, apiDir }) => { }, }) - console.log('[INFO]: Watching for file changes in', rootDir) - server.listen({ port: 3000 }) + server + .listen({ port: portNumber }) + .then(() => { + logger.log(`API now serving at http://localhost:${portNumber}${apiDir}`) + }) + .catch((err) => logger.error(err)) } -- 2.45.2 From 903c01c005673156f9e3401b4d7adf98cb99163d Mon Sep 17 00:00:00 2001 From: Ayo Date: Wed, 3 Jun 2026 22:20:13 +0200 Subject: [PATCH 06/10] refactor: remove unused type import --- packages/core/src/commands/serve.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/commands/serve.ts b/packages/core/src/commands/serve.ts index 74f13cc..1ef54dd 100644 --- a/packages/core/src/commands/serve.ts +++ b/packages/core/src/commands/serve.ts @@ -8,7 +8,6 @@ import { resolve } from 'pathe' // import { fileURLToPath } from 'node:url' // import { dirname } from 'pathe' import { getMcFlyConfig } from '../get-config.js' -import type { McFlyConfig } from '../../../config/dist/define-config.js' // const __filename = fileURLToPath(import.meta.url) // const __dirname = dirname(__filename) -- 2.45.2 From 8a0e463fb2e32c4d498d7c9e8842ab18b652e0a9 Mon Sep 17 00:00:00 2001 From: Ayo Date: Thu, 4 Jun 2026 09:20:17 +0200 Subject: [PATCH 07/10] chore: add rootDir to config package tsconfig --- packages/config/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/config/tsconfig.json b/packages/config/tsconfig.json index ab2dec0..8756fd8 100644 --- a/packages/config/tsconfig.json +++ b/packages/config/tsconfig.json @@ -5,6 +5,7 @@ "allowJs": true, "emitDeclarationOnly": false, "declarationDir": "./dist", - "outDir": "./dist" + "outDir": "./dist", + "rootDir": "./src" } } -- 2.45.2 From 6c3efdec325349204640df93899cc90d59689ebe Mon Sep 17 00:00:00 2001 From: Ayo Date: Thu, 4 Jun 2026 09:28:40 +0200 Subject: [PATCH 08/10] chore: add serve command TODO --- packages/core/src/commands/serve.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/commands/serve.ts b/packages/core/src/commands/serve.ts index 1ef54dd..3ed568a 100644 --- a/packages/core/src/commands/serve.ts +++ b/packages/core/src/commands/serve.ts @@ -33,6 +33,7 @@ async function serve(args: ParsedArgs) { /** * TODO: config + * - separate `start` & `dev` commands * - srcDir, apiDir ? * - autoLoad config * - fastify config -- 2.45.2 From a1bfd77968b85ca18cf29d30d14fb400a4ee286d Mon Sep 17 00:00:00 2001 From: Ayo Date: Thu, 4 Jun 2026 09:32:13 +0200 Subject: [PATCH 09/10] chore: update project status --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7583d1f..f25fa55 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,13 @@ I thought: ## Project Status -We are currently in a Proof of Concept phase. All parts are subject to breaking changes in minor releases. +We are currently in a focused rewrite. All parts are subject to breaking changes in minor releases. -πŸ‘‰ [Road to v1.0.0 todo items](https://github.com/ayoayco/McFly/issues?q=is%3Aissue%20state%3Aopen%20milestone%3Av1.0.0) +- [x] file-based API routing via fastify as server framework +- [] file-based HTML pages routing & templating via Eta +- [] auto-registry of custom elements +- [] SSR custom elements +- [] SSG ## Try it today -- 2.45.2 From 9928a9b125e9ff3d1698979c1e27a6edfab0c411 Mon Sep 17 00:00:00 2001 From: Ayo Date: Thu, 4 Jun 2026 09:43:43 +0200 Subject: [PATCH 10/10] chore: udpate readme --- README.md | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index f25fa55..efcac10 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,10 @@ I thought: We are currently in a focused rewrite. All parts are subject to breaking changes in minor releases. - [x] file-based API routing via fastify as server framework -- [] file-based HTML pages routing & templating via Eta -- [] auto-registry of custom elements -- [] SSR custom elements -- [] SSG +- [ ] file-based HTML pages routing & templating via Eta +- [ ] auto-registry of custom elements +- [ ] SSR custom elements +- [ ] SSG ## Try it today @@ -43,15 +43,7 @@ Run the following to generate a McFly starter project. npm create mcfly@latest ``` -## How it works (for the nerds) - -It is primarily a runtime middleware for [Nitro](https://nitro.build). Every time a page is requested, the McFly middleware intercepts and assembles the view for the requestor. McFly does this with the assets it knows about which are mostly: pages, components, public assets. Additionally, Nitro is also capable of generating static assets on build time. - -These patterns are commonly referred to as Server-Side Rendering and Static Site Generation (SSR & SSG). - -The idea is to have a plugin system which allows for the core functionality to only "lean" on web platform features. Anything not yet a standard is implemented as a plugin which will be easily "swapped" away when the platform catches up. - -## Features +## Target Features βœ… Use vanilla custom elements (or sugar-coated web components)
βœ… Write server-powered .html pages
@@ -61,19 +53,7 @@ The idea is to have a plugin system which allows for the core functionality to o ## Special directories -**1. `./src/pages/`** - -- file-based routing for `.html` files -- directly use custom elements & static fragments (no imports or registry maintenance needed) -- use `