Cat is a framework that provides a minimalistic but powerful way to build reactive UIs, with 0 dependencies or runtimes needed, including for the framework itself. It's an AOT compiler that generates highly optimized and lightweight code for efficient performance and memory usage. It wires all the logic for self-contained, fine-grained reactive components.
Task
Let's start setting up the foundations, you must setup a compiler that, for now, only search for the files with the convention: {filename}.comp.html, and inject their content inside the index.html.
Requirements
Our framework must look at the cat.config.json at the root of the project, which for now it's going to have a single parameter, "root": "index.html", that provide the path where the index.html it's placed in the project tree.
This file can be created with default values by running the command npm run cat init. By default the index.html path it's defined at the root of the project.
Our framework it's going to set up a development server to facilitate the development stage. By running npm run cat start. Powered by express.js.
When the development server it's on, each time the user do a request to the server, our framework compile the app again, in case a change was made, to always load with the latest changes.
Execute the task, with its requirements.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure, I'd be happy to help you set up the foundational components of your Cat framework according to your requirements. Below, I'll provide step-by-step instructions with code samples to execute your task.
Overview
We will:
Initialize an NPM project.
Create a cat.config.json with default values using the npm run cat init command.
Set up a development server powered by Express.js, which will recompile the app on each request when running npm run cat start.
Implement a basic compiler that injects content from {filename}.comp.html files into index.html.
Step 1: Initialize Your Project
First, let's set up an NPM project.
bash
mkdir cat-framework
cd cat-framework
npm init -y
Step 2: Install Dependencies
We'll need Express.js for our development server.
bash
npm install express
Step 3: Set Up NPM Scripts
In your package.json, add the following scripts to handle the cat commands:
Place these files in the root directory or any subdirectory.
Step 7: Run the Development Server
Start the server:
bash
npm run cat:start
You should see:
code
Cat development server is running at http://localhost:3000
Step 8: Test It Out
Open your browser and navigate to http://localhost:3000. You should see the index.html with the content of header.comp.html and footer.comp.html injected at the appropriate placeholders.
Let's map the implemented features to your requirements:
cat.config.json at the root of the project:
The init() function creates cat.config.json with the root set to index.html.
Create cat.config.json with default values via npm run cat init:
The npm run cat:init command runs the init() function, creating the config file if it doesn't exist.
Set up a development server using npm run cat start powered by Express.js:
The start() function initializes an Express.js server that listens on port 3000.
Recompile the app on each request to reflect the latest changes:
The server calls compileApp() on every request before serving the page, ensuring any changes in component files are included.
Additional Notes
Hot Reloading: The current setup recompiles on each request. For a more efficient workflow, consider integrating a file-watcher (e.g., chokidar) to recompile when files change.
Dependencies: Ensure express is listed under dependencies in package.json, as we're using it in production (development server).
Summary
We've successfully:
Set up a basic framework that compiles component files into index.html.
Created scripts to initialize the config and start the development server.
Ensured the app recompiles on each request to include the latest changes.
This foundational setup meets all your specified requirements and provides a starting point for further development of the Cat framework.
Feel free to customize and expand upon this foundation to suit your framework's evolving needs!