Simple tool for start BrowserSyn on Yii2 Instalation

Hello. I just write some Python tool to easily start BrowserSync on a Yii2 instalation running on a local web server.

Requirements:

  • NodeJS (in you local machine)

  • BrowserSync.io installed Globally

  • Local webserver running the instalation

Because I can’t post the link to my Github repository, this is the code:




#!/usr/bin/python

# Imports.

import sys

import os

import argparse


def start_bs(tool, domain, template_name = False) :

    if tool == 'joomla':

        os.system('browser-sync start --proxy "'+domain+'" --files "templates/'+template_name+'/css/*.scss" "templates/'+template_name+'/js/*.js" "templates/'+template_name+'/index.php"')

        pass

    if tool == 'yii2-a':

        os.system('browser-sync start --proxy "'+domain+'" --files "frontend/web/css/*.scss" "frontend/web/js/*.js" "frontend/views/*/*.php" "backend/web/css/*.scss" "backend/web/js/*.js" "backend/views/*/*.php"')

        pass

    if tool == 'yii2-b':

        os.system('browser-sync start --proxy "'+domain+'" --files "web/css/*.scss" "web/js/*.js" "views/*/*.php"')

        pass


# Dealing with arguments.

parser = argparse.ArgumentParser(description='Start BrowserSync for Joomla 3 site development, or Advanced Yii2 Development')

parser.add_argument('tool', action='store',  help='Define the tool (joomla, yii2-b or yii2-a)')

parser.add_argument('domain', action='store',  help='Define the local domain')

parser.add_argument('-tn', action='store',  help='(optional) For Joomla, the name of the template folder')

arguments = parser.parse_args()


# Main Script

if arguments.tool == 'joomla':

    if arguments.tn :

        start_bs(arguments.tool, arguments.domain, arguments.tn)

    else:

        parser.error("If tool is Joomla, the template name is required: startbs.py [-h] tool domain -tn template_name")

else:

    start_bs(arguments.tool, arguments.domain)