publish-check.jsā¢1.55 kB
#!/usr/bin/env node
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { readFileSync } from 'fs';
console.log('š Running pre-publish checks...\n');
// Check if build directory exists
if (!existsSync('build')) {
console.error('ā Build directory not found. Run "npm run build" first.');
process.exit(1);
}
// Check if main entry point exists
if (!existsSync('build/index.js')) {
console.error('ā Main entry point build/index.js not found.');
process.exit(1);
}
// Check if package.json is valid
try {
const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
if (!pkg.name || !pkg.version || !pkg.description) {
console.error('ā package.json is missing required fields (name, version, description).');
process.exit(1);
}
if (pkg.private === true) {
console.error('ā Package is marked as private. Set "private": false to publish.');
process.exit(1);
}
console.log(`ā
Package: ${pkg.name}@${pkg.version}`);
console.log(`ā
Description: ${pkg.description}`);
} catch (error) {
console.error('ā Invalid package.json:', error.message);
process.exit(1);
}
// Check if README exists
if (!existsSync('README.md')) {
console.error('ā README.md not found.');
process.exit(1);
}
// Check if LICENSE exists
if (!existsSync('LICENSE')) {
console.error('ā LICENSE file not found.');
process.exit(1);
}
console.log('\nā
All pre-publish checks passed!');
console.log('\nš¦ Ready to publish. Run:');
console.log(' npm publish --access public');