securesharkinputs
Version:
Advanced enterprise validation library with multi-layer security protection for SecureShark
138 lines (114 loc) ⢠4.54 kB
JavaScript
const fs = require('fs');
const path = require('path');
console.log('š”ļø SecureSharkInputs - Installing templates...');
// Get the project root (where package.json is located)
const projectRoot = process.env.INIT_CWD || process.cwd();
console.log(`š Project root: ${projectRoot}`);
// Check if we're in a valid npm install context
if (!process.env.npm_package_name) {
console.log('ā¹ļø Not running in npm install context, skipping template installation');
console.log('š” To install templates manually, run: node node_modules/securesharkinputs/scripts/install-templates.js');
process.exit(0);
}
// Define template source and destination paths
const templates = [
{
source: path.join(__dirname, '../templates/react-form-template.tsx'),
destination: path.join(projectRoot, 'src/components/SecureSharkForm.tsx'),
description: 'React form template with ValidationShark'
}
];
// Create src/components directory if it doesn't exist
const componentsDir = path.join(projectRoot, 'src/components');
try {
if (!fs.existsSync(componentsDir)) {
fs.mkdirSync(componentsDir, { recursive: true });
console.log('ā
Created src/components directory');
} else {
console.log('ā
src/components directory already exists');
}
} catch (error) {
console.error(`ā Error creating components directory: ${error.message}`);
console.log('š” You can create the directory manually and run the script again');
}
// Copy templates
let installedCount = 0;
templates.forEach(template => {
try {
console.log(`š Checking template: ${template.source}`);
if (fs.existsSync(template.source)) {
// Check if destination already exists
if (fs.existsSync(template.destination)) {
console.log(`ā ļø Template already exists: ${template.destination}`);
console.log('š” Skipping to avoid overwriting existing files');
return;
}
fs.copyFileSync(template.source, template.destination);
console.log(`ā
Installed: ${template.description}`);
console.log(` Location: ${template.destination}`);
installedCount++;
} else {
console.warn(`ā ļø Template not found: ${template.source}`);
console.log(`š” Make sure the package is properly installed`);
}
} catch (error) {
console.error(`ā Error installing template: ${error.message}`);
console.log(`š” You can copy the template manually from: ${template.source}`);
}
});
// Create a setup guide
const setupGuide = `# SecureSharkInputs Setup Guide
## š Quick Start
1. **Import the template in your component:**
\`\`\`tsx
import SecureSharkForm from './components/SecureSharkForm';
\`\`\`
2. **Use it in your app:**
\`\`\`tsx
function App() {
return (
<div>
<SecureSharkForm />
</div>
);
}
\`\`\`
3. **Test security features:**
- Try XSS: \`<script>alert('xss')</script>\`
- Try SQL Injection: \`'; DROP TABLE users; --\`
- Try Data Theft: \`document.cookie\`
## š Documentation
- **NPM Package:** https://www.npmjs.com/package/securesharkinputs
- **GitHub:** https://github.com/AzzADesigns/SecureSharkInputs
- **Full Documentation:** See README.md in the package
## š”ļø Features
- ā
XSS Protection
- ā
SQL Injection Protection
- ā
Data Theft Protection
- ā
Form Blocking
- ā
Real-time Validation
- ā
React Hook Form Integration (included in library)
## šÆ Customization
Modify the template at \`src/components/SecureSharkForm.tsx\` to match your needs.
## š§ Manual Installation
If templates weren't installed automatically, run:
\`\`\`bash
node node_modules/securesharkinputs/scripts/install-templates.js
\`\`\`
`;
try {
const guidePath = path.join(projectRoot, 'SECURESHARK_SETUP.md');
fs.writeFileSync(guidePath, setupGuide);
console.log('ā
Created setup guide: SECURESHARK_SETUP.md');
} catch (error) {
console.error(`ā Error creating setup guide: ${error.message}`);
}
if (installedCount > 0) {
console.log('\nš SecureSharkInputs templates installed successfully!');
console.log('š Check SECURESHARK_SETUP.md for usage instructions');
} else {
console.log('\nā ļø No templates were installed');
console.log('š” You can install them manually by running:');
console.log(' node node_modules/securesharkinputs/scripts/install-templates.js');
}