first commit
This commit is contained in:
1
app/scripts/.gitignore
vendored
Normal file
1
app/scripts/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.js
|
||||
74
app/scripts/git-prompt.ts
Normal file
74
app/scripts/git-prompt.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Git Pull Setup
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Ask user whether to pull from Git
|
||||
const pull_remote_repository: string = prompt('Do you want to pull from Git? (yes/no): ');
|
||||
|
||||
if (pull_remote_repository.toLowerCase() === 'yes' || pull_remote_repository.toLowerCase() === 'y') {
|
||||
console.log('Pulling latest changes from Git...');
|
||||
try {
|
||||
execSync('git fetch', { stdio: 'inherit' }); // Execute git fetch
|
||||
execSync('git pull', { stdio: 'inherit', timeout: 5000 }); // Execute git pull with timeout of 5s
|
||||
console.log('Pull successful!');
|
||||
} catch (err: any) {
|
||||
// If there's an error, log it and exit with an error code
|
||||
if (err.signal === 'SIGTERM') {
|
||||
console.error('Git pull timed out.');
|
||||
} else {
|
||||
console.error('Error pulling from Git:', err);
|
||||
}
|
||||
process.exit(1); // Exit with non-zero code to signal failure
|
||||
}
|
||||
} else {
|
||||
console.log('Skipping Git pull.');
|
||||
}
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
husky initialization
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
const source = path.join(__dirname, "..", ".husky", "pre-commit");
|
||||
const destinationDir = path.join(__dirname, "..", ".husky", "_");
|
||||
const destination = path.join(destinationDir, "pre-commit");
|
||||
console.log('source: ', source);
|
||||
console.log('destination: ', destination);
|
||||
|
||||
// Verify if the source file exists
|
||||
if (!fs.existsSync(source)) {
|
||||
console.error("Source file does not exist:", source);
|
||||
process.exit(1); // Exit with an error code
|
||||
}
|
||||
|
||||
// Ensure the destination directory exists
|
||||
if (!fs.existsSync(destinationDir)) {
|
||||
fs.mkdirSync(destinationDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Read and write the content manually
|
||||
fs.readFile(source, "utf-8", (readErr, data) => {
|
||||
if (readErr) {
|
||||
console.error("Failed to read source file:", readErr);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// console.log(`sourceData :`, data);
|
||||
}
|
||||
|
||||
fs.writeFile(destination, data.toString(), (writeErr) => {
|
||||
if (writeErr) {
|
||||
console.error("Failed to write to destination file:", writeErr);
|
||||
} else {
|
||||
// console.log('Data to be written in destination: ', data.toString());
|
||||
console.log("Successfully copied pre-commit hook to", destination);
|
||||
}
|
||||
});
|
||||
});
|
||||
76
app/scripts/validate-filenames.ts
Normal file
76
app/scripts/validate-filenames.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import * as glob from 'glob';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Function to check if a filename is in camelCase
|
||||
function isCamelCase(filename: string): boolean {
|
||||
const camelCasePattern = /^[a-z]+([A-Z][a-z]*)*$/; // Regular expression to match camelCase pattern
|
||||
return camelCasePattern.test(filename);
|
||||
}
|
||||
|
||||
// Function to convert a filename to camelCase
|
||||
function toCamelCase(filename: string): string {
|
||||
return filename
|
||||
.replace(/[_-]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''))
|
||||
.replace(/^[A-Z]/, (firstChar) => firstChar.toLowerCase()); // Ensure the first letter is lowercase
|
||||
}
|
||||
|
||||
// Function to get all non-camelCase filenames in the specified directory
|
||||
function getNonCamelCaseFiles(directory: string): string[] {
|
||||
const files = glob.sync(`${directory}/**/*.*`); // Get all files in the specified directory
|
||||
return files.filter((filePath) => {
|
||||
const filename = path.basename(filePath, path.extname(filePath)); // Get the filename without the extension
|
||||
return !isCamelCase(filename); // Filter non-camelCase files
|
||||
});
|
||||
}
|
||||
|
||||
// Function to prompt the user for renaming non-camelCase files or proceed automatically in non-interactive mode
|
||||
function promptUserForRenaming(nonCamelCaseFiles: string[]): boolean {
|
||||
if (process.stdout.isTTY) {
|
||||
// If running interactively, prompt the user
|
||||
const answer: string = prompt('Do you want to rename these files to camelCase? (yes/no): ');
|
||||
return answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y';
|
||||
} else {
|
||||
// If running in non-interactive mode, log default action and proceed without prompt
|
||||
console.log("Running in non-interactive mode. Defaulting to renaming files.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to rename files to camelCase
|
||||
function renameFiles(nonCamelCaseFiles: string[]): void {
|
||||
nonCamelCaseFiles.forEach((filePath) => {
|
||||
const dir = path.dirname(filePath); // Get the directory path
|
||||
const ext = path.extname(filePath); // Get the file extension
|
||||
const oldFilename = path.basename(filePath, ext); // Get the filename without extension
|
||||
const newFilename = toCamelCase(oldFilename) + ext; // Convert to camelCase and add back the extension
|
||||
const newFilePath = path.join(dir, newFilename); // Generate the new file path
|
||||
|
||||
try {
|
||||
fs.renameSync(filePath, newFilePath); // Rename the file
|
||||
console.log(`✅ Renamed: ${filePath} -> ${newFilePath}`);
|
||||
} catch (error) {
|
||||
console.error(`❌ Error renaming ${filePath}:`, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Main function to execute the script
|
||||
function main(): void {
|
||||
const directory = 'src'; // Specify your target directory
|
||||
const nonCamelCaseFiles = getNonCamelCaseFiles(directory); // Get non-camelCase files
|
||||
|
||||
if (nonCamelCaseFiles.length > 0) {
|
||||
console.error('❌ The following files are not in camelCase:');
|
||||
nonCamelCaseFiles.forEach((file) => console.error(`- ${file}`));
|
||||
|
||||
// Prompt user for renaming in interactive mode or proceed automatically in non-interactive mode
|
||||
renameFiles(nonCamelCaseFiles);
|
||||
} else {
|
||||
console.log('✅ All filenames are in camelCase.');
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the main function
|
||||
main();
|
||||
Reference in New Issue
Block a user