navilo 1.2.6 → 1.2.9

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.
Files changed (2) hide show
  1. package/bin/navilo.js +49 -49
  2. package/package.json +1 -1
package/bin/navilo.js CHANGED
@@ -85,68 +85,68 @@ function installDependency(packageManager, pkg) {
85
85
 
86
86
  const commands = {
87
87
  init: async () => {
88
- console.log('Initializing Navilo...');
88
+ console.log('Initializing Navilo...');
89
89
 
90
90
  const packageManager = await resolvePackageManager();
91
91
  console.log(`Using package manager: ${packageManager}`);
92
92
 
93
- const packageJsonPath = path.join(process.cwd(), 'package.json');
94
- if (fs.existsSync(packageJsonPath)) {
95
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
96
- const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
93
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
94
+ if (fs.existsSync(packageJsonPath)) {
95
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
96
+ const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
97
97
 
98
98
  if (!dependencies['navilo']) {
99
99
  console.log('Installing navilo...');
100
100
  installDependency(packageManager, 'navilo');
101
101
  }
102
102
 
103
- if (!dependencies['react-router-dom'] || dependencies['react-router-dom'] !== '^6.16.0') {
104
- console.log('Installing react-router-dom@^6.16.0...');
103
+ if (!dependencies['react-router-dom'] || dependencies['react-router-dom'] !== '^6.16.0') {
104
+ console.log('Installing react-router-dom@^6.16.0...');
105
105
  installDependency(packageManager, 'react-router-dom@^6.16.0');
106
- }
107
- } else {
108
- console.log('package.json not found. Please run in a valid project directory.');
109
- return;
110
- }
106
+ }
107
+ } else {
108
+ console.log('package.json not found. Please run in a valid project directory.');
109
+ return;
110
+ }
111
111
 
112
- const viteConfigPath = path.join(process.cwd(), 'vite.config.ts');
113
- if (fs.existsSync(viteConfigPath)) {
114
- let viteConfig = fs.readFileSync(viteConfigPath, 'utf-8');
115
- if (!viteConfig.includes('navilo(')) {
116
- viteConfig = viteConfig.replace(/plugins: \[(.*)\]/s, (match, plugins) => {
117
- return `plugins: [${plugins.trim()}, navilo({ pagesDir: 'src/app' })]`;
118
- });
119
- viteConfig = "import navilo from 'navilo';\n" + viteConfig;
120
- fs.writeFileSync(viteConfigPath, viteConfig);
121
- console.log('Updated vite.config.ts');
112
+ const viteConfigPath = path.join(process.cwd(), 'vite.config.ts');
113
+ if (fs.existsSync(viteConfigPath)) {
114
+ let viteConfig = fs.readFileSync(viteConfigPath, 'utf-8');
115
+ if (!viteConfig.includes('navilo(')) {
116
+ viteConfig = viteConfig.replace(/plugins: \[(.*)\]/s, (match, plugins) => {
117
+ return `plugins: [${plugins.trim()}, navilo({ pagesDir: 'src/app' })]`;
118
+ });
119
+ viteConfig = "import {navilo} from 'navilo';\n" + viteConfig;
120
+ fs.writeFileSync(viteConfigPath, viteConfig);
121
+ console.log('Updated vite.config.ts');
122
+ }
123
+ } else {
124
+ console.log('vite.config.ts not found. Please ensure you are in a Vite project.');
122
125
  }
123
- } else {
124
- console.log('vite.config.ts not found. Please ensure you are in a Vite project.');
125
- }
126
126
 
127
- const viteEnvDtsPath = path.join(process.cwd(), 'src/vite-env.d.ts');
128
- const declaration = `/// <reference types="vite/client" />
127
+ const viteEnvDtsPath = path.join(process.cwd(), 'src/vite-env.d.ts');
128
+ const declaration = `/// <reference types="vite/client" />
129
129
  declare module 'virtual:navilo-routes' {
130
130
  export const router;
131
131
  }
132
132
  `;
133
- if (fs.existsSync(viteEnvDtsPath)) {
134
- let content = fs.readFileSync(viteEnvDtsPath, 'utf-8');
135
- if (!content.includes('virtual:navilo-routes')) {
136
- content += '\n' + declaration;
137
- fs.writeFileSync(viteEnvDtsPath, content);
133
+ if (fs.existsSync(viteEnvDtsPath)) {
134
+ let content = fs.readFileSync(viteEnvDtsPath, 'utf-8');
135
+ if (!content.includes('virtual:navilo-routes')) {
136
+ content += '\n' + declaration;
137
+ fs.writeFileSync(viteEnvDtsPath, content);
138
+ }
139
+ } else {
140
+ fs.writeFileSync(viteEnvDtsPath, declaration);
138
141
  }
139
- } else {
140
- fs.writeFileSync(viteEnvDtsPath, declaration);
141
- }
142
- console.log('Updated/created vite-env.d.ts');
142
+ console.log('Updated/created vite-env.d.ts');
143
143
 
144
144
 
145
- const appFilePath = path.join(process.cwd(), 'src/App.tsx');
146
- if (fs.existsSync(appFilePath)) {
147
- let appFileContent = fs.readFileSync(appFilePath, 'utf-8');
148
- if (!appFileContent.includes('virtual:navilo-routes')) {
149
- appFileContent = `import { RouterProvider } from "react-router-dom";
145
+ const appFilePath = path.join(process.cwd(), 'src/App.tsx');
146
+ if (fs.existsSync(appFilePath)) {
147
+ let appFileContent = fs.readFileSync(appFilePath, 'utf-8');
148
+ if (!appFileContent.includes('virtual:navilo-routes')) {
149
+ appFileContent = `import { RouterProvider } from "react-router-dom";
150
150
  import { router } from 'virtual:navilo-routes';
151
151
 
152
152
  export function App() {
@@ -155,15 +155,15 @@ export function App() {
155
155
  );
156
156
  }
157
157
  `;
158
- fs.writeFileSync(appFilePath, appFileContent);
159
- console.log('Updated App.tsx');
158
+ fs.writeFileSync(appFilePath, appFileContent);
159
+ console.log('Updated App.tsx');
160
+ }
161
+ } else {
162
+ console.log('src/App.tsx not found. You will need to manually set up the router provider.');
160
163
  }
161
- } else {
162
- console.log('src/App.tsx not found. You will need to manually set up the router provider.');
163
- }
164
164
 
165
- console.log('Navilo initialization complete! 🎉');
166
- },
165
+ console.log('Navilo initialization complete! 🎉');
166
+ },
167
167
  };
168
168
 
169
169
  const command = process.argv[2];
@@ -175,5 +175,5 @@ if (commands[command]) {
175
175
  process.exit(1);
176
176
  });
177
177
  } else {
178
- console.log('Unknown command. Available commands: init');
178
+ console.log('Unknown command. Available commands: init');
179
179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "navilo",
3
- "version": "1.2.6",
3
+ "version": "1.2.9",
4
4
  "description": "File-based routing plugin for Vite + React applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",