Skip to content

Commit

Permalink
Add open option for server and gulp check for update. Resolve #11
Browse files Browse the repository at this point in the history
  • Loading branch information
equiman committed Nov 8, 2017
1 parent 715429c commit 9123146
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 25 deletions.
29 changes: 29 additions & 0 deletions dev/controller/GIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,34 @@ public static void CmdReset(string path) {
Exceptions.General(Ex.Message);
}
}

public static void CmdFetch(string path){
try
{
$"git -C {path.Slash()} fetch".Term();
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}

public static bool CmdStatus(string path){
bool status = false;
string response = "";
try
{
string search = "Your branch is up-to-date";
Response result = new Response();
result = $"git -C {path.Slash()} status".Term();
response = Shell.ExtractLine(result.stdout, search);
if (!String.IsNullOrEmpty(response)){
status = true;
}
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
return status;
}
}
}
7 changes: 4 additions & 3 deletions dev/controller/Gulp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void CmdUglify(string dir){
Exceptions.General(Ex.Message);
}
}
public static void CmdServer(string path, string dir, string ipt, string dmn, string flv, string srv, bool syn, string lip, string ptc){
public static void CmdServer(string path, string dir, string ipt, string dmn, string flv, string srv, bool syn, string lip, string ptc, bool opn){
try
{
StringBuilder cmd = new StringBuilder();
Expand All @@ -29,15 +29,16 @@ public static void CmdServer(string path, string dir, string ipt, string dmn, st
cmd.Append($" --ipt {ipt.Slash()}");
}
cmd.Append($" --dmn {dmn}");
cmd.Append($" --ptc {ptc}");
if (!String.IsNullOrEmpty(flv)){
cmd.Append($" --flv {flv.ToUpper()}");
}
if (!String.IsNullOrEmpty(srv)){
cmd.Append($" --srv {srv}");
}
cmd.Append($" --sync {(syn ? "Y" : "N")}");
cmd.Append($" --host {lip}");
cmd.Append($" --ptc {ptc}");
cmd.Append($" --sync {(syn ? "Y" : "N")}");
cmd.Append($" --open {(opn ? "Y" : "N")}");
cmd.Append($" --os {Os.Platform()}");
cmd.ToString().Term(Output.External, dir);
}
Expand Down
131 changes: 109 additions & 22 deletions dev/view/Gulp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void List(ref List<Option> opts) {
opts.Add(new Option{opt="g>n" , stt=false, act=Gulp.Number });
opts.Add(new Option{opt="g>s" , stt=false, act=Gulp.Sync });
opts.Add(new Option{opt="g>p" , stt=false, act=Gulp.Protocol });
opts.Add(new Option{opt="g>o" , stt=false, act=Gulp.Open });
opts.Add(new Option{opt="gu" , stt=false, act=Gulp.Uglify });
opts.Add(new Option{opt="gr" , stt=false, act=Gulp.Revert });
opts.Add(new Option{opt="gs" , stt=false, act=Gulp.Server });
Expand All @@ -37,9 +38,9 @@ public static void Status(){
g_cnf.Append($"{_cp.gbs.ptc}://");
if (!String.IsNullOrEmpty(_cp.gbs.dmn))
{
g_cnf.Append(_cp.gbs.dmn);
g_cnf.Append($"{_cp.gbs.dmn}/");
}
g_cnf.Append(Flavors.Name(_cp.gbs.flv));
g_cnf.Append(Selector.Name(Selector.Flavor, _cp.gbs.flv));
g_cnf.Append(_cp.gbs.srv);
if (!String.IsNullOrEmpty(_cp.gbs.ipt))
{
Expand All @@ -55,6 +56,7 @@ public static void Status(){
Options.Valid("g>n", Variables.Valid("gp"));
Options.Valid("g>s", Variables.Valid("gp"));
Options.Valid("g>p", Variables.Valid("gp"));
Options.Valid("g>o", Variables.Valid("gp"));
Options.Valid("gu" , Variables.Valid("gp") && !Strings.SomeNullOrEmpty(_cp.spr));
Options.Valid("gr" , Variables.Valid("gp") && !Strings.SomeNullOrEmpty(_cp.spr));
Options.Valid("gs" , Variables.Valid("gp") && _cp.mnu.g_val);
Expand All @@ -75,23 +77,25 @@ public static void Start() {
}

public static void Select() {
Gulp.Check();

Colorify.Default();
Console.Clear();

try
{
Section.Header("GULP SERVER CONFIGURATION");
Section.Header("GULP SERVER");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

$"".fmNewLine();
$"{" [P] Protocol:" , -25}".txtPrimary(); $"{_cp.gbs.ptc}".txtDefault(ct.WriteLine);
$"{" [I] Internal Path:", -25}".txtPrimary(); $"{_cp.gbs.ipt}".txtDefault(ct.WriteLine);
$"{" [D] Dimension:" , -25}".txtPrimary(); $"{_cp.gbs.dmn}".txtDefault(ct.WriteLine);
string g_cnf = Flavors.Name(_cp.gbs.flv);
string g_cnf = Selector.Name(Selector.Flavor, _cp.gbs.flv);
$"{" [F] Flavor:" , -25}".txtPrimary(); $"{g_cnf}".txtDefault(ct.WriteLine);
$"{" [N] Number:" , -25}".txtPrimary(); $"{_cp.gbs.srv}".txtDefault(ct.WriteLine);
$"{" [S] Sync:" , -25}".txtPrimary(); $"{(_cp.gbs.syn ? "Yes" : "No")}".txtDefault(ct.WriteLine);
$"{" [O] Open:" , -25}".txtPrimary(); $"{(_cp.gbs.opn ? "Yes" : "No")}".txtDefault(ct.WriteLine);

$"{"[EMPTY] Exit", 82}".txtDanger(ct.WriteLine);

Expand Down Expand Up @@ -119,7 +123,7 @@ public static void Protocol() {

try
{
Section.Header("GULP SERVER CONFIGURATION > PROTOCOL");
Section.Header("GULP SERVER", "PROTOCOL");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

Expand Down Expand Up @@ -160,7 +164,7 @@ public static void InternalPath() {

try
{
Section.Header("GULP SERVER CONFIGURATION > INTERNAL PATH");
Section.Header("GULP SERVER", "INTERNAL PATH");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

Expand All @@ -176,7 +180,7 @@ public static void InternalPath() {
$"{" Make your choice: ", -25}".txtInfo();
string opt_ipt = Console.ReadLine();
_cp.gbs.ipt = $"{opt_ipt}";

Menu.Status();
Select();
}
Expand All @@ -191,7 +195,7 @@ public static void Dimension() {

try
{
Section.Header("GULP SERVER CONFIGURATION > DIMENSION");
Section.Header("GULP SERVER", "DIMENSION");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

Expand Down Expand Up @@ -248,11 +252,11 @@ public static void Flavor() {

try
{
Section.Header("GULP SERVER CONFIGURATION > FLAVOR");
Section.Header("GULP SERVER", "FLAVOR");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

Flavors.Start();
Selector.Start(Selector.Flavor, "a");

string opt_flv = Console.ReadLine();
opt_flv = opt_flv?.ToLower();
Expand Down Expand Up @@ -288,7 +292,7 @@ public static void Number() {

try
{
Section.Header("GULP SERVER CONFIGURATION > NUMBER");
Section.Header("GULP SERVER", "NUMBER");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

Expand Down Expand Up @@ -324,19 +328,12 @@ public static void Sync() {

try
{
Section.Header("GULP SERVER CONFIGURATION > SYNC");
Section.Header("GULP SERVER", "SYNC");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

$"".fmNewLine();
$" {"Y", 2}] Yes".txtPrimary(ct.WriteLine);
$" {"N", 2}] No".txtPrimary(); $" (Default)".txtInfo(ct.WriteLine);
$"".fmNewLine();
$"{"[EMPTY] Default", 82}".txtInfo(ct.WriteLine);

Section.HorizontalRule();
Selector.Start(Selector.Logical, "n");

$"{" Make your choice: ", -25}".txtInfo();
string opt_syn = Console.ReadLine();
opt_syn = opt_syn?.ToLower();

Expand All @@ -361,6 +358,43 @@ public static void Sync() {
Exceptions.General(Ex.Message);
}
}

public static void Open() {
Colorify.Default();
Console.Clear();

try
{
Section.Header("GULP SERVER", "OPEN");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

Selector.Start(Selector.Logical, "y");

string opt_opn = Console.ReadLine();
opt_opn = opt_opn?.ToLower();

switch (opt_opn)
{
case "y":
case "":
_cp.gbs.opn = true;
break;
case "n":
_cp.gbs.opn = false;
break;
default:
Message.Error();
break;
}

Menu.Status();
Select();
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}

public static void Uglify() {
Colorify.Default();
Expand Down Expand Up @@ -460,13 +494,66 @@ public static void Server() {
_cp.gbs.srv,
_cp.gbs.syn,
_cp.ipl,
_cp.gbs.ptc
_cp.gbs.ptc,
_cp.gbs.opn
);
Menu.Start();
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}

public static void Check(){
try
{
string dirPath = Paths.Combine(Variables.Value("gp"));

if (Directory.Exists(Paths.Combine(dirPath, ".git"))){
Git.CmdFetch(dirPath);
bool updated = Git.CmdStatus(dirPath);
if (!updated){
StringBuilder msg = new StringBuilder();
msg.Append($"There is a new Gulp project version available.");
msg.Append(Environment.NewLine);
msg.Append($" Do you want update it?");
bool update = Message.Confirmation(msg.ToString());
if (update){
Upgrade();
}
}
}
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}

public static void Upgrade() {
Colorify.Default();
Console.Clear();

try
{
Section.Header("GULP SERVER", "UPDATE");
Section.SelectedProject();
Section.CurrentConfiguration(_cp.mnu.g_val, _cp.mnu.g_cnf);

string dirPath = Paths.Combine(Variables.Value("gp"));

$"".fmNewLine();
$" --> Updating...".txtInfo(ct.WriteLine);
Git.CmdPull(dirPath);

Section.HorizontalRule();
Section.Pause();

Menu.Status();
Select();
}
catch (Exception Ex){
Exceptions.General(Ex.Message);
}
}
}
}

0 comments on commit 9123146

Please sign in to comment.