mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
feat: refine development command logs
This commit is contained in:
@@ -216,8 +216,6 @@ mod {module_name};
|
||||
}
|
||||
|
||||
pub fn bundle_axum_source() -> io::Result<()> {
|
||||
println!("Axum project bundling");
|
||||
|
||||
let base_path = std::env::current_dir().unwrap();
|
||||
|
||||
let mut source_builder = SourceBuilder::new(Mode::Dev);
|
||||
|
||||
+32
-26
@@ -4,64 +4,70 @@ use watchexec_supervisor::command::{Command, Program};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use watchexec::Watchexec;
|
||||
use watchexec_signals::Signal;
|
||||
use watchexec_supervisor::job::start_job;
|
||||
use watchexec_supervisor::job::{start_job, Job};
|
||||
|
||||
use crate::source_builder::bundle_axum_source;
|
||||
|
||||
// What is the development pipeline?
|
||||
//
|
||||
// 1. Any file gets updates (rs/js/ts)
|
||||
// 2. Client side vite works separately
|
||||
// 3. Stop the dev server
|
||||
// 4. Build the ssr client bundle
|
||||
// 5. Restart the server
|
||||
//
|
||||
//
|
||||
// The current solution is not optimized
|
||||
// - We should avoid to bundle static lib (i.e. react) in the main bundle
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn watch() -> Result<()> {
|
||||
let (watch_client, _) = start_job(Arc::new(Command {
|
||||
fn watch_react_src() -> Job {
|
||||
start_job(Arc::new(Command {
|
||||
program: Program::Exec {
|
||||
prog: "node_modules/.bin/tuono-dev-watch".into(),
|
||||
args: vec![],
|
||||
},
|
||||
options: Default::default(),
|
||||
}));
|
||||
}))
|
||||
.0
|
||||
}
|
||||
|
||||
watch_client.start().await;
|
||||
|
||||
let (run_server, _) = start_job(Arc::new(Command {
|
||||
fn build_rust_src() -> Job {
|
||||
start_job(Arc::new(Command {
|
||||
program: Program::Exec {
|
||||
prog: "cargo".into(),
|
||||
args: vec!["run".to_string()],
|
||||
args: vec!["run".to_string(), "-q".to_string()],
|
||||
},
|
||||
options: Default::default(),
|
||||
}));
|
||||
}))
|
||||
.0
|
||||
}
|
||||
|
||||
let (build_ssr_bundle, _) = start_job(Arc::new(Command {
|
||||
fn build_react_ssr_src() -> Job {
|
||||
start_job(Arc::new(Command {
|
||||
program: Program::Exec {
|
||||
prog: "node_modules/.bin/tuono-dev-ssr".into(),
|
||||
args: vec![],
|
||||
},
|
||||
options: Default::default(),
|
||||
}));
|
||||
}))
|
||||
.0
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn watch() -> Result<()> {
|
||||
println!("Starting development environment...");
|
||||
watch_react_src().start().await;
|
||||
|
||||
let run_server = build_rust_src();
|
||||
|
||||
let build_ssr_bundle = build_react_ssr_src();
|
||||
|
||||
build_ssr_bundle.start().await;
|
||||
|
||||
run_server.start().await;
|
||||
|
||||
println!("\nDevelopment app ready at http://localhost:3000/");
|
||||
|
||||
let wx = Watchexec::new(move |mut action| {
|
||||
for event in action.events.iter() {
|
||||
for path in event.paths() {
|
||||
if path.0.to_string_lossy().ends_with(".rs")
|
||||
// Either tsx and jsx
|
||||
|| path.0.to_string_lossy().ends_with("sx")
|
||||
{
|
||||
println!("Reloading...");
|
||||
run_server.stop();
|
||||
println!("Reloading server...");
|
||||
build_ssr_bundle.stop();
|
||||
build_ssr_bundle.start();
|
||||
bundle_axum_source();
|
||||
bundle_axum_source().expect("Failed to bunlde rust source");
|
||||
run_server.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { build, createServer } from 'vite'
|
||||
import { build, createServer, InlineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react-swc'
|
||||
import { ViteFsRouter } from './tuono-vite-plugin'
|
||||
|
||||
const BASE_CONFIG = {
|
||||
silent: true,
|
||||
const BASE_CONFIG: InlineConfig = {
|
||||
root: '.tuono',
|
||||
logLevel: 'silent',
|
||||
publicDir: '../public',
|
||||
cacheDir: 'cache',
|
||||
envDir: '../',
|
||||
@@ -13,7 +13,6 @@ const BASE_CONFIG = {
|
||||
|
||||
export function developmentSSRBundle() {
|
||||
;(async () => {
|
||||
console.log('Build SSR')
|
||||
await build({
|
||||
...BASE_CONFIG,
|
||||
build: {
|
||||
@@ -23,6 +22,8 @@ export function developmentSSRBundle() {
|
||||
emptyOutDir: true,
|
||||
rollupOptions: {
|
||||
input: './.tuono/server-main.tsx',
|
||||
// Silent all logs
|
||||
onLog() {},
|
||||
output: {
|
||||
entryFileNames: 'dev-server.js',
|
||||
format: 'iife',
|
||||
@@ -39,7 +40,6 @@ export function developmentSSRBundle() {
|
||||
|
||||
export function developmentCSRWatch() {
|
||||
;(async () => {
|
||||
console.log('Watch files')
|
||||
const server = await createServer({
|
||||
...BASE_CONFIG,
|
||||
server: {
|
||||
|
||||
@@ -134,12 +134,9 @@ export function hasParentRoute(
|
||||
|
||||
export async function routeGenerator(config = defaultConfig): Promise<void> {
|
||||
if (!isFirst) {
|
||||
console.log('Generating routes...')
|
||||
isFirst = true
|
||||
} else if (skipMessage) {
|
||||
skipMessage = false
|
||||
} else {
|
||||
console.log('Regenerating routes')
|
||||
}
|
||||
|
||||
const checkLatest = (): boolean => {
|
||||
@@ -194,7 +191,6 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
|
||||
node.parent.children = node.parent.children ?? []
|
||||
node.parent.children.push(node)
|
||||
}
|
||||
console.log('pushed')
|
||||
routeNodes.push(node)
|
||||
}
|
||||
|
||||
@@ -349,10 +345,4 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
|
||||
routeConfigFileContent,
|
||||
)
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[emoticon] Processed ${routeNodes.length === 1 ? 'route' : 'routes'} in ${
|
||||
Date.now() - start
|
||||
}ms`,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ export const splitFile = async ({
|
||||
compile,
|
||||
filename,
|
||||
}: SplitFileFnArgs): Promise<CompileOutput> => {
|
||||
console.log('Split file [splitFile fn]', code)
|
||||
return compile({
|
||||
code,
|
||||
filename,
|
||||
@@ -220,7 +219,6 @@ export const splitFile = async ({
|
||||
]),
|
||||
)
|
||||
} else {
|
||||
console.log(splitNode)
|
||||
throw new Error(
|
||||
`Unexpected splitNode type ${splitNode.type}`,
|
||||
)
|
||||
|
||||
@@ -9,7 +9,6 @@ import { SPLIT_PREFIX } from './constants'
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
const ROUTES_DIRECTORY_PATH = './src/routes'
|
||||
const DEBUG = true
|
||||
|
||||
let lock = false
|
||||
|
||||
@@ -20,10 +19,8 @@ export function RouterGenerator(): Plugin {
|
||||
|
||||
try {
|
||||
// TODO: generator function
|
||||
console.log('Generating [generate fn]')
|
||||
await routeGenerator()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
} finally {
|
||||
lock = false
|
||||
}
|
||||
@@ -34,7 +31,6 @@ export function RouterGenerator(): Plugin {
|
||||
|
||||
if (filePath.startsWith(ROUTES_DIRECTORY_PATH)) {
|
||||
// TODO: generator function
|
||||
console.log('Generating [handleFile fn]')
|
||||
await generate()
|
||||
}
|
||||
}
|
||||
@@ -57,7 +53,6 @@ export function RouterGenerator(): Plugin {
|
||||
|
||||
export function RouterCodeSplitter(): Plugin {
|
||||
const ROOT: string = process.cwd()
|
||||
console.log('ROOT', ROOT)
|
||||
|
||||
return {
|
||||
name: 'vite-plugin-tuono-fs-router-code-splitter',
|
||||
@@ -75,36 +70,14 @@ export function RouterCodeSplitter(): Plugin {
|
||||
|
||||
const compile = makeCompile({ root: ROOT })
|
||||
|
||||
if (DEBUG) console.info('Route: ', id)
|
||||
|
||||
if (id.includes(SPLIT_PREFIX)) {
|
||||
console.log('Split')
|
||||
if (DEBUG) console.info('Splitting route: ', id)
|
||||
|
||||
const compiled = await splitFile({
|
||||
code,
|
||||
compile,
|
||||
filename: id,
|
||||
})
|
||||
|
||||
if (DEBUG) {
|
||||
console.info('')
|
||||
console.info('Split Output')
|
||||
console.info('')
|
||||
//console.info(compiled.code)
|
||||
console.info('')
|
||||
console.info('')
|
||||
console.info('')
|
||||
console.info('')
|
||||
console.info('')
|
||||
console.info('')
|
||||
console.info('')
|
||||
console.info('')
|
||||
}
|
||||
|
||||
return compiled
|
||||
} else {
|
||||
console.log('Non split')
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user