Clean your package before publish by removing development-specific files and configuration
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Advanced file filtering, README cleaning, and JavaScript comment removal capabilities.
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:
.git, .vscode, node_modules, test.travis.yml, appveyor.yml, .githubpackage-lock.json, yarn.lock, pnpm-lock.yaml/^\.eslintrc/, /^\.prettierrc/, /^\.babelrc/*.test.js, coverage/, .DS_StoreUsage 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)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:
## headinghomepage field if available, otherwise generates GitHub URLUsage 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"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:
**/*.js files in directory// comment)/* comment */)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;
}Direct filename matching:
const filter = createFilesFilter(['README.md', 'LICENSE']);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 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
]);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
]);