-
Notifications
You must be signed in to change notification settings - Fork 18
Allow to use any template by giving its path #78
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
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,25 @@ | ||
| Usage : template <name> <path> <options> | ||
| <name> : The name for the template to generate, the "default" | ||
| template will be created when none is specified. | ||
| <name> : The name or the path for the template to generate. | ||
| The "default" template will be created when none is specified. | ||
T1mL3arn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <path> : The name for the path to create the template in, default | ||
| is the name of the template itself. | ||
T1mL3arn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,12 @@ class FlxTools extends CommandLineRunner | |
| displayInfo(); | ||
| } | ||
|
|
||
| override public function createConsole() | ||
| { | ||
| final isHaxelibRun = Sys.getEnv('HAXELIB_RUN') != null; | ||
| return new massive.sys.cmd.Console(isHaxelibRun); | ||
| } | ||
|
|
||
|
Member
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. What is this?
Author
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. This properly determines if tools are run by |
||
| static function displayInfo() | ||
| { | ||
| displayLogo(); | ||
|
|
||
| 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."); | ||
|
Author
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...'); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.