file-based-routing-cli
Advanced tools
+1
-1
| { | ||
| "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", |
+25
-10
@@ -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); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
10983
7.26%240
5.73%