-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to use any template by giving its path #78
Open
T1mL3arn
wants to merge
2
commits into
HaxeFlixel:dev
Choose a base branch
from
T1mL3arn:tpl-patch
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
Usage : template <name> <path> <options> | ||
<name> : The name for the template to generate, the "default" | ||
template will be created when none is specified. | ||
<path> : The name for the path to create the template in, default | ||
is the name of the template itself. | ||
Usage : template <tpl-name | tpl-path> <target-path> <options> | ||
<tpl-name | tpl-path> : | ||
The name or the path of the template to generate. | ||
The "default" template will be created when none is specified. | ||
<target-path> : | ||
The path to create the template in, default is the name | ||
of the template itself. | ||
<options> : The options available will depend on the specific | ||
template's template.json. The default template has options | ||
such as -n for project name and -w -h for width and height. | ||
Eg. flixel tpl -n "Name" -w 680 -h 480 | ||
-ide <subl|fd|idea|vscode|none> : The IDE to use (overrides the configuration). | ||
-ide <subl|fd|idea|vscode|none> : The IDE to use (overrides the configuration). | ||
|
||
Examples : | ||
|
||
flixel tpl -n "Hello World" | ||
Creates a project with name "Hello World" | ||
from the "default" template, | ||
inside "./Hello World" directory. | ||
flixel tpl ./my-game -n MyGame | ||
Creates a project with name "MyGame" | ||
from the "default" template, | ||
inside "./my-game" directory. | ||
flixel tpl ../platformer-template . -n "Marevo" | ||
Creates a project with name "Marevo" | ||
from the template found in "../platformer-template" directory, | ||
inside current directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package commands; | ||
|
||
import FlxTools.IDE; | ||
import haxe.io.Path; | ||
import massive.sys.cmd.Command; | ||
import sys.FileSystem; | ||
import utils.CommandUtils; | ||
import utils.FileSysUtils; | ||
import utils.ProjectUtils; | ||
import utils.TemplateUtils; | ||
|
||
|
@@ -14,6 +16,32 @@ class Template extends Command | |
|
||
override public function execute() | ||
{ | ||
/* | ||
Ways to use `template` command | ||
NOTE: literaly no one on github used "flixel tpl ./<new_dir> | ||
|
||
- tpl | ||
creates "FlxProject" from "default" tpl inside "%cwd/default" dir | ||
- tpl -n MyGame | ||
creates "MyGame" from "default" tpl inside "%cwd/MyGame" dir | ||
- tpl demo | ||
creates "FlxProject" from "demo" tpl inside "%cwd/demo" dir | ||
- tpl demo -n MyGame | ||
creates "MyGame" from "demo" tpl inside "%cwd/MyGame" dir | ||
- tpl ./my-game | ||
creates "FlxProject" from "default" tpl inside "%cwd/my-game" dir | ||
- tpl ./my-game -n MyGame | ||
creates "MyGame" from "default" tpl inside "%cwd/my-game" dir | ||
- tpl demo my-game | ||
creates "FlxProject" from "demo" tpl inside "%cwd/my-game" dir | ||
- tpl demo my-game -n MyGame | ||
creates "MyGame" from "demo" tpl inside "%cwd/MyGame" dir | ||
- tpl ./demo ./../my-game | ||
creates "FlxProject" from "./demo" tpl inside "%cwd/../my-game" dir | ||
- tpl ../demo ./../my-game -n MyGame | ||
creates "MyGame" from "./demo" tpl inside "%cwd/../my-game" dir | ||
*/ | ||
|
||
TemplateUtils.verifyTemplatesLoaded(); | ||
|
||
var targetPath = ""; | ||
|
@@ -30,12 +58,9 @@ class Template extends Command | |
|
||
ideOption = ProjectUtils.resolveIDEChoice(console, autoContinue); | ||
|
||
if (console.getOption("-n") != null) | ||
targetPath = console.getOption("-n"); | ||
|
||
// support a path as an arg without name for default | ||
// flixel t ./<new_directory> <options> | ||
if (templateName.startsWith("./")) | ||
// flixel tpl ./<new_directory> <options> | ||
if (FileSysUtils.isDirectoryPath(templateName) && targetPath == "") | ||
{ | ||
targetPath = templateName; | ||
templateName = ""; | ||
|
@@ -48,11 +73,30 @@ class Template extends Command | |
{ | ||
var template:TemplateProject = TemplateUtils.get(templateName); | ||
|
||
// to fake existence of non-existed templates, | ||
// will be deleted before merge | ||
if (template == null) | ||
{ | ||
trace('template was faked'); | ||
template = { | ||
name: templateName, | ||
path: 'some/path/to/${templateName}', | ||
template: { | ||
replacements: [ | ||
{ | ||
replacement: "FlxProject", | ||
cmdOption: "-n", | ||
pattern: "${PROJECT_NAME}" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
if (template == null) | ||
{ | ||
error("Error getting the template with the name of " | ||
+ templateName | ||
+ " make sure you have installed flixel-templates ('haxelib install flixel-templates')"); | ||
error('Error getting the template with the name of "${templateName}"' | ||
+ "\nMake sure you have installed flixel-templates ('haxelib install flixel-templates')"); | ||
} | ||
else | ||
{ | ||
|
@@ -62,15 +106,27 @@ class Template extends Command | |
// override the template defaults form the command arguments | ||
template = addOptionReplacement(template); | ||
|
||
// try to use project name as target path | ||
if (targetPath == "" && console.getOption('-n') != null) | ||
targetPath = console.getOption('-n'); | ||
|
||
if (targetPath == "") | ||
{ | ||
targetPath = Sys.getCwd() + templateName; | ||
targetPath = Path.join([Sys.getCwd(), templateName]); | ||
} | ||
else if (!targetPath.startsWith("/")) | ||
else if (!Path.isAbsolute(targetPath)) | ||
{ | ||
targetPath = CommandUtils.combine(Sys.getCwd(), CommandUtils.stripPath(targetPath)); | ||
targetPath = Path.join([Sys.getCwd(), targetPath]); | ||
} | ||
|
||
// used for tests, will be deleted before merge | ||
Sys.print('\n--------- | ||
template name: ${template.name} | ||
template path: ${template.path} | ||
target path: $targetPath | ||
project name: ${console.getOption("-n") != null ? console.getOption("-n") : "FlxProject"} | ||
---------\n'); | ||
|
||
if (FileSystem.exists(targetPath)) | ||
{ | ||
Sys.println("Warning::" + targetPath); | ||
|
@@ -79,7 +135,7 @@ class Template extends Command | |
|
||
if (!autoContinue) | ||
{ | ||
answer = CommandUtils.askYN("Directory exists - do you want to delete it first?"); | ||
answer = CommandUtils.askYN("Directory exists - do you want to delete it first? Type . to abort."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add |
||
} | ||
|
||
if (answer == Answer.Yes) | ||
|
@@ -94,6 +150,11 @@ class Template extends Command | |
exit(); | ||
} | ||
} | ||
else if (answer == null) | ||
{ | ||
Sys.println("Aborted by user"); | ||
exit(); | ||
} | ||
} | ||
|
||
Sys.println('Copying template files...'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This properly determines if tools are run by
haxelib
. During tests of this patch I run the tools directly byneko run.n
, and withoutHAXELIB_RUN
var check there is a bug when last.
argument passed to the tools is ignored. See massive-oss/mlib/pull/25