Comparing version 1.0.0 to 1.0.1
#!/usr/bin/env node | ||
import generatePDF from '../src/generatePDF.js' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import generate from '../src/generate.js' // Import the generate function | ||
// Définir le chemin du projet | ||
/** | ||
* The path to the current working directory, which is assumed to be the project root. | ||
* @type {string} | ||
*/ | ||
const projectPath = process.cwd() | ||
const outputPath = path.join(projectPath, 'dist/doc.pdf') | ||
// Assurez-vous que le répertoire de sortie existe | ||
if (!fs.existsSync(path.join(projectPath, 'dist'))) { | ||
fs.mkdirSync(path.join(projectPath, 'dist')) | ||
/** | ||
* Default output path where the generated PDF will be saved. | ||
* @type {string} | ||
*/ | ||
let outputPath = path.join(projectPath, 'docs/doc.pdf') | ||
/** | ||
* Default gitignore file name. | ||
* @type {string} | ||
*/ | ||
let gitignoreFileName = '.gitignore' | ||
/** | ||
* Path to the configuration file. | ||
* @type {string} | ||
*/ | ||
const configPath = path.join(projectPath, 'docpdf.config.js') | ||
/** | ||
* Check if docpdf.config.js exists and use its settings if available. | ||
*/ | ||
if (fs.existsSync(configPath)) { | ||
const config = require(configPath) | ||
if (config.outputPath) { | ||
outputPath = path.join(projectPath, config.outputPath) | ||
} | ||
if (config.gitignoreFileName) { | ||
gitignoreFileName = config.gitignoreFileName | ||
} | ||
} | ||
generatePDF(projectPath, outputPath) | ||
/** | ||
* Ensure the output directory exists. If it does not exist, create it. | ||
*/ | ||
const outputDir = path.dirname(outputPath) | ||
if (!fs.existsSync(outputDir)) { | ||
fs.mkdirSync(outputDir, { recursive: true }) | ||
} | ||
// Generate the PDF document using the project path, output path, and gitignore file name. | ||
generate(projectPath, outputPath, gitignoreFileName) |
{ | ||
"name": "docpdf", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A simple solution for generating PDF documentation for a given project.", | ||
@@ -8,4 +8,4 @@ "main": "src/index.js", | ||
"scripts": { | ||
"test": "mocha tests/**/*.test.js", | ||
"start": "node src/index.js" | ||
"start": "node src/index.js", | ||
"test": "jest" | ||
}, | ||
@@ -24,5 +24,8 @@ "repository": { | ||
"dependencies": { | ||
"ignore": "^5.3.1", | ||
"pdfkit": "^0.12.1" | ||
}, | ||
"devDependencies": { | ||
"esbuild-jest": "^0.5.0", | ||
"jest": "^29.7.0", | ||
"mocha": "^8.4.0" | ||
@@ -39,3 +42,11 @@ }, | ||
"test": "tests" | ||
}, | ||
"standard": { | ||
"globals": [ | ||
"jest", | ||
"describe", | ||
"it", | ||
"expect" | ||
] | ||
} | ||
} |
# docpdf | ||
A simple way of generate a PDF file about a repository | ||
docpdf is a Node.js module that generates PDF documentation from various sources. It is designed to be flexible and easy to use for developers who need to create documentation for their projects. | ||
## Features | ||
- Convert Markdown files to PDFs | ||
- Aggregate multiple documentation sources | ||
- Support for custom themes and styles | ||
## Installation | ||
1. Clone the repository: | ||
```sh | ||
git clone https://github.com/floor/docpdf.git | ||
``` | ||
2. Navigate to the project directory: | ||
```sh | ||
cd docpdf | ||
``` | ||
3. Install dependencies: | ||
```sh | ||
npm install | ||
``` | ||
## Usage | ||
To generate a PDF, run: | ||
```sh | ||
npm run docpdf |
@@ -1,8 +0,26 @@ | ||
import generatePDF from './generatePDF.js' | ||
import generate from './generate.js' | ||
import fs from 'fs' | ||
import path from 'path' | ||
/** | ||
* Main function to generate a PDF document for a project. | ||
*/ | ||
const main = () => { | ||
const projectPath = '../../../../' // Path to the project | ||
generatePDF(projectPath) | ||
// Default configuration values | ||
let gitignoreFileName = '.gitignore' | ||
let outputPath = 'dist/doc.pdf' | ||
// Check if docpdf.config.js exists | ||
const configPath = path.join(projectPath, 'docpdf.config.js') | ||
if (fs.existsSync(configPath)) { | ||
const config = require(configPath) | ||
gitignoreFileName = config.gitignoreFileName || gitignoreFileName | ||
outputPath = config.outputPath || outputPath | ||
} | ||
generate(projectPath, outputPath, gitignoreFileName) | ||
} | ||
main() |
@@ -1,24 +0,51 @@ | ||
let lastText = '' | ||
import output from './output.js' | ||
const output = (text) => { | ||
process.stdout.clearLine() | ||
process.stdout.cursorTo(0) | ||
process.stdout.write(text) | ||
lastText = text | ||
} | ||
// Hide and show terminal cursor using ANSI escape codes | ||
const hideCursor = () => process.stdout.write('\x1B[?25l') | ||
const showCursor = () => process.stdout.write('\x1B[?25h') | ||
process.stdout.on('resize', () => { | ||
output(lastText) | ||
}) | ||
let init = false | ||
const progress = (current, total) => { | ||
if (current === null) { | ||
process.stdout.write('\n') | ||
/** | ||
* Updates and displays a progress bar in the terminal, estimating remaining time. | ||
* | ||
* @param {number|null} count - The current count of processed items, or null to reset. | ||
* @param {number} total - The total number of items to be processed. | ||
* @param {number} startTime - The timestamp when the processing started. | ||
* @param {string} item - A description of the current item being processed. | ||
*/ | ||
const progress = (count, total, startTime, item) => { | ||
if (count === null) { | ||
// Clear the line and reset cursor visibility and initialization flag | ||
output('\r' + ' '.repeat(100)) // Clear the line | ||
console.log('') // Move to a new line | ||
showCursor() | ||
init = false // Reset init flag | ||
return | ||
} | ||
const percent = ((current / total) * 100).toFixed(2) | ||
output(`Progress: ${current}/${total} (${percent}%)`) | ||
if (!init) { | ||
hideCursor() // Hide cursor when initializing | ||
init = true | ||
} | ||
const currentTime = Date.now() | ||
const elapsedTime = (currentTime - startTime) / 1000 // Elapsed time in seconds | ||
const estimatedTime = (total / count) * elapsedTime - elapsedTime // Estimate remaining time in seconds | ||
const estimatedMinutes = Math.floor(estimatedTime / 60) // Convert remaining time to minutes | ||
const estimatedSeconds = Math.floor(estimatedTime % 60).toString().padStart(2, '0') // Convert remaining seconds and pad with leading zero | ||
const progressBarLength = 30 | ||
const progress = Math.floor((count / total) * progressBarLength) // Calculate progress bar length | ||
const progressBar = '[' + '\x1b[92m' + '▮'.repeat(progress) + '\x1b[0m' + ' '.repeat(progressBarLength - progress) + ']' // Create progress bar | ||
const percent = (count / total * 100).toFixed(2) // Calculate percentage completed | ||
const pad = (num) => num.toLocaleString('en-US').padStart(10, ' ') // Function to pad numbers for alignment | ||
const text = `${pad(count.toLocaleString('en-US'))} / ${total.toLocaleString('en-US')} | ETA: ${estimatedMinutes}m${estimatedSeconds}s | ${percent}% ${progressBar} < ${item}` | ||
output(text) // Use the output module to update the line with progress information | ||
} | ||
export default progress |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
814392
16
510
32
2
3
9
1
+ Addedignore@^5.3.1
+ Addedignore@5.3.2(transitive)