You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

file-based-routing-cli

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-based-routing-cli - npm Package Compare versions

Comparing version
1.1.3
to
1.1.4
+1
-1
package.json
{
"name": "file-based-routing-cli",
"version": "1.1.3",
"version": "1.1.4",
"description": "CLI tool for file-based routing in React projects",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -22,5 +22,10 @@ import { watch } from "chokidar";

console.log(
chalk.blue(`Watching for file changes in ${pagesPath} directory...`)
);
console.log(chalk.gray(`Using routing file: ${routingPath}`));
const watcher = watch(`${pagesPath}/**/*.{jsx,tsx}`, {
persistent: true,
ignoreInitial: false,
ignoreInitial: true,
awaitWriteFinish: {

@@ -32,32 +37,42 @@ stabilityThreshold: 300,

console.log(
chalk.blue(`Watching for file changes in ${pagesPath} directory...`)
);
watcher
.on("add", async (path) => {
await handleFileAdd(path, pages);
console.log(chalk.yellow(`File added: ${path}`));
await handleFileAdd(path, pages, routingPath);
})
.on("unlink", async (path) => {
await handleFileRemove(path, pages);
console.log(chalk.yellow(`File removed: ${path}`));
await handleFileRemove(path, pages, routingPath);
})
.on("error", (error) => {
console.error(chalk.red(`Watcher error: ${error}`));
})
.on("ready", () => {
console.log(chalk.green("Watcher is ready and watching for changes"));
});
}
async function handleFileAdd(path, pages) {
async function handleFileAdd(path, pages, routingPath) {
const { name, ext, relativePath, route, component } = parsePagePath(path);
try {
console.log(chalk.cyan(`Processing file: ${path}`));
console.log(chalk.cyan(`Component: ${component}, Route: ${route}`));
const stats = await fs.stat(path);
if (stats.size === 0) {
console.log(chalk.cyan(`File is empty, creating component template...`));
await writeFile(path, componentTemplate(component));
}
pages.push({ file: relativePath + ext, component, route });
console.log(chalk.cyan(`Updating routing file: ${routingPath}`));
await updateRouting(pages, routingPath);
console.log(chalk.green(`Added route: ${route} -> ${component}`));
} catch (error) {
console.error("Error handling file addition:", error);
console.error(chalk.red("Error handling file addition:"), error);
}
}
async function handleFileRemove(path, pages) {
async function handleFileRemove(path, pages, routingPath) {
const { name } = parsePagePath(path);

@@ -64,0 +79,0 @@ const index = pages.findIndex((p) => p.component === name);