New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ryan-henness-trimble/mini-docs

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ryan-henness-trimble/mini-docs - npm Package Compare versions

Comparing version 0.0.0-beta.7 to 0.0.0-beta.8

dist/models.js

4

dist/bin/mini-docs-cli.js

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

.requiredOption('-o, --output <output>', 'Output directory')
.option('-b, --base-url-path <baseUrlPath>', 'base URL path for generated documentation', '/')
.option('-b, --base-url-path <basePath>', 'base URL path for generated documentation', '/')
.parse(process.argv);

@@ -17,3 +17,3 @@

setupRenderers(options.baseUrlPath, console.log);
const fileSystemStructure = generateFileSystemStructure(options.input, options.input, options.baseUrlPath);
const fileSystemStructure = generateFileSystemStructure(options.input, options.input, options.basePath);
generateIndexPage(fileSystemStructure, options.output, options.baseUrlPath).then(() => {

@@ -20,0 +20,0 @@ console.log(JSON.stringify(fileSystemStructure, null, 4));

@@ -22,2 +22,3 @@ "use strict";

const ejs_1 = __importDefault(require("ejs"));
const PathHelpers_1 = __importDefault(require("./PathHelpers"));
// Load necessary Prism languages

@@ -36,41 +37,11 @@ require('prismjs/components/prism-css');

const INDEX_TEMPLATE_PATH = path_1.default.resolve(__dirname, 'templates/index.ejs');
const generateFileSystemStructure = (rootPath, inputPath) => {
const stats = fs.statSync(inputPath);
const fileName = path_1.default.basename(inputPath);
const generateFileSystemStructure = (inputDirPath, itemRelativePath) => {
const stats = fs.statSync(itemRelativePath);
const fileName = path_1.default.basename(itemRelativePath);
const name = convertKebabToWords(fileName).replace(MD_EXTENSION, '');
// Normalize paths to use forward slashes
const normalizedRootPath = rootPath.replace(/\\/g, '/');
const normalizedInputPath = inputPath.replace(/\\/g, '/');
// Subtract the rootPath from the inputPath
let relativePath = normalizedInputPath;
if (relativePath.startsWith(normalizedRootPath)) {
relativePath = relativePath.slice(normalizedRootPath.length);
// Remove leading slash if present
if (relativePath.startsWith('/')) {
relativePath = relativePath.slice(1);
}
}
const inputDirItemRelativePath = PathHelpers_1.default.resolveInputDirRelativePath(inputDirPath, itemRelativePath);
if (stats.isFile()) {
return {
type: 'file',
name: name,
fileName: fileName,
relativePath: relativePath,
fullPath: inputPath
};
return buildMdFile(name, inputDirPath, inputDirItemRelativePath);
}
const directory = {
type: 'directory',
name: name,
fileName: fileName,
relativePath: relativePath,
fullPath: inputPath,
contents: []
};
const items = fs.readdirSync(inputPath);
for (const item of items) {
const itemPath = path_1.default.join(inputPath, item);
directory.contents.push(generateFileSystemStructure(rootPath, itemPath));
}
return directory;
return buildMdDirectory(name, inputDirPath, inputDirItemRelativePath, itemRelativePath);
};

@@ -101,4 +72,4 @@ exports.generateFileSystemStructure = generateFileSystemStructure;

if (item.type === 'file') {
if (item.relativePath.endsWith(MD_EXTENSION)) {
const fileContent = yield fs.readFile(item.fullPath, UTF_8);
if (item.absolutePath.endsWith(MD_EXTENSION)) {
const fileContent = yield fs.readFile(item.absolutePath, UTF_8);
const htmlContent = marked.parse(fileContent, { renderer: customRenderer });

@@ -109,5 +80,6 @@ const renderedHtml = yield ejs_1.default.renderFile(DOCUMENT_TEMPLATE_PATH, {

sidenavContents: sidenavContents.contents,
basePath: basePath
basePath: basePath,
PathHelpers: PathHelpers_1.default
});
const outputFilePath = path_1.default.join(outputPath, item.relativePath.replace(MD_EXTENSION, HTML_EXTENSION));
const outputFilePath = path_1.default.join(outputPath, PathHelpers_1.default.getItemRelativePath(item).replace(MD_EXTENSION, HTML_EXTENSION));
yield fs.outputFile(outputFilePath, renderedHtml);

@@ -123,3 +95,3 @@ }

exports.generatePages = generatePages;
// TODO - Create a better index page. This is just a placeholder.
// TODO - Create a better index page pattern. This is just a placeholder.
const generateIndexPage = (sidenavContents, outputPath, basePath) => __awaiter(void 0, void 0, void 0, function* () {

@@ -132,3 +104,4 @@ if (sidenavContents.type === 'file') {

sidenavContents: sidenavContents.contents,
basePath: basePath
basePath: basePath,
PathHelpers: PathHelpers_1.default
});

@@ -142,1 +115,24 @@ const outputFilePath = path_1.default.join(outputPath, 'index.html');

};
const buildMdFile = (name, inputDirPath, inputDirItemRelativePath) => {
return {
type: 'file',
name: name,
inputDir: PathHelpers_1.default.resolveAbsolutePath(inputDirPath),
absolutePath: PathHelpers_1.default.resolveAbsolutePath(inputDirPath, inputDirItemRelativePath)
};
};
const buildMdDirectory = (name, inputDirPath, inputDirItemRelativePath, itemRelativePath) => {
const directory = {
type: 'directory',
name: name,
inputDir: PathHelpers_1.default.resolveAbsolutePath(inputDirPath),
absolutePath: PathHelpers_1.default.resolveAbsolutePath(inputDirPath, inputDirItemRelativePath),
contents: []
};
const items = fs.readdirSync(itemRelativePath);
for (const item of items) {
const itemPath = path_1.default.join(itemRelativePath, item);
directory.contents.push(generateFileSystemStructure(inputDirPath, itemPath));
}
return directory;
};
{
"name": "@ryan-henness-trimble/mini-docs",
"version": "0.0.0-beta.7",
"version": "0.0.0-beta.8",
"description": "",

@@ -33,3 +33,3 @@ "main": "index.js",

"devDependencies": {
"@ryan-henness-trimble/mini-docs": "^0.0.0-beta.6",
"@ryan-henness-trimble/mini-docs": "^0.0.0-beta.7",
"@types/ejs": "^3.1.5",

@@ -36,0 +36,0 @@ "@types/fs-extra": "^11.0.4",

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

.requiredOption('-o, --output <output>', 'Output directory')
.option('-b, --base-url-path <baseUrlPath>', 'base URL path for generated documentation', '/')
.option('-b, --base-url-path <basePath>', 'base URL path for generated documentation', '/')
.parse(process.argv);

@@ -17,3 +17,3 @@

setupRenderers(options.baseUrlPath, console.log);
const fileSystemStructure = generateFileSystemStructure(options.input, options.input, options.baseUrlPath);
const fileSystemStructure = generateFileSystemStructure(options.input, options.input, options.basePath);
generateIndexPage(fileSystemStructure, options.output, options.baseUrlPath).then(() => {

@@ -20,0 +20,0 @@ console.log(JSON.stringify(fileSystemStructure, null, 4));

@@ -7,2 +7,4 @@ const fs = require('fs-extra');

import ejs from 'ejs';
import PathHelpers from './PathHelpers';
import { MdDirectory, MdFile } from './models';

@@ -18,20 +20,2 @@ // Load necessary Prism languages

// Figure out which paths we need here... There is a third that represents the deployedPath (basePath + relativePath?). Does that even belong here? Or should it go somewhere else?
interface File {
type: 'file';
name: string;
fileName: string;
relativePath: string;
fullPath: string;
}
interface Directory {
type: 'directory';
name: string;
fileName: string;
relativePath: string;
fullPath: string;
contents: Array<Directory | File>;
}
const MD_EXTENSION = '.md';

@@ -43,47 +27,14 @@ const HTML_EXTENSION = '.html';

const generateFileSystemStructure = (rootPath: string, inputPath: string): Directory | File => {
const stats = fs.statSync(inputPath);
const fileName = path.basename(inputPath);
const generateFileSystemStructure = (inputDirPath: string, itemRelativePath: string): MdDirectory | MdFile => {
const stats = fs.statSync(itemRelativePath);
const fileName = path.basename(itemRelativePath);
const name = convertKebabToWords(fileName).replace(MD_EXTENSION, '');
// Normalize paths to use forward slashes
const normalizedRootPath = rootPath.replace(/\\/g, '/');
const normalizedInputPath = inputPath.replace(/\\/g, '/');
const inputDirItemRelativePath = PathHelpers.resolveInputDirRelativePath(inputDirPath, itemRelativePath);
// Subtract the rootPath from the inputPath
let relativePath = normalizedInputPath;
if (relativePath.startsWith(normalizedRootPath)) {
relativePath = relativePath.slice(normalizedRootPath.length);
// Remove leading slash if present
if (relativePath.startsWith('/')) {
relativePath = relativePath.slice(1);
}
}
if (stats.isFile()) {
return {
type: 'file',
name: name,
fileName: fileName,
relativePath: relativePath,
fullPath: inputPath
};
return buildMdFile(name, inputDirPath, inputDirItemRelativePath)
}
const directory: Directory = {
type: 'directory',
name: name,
fileName: fileName,
relativePath: relativePath,
fullPath: inputPath,
contents: []
};
const items = fs.readdirSync(inputPath);
for (const item of items) {
const itemPath = path.join(inputPath, item);
directory.contents.push(generateFileSystemStructure(rootPath, itemPath));
}
return directory;
return buildMdDirectory(name, inputDirPath, inputDirItemRelativePath, itemRelativePath);
}

@@ -118,6 +69,6 @@

const generatePages = async (item: Directory | File, outputPath: string, sidenavContents: Directory, basePath: string): Promise<void> => {
const generatePages = async (item: MdDirectory | MdFile, outputPath: string, sidenavContents: MdDirectory, basePath: string): Promise<void> => {
if (item.type === 'file') {
if (item.relativePath.endsWith(MD_EXTENSION)) {
const fileContent = await fs.readFile(item.fullPath, UTF_8);
if (item.absolutePath.endsWith(MD_EXTENSION)) {
const fileContent = await fs.readFile(item.absolutePath, UTF_8);
const htmlContent = marked.parse(fileContent, { renderer: customRenderer });

@@ -128,6 +79,7 @@ const renderedHtml = await ejs.renderFile(DOCUMENT_TEMPLATE_PATH, {

sidenavContents: sidenavContents.contents,
basePath: basePath
basePath: basePath,
PathHelpers: PathHelpers
});
const outputFilePath = path.join(outputPath, item.relativePath.replace(MD_EXTENSION, HTML_EXTENSION));
const outputFilePath = path.join(outputPath, PathHelpers.getItemRelativePath(item).replace(MD_EXTENSION, HTML_EXTENSION));
await fs.outputFile(outputFilePath, renderedHtml);

@@ -142,4 +94,4 @@ }

// TODO - Create a better index page. This is just a placeholder.
const generateIndexPage = async (sidenavContents: Directory | File, outputPath: string, basePath: string): Promise<void> => {
// TODO - Create a better index page pattern. This is just a placeholder.
const generateIndexPage = async (sidenavContents: MdDirectory | MdFile, outputPath: string, basePath: string): Promise<void> => {
if (sidenavContents.type === 'file') {

@@ -152,3 +104,4 @@ return;

sidenavContents: sidenavContents.contents,
basePath: basePath
basePath: basePath,
PathHelpers: PathHelpers
});

@@ -164,1 +117,28 @@ const outputFilePath = path.join(outputPath, 'index.html');

}
const buildMdFile = (name: string, inputDirPath: string, inputDirItemRelativePath: string): MdFile => {
return {
type: 'file',
name: name,
inputDir: PathHelpers.resolveAbsolutePath(inputDirPath),
absolutePath: PathHelpers.resolveAbsolutePath(inputDirPath, inputDirItemRelativePath)
};
}
const buildMdDirectory = (name: string, inputDirPath: string, inputDirItemRelativePath: string, itemRelativePath: string): MdDirectory => {
const directory: MdDirectory = {
type: 'directory',
name: name,
inputDir: PathHelpers.resolveAbsolutePath(inputDirPath),
absolutePath: PathHelpers.resolveAbsolutePath(inputDirPath, inputDirItemRelativePath),
contents: []
};
const items = fs.readdirSync(itemRelativePath);
for (const item of items) {
const itemPath = path.join(itemRelativePath, item);
directory.contents.push(generateFileSystemStructure(inputDirPath, itemPath));
}
return directory;
}

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

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

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