Skip to content

Instantly share code, notes, and snippets.

@mad9scientist
Last active July 17, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mad9scientist/3fadd8f98140a9d5928af9907cb5c614 to your computer and use it in GitHub Desktop.
Save mad9scientist/3fadd8f98140a9d5928af9907cb5c614 to your computer and use it in GitHub Desktop.

LaraMake

Version: Dirty-n-Rough (v 0.1.0) Author: Chris Holbrook

A Simple Windows version of Laravel Valet

A Windows batch file that setup a new Laravel Project, Setup your host file, and open your text editor and browser.

Requirements

  • PHP
  • SQLite (Optional: MySQL or MariaDB)
  • Windows
  • Composer
  • Laravel Installer
  • Administrative Rights

This script assumes the following factors:

  • You store your projects at: C:\projects\
  • You use Sublime Text 3, and is installed in the default location
  • You use Firefox, and is installed in the default location
  • Windows is installed on a partition of C:
  • PHP is locally installed
  • Composer is Installed
  • Laravel Installer is installed
  • You can obtain Administrative Rights on the machine

Setup

Theretically you should be able to drop the laramake.bat in to a folder that is already in your $PATH (e.g. C:\Windows) and should be able to open a new command prompt have access to it. If you rename the file to laramake (without the .bat) you should be able to call it from the prompt like so:

$ laramake

NOTE: Also, you could rename the file to anything you want, e.g. laraboom, laramagic, etc

Workflow

  • Open your Terminal - Command Prompt
  • Type laramake at the command line
  • If you have User Access Control activated, you will be prompted for Administrative Access - Yes
  • Then you will be asked for a project name. This will the URL and Folder Name for your project, you should only use alphanumeric, hyphens, and dots in this name (URL complaint symbols). For an example: demo
  • Then Laravel will be installed.
  • Then Your Git Repo is initialized.
  • Then Sublime opens with your project files
  • Then you will be asked if you would to add entries to your host files. This is what make the .dev domain work on your computer. Two entries will be created along with a note, use the project name demo the entries create looks like:
# Project demo at c:\projects\demo
127.0.0.1	demo.dev
127.0.0.1	www.demo.dev
  • Then the built-in Laravel/PHP web server is started - in its own windows - at project-name.dev on port 80
  • Then Firefox is launched and pointed to project-name.dev
  • Then two extra command prompt windows are open for your needs, e.g. Git, Task Runner, Generators, etc.
  • And finally a summary: where your files are located and the projects URL

Know problems

  • Must be CAREFUL on Path for Project. I have already put a project in my System32 folder.
  • Hard Coded for the following things:
    • Project Path
    • Host File
    • Text Editor/IDE Path
    • Hard Coded to Firefox
  • Could use xip.io Domains
  • Assume use of a SQLite Database instead of MySQL/MariaDB (you could always install MySQL and use it anyway).
  • No Error Handling :\
  • Windows Only - The whole point.
  • No Tests

Source for the Idea

Twitter - Matt Stauffer ‏ @stauffermatt

@echo off
:: UAC Request and Host File Update
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto SetupProject)
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"="
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:SetupProject
SET ProjPath=C:\project
SET Project=
SET /P Project="What is your project's name? "
cd c:\projects
ECHO [Laravel Installing]
ECHO ================================================================
ECHO Installing Laravel to: C:\projects\%Project%
call laravel new %Project%
ECHO ================================================================
cd c:\projects\%Project%
ECHO [Setting up Git]
ECHO ================================================================
git init
git add .
git commit -m "Initial Commit for %Project%. Installed Laravel."
ECHO.
ECHO [Git Setup Complete]
ECHO.
ECHO.
ECHO [Opening Sublime Text]
ECHO ================================================================
"c:\Program Files\Sublime Text 3\subl.exe" c:\projects\%Project%\
:LOOP
ECHO [Host File Edit]
ECHO ================================================================
SET Choice=
SET /P Choice="Do you want to modify your HOSTS file ? (Y/N)"
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
IF /I '%Choice%'=='Y' GOTO UPDATEHOST
IF /I '%Choice%'=='N' GOTO END
ECHO Please type Y (for Yes) or N (for No) to proceed!
ECHO.
GOTO Loop
:UPDATEHOST
ECHO # Project %1 at c:\projects\%Project% >> "c:\Windows\System32\drivers\etc\hosts"
ECHO 127.0.0.1 %Project%.dev >> "c:\Windows\System32\drivers\etc\hosts"
ECHO 127.0.0.1 www.%Project%.dev >> "c:\Windows\System32\drivers\etc\hosts"
ECHO .>> "c:\Windows\System32\drivers\etc\hosts"
ECHO ================================================================
ECHO [Start Webserver]
start cmd /C php c:\projects\%Project%\artisan serve --port=80 --host=%Project%.dev
ECHO [Launch Browser]
"c:\Program Files (x86)\Mozilla Firefox\firefox.exe" http://%Project%.dev
ECHO [Extra Command Lines]
start cmd /k echo [Command Center]
start cmd /k echo [Task Runner]
:END
ECHO ================================================================
ECHO.
ECHO Your project has been created and your ready to go!
ECHO.
ECHO Your Project is located at:
ECHO C:\Projects\%Project%
ECHO.
ECHO Your Project's URL is:
ECHO http://%Project%.dev
ECHO.
ECHO Now Create Something Awesome!
ECHO.
ECHO.
ECHO This window will now self-destruct!
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment