navilo 1.2.5 → 1.2.6

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
@@ -36,6 +36,14 @@ You can use the CLI to setup your project automatically.
36
36
  npx navilo init
37
37
  ```
38
38
 
39
+ You can also pass your package manager directly:
40
+
41
+ ```bash
42
+ npx navilo init --pm pnpm
43
+ ```
44
+
45
+ Supported values: `pnpm`, `yarn`, `npm`, `bun`.
46
+
39
47
  Or you can do the following steps manually:
40
48
 
41
49
  ### Vite Config
package/bin/navilo.js CHANGED
@@ -3,18 +3,106 @@
3
3
  const { execSync } = require('child_process');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
+ const readline = require('readline');
7
+
8
+ const SUPPORTED_PACKAGE_MANAGERS = ['pnpm', 'yarn', 'npm', 'bun'];
9
+
10
+ function parsePackageManagerArg(argv) {
11
+ const pmEqArg = argv.find((arg) => arg.startsWith('--pm='));
12
+ if (pmEqArg) return pmEqArg.split('=')[1]?.trim();
13
+
14
+ const packageManagerEqArg = argv.find((arg) => arg.startsWith('--package-manager='));
15
+ if (packageManagerEqArg) return packageManagerEqArg.split('=')[1]?.trim();
16
+
17
+ const pmIndex = argv.findIndex((arg) => arg === '--pm');
18
+ if (pmIndex !== -1) return argv[pmIndex + 1]?.trim();
19
+
20
+ const packageManagerIndex = argv.findIndex((arg) => arg === '--package-manager');
21
+ if (packageManagerIndex !== -1) return argv[packageManagerIndex + 1]?.trim();
22
+
23
+ return null;
24
+ }
25
+
26
+ function detectPackageManagerFromLockFiles(cwd) {
27
+ if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
28
+ if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn';
29
+ if (fs.existsSync(path.join(cwd, 'bun.lockb')) || fs.existsSync(path.join(cwd, 'bun.lock'))) return 'bun';
30
+ if (fs.existsSync(path.join(cwd, 'package-lock.json'))) return 'npm';
31
+ return 'npm';
32
+ }
33
+
34
+ function askQuestion(query) {
35
+ const rl = readline.createInterface({
36
+ input: process.stdin,
37
+ output: process.stdout,
38
+ });
39
+
40
+ return new Promise((resolve) => {
41
+ rl.question(query, (answer) => {
42
+ rl.close();
43
+ resolve(answer.trim());
44
+ });
45
+ });
46
+ }
47
+
48
+ async function resolvePackageManager() {
49
+ const pmFromArgs = parsePackageManagerArg(process.argv.slice(3));
50
+
51
+ if (pmFromArgs) {
52
+ if (!SUPPORTED_PACKAGE_MANAGERS.includes(pmFromArgs)) {
53
+ throw new Error(
54
+ `Invalid package manager "${pmFromArgs}". Use one of: ${SUPPORTED_PACKAGE_MANAGERS.join(', ')}`
55
+ );
56
+ }
57
+ return pmFromArgs;
58
+ }
59
+
60
+ const detected = detectPackageManagerFromLockFiles(process.cwd());
61
+ const answer = await askQuestion(
62
+ `Choose package manager [pnpm/yarn/npm/bun] (default: ${detected}): `
63
+ );
64
+
65
+ if (!answer) return detected;
66
+
67
+ if (!SUPPORTED_PACKAGE_MANAGERS.includes(answer)) {
68
+ console.log(`Invalid selection "${answer}". Falling back to ${detected}.`);
69
+ return detected;
70
+ }
71
+
72
+ return answer;
73
+ }
74
+
75
+ function installDependency(packageManager, pkg) {
76
+ const installCommands = {
77
+ npm: `npm install ${pkg}`,
78
+ pnpm: `pnpm add ${pkg}`,
79
+ yarn: `yarn add ${pkg}`,
80
+ bun: `bun add ${pkg}`,
81
+ };
82
+
83
+ execSync(installCommands[packageManager], { stdio: 'inherit' });
84
+ }
6
85
 
7
86
  const commands = {
8
- init: () => {
87
+ init: async () => {
9
88
  console.log('Initializing Navilo...');
10
89
 
90
+ const packageManager = await resolvePackageManager();
91
+ console.log(`Using package manager: ${packageManager}`);
92
+
11
93
  const packageJsonPath = path.join(process.cwd(), 'package.json');
12
94
  if (fs.existsSync(packageJsonPath)) {
13
95
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
14
96
  const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
97
+
98
+ if (!dependencies['navilo']) {
99
+ console.log('Installing navilo...');
100
+ installDependency(packageManager, 'navilo');
101
+ }
102
+
15
103
  if (!dependencies['react-router-dom'] || dependencies['react-router-dom'] !== '^6.16.0') {
16
104
  console.log('Installing react-router-dom@^6.16.0...');
17
- execSync('npm install react-router-dom@^6.16.0', { stdio: 'inherit' });
105
+ installDependency(packageManager, 'react-router-dom@^6.16.0');
18
106
  }
19
107
  } else {
20
108
  console.log('package.json not found. Please run in a valid project directory.');
@@ -81,7 +169,11 @@ export function App() {
81
169
  const command = process.argv[2];
82
170
 
83
171
  if (commands[command]) {
84
- commands[command]();
172
+ Promise.resolve(commands[command]())
173
+ .catch((error) => {
174
+ console.error(error.message);
175
+ process.exit(1);
176
+ });
85
177
  } else {
86
178
  console.log('Unknown command. Available commands: init');
87
179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "navilo",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "File-based routing plugin for Vite + React applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",