Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

repo2pdf

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

repo2pdf - npm Package Compare versions

Comparing version 2.0.4 to 2.1.0

111

dist/clone.js

@@ -43,3 +43,3 @@ #!/usr/bin/env node

spinner.succeed("Setup complete");
askForRepoUrl();
configQuestions();
})

@@ -52,8 +52,35 @@ .catch((err) => {

});
function askForRepoUrl() {
function configQuestions() {
return __awaiter(this, void 0, void 0, function* () {
const questions = [
{
type: "list",
name: "localRepo",
message: "Do you want to use a local repository?",
choices: ["Yes", "No"],
filter: function (val) {
return val.toLowerCase() === "yes";
},
},
{
name: "localRepoPath",
message: "Please provide the full path to the local repository:",
when(answers) {
return answers.localRepo;
},
validate: function (value) {
if (fs_1.default.existsSync(value)) {
return true;
}
else {
return "Please enter a valid directory path.";
}
},
},
{
name: "repoUrl",
message: "Please provide a GitHub repository URL:",
when(answers) {
return !answers.localRepo;
},
validate: function (value) {

@@ -145,2 +172,5 @@ var pass = value.match(/^https:\/\/github.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/);

choices: ["No", "Yes"],
when(answers) {
return !answers.localRepo;
},
filter: function (val) {

@@ -164,9 +194,9 @@ return val.toLowerCase() === "yes";

console.log(chalk.cyanBright("\nProcessing your request...\n"));
main(answers.repoUrl, answers.addLineNumbers, answers.addHighlighting, answers.addPageNumbers, answers.removeComments, answers.removeEmptyLines, answers.onePdfPerFile, answers.outputFileName, answers.outputFolderName, answers.keepRepo);
main(answers.localRepo ? answers.localRepoPath : answers.repoUrl, answers.localRepo, answers.addLineNumbers, answers.addHighlighting, answers.addPageNumbers, answers.removeComments, answers.removeEmptyLines, answers.onePdfPerFile, answers.outputFileName, answers.outputFolderName, answers.keepRepo);
});
}
function main(repoUrl, addLineNumbers, addHighlighting, addPageNumbers, removeComments, removeEmptyLines, onePdfPerFile, outputFileName, outputFolderName, keepRepo) {
function main(repoPath, useLocalRepo, addLineNumbers, addHighlighting, addPageNumbers, removeComments, removeEmptyLines, onePdfPerFile, outputFileName, outputFolderName, keepRepo) {
return __awaiter(this, void 0, void 0, function* () {
const gitP = (0, simple_git_1.default)();
const tempDir = "./tempRepo";
let tempDir = "./tempRepo";
let doc = null;

@@ -181,38 +211,41 @@ if (!onePdfPerFile) {

let fileCount = 0;
const spinner = ora(chalk.blueBright("Cloning repository...")).start();
let ignoreConfig = null;
gitP
.clone(repoUrl, tempDir)
.then(() => __awaiter(this, void 0, void 0, function* () {
spinner.succeed(chalk.greenBright("Repository cloned successfully"));
const spinner = ora(chalk.blueBright("Setting everything up...")).start();
try {
if (useLocalRepo) {
tempDir = repoPath;
}
else {
spinner.start(chalk.blueBright("Cloning repository..."));
yield gitP.clone(repoPath, tempDir);
spinner.succeed(chalk.greenBright("Repository cloned successfully"));
}
spinner.start(chalk.blueBright("Processing files..."));
ignoreConfig = yield (0, loadIgnoreConfig_1.default)(tempDir);
appendFilesToPdf(tempDir, removeComments).then(() => {
if (!onePdfPerFile) {
if (doc) {
//Global Edits to All Pages (Header/Footer, etc)
let pages = doc.bufferedPageRange();
for (let i = 0; i < pages.count; i++) {
doc.switchToPage(i);
if (addPageNumbers) {
let oldBottomMargin = doc.page.margins.bottom;
doc.page.margins.bottom = 0;
doc.text(`Page: ${i + 1} of ${pages.count}`, 0, doc.page.height - oldBottomMargin / 2, { align: "center" });
doc.page.margins.bottom = oldBottomMargin;
}
yield appendFilesToPdf(tempDir, removeComments);
if (!onePdfPerFile) {
if (doc) {
let pages = doc.bufferedPageRange();
for (let i = 0; i < pages.count; i++) {
doc.switchToPage(i);
if (addPageNumbers) {
let oldBottomMargin = doc.page.margins.bottom;
doc.page.margins.bottom = 0;
doc.text(`Page: ${i + 1} of ${pages.count}`, 0, doc.page.height - oldBottomMargin / 2, { align: "center" });
doc.page.margins.bottom = oldBottomMargin;
}
doc === null || doc === void 0 ? void 0 : doc.end();
}
doc === null || doc === void 0 ? void 0 : doc.end();
}
spinner.succeed(chalk.greenBright(`${onePdfPerFile ? "PDFs" : "PDF"} created with ${fileCount} files processed.`));
if (!keepRepo) {
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
spinner.succeed(chalk.greenBright("Temporary repository has been deleted."));
}
});
}))
.catch((err) => {
}
spinner.succeed(chalk.greenBright(`${onePdfPerFile ? "PDFs" : "PDF"} created with ${fileCount} files processed.`));
if (!keepRepo && !useLocalRepo) {
fs_1.default.rmSync(tempDir, { recursive: true, force: true });
spinner.succeed(chalk.greenBright("Temporary repository has been deleted."));
}
}
catch (err) {
spinner.fail(chalk.redBright("An error occurred"));
console.error(err);
});
}
function appendFilesToPdf(directory, removeComments = false) {

@@ -284,7 +317,11 @@ var _a;

if (addHighlighting && highlight_js_1.default.getLanguage(extension)) {
highlightedCode = highlight_js_1.default.highlight(data, { language: extension }).value;
highlightedCode = highlight_js_1.default.highlight(data, {
language: extension,
}).value;
}
else {
// Use plaintext highlighting if language is not supported
highlightedCode = highlight_js_1.default.highlight(data, { language: "plaintext" }).value;
highlightedCode = highlight_js_1.default.highlight(data, {
language: "plaintext",
}).value;
}

@@ -294,3 +331,5 @@ }

// Use plaintext highlighting if an error occurs
highlightedCode = highlight_js_1.default.highlight(data, { language: "plaintext" }).value;
highlightedCode = highlight_js_1.default.highlight(data, {
language: "plaintext",
}).value;
}

@@ -297,0 +336,0 @@ const hlData = (0, syntax_1.htmlToJson)(highlightedCode);

@@ -11,2 +11,6 @@ "use strict";

"repo2pdf.ignore",
".vscode",
".idea",
".vs",
"node_modules",
];

@@ -13,0 +17,0 @@ exports.universalExcludedNames = universalExcludedNames;

{
"name": "repo2pdf",
"version": "2.0.4",
"version": "2.1.0",
"description": "A Node.js utility for generating a PDF document from a GitHub repository",

@@ -5,0 +5,0 @@ "main": "dist/clone.js",

@@ -61,4 +61,6 @@ # Repo-to-PDF

You will be prompted to provide the following information:
- The URL of the GitHub repository
You will be prompted to provide the following information:'
- Whether or not you want to clone a repository or use a local repository
- The path to the local repository (if you chose to use a local repository)
- The URL of the repository you want to clone (if you chose to clone a repository)
- Whether or not you want line numbers in the pdf

@@ -86,2 +88,4 @@ - Whether or not you want highlighting in the pdf

Please note that if you use a local repository, the `repo2pdf.ignore` file must be in the root of the repository directory. And you might need to add more directories to the ignore list, as the script not automatically ignores different build files and directories.
### Example of file structure

@@ -88,0 +92,0 @@

@@ -44,3 +44,3 @@ #!/usr/bin/env node

spinner.succeed("Setup complete")
askForRepoUrl()
configQuestions()
})

@@ -54,6 +54,8 @@ .catch((err) => {

async function askForRepoUrl() {
async function configQuestions() {
const questions: {
type?: string
name: [
"localRepo",
"localRepoPath",
"repoUrl",

@@ -78,4 +80,30 @@ "addLineNumbers",

{
type: "list",
name: "localRepo",
message: "Do you want to use a local repository?",
choices: ["Yes", "No"],
filter: function (val: string) {
return val.toLowerCase() === "yes"
},
},
{
name: "localRepoPath",
message: "Please provide the full path to the local repository:",
when(answers: { localRepo: any }) {
return answers.localRepo
},
validate: function (value: string) {
if (fs.existsSync(value)) {
return true
} else {
return "Please enter a valid directory path."
}
},
},
{
name: "repoUrl",
message: "Please provide a GitHub repository URL:",
when(answers: { localRepo: any }) {
return !answers.localRepo
},
validate: function (value: string) {

@@ -170,2 +198,5 @@ var pass = value.match(

choices: ["No", "Yes"],
when(answers: { localRepo: any }) {
return !answers.localRepo
},
filter: function (val: string) {

@@ -194,3 +225,4 @@ return val.toLowerCase() === "yes"

main(
answers.repoUrl,
answers.localRepo ? answers.localRepoPath : answers.repoUrl,
answers.localRepo,
answers.addLineNumbers,

@@ -209,3 +241,4 @@ answers.addHighlighting,

async function main(
repoUrl: string,
repoPath: string,
useLocalRepo: boolean,
addLineNumbers: any,

@@ -222,3 +255,3 @@ addHighlighting: any,

const gitP = git()
const tempDir = "./tempRepo"
let tempDir = "./tempRepo"

@@ -235,58 +268,64 @@ let doc: typeof PDFDocument | null = null

let fileCount = 0
const spinner = ora(chalk.blueBright("Cloning repository...")).start()
let ignoreConfig: IgnoreConfig | null = null
gitP
.clone(repoUrl, tempDir)
.then(async () => {
const spinner = ora(chalk.blueBright("Setting everything up...")).start()
try {
if (useLocalRepo) {
tempDir = repoPath
} else {
spinner.start(chalk.blueBright("Cloning repository..."))
await gitP.clone(repoPath, tempDir)
spinner.succeed(chalk.greenBright("Repository cloned successfully"))
spinner.start(chalk.blueBright("Processing files..."))
}
ignoreConfig = await loadIgnoreConfig(tempDir)
spinner.start(chalk.blueBright("Processing files..."))
appendFilesToPdf(tempDir, removeComments).then(() => {
if (!onePdfPerFile) {
if (doc) {
//Global Edits to All Pages (Header/Footer, etc)
let pages = doc.bufferedPageRange()
for (let i = 0; i < pages.count; i++) {
doc.switchToPage(i)
ignoreConfig = await loadIgnoreConfig(tempDir)
if (addPageNumbers) {
let oldBottomMargin = doc.page.margins.bottom
doc.page.margins.bottom = 0
doc.text(
`Page: ${i + 1} of ${pages.count}`,
0,
doc.page.height - oldBottomMargin / 2,
{ align: "center" }
)
doc.page.margins.bottom = oldBottomMargin
}
}
doc?.end()
await appendFilesToPdf(tempDir, removeComments)
if (!onePdfPerFile) {
if (doc) {
let pages = doc.bufferedPageRange()
for (let i = 0; i < pages.count; i++) {
doc.switchToPage(i)
if (addPageNumbers) {
let oldBottomMargin = doc.page.margins.bottom
doc.page.margins.bottom = 0
doc.text(
`Page: ${i + 1} of ${pages.count}`,
0,
doc.page.height - oldBottomMargin / 2,
{ align: "center" }
)
doc.page.margins.bottom = oldBottomMargin
}
}
doc?.end()
}
}
spinner.succeed(
chalk.greenBright(
`${
onePdfPerFile ? "PDFs" : "PDF"
} created with ${fileCount} files processed.`
)
)
if (!keepRepo) {
fs.rmSync(tempDir, { recursive: true, force: true })
spinner.succeed(
chalk.greenBright("Temporary repository has been deleted.")
)
}
})
})
.catch((err) => {
spinner.fail(chalk.redBright("An error occurred"))
console.error(err)
})
spinner.succeed(
chalk.greenBright(
`${
onePdfPerFile ? "PDFs" : "PDF"
} created with ${fileCount} files processed.`
)
)
if (!keepRepo && !useLocalRepo) {
fs.rmSync(tempDir, { recursive: true, force: true })
spinner.succeed(
chalk.greenBright("Temporary repository has been deleted.")
)
}
} catch (err) {
spinner.fail(chalk.redBright("An error occurred"))
console.error(err)
}
async function appendFilesToPdf(directory: string, removeComments = false) {

@@ -371,10 +410,16 @@ const files = await fsPromises.readdir(directory)

if (addHighlighting && hljs.getLanguage(extension)) {
highlightedCode = hljs.highlight(data, { language: extension }).value
highlightedCode = hljs.highlight(data, {
language: extension,
}).value
} else {
// Use plaintext highlighting if language is not supported
highlightedCode = hljs.highlight(data, { language: "plaintext" }).value
highlightedCode = hljs.highlight(data, {
language: "plaintext",
}).value
}
} catch (error) {
// Use plaintext highlighting if an error occurs
highlightedCode = hljs.highlight(data, { language: "plaintext" }).value
highlightedCode = hljs.highlight(data, {
language: "plaintext",
}).value
}

@@ -381,0 +426,0 @@ const hlData = htmlToJson(highlightedCode)

@@ -8,2 +8,6 @@ const universalExcludedNames = [

"repo2pdf.ignore",
".vscode",
".idea",
".vs",
"node_modules",
]

@@ -10,0 +14,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc