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

@spruceid/mergemaid

Package Overview
Dependencies
Maintainers
8
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spruceid/mergemaid - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

sample/index-1.svg

1

lib/cli/help.js

@@ -11,2 +11,3 @@ const help = () => {

console.log('--prefix Adds a prefix to each output file, in case the output directory is the same as input.');
console.log('--post-process-all Runs post process on input and output files.');
console.log('--debug Noisy logging, including information about inputs and injectors.\n\n');

@@ -13,0 +14,0 @@

@@ -16,2 +16,3 @@ /**

let prefixIndex = undefined;
let postProcessAllIndex = undefined;
let outputDirectory = undefined;

@@ -63,2 +64,7 @@

if (arg === '--post-process-all') {
postProcessAllIndex = i;
mergemaidOptions.postProcessAll = true;
}
/**

@@ -68,3 +74,3 @@ * Include input paths as long as they occur before the -out, -svg, etc.

*/
if (!outIndex && !svgIndex && !debugIndex && !prefixIndex) {
if (!outIndex && !svgIndex && !debugIndex && !prefixIndex && !postProcessAllIndex) {
mergeList.push(arg);

@@ -71,0 +77,0 @@ }

41

lib/document-manager.js

@@ -110,9 +110,34 @@ const path = require('path');

getFiles(dirPath, arrayOfFiles, outputDirectory) {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
if (dirPath === outputDirectory) {
return arrayOfFiles;
}
files.forEach(file => {
const isDirectory = fs.statSync(dirPath + '/' + file).isDirectory();
if (isDirectory) {
arrayOfFiles = this.getFiles(dirPath + '/' + file, arrayOfFiles, outputDirectory);
} else {
const filePath = path.join(dirPath, '/', file);
arrayOfFiles.push(filePath);
}
})
return arrayOfFiles;
}
/**
* Returns an absolute path to input files for initial file aggregation.
* @param {string[] | string} filesOrDirectory Can be a single file or directory or a mix of files and directories.
* @param {string | undefined} outputDirectory
* @returns {string[]}
*/
getInputFiles(filesOrDirectory) {
const filesFound = [];
getInputFiles(filesOrDirectory, outputDirectory) {
let filesFound = [];

@@ -128,11 +153,7 @@ let filesOrDirectoryCollection = typeof filesOrDirectory === 'string' ?

if (isDirectory) {
const filePaths = fs.readdirSync(absolutePath);
for (const filePath of filePaths) {
const absoluteFilePath = path.join(absolutePath, filePath);
filesFound.push(absoluteFilePath);
filesFound = this.getFiles(absolutePath, filesFound, outputDirectory);
} else {
if (absolutePath !== outputDirectory) {
filesFound.push(absolutePath);
}
} else {
filesFound.push(absolutePath);
}

@@ -139,0 +160,0 @@ }

@@ -13,3 +13,7 @@ const DocumentManager = require('./document-manager');

this.messages = new Messages(options.debug);
this.postProcess = new PostProcess(options.root, options.prefix, options.debug);
this.postProcess = new PostProcess(
options.root,
options.prefix,
options.debug,
options.postProcessAll);

@@ -39,2 +43,3 @@ /**

/** @type {import('./types/segments').BlockDictionary | undefined} */
this.input = undefined;

@@ -216,8 +221,11 @@ this.master = [];

*/
this.inputFiles = this.documentManager.getInputFiles(fileOrDirectory);
this.outputDirectory = this.documentManager.getOutputDirectory(
fileOrDirectory,
outputDirectory
);
this.inputFiles = this.documentManager.getInputFiles(
fileOrDirectory,
this.outputDirectory
);
/**

@@ -229,3 +237,3 @@ * Process files.

this.messages.log(this.input);
if (this.input) {

@@ -241,3 +249,3 @@ this.output = this.injector.populateBlocks(this.master, this.input);

if (this.generateSGV) {
this.postProcess.generateSVG(this.output, this.outputDirectory);
this.postProcess.generateSVG(this.input, this.output, this.outputDirectory);
}

@@ -244,0 +252,0 @@ } else {

@@ -5,3 +5,3 @@ const mermaid = require("headless-mermaid");

class PostProcess {
constructor(root, prefix, debug) {
constructor(root, prefix, debug, postProcessAll) {
this.config = {

@@ -16,2 +16,8 @@ securityLevel: 'loose',

this.documentManager = new DocumentManager(root, prefix, debug);
/**
* Options with defaults.
*/
this.postProcessAll = typeof postProcessAll === 'boolean' ?
postProcessAll : false;
}

@@ -47,2 +53,55 @@

/**
* Generates SVGs from the input directory.
* @param {import('./types/segments').BlockDictionary | undefined} input
* @param {string} outputDirectory
*/
async operateOnInput(input, outputDirectory) {
if (!input) {
return;
}
const list = Object.values(input);
if (list?.length) {
for (const block of list) {
if (block.extension === '.md') {
const joined = block?.lines.join('\n');
const blocks = this.splitByMermaidBlocks(joined);
/**
* Handles Markdown files.
*/
for (const [i, diagram] of blocks.entries()) {
const svg = await this.makeSVGFromBlock(diagram);
if (svg) {
this.documentManager.write(
svg,
`${block.fileName}-${i + 1}.svg`,
outputDirectory
);
}
}
}
/**
* Handles Mermaid files.
*/
if (block.extension === '.mmd') {
const joined = block?.lines.join('\n');
const svg = await this.makeSVGFromBlock(joined);
if (svg) {
this.documentManager.write(
svg,
`${block.fileName}.svg`,
outputDirectory
);
}
}
}
}
}
/**
* Generates SVGs from the output.

@@ -52,3 +111,3 @@ * @param {import('./types/segments').Block[]} output

*/
async generateSVG(output, outputDirectory) {
async operateOnOutput(output, outputDirectory) {
if (output?.length) {

@@ -73,4 +132,18 @@ for (const block of output.values()) {

}
/**
* Generates SVGs from input/output.
* @param {import('./types/segments').BlockDictionary | undefined} input
* @param {import('./types/segments').Block[]} output
* @param {string} outputDirectory
*/
async generateSVG(input, output, outputDirectory) {
if (this.postProcessAll) {
await this.operateOnInput(input, outputDirectory);
}
await this.operateOnOutput(output, outputDirectory);
}
}
module.exports = PostProcess;
{
"name": "@spruceid/mergemaid",
"version": "0.0.3",
"version": "0.0.4",
"description": "Tool for merging mermaid sequence diagrams",

@@ -5,0 +5,0 @@ "contributors": [

@@ -8,10 +8,10 @@ const Mergemaid = require('../../lib/mergemaid');

generateSVG: true,
postProcessAll: false,
postProcessAll: true,
debug: false
});
mergemaid.merge('../manual/imports/index.md', '../manual/imports/dist');
// mergemaid.merge('../tests/imports', '../tests/imports/dist');
// mergemaid.merge('../tests/imports');
// mergemaid.merge('../tests/links', '../tests/links/dist');
// mergemaid.merge('../tests/functions', '../tests/functions/dist');
// mergemaid.merge('../manual/imports/index.md', '../manual/imports/dist');
mergemaid.merge('../manual/imports', '../manual/imports/dist');
// mergemaid.merge('../manual/imports');
// mergemaid.merge('../manual/links', '../manual/links/dist');
// mergemaid.merge('../manual/functions', '../manual/functions/dist');

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