navilo 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,17 +30,21 @@ Navilo automatically generates a route tree from your `src/app` (or custom) dire
30
30
 
31
31
  ## Quick Start
32
32
 
33
- ### Vite Config
33
+ You can use the CLI to setup your project automatically.
34
34
 
35
- 1. Install react router dom since its our peer dependency
35
+ ```bash
36
+ npx navilo init
37
+ ```
38
+
39
+ Or you can do the following steps manually:
36
40
 
41
+ ### Vite Config
42
+ 1. Install react router dom since its our peer dependency
37
43
  ```bash
38
44
  npm install react-router-dom@6.16.0
39
-
40
45
  ```
41
46
 
42
47
  2.Add the navilo to plugin in vite config
43
-
44
48
  ```ts
45
49
  // vite.config.ts
46
50
  import {defineConfig} from 'vite';
@@ -70,7 +74,7 @@ declare module 'virtual:navilo-routes' {
70
74
 
71
75
  ```tsx
72
76
  import {RouterProvider} from "react-router-dom";
73
- import {router} from 'virtual:preluder-routes';
77
+ import {router} from 'virtual:navilo-routes';
74
78
 
75
79
  export function App() {
76
80
  return (
package/bin/navilo.js ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ const commands = {
8
+ init: () => {
9
+ console.log('Initializing Navilo...');
10
+
11
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
12
+ if (fs.existsSync(packageJsonPath)) {
13
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
14
+ const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
15
+ if (!dependencies['react-router-dom'] || dependencies['react-router-dom'] !== '^6.16.0') {
16
+ console.log('Installing react-router-dom@^6.16.0...');
17
+ execSync('npm install react-router-dom@^6.16.0', { stdio: 'inherit' });
18
+ }
19
+ } else {
20
+ console.log('package.json not found. Please run in a valid project directory.');
21
+ return;
22
+ }
23
+
24
+ const viteConfigPath = path.join(process.cwd(), 'vite.config.ts');
25
+ if (fs.existsSync(viteConfigPath)) {
26
+ let viteConfig = fs.readFileSync(viteConfigPath, 'utf-8');
27
+ if (!viteConfig.includes('navilo(')) {
28
+ viteConfig = viteConfig.replace(/plugins: \[(.*)\]/s, (match, plugins) => {
29
+ return `plugins: [${plugins.trim()}, navilo({ pagesDir: 'src/app' })]`;
30
+ });
31
+ viteConfig = "import navilo from 'navilo';\n" + viteConfig;
32
+ fs.writeFileSync(viteConfigPath, viteConfig);
33
+ console.log('Updated vite.config.ts');
34
+ }
35
+ } else {
36
+ console.log('vite.config.ts not found. Please ensure you are in a Vite project.');
37
+ }
38
+
39
+ const viteEnvDtsPath = path.join(process.cwd(), 'src/vite-env.d.ts');
40
+ const declaration = `/// <reference types="vite/client" />
41
+ declare module 'virtual:navilo-routes' {
42
+ export const router;
43
+ }
44
+ `;
45
+ if (fs.existsSync(viteEnvDtsPath)) {
46
+ let content = fs.readFileSync(viteEnvDtsPath, 'utf-8');
47
+ if (!content.includes('virtual:navilo-routes')) {
48
+ content += '\n' + declaration;
49
+ fs.writeFileSync(viteEnvDtsPath, content);
50
+ }
51
+ } else {
52
+ fs.writeFileSync(viteEnvDtsPath, declaration);
53
+ }
54
+ console.log('Updated/created vite-env.d.ts');
55
+
56
+
57
+ const appFilePath = path.join(process.cwd(), 'src/App.tsx');
58
+ if (fs.existsSync(appFilePath)) {
59
+ let appFileContent = fs.readFileSync(appFilePath, 'utf-8');
60
+ if (!appFileContent.includes('virtual:navilo-routes')) {
61
+ appFileContent = `import { RouterProvider } from "react-router-dom";
62
+ import { router } from 'virtual:navilo-routes';
63
+
64
+ export function App() {
65
+ return (
66
+ <RouterProvider router={router} />
67
+ );
68
+ }
69
+ `;
70
+ fs.writeFileSync(appFilePath, appFileContent);
71
+ console.log('Updated App.tsx');
72
+ }
73
+ } else {
74
+ console.log('src/App.tsx not found. You will need to manually set up the router provider.');
75
+ }
76
+
77
+ console.log('Navilo initialization complete! 🎉');
78
+ },
79
+ };
80
+
81
+ const command = process.argv[2];
82
+
83
+ if (commands[command]) {
84
+ commands[command]();
85
+ } else {
86
+ console.log('Unknown command. Available commands: init');
87
+ }
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "navilo",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "File-based routing plugin for Vite + React applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "files": [
9
- "dist"
9
+ "dist",
10
+ "bin"
10
11
  ],
12
+ "bin": {
13
+ "navilo": "bin/navilo.js"
14
+ },
11
15
  "scripts": {
12
16
  "build": "tsup",
13
17
  "dev": "tsup --watch",
14
- "typecheck": "tsc --noEmit"
18
+ "typecheck": "tsc --noEmit",
19
+ "prepack": "npm run build"
15
20
  },
16
21
  "keywords": [
17
22
  "vite",
@@ -47,4 +52,4 @@
47
52
  "vitest": "^3.2.4"
48
53
  },
49
54
  "packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
50
- }
55
+ }