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

doc-snippets

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doc-snippets - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

build/lib/defaults/defaultIgnorePaths.d.ts

11

build/cli.js

@@ -46,6 +46,4 @@ "use strict";

case 0:
commander_1.program.name("doc-snippets").description("Tools for documentation snippets.");
commander_1.program
.name("polywrap-snippet-tools")
.description("Tools for Polywrap Documentation snippets.");
commander_1.program
.command("combine")

@@ -56,9 +54,10 @@ .description("Extracts snippets from the snippets directory and outputs a copy of the documentation directory with snippets injected into it")

.argument("<outputDir>", "The output directory")
.option("-i, --ignore <ignoredPaths...>", "Ignore specified paths")
.option("-i, --ignore <paths...>", "Ignore specified paths")
.option("-e, --exts <exts...>", "Extensions to parse")
.action(function (snippetsDir, docsDir, outputDir, _a) {
var ignore = _a.ignore;
var ignore = _a.ignore, exts = _a.exts;
return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, (0, combine_1.combineDocsAndSnippets)(snippetsDir, docsDir, outputDir, ignore)];
case 0: return [4 /*yield*/, (0, combine_1.combineDocsAndSnippets)(snippetsDir, docsDir, outputDir, exts, ignore)];
case 1:

@@ -65,0 +64,0 @@ _b.sent();

@@ -1,1 +0,1 @@

export declare function combineDocsAndSnippets(snippetsDir: string, docsDir: string, outputDir: string, ignorePaths?: string[]): Promise<void>;
export declare function combineDocsAndSnippets(snippetsDir: string, docsDir: string, outputDir: string, parseExts?: string[], ignorePaths?: string[]): Promise<void>;

@@ -70,3 +70,3 @@ "use strict";

var fs_1 = __importDefault(require("fs"));
function combineDocsAndSnippets(snippetsDir, docsDir, outputDir, ignorePaths) {
function combineDocsAndSnippets(snippetsDir, docsDir, outputDir, parseExts, ignorePaths) {
return __awaiter(this, void 0, void 0, function () {

@@ -83,3 +83,6 @@ var snippets;

console.log("- Extract Snippets");
return [4 /*yield*/, (0, extract_1.extractSnippets)(snippetsDir, ignorePaths)];
return [4 /*yield*/, (0, extract_1.extractSnippets)(snippetsDir, {
parseExts: parseExts,
ignorePaths: ignorePaths,
})];
case 1:

@@ -86,0 +89,0 @@ snippets = _a.sent();

/**
* @typedef ExtractSnippetsOptions
* @type {object}
* @property {string[]} [parseExts] A list of file extensions which will be parsed for Snippets
* @property {string[]} [ignorePaths] A list of paths in `gitignore` format which will be ignored when parsing
*/
declare type ExtractSnippetsOptions = {
parseExts?: string[];
ignorePaths?: string[];
};
/**
* Extract snippets from all files within a directory
* @param {string} dir - The directory to search and extract snippets from
* @returns
* @param {string} dir The directory to search and extract snippets from
* @param {ExtractSnippetsOptions} options Extraction options
* @returns {Record<string, string>} A Record containing all extracted Snippets
*/
export declare function extractSnippets(dir: string, ignorePaths?: string[]): Promise<Record<string, string>>;
export declare function extractSnippets(dir: string, options?: ExtractSnippetsOptions): Promise<Record<string, string>>;
export {};

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

exports.extractSnippets = void 0;
var defaults_1 = require("./defaults");
var path_1 = __importDefault(require("path"));

@@ -60,19 +61,25 @@ var fs_1 = __importDefault(require("fs"));

* Extract snippets from all files within a directory
* @param {string} dir - The directory to search and extract snippets from
* @returns
* @param {string} dir The directory to search and extract snippets from
* @param {ExtractSnippetsOptions} options Extraction options
* @returns {Record<string, string>} A Record containing all extracted Snippets
*/
function extractSnippets(dir, ignorePaths) {
function extractSnippets(dir, options) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var snippets, ignoreInstance;
return __generator(this, function (_a) {
switch (_a.label) {
var snippets, ignoreInstance, exts;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
snippets = {};
ignoreInstance = (0, ignore_1.default)();
if (ignorePaths) {
ignoreInstance.add(ignorePaths);
if (options === null || options === void 0 ? void 0 : options.ignorePaths) {
ignoreInstance.add(options.ignorePaths);
}
return [4 /*yield*/, searchAndExtractSnippetsFromDir(snippets, dir, ignoreInstance)];
else {
ignoreInstance.add(defaults_1.defaultIgnorePaths);
}
exts = (_a = options === null || options === void 0 ? void 0 : options.parseExts) !== null && _a !== void 0 ? _a : defaults_1.defaultParseExts;
return [4 /*yield*/, searchAndExtractSnippetsFromDir(snippets, dir, exts, ignoreInstance)];
case 1:
_a.sent();
_b.sent();
return [2 /*return*/, snippets];

@@ -84,5 +91,5 @@ }

exports.extractSnippets = extractSnippets;
function searchAndExtractSnippetsFromDir(snippets, dir, ignoreInstance) {
function searchAndExtractSnippetsFromDir(snippets, dir, exts, ignoreInstance) {
return __awaiter(this, void 0, void 0, function () {
var dirents, exts, filter, match, dirents_1, dirents_1_1, dirent, direntPath, e_1_1;
var dirents, match, dirents_1, dirents_1_1, dirent, direntPath, e_1_1;
var e_1, _a;

@@ -93,4 +100,2 @@ return __generator(this, function (_b) {

dirents = fs_1.default.readdirSync(dir, { withFileTypes: true });
exts = [".ts", ".json", ".yaml", ".txt", ".md", ".graphql", ".cue"];
filter = ["node_modules"];
match = function (str, tests) {

@@ -133,4 +138,4 @@ var e_2, _a;

case 4:
if (!(dirent.isDirectory() && !match(dirent.name, filter))) return [3 /*break*/, 6];
return [4 /*yield*/, searchAndExtractSnippetsFromDir(snippets, direntPath, ignoreInstance)];
if (!dirent.isDirectory()) return [3 /*break*/, 6];
return [4 /*yield*/, searchAndExtractSnippetsFromDir(snippets, direntPath, exts, ignoreInstance)];
case 5:

@@ -137,0 +142,0 @@ _b.sent();

{
"name": "doc-snippets",
"version": "0.2.0",
"version": "0.3.0",
"description": "Extract and inject snippets from code into markdown files",

@@ -5,0 +5,0 @@ "author": {

@@ -27,5 +27,2 @@ # doc-snippets

Currently, `doc-snippets` extracts snippets from the following file types:
`.ts`, `.json`, `.yaml`, `.txt`, `.md`, `.graphql`, and `.cue`.
Snippets are injected only into `.md` files.

@@ -49,3 +46,7 @@

- `-i, --ignore <paths...>` - Ignore listed paths. Paths should be formatted according to the [gitignore spec 2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
- By default, only `node_modules` is ignored.
- `-e, --exts <exts...>` - Parse files with listed extensions
- By default, files with the following extensions are parsed: `.ts`, `.json`, `.yaml`, `.txt`, `.md`, `.graphql`, and `.cue`
### In your own code

@@ -52,0 +53,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