dependency-docs-generator 1.0.1 → 1.0.2

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/index.js +19 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,25 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  const fs = require('fs');
3
3
  const axios = require('axios');
4
+ const path = require('path'); // Added for path handling
4
5
 
5
6
  async function generateDocs() {
6
7
  try {
7
- // 1. Read the local package.json
8
- const packageData = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
8
+ // 1. Get the path of the package.json in the user's current folder
9
+ const targetPath = path.join(process.cwd(), 'package.json');
10
+
11
+ // Check if the file actually exists before trying to read it
12
+ if (!fs.existsSync(targetPath)) {
13
+ console.error("❌ Error: No package.json found in this directory. Are you in the right folder?");
14
+ return;
15
+ }
16
+
17
+ const packageData = JSON.parse(fs.readFileSync(targetPath, 'utf8'));
9
18
  const dependencies = packageData.dependencies || {};
10
19
  const depNames = Object.keys(dependencies);
11
20
 
12
21
  if (depNames.length === 0) {
13
- console.log("No dependencies found!");
22
+ console.log("No dependencies found in package.json!");
14
23
  return;
15
24
  }
16
25
 
17
26
  let markdownContent = "# Project Dependency Guide\n\n";
18
27
  markdownContent += "| Package | Description | Version |\n| --- | --- | --- |\n";
19
28
 
20
- console.log(`Found ${depNames.length} packages. Fetching data...`);
29
+ console.log(`🔍 Found ${depNames.length} packages. Fetching data from npm...`);
21
30
 
22
- // 2. Fetch data for each package
23
31
  for (const name of depNames) {
24
32
  try {
25
33
  const response = await axios.get(`https://registry.npmjs.org/${name}`);
@@ -32,12 +40,14 @@ async function generateDocs() {
32
40
  }
33
41
  }
34
42
 
35
- // 3. Write to DEPENDENCIES.md
36
- fs.writeFileSync('DEPENDENCIES.md', markdownContent);
37
- console.log("✅ DEPENDENCIES.md has been generated!");
43
+ // 3. Write to DEPENDENCIES.md in the user's current folder
44
+ const outputPath = path.join(process.cwd(), 'DEPENDENCIES.md');
45
+ fs.writeFileSync(outputPath, markdownContent);
46
+
47
+ console.log("✅ DEPENDENCIES.md has been generated successfully!");
38
48
 
39
49
  } catch (err) {
40
- console.error("Error reading package.json:", err.message);
50
+ console.error("Error:", err.message);
41
51
  }
42
52
  }
43
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dependency-docs-generator",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Automatically generates a README guide for your project dependencies",
5
5
  "license": "ISC",
6
6
  "author": "purushothaman",