220 lines
6.4 KiB
Python
220 lines
6.4 KiB
Python
import os as _os
|
|
import argparse as _argparse
|
|
|
|
from lib.string import *
|
|
from lib.command import *
|
|
from lib.execute import *
|
|
|
|
|
|
def main():
|
|
## args
|
|
argument_parser = _argparse.ArgumentParser(
|
|
prog = "laravel-steer",
|
|
)
|
|
argument_parser.add_argument(
|
|
"action",
|
|
type = str,
|
|
choices = [
|
|
"clear",
|
|
"build",
|
|
"run",
|
|
"logs",
|
|
],
|
|
metavar = "<action>",
|
|
)
|
|
argument_parser.add_argument(
|
|
"-v",
|
|
"--verbose",
|
|
action = "store_true",
|
|
default = False,
|
|
)
|
|
argument_parser.add_argument(
|
|
"-q",
|
|
"--dry-run",
|
|
action = "store_true",
|
|
default = False,
|
|
)
|
|
argument_parser.add_argument(
|
|
"-s",
|
|
"--source-directory",
|
|
type = str,
|
|
default = None,
|
|
metavar = "<source-directory>",
|
|
)
|
|
argument_parser.add_argument(
|
|
"-b",
|
|
"--build-directory",
|
|
type = str,
|
|
default = None,
|
|
metavar = "<build-directory>",
|
|
)
|
|
argument_parser.add_argument(
|
|
"-u",
|
|
"--unlock",
|
|
action = "store_true",
|
|
default = False,
|
|
help = "do not copy composer.lock",
|
|
)
|
|
argument_parser.add_argument(
|
|
"-x",
|
|
"--exclude",
|
|
type = str,
|
|
action = "append",
|
|
default = None,
|
|
metavar = "<exclude>",
|
|
dest = "excludes",
|
|
)
|
|
argument_parser.add_argument(
|
|
"-e",
|
|
"--env-path",
|
|
type = str,
|
|
default = None,
|
|
metavar = "<env-path>",
|
|
)
|
|
argument_parser.add_argument(
|
|
"-p",
|
|
"--port",
|
|
type = int,
|
|
default = None,
|
|
metavar = "<port>",
|
|
)
|
|
args = argument_parser.parse_args()
|
|
|
|
## exec
|
|
if (args.action == "clear"):
|
|
if (args.build_directory is None):
|
|
raise ValueError("build directory required")
|
|
else:
|
|
execute(
|
|
command_remove(args.build_directory),
|
|
{
|
|
"show": args.verbose,
|
|
"run": (not args.dry_run),
|
|
}
|
|
)
|
|
elif (args.action == "build"):
|
|
if (args.source_directory is None):
|
|
raise ValueError("source directory required")
|
|
else:
|
|
if (args.build_directory is None):
|
|
raise ValueError("build directory required")
|
|
else:
|
|
execute(
|
|
command_directory_create(args.build_directory),
|
|
{
|
|
"show": args.verbose,
|
|
"run": (not args.dry_run),
|
|
}
|
|
)
|
|
if (not args.unnock):
|
|
pass
|
|
else:
|
|
execute(
|
|
command_remove(
|
|
_os.path.join(args.build_directory, "composer.lock")
|
|
)
|
|
)
|
|
execute(
|
|
command_rsync(
|
|
args.source_directory,
|
|
args.build_directory,
|
|
{
|
|
"verbose": args.verbose,
|
|
"excludes": (
|
|
[
|
|
".editorconfig",
|
|
".env.example",
|
|
".env",
|
|
"vendor/",
|
|
"_ide_helper.php",
|
|
]
|
|
+
|
|
(
|
|
["composer.lock"]
|
|
if args.unlock else
|
|
[]
|
|
)
|
|
+
|
|
(args.excludes or [])
|
|
),
|
|
}
|
|
),
|
|
{
|
|
"show": args.verbose,
|
|
"run": (not args.dry_run),
|
|
}
|
|
)
|
|
execute(
|
|
command_generic(
|
|
"composer",
|
|
[
|
|
{"value": "install"},
|
|
]
|
|
),
|
|
{
|
|
"directory": args.build_directory,
|
|
"show": args.verbose,
|
|
"run": (not args.dry_run),
|
|
}
|
|
)
|
|
if (args.env_path is None):
|
|
pass
|
|
else:
|
|
execute(
|
|
command_copy(
|
|
args.env_path,
|
|
_os.path.join(args.build_directory, ".env"),
|
|
),
|
|
{
|
|
"show": args.verbose,
|
|
"run": (not args.dry_run),
|
|
}
|
|
)
|
|
elif (args.action == "run"):
|
|
if (args.port is None):
|
|
raise ValueError("port required")
|
|
else:
|
|
execute(
|
|
command_generic(
|
|
"php",
|
|
[
|
|
{"value": "artisan"},
|
|
{"value": "serve"},
|
|
{"name": "host", "value": "0.0.0.0"},
|
|
{"name": "port", "value": ("%u" % args.port)},
|
|
]
|
|
),
|
|
{
|
|
"directory": args.build_directory,
|
|
"show": args.verbose,
|
|
"run": (not args.dry_run),
|
|
}
|
|
)
|
|
elif (args.action == "logs"):
|
|
if (args.build_directory is None):
|
|
raise ValueError("build directory required")
|
|
else:
|
|
execute(
|
|
command_generic(
|
|
"tail",
|
|
[
|
|
{"name": "follow"},
|
|
{"value": "storage/logs/laravel.log"},
|
|
]
|
|
),
|
|
{
|
|
"directory": args.build_directory,
|
|
"show": args.verbose,
|
|
"run": (not args.dry_run),
|
|
}
|
|
)
|
|
else:
|
|
raise ValueError(
|
|
string_coin(
|
|
"invalid action: {{action}}",
|
|
{
|
|
"action": args.action,
|
|
}
|
|
)
|
|
)
|