CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-clean-publish

Clean your package before publish by removing development-specific files and configuration

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

file-processing.mddocs/

File Processing

Advanced file filtering, README cleaning, and JavaScript comment removal capabilities.

Capabilities

File Filtering

Creates sophisticated filter functions for determining which files to include during package cleaning.

/**
 * Creates filter function for files based on ignore patterns
 * @param ignoreFiles - Array of file patterns to exclude (strings or RegExp)
 * @returns Filter function that returns true for files to include
 */
function createFilesFilter(ignoreFiles?: Array<string | RegExp>): Function;

/**
 * Creates matcher function for ignoring files based on pattern
 * @param ignorePattern - Pattern to match (string, RegExp, or glob pattern)
 * @returns Matcher function for the specific pattern
 */
function createIgnoreMatcher(ignorePattern: string | RegExp): Function;

Default Ignored Files:

The following files and patterns are ignored by default:

  • Development directories: .git, .vscode, node_modules, test
  • CI/Build files: .travis.yml, appveyor.yml, .github
  • Lock files: package-lock.json, yarn.lock, pnpm-lock.yaml
  • Config files: /^\.eslintrc/, /^\.prettierrc/, /^\.babelrc/
  • Development files: *.test.js, coverage/, .DS_Store

Usage Examples:

import { createFilesFilter, createIgnoreMatcher } from 'clean-publish/core.js';

// Create filter with custom patterns
const filter = createFilesFilter([
  '*.test.js',           // String pattern
  /\.spec\./,            // RegExp pattern
  'coverage/**',         // Glob pattern
  'docs/internal/'       // Directory pattern
]);

// Use filter to check files
console.log(filter('src/index.js'));      // true (include)
console.log(filter('src/test.spec.js'));  // false (exclude)
console.log(filter('coverage/report.html')); // false (exclude)

// Create specific matcher
const testMatcher = createIgnoreMatcher(/\.test\.js$/);
console.log(testMatcher('index.js'));     // true (include)
console.log(testMatcher('index.test.js')); // false (exclude)

README Documentation Cleaning

Cleans README.md files to keep only essential content for published packages.

/**
 * Cleans README.md to keep only main section and add docs link
 * @param drectoryName - Directory containing README.md to clean
 * @param repository - Repository URL or object for docs link
 * @param homepage - Homepage URL (takes precedence over repository)
 * @returns Promise that resolves when README is cleaned
 */
function cleanDocs(drectoryName: string, repository?: string | object, homepage?: string): Promise<void>;

/**
 * Extracts README URL from repository configuration
 * @param repository - Repository URL string or object
 * @returns GitHub README URL or null if not extractable
 */
function getReadmeUrlFromRepository(repository: string | object): string | null;

Cleaning Process:

  1. Reads existing README.md
  2. Keeps only content before first ## heading
  3. Adds "## Docs" section with link to full documentation
  4. Uses homepage field if available, otherwise generates GitHub URL

Usage Examples:

import { cleanDocs, getReadmeUrlFromRepository } from 'clean-publish/core.js';

// Clean with repository URL
await cleanDocs('/tmp/clean-build', 'https://github.com/user/repo');

// Clean with repository object
await cleanDocs('/tmp/clean-build', {
  type: 'git',
  url: 'https://github.com/user/repo.git'
});

// Clean with homepage preference
await cleanDocs('/tmp/clean-build', 
  'https://github.com/user/repo',
  'https://user.github.io/repo'
);

// Extract README URL
const url = getReadmeUrlFromRepository('https://github.com/user/repo.git');
console.log(url); // "https://github.com/user/repo#readme"

JavaScript Comment Removal

Removes inline comments and block comments from JavaScript files to reduce package size.

/**
 * Removes inline comments from JavaScript files in directory
 * @param drectoryName - Directory to process recursively
 * @returns Promise that resolves when all JS files are processed
 */
function cleanComments(drectoryName: string): Promise<void>;

Comment Cleaning Process:

  1. Finds all **/*.js files in directory
  2. Removes single-line comments (// comment)
  3. Removes block comments (/* comment */)
  4. Normalizes whitespace and newlines
  5. Preserves code structure and functionality

Usage Examples:

import { cleanComments } from 'clean-publish/core.js';

// Clean all JS files in directory
await cleanComments('/tmp/clean-build');

Before cleaning:

// Main application entry point
function hello(name) {
  /* 
   * Greet the user with their name
   * TODO: Add internationalization
   */
  console.log(`Hello, ${name}!`); // Log greeting
  return name; // Return for chaining
}

After cleaning:

function hello(name) {
  console.log(`Hello, ${name}!`);
  return name;
}

Pattern Matching Details

String Patterns

Direct filename matching:

const filter = createFilesFilter(['README.md', 'LICENSE']);

RegExp Patterns

Regular expression matching against full file path:

const filter = createFilesFilter([
  /\.test\.js$/,           // Test files
  /^src\/.*\.spec\.js$/,   // Spec files in src/
  /\.(md|txt)$/i          // Documentation files
]);

Glob Patterns

Glob pattern matching with ** and * support:

const filter = createFilesFilter([
  'docs/**',               // All files in docs directory
  '**/*.test.js',          // Test files anywhere
  'src/**/fixtures/*'      // Fixture files in src subdirectories
]);

Pattern Combination

All pattern types can be combined in a single filter:

const filter = createFilesFilter([
  'node_modules',          // String: exact directory name
  /\.log$/,               // RegExp: log files
  'coverage/**',          // Glob: coverage directory
  '.env.*'                // String: environment files
]);

docs

cli-commands.md

configuration.md

core-operations.md

file-processing.md

index.md

utilities.md

tile.json