Skip to content

Commit

Permalink
add capability to set to Fano specific release tag
Browse files Browse the repository at this point in the history
  • Loading branch information
zamronypj committed Aug 18, 2020
1 parent 5d08e91 commit 76f257b
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 54 deletions.
58 changes: 58 additions & 0 deletions src/Tasks/Implementations/Project/Core/AddFanoRepoTaskImpl.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
(*!------------------------------------------------------------
* Fano CLI Application (https://fanoframework.github.io)
*
* @link https://github.com/fanoframework/fano-cli
* @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara
* @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT)
*------------------------------------------------------------- *)
unit AddFanoRepoTaskImpl;

interface

{$MODE OBJFPC}
{$H+}

uses

TaskOptionsIntf,
TaskIntf,
BaseGitRepoTaskImpl;

type

(*!--------------------------------------
* Task that add fano web framework git repository
* as submodule
*
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
*---------------------------------------*)
TAddFanoRepoTask = class(TBaseGitRepoTask)
public
function run(
const opt : ITaskOptions;
const longOpt : shortstring
) : ITask; override;
end;

implementation

uses

sysutils;

function TAddFanoRepoTask.run(
const opt : ITaskOptions;
const longOpt : shortstring
) : ITask;
var outputString : string;
begin
//need to call parent run() so baseDirectory can be initialized
inherited run(opt, longOpt);

// following line equals calling following command on shell
// $ git submodule add fano_repo_url vendor/fano
runGit(baseDirectory, ['submodule', 'add', FANO_REPO, 'vendor/fano'], outputString);
writeln(outputString);
result := self;
end;
end.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
(*!------------------------------------------------------------
* Fano CLI Application (https://fanoframework.github.io)
*
* @link https://github.com/fanoframework/fano-cli
* @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara
* @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT)
*------------------------------------------------------------- *)
unit CheckoutFanoRepoTaskImpl;

interface

{$MODE OBJFPC}
{$H+}

uses

TaskOptionsIntf,
TaskIntf,
BaseGitRepoTaskImpl;

type

(*!--------------------------------------
* Task that checkout fano web framework
* to a specific release version
*
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
*---------------------------------------*)
TCheckoutFanoRepoTask = class(TBaseGitRepoTask)
public
function run(
const opt : ITaskOptions;
const longOpt : shortstring
) : ITask; override;
end;

implementation

uses

sysutils;

function TCheckoutFanoRepoTask.run(
const opt : ITaskOptions;
const longOpt : shortstring
) : ITask;
var outputString : string;
branch, fanoAbsDir : string;
begin
//need to call parent run() so baseDirectory can be initialized
inherited run(opt, longOpt);

if opt.hasOption('fano-ver') then
begin
branch := opt.getOptionValueDef('fano-ver', 'master');
fanoAbsDir := getCurrentDir() + '/' + baseDirectory + '/vendor/fano';
// following line equals calling following command on shell
// $ cd vendor/fano
// $ git checkout [[tag/branch]]
runGit(fanoAbsDir, ['checkout', branch ], outputString);
if (branch <> 'master') then
begin
runGit(fanoAbsDir, ['checkout', '-b', 'fano-' + branch ], outputString);
end;
writeln(outputString);
end;
result := self;
end;
end.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ implementation
EmptyDirCheckTaskImpl,
CompositeSessionTaskImpl,
WithGitRepoTaskImpl,
WithGitInitialCommitTaskImpl;
WithGitInitialCommitTaskImpl,
GroupTaskImpl,
AddFanoRepoTaskImpl,
CheckoutFanoRepoTaskImpl,
StageRepoTaskImpl;

constructor TCreateProjectTaskFactory.create(
const depFactory : ITaskFactory;
Expand Down Expand Up @@ -91,11 +95,15 @@ implementation
TCreateAdditionalFilesTask.create(textFileCreator, contentModifier),
fBootstrapTaskFactory.build(),
TWithGitRepoTask.create(
TInitGitRepoTask.create(
TGroupTask.create([
TInitGitRepoTask.create(),
TAddFanoRepoTask.create(),
TCheckoutFanoRepoTask.create(),
TStageRepoTask.create(),
TWithGitInitialCommitTask.create(
TCommitGitRepoTask.create()
)
)
])
)
);
end;
Expand Down
55 changes: 7 additions & 48 deletions src/Tasks/Implementations/Project/Core/InitGitRepoTaskImpl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ interface
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
*---------------------------------------*)
TInitGitRepoTask = class(TBaseGitRepoTask)
private
commitRepoTask : ITask;
procedure initGitRepository(const baseDir : string);
procedure addFanoRepository(const baseDir : string);
procedure stageFileToRepository(const baseDir : string);
public
constructor create(const commitRepo : ITask);
destructor destroy(); override;

function run(
const opt : ITaskOptions;
const longOpt : shortstring
Expand All @@ -48,53 +40,20 @@ implementation

sysutils;


constructor TInitGitRepoTask.create(const commitRepo : ITask);
begin
commitRepoTask := commitRepo;
end;

destructor TInitGitRepoTask.destroy();
begin
inherited destroy();
commitRepoTask := nil;
end;

procedure TInitGitRepoTask.initGitRepository(const baseDir : string);
var outputString : string;
begin
///$ git init
runGit(baseDir, ['init'], outputString);
writeln(outputString);
end;

procedure TInitGitRepoTask.addFanoRepository(const baseDir : string);
var outputString : string;
begin
///$ git submodule add fano_repo_url vendor/fano
runGit(baseDir, ['submodule', 'add', FANO_REPO, 'vendor/fano'], outputString);
writeln(outputString);
end;

procedure TInitGitRepoTask.stageFileToRepository(const baseDir : string);
var outputString : string;
begin
///$ git add .
runGit(baseDir, ['add', '.'], outputString);
writeln(outputString);
end;

function TInitGitRepoTask.run(
const opt : ITaskOptions;
const longOpt : shortstring
) : ITask;
var outputString : string;
begin
//need to call parent run() so baseDirectory can be initialized
inherited run(opt, longOpt);
initGitRepository(baseDirectory);
addFanoRepository(baseDirectory);
stageFileToRepository(baseDirectory);
commitRepoTask.run(opt, longOpt);

//following line equals calling following command on shell
// $ git init
runGit(baseDirectory, ['init'], outputString);
writeln(outputString);

result := self;
end;
end.
59 changes: 59 additions & 0 deletions src/Tasks/Implementations/Project/Core/StageRepoTaskImpl.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(*!------------------------------------------------------------
* Fano CLI Application (https://fanoframework.github.io)
*
* @link https://github.com/fanoframework/fano-cli
* @copyright Copyright (c) 2018 - 2020 Zamrony P. Juhara
* @license https://github.com/fanoframework/fano-cli/blob/master/LICENSE (MIT)
*------------------------------------------------------------- *)
unit StageRepoTaskImpl;

interface

{$MODE OBJFPC}
{$H+}

uses

TaskOptionsIntf,
TaskIntf,
BaseGitRepoTaskImpl;

type

(*!--------------------------------------
* Task that stage new files so it is
*ready for commit
*
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
*---------------------------------------*)
TStageRepoTask = class(TBaseGitRepoTask)
public
function run(
const opt : ITaskOptions;
const longOpt : shortstring
) : ITask; override;
end;

implementation

uses

sysutils;

function TStageRepoTask.run(
const opt : ITaskOptions;
const longOpt : shortstring
) : ITask;
var outputString : string;
begin
//need to call parent run() so baseDirectory can be initialized
inherited run(opt, longOpt);

// following line equals calling following command on shell
// $ git add .
runGit(baseDirectory, ['add', '.'], outputString);
writeln(outputString);

result := self;
end;
end.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ implementation
CommitGitRepoTaskImpl,
CreateProjectTaskImpl,
WithGitRepoTaskImpl,
WithGitInitialCommitTaskImpl;
WithGitInitialCommitTaskImpl,
AddFanoRepoTaskImpl,
CheckoutFanoRepoTaskImpl,
StageRepoTaskImpl,
GroupTaskImpl;

constructor TCreateDaemonProjectTaskFactory.create(
const depFactory : ITaskFactory;
Expand All @@ -80,11 +84,15 @@ implementation
TCreateAdditionalFilesTask.create(textFileCreator, contentModifier),
fBootstrapTaskFactory.build(),
TWithGitRepoTask.create(
TInitGitRepoTask.create(
TGroupTask.create([
TInitGitRepoTask.create(),
TAddFanoRepoTask.create(),
TCheckoutFanoRepoTask.create(),
TStageRepoTask.create(),
TWithGitInitialCommitTask.create(
TCommitGitRepoTask.create()
)
)
])
)
);
end;
Expand Down

0 comments on commit 76f257b

Please sign in to comment.