Skip to content

Instantly share code, notes, and snippets.

@HichemTab-tech
Last active June 12, 2024 01:18
Show Gist options
  • Save HichemTab-tech/7c504ae97294de5022c6479ac42af2b9 to your computer and use it in GitHub Desktop.
Save HichemTab-tech/7c504ae97294de5022c6479ac42af2b9 to your computer and use it in GitHub Desktop.
Automated Setup Script for NPM jQuery Plugin Projects

Automated Setup Script for NPM jQuery Plugin Projects

This script automates the setup process for NPM jQuery plugin projects. It clones a specified GitHub repository, replaces placeholders in project files, renames files, updates package.json, and executes npm install to install project dependencies.

Usage

  1. Clone this repository to your local machine.
  2. Navigate to the directory containing the scripts.
  3. Run setup_project.bat (for Windows) or setup_project.sh (for Unix-based systems) by double-clicking or executing them in your terminal.
  4. Follow the prompts to provide necessary information such as project name, script names, package name, and descriptions.
  5. The script will perform the necessary replacements and updates and then execute npm install to install dependencies.

Note

  • Ensure you have Git and Node.js installed on your system for the script to work properly.
  • After running the script, you'll have a fully configured NPM jQuery plugin project ready for development.
@echo off
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%~dp0setup_project.ps1"
pause
# Prompt user for the folder name (GITHUB_REPO_NAME)
$folder_name = Read-Host "Enter the folder name for your project (e.g., OTP-designer-jquery)"
# Create the folder and change to that directory
New-Item -ItemType Directory -Path $folder_name
Set-Location $folder_name
# Clone the repository into the current directory
git clone https://github.com/HichemTab-tech/default-npm-project .
# Prompt user for other replacement values
$main_script_name = Read-Host "Enter your main script name (e.g., otpdesigner.js)"
$package_name = Read-Host "Enter your package name (e.g., otp-designer-jquery)"
$library_function_name = Read-Host "Enter your library function name (e.g., otpdesigner)"
$keywords = Read-Host "Enter keywords (comma-separated)"
$short_description = Read-Host "Enter short description"
$long_description = Read-Host "Enter long description"
# Function to replace placeholders in files, excluding README.md
function Replace-Placeholder {
param (
[string]$placeholder,
[string]$replacement
)
# Find all files in the project except README.md and replace the placeholder
Get-ChildItem -Recurse -File | Where-Object { $_.Name -ne "README.md" } | ForEach-Object {
(Get-Content $_.FullName) -replace $placeholder, $replacement | Set-Content $_.FullName
}
}
# Replace placeholders in the project
Replace-Placeholder "GITHUB_REPO_NAME" $folder_name
Replace-Placeholder "LIBRARY_MAIN_SCRIPT_NAME" $main_script_name
Replace-Placeholder "PACKAGE_NAME" $package_name
Replace-Placeholder "LIBRARY_FUNCTION_NAME" $library_function_name
# Rename the main script file
$oldFilePath = "src/lib.js"
$newFileName = $main_script_name + ".js"
Rename-Item -Path $oldFilePath -NewName $newFileName
# Update package.json with keywords and short description
$json = Get-Content -Raw -Path package.json | ConvertFrom-Json
$keywordsArray = $keywords -split ","
$json.keywords += $keywordsArray
$json.description = $short_description
$json | ConvertTo-Json -Compress | Set-Content -Path package.json
# Append long description to README.md
Add-Content -Path README.md -Value "`n# $folder_name`n$long_description"
Write-Host "Replacements completed successfully!"
Write-Host "Now installing npm packages..."
# Run npm install
npm install
Write-Host "Npm packages installed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment