Adding presets to the Laravel install process | Re-building Lambo | Matt Stauffer Livestream

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] all right what's up friends all right as usual let's check to make sure the tweets went out let's check to make sure my audio is going everything looks go so good so far all right tweet went out audio looks like it's working the video looks like it's working audio check audio check audio check got episode notes we know what we're doing and there's a lot on our plate right now so why don't we get going with it I don't think we have time to waste because this is a pretty big pretty big project we have in our hands and I don't think we're gonna get it done in this amount of time so let's let's run with it also thanks for watching yeah thank you I like my shirt I'm guessing BLT one is well in a place that's definitely love the dirt PDW oh sure thanks so one quick note for all of you all I am almost done with writing my blog post getting everybody introduct introduced to how to do streaming I've been working on that for the last few evenings it's got a lot going on here so to keep keep looking out for it this is possibly even longer than my last one so cool what are we doing today we're working with a tool called Lambeau if you're not familiar with Lambeau Lambeau is a wrapper around the lair rail installer and it does things like run the lair installer initialize to get repo allowed you to add different presets and stuff like that or well to toggle particular flags that are gonna turn certain things on or off and in the past anytime somebody wanted to add something we had to really decide is this worth adding a whole command line flag just for that one thing and so we've had we actually have a an issue open a pull request open it was unfortunately opened right around the time when we were deciding this which to PHP which is crazy because that's three years ago to add presets and we had this big suite of conversations around how to use them so you might kind of come back over here in a bit to see what the syntax was that we ended up with but this is what we were looking like right there recipes space you know and then come up space list of the recipes you wanted to apply and so we're doing that same thing here it's funny because I think I'm the one who called it recipes now that I look at it but I kind of think I prefer presets because that's what my brain has been thinking and I Presets makes more a little more sense so Jeff Finley wonderfully built this thing and it's not gonna be useful anymore because this is in the old shell bash version but basically what his version did was it looks for a shell script in your recipes directory and if that exists with anyone that recipe if that existed that runs it so that one was pretty simple we're gonna build a more complicated one John says if you were here for our last stream John said it was we were having trouble figuring out how to spin up them from within PHP process and he sell it says he figured out oh my gosh you guys I didn't switch I'm sitting here clicking through this whole repo and it's I should just start showing screen because I do this every friggin time sorry y'all there's a presets thing that I've been scrolling through this whole time showing y'all but it's okay because there wasn't much you missed it was all shell scripts and so all it did was kind of open up a shell script with the name of the recipe you wanted to run so it's similar to what we're doing so here's what I'm imagining I'm imagining that we both have a suite of presets that we have built in but the ability also for people to thanks the ability we have the ability for people to publish their own to customize their own locally and publish their own that other people can use which is going to be interesting so the biggest question I have there is what does thanks Len the biggest I should have there is what does it look like for people to publish it do they have to publish an entire package just for a single preset do they have maybe published one package that has a bunch of presets in it do people have to bring them in with packages tis there another way to do it and does it make sense for me to take responsibility for the lambo presets either repo or a whole new organization called lambo presets I've been thinking about that a lot and I actually don't know the answer so what I'm gonna hope to do is build it where we just build the basic ones now and hopefully as we think about it and as you all think about those questions I just asked we can figure out the solution to what does what's the best way to make it possible for people to have priests premade presets personal only on my machine presets and presets that other people in the community can publish but for now let's just build the functionality so let's add that as a decide later finish updating Docs for the alpha you know what else this PHP version is still called the alpha and so one thing I need to do is get more people try this alpha so we can release it because right now the readme is for the old one because most people won't be using this new PHP version so we really should figure that out release alpha to beta ask for input and then decide how third-party presets will be provided good morning Sherwin in case anybody didn't know I put it up on Twitter that this is my first ever self haircut where I don't so in college I but I literally just just kind of buzzed it and so um I literally put on like a 1 and just did my whole hat this is my first time ever giving myself a fade John asks of the presets gonna be shell or PHP I don't know but I'm kind of leaning towards PHP because I had an interesting idea so let's go take a look okay well I had an interesting idea where we would build structures around the the shell things but so for example the tongue close could your barber I've been cutting my my son's hair for ages so okay so sorry I was thinking presets so I was thinking that it's possible we could build like a structure so let me show you all what I was thinking about this first okay so I was imagining we could build a structure where you have like a PHP class and I think it may be just too complicated you know something like telescope preset extends you know maybe lambo slash preset or something like that right and I think this may be overly complicated and we might just need to do it as a shell script instead but I'm not sure and so I was thinking that first of all there could be like a execute or something like that or a run but then there also could be some things that are handing that is always H and I'm not sure what theme it is so I was thinking that there's something here that could I know there's a bang editor that works on twitch but I don't know if it works in Oh what just happened oh yeah I don't have my um my theme there okay so I'll tell you my theme in just a second remind me once I finished getting this idea and this thought out I've got a Mitch okay so I was thinking one thing we could do is have something like compose or packages and the question here is is there any benefit for doing it this way versus is there any benefit that people would get Unser's there's benefit for you have ideas but there's any testing or usefulness that we can do here or extension or whatever that we can do here that was more beneficial than literally just doing a shell script where you run a bunch of commands so if you could imagine the lambo preset in this context like the parent one would do would would have like a so we'd have to figure out some way where this would always run its parent so they would probably I don't want to have to require if we were to do this I wouldn't have to want to have to require people to do this like this so we would probably have it do something like you know basically lambo itself would always run like a before method here or something like that and then so lambo itself it was running a preset it would be preset equals a new telescope preset and then preset before and then preset run and then preset after something like that I was thinking this was how it would work and I just don't know if this is overkill oh my goodness baby thank you so much for hosting the stream when they're spiking this composer package we need to also do installation steps after the modes required like telescope oh that is a fantastic point although even if that were the case we could build those steps into run but the big question for me is is there benefit benefit to doing this versus just doing it come on having one look like this you know and just and then you know whatever the other steps here so on the one hand this one in the right is so much simpler than this one on the left and on the other hand yeah well honestly John that could run in preset in that in the run instead it would even have to be an after on the other hand I kind of like this because I feel like building it with structure has the ability for us to potentially come up with other creative things were doing later but I don't know so I've been thinking about this a lot and I honestly don't know so I'm I'm probably gonna do this right here because let's say someone wanted to do like find and replace and that kind of stuff I think that most people who live in laravel world would be more prepared to do more complicated things like find and replace whatever in PHP than they would in bash and if they were building those more complicated things and they wanted to test them and be a lot easier in PHP you know what I think I just talked myself into doing it this way so this is what we're gonna do so let's go figure out where it would most make sense for this to be I think come to put it in presets yeah is the wrong comment thanks Ari's I knew that but I just didn't want to take the time to figure okay so we're gonna have a base preset and it's gonna be so namespace what is the namespace for these is it lambo its app okay and then class abstract class base preset and so this is gonna have public function so I guess a preset doesn't have to have well okay there we go public function before and after and we'll do this to make them extensible their public so that an individual preset can decide to override before and after an extended or whatever I don't know why I would do that but there's not going to hurt us and then we've got an abstract public function run we're also probably to want to help her so one of the things I had mentioned in my goals here is that I would love for them to potentially take parameters so one thing I would love input from you all is is this a simple enough thing for parameters ooh you know what if we're allowing comma separated parameters then the presets have to be separated by something that in commas oof that's tough hmm maybe we do this I'm not sure using the PHP you can make meta presets yeah I agree what's the mostly Ravalli way to allow a list of things each of which can take potentially multiple parameters I'm thinking like middleware groups like route middleware that take parameters magic it's the best way somebody followed but it's not telling me who no because I don't have OBS open oh okay I have it's because I have something in front of it because Bogdanovich was asking me what which theme I'm using so let me actually add myself a note that says add I term oh my zhs and oh my za / gz h s theme info - bang editor and update bang editor or BS code thanks so much Debbie I also AM probably switching to PHP storm soon just so you'll know okay let me look at my theme real quick it's D stuffed T that is D stuff T theme okay so let's get out of here and then I'm gonna come back in to obs so now next time somebody follows me I actually can see it is yeah I did some massive reef actors in that ATL family meal thing that even with V s code was just it just took away too long and I knew that in phpstorm it would be faster I used to be a phpstorm addict until it started getting really really really slow but I've got a fast iMac now I'm at least it with the office so I'll probably switch to that I probably won't switch to that until this stay-at-home shelter at home is over though I'm in the office now but I'm gonna be taking my I'm not going to take my camera home but I'm gonna take my nice mic home so I can do my streams from there I know because most excited if I could set up github actions that is interesting maybe we could do that okay so let's look what I was thinking about is what's the best syntax so if you are going to define a whole bunch of route middlewares each of which take parameters what or how do you find them some middleware quotes so it's I think they're probably in quotes thanks for all this with you I have not done github actions yet it's actually a to-do list item for me do you configure github actions purely in a file that's in the repo or do you have to push them up in they low good vibes I'm from Tanzania what do you think it's good way to earn money from third world country that's great oh if it's a file in the repo we could definitely do that I love that idea thanks for saying hi lilo that's a great question that I couldn't answer now for sure thank you so much Chris Pitts you wonderful human being laravel thank you so much Debbie laravel route parameters oh no route middleware parameters that's what I want I love how we're still getting a 5.6 Doc's there I don't think stack is gonna be my most useful way oh okay so it used well hold on but how would you handle if there's multiple min or whaler in there thank you so much fami grab this and then add github actions preset inspired by a bee thank you so much my friend does anybody know this the passing multiple middleware with multiple parameter which have parameters what the way is to do that I just really want to use the weight I don't care about this okay you know what we're gonna come back to middleware and we're gonna go up to the latest Docs and save just in case middleware parameters okay role : editor man hey James I don't want to lose my whole time on just trying to figure out this one thing I definitely should have done that ahead of time all right gonna switch to evil Google no this is the docs were already there Wow middleware is one of those words that looks really weird passing parameters middle area level five one let's see if I cover that idea ah so this is the thing if you have a middleware with multiple parameters you pass them as commas so I'm assuming that if we do that it probably would have to be something else in between the middle layers probably like a pipe so I'm just gonna do a pipe for now even though I don't really love a pipe because I'm not sure how else to handle it and then know if somebody else has a better idea please tell me because I don't like this idea using the pipe rammer you can do command : yeah that's exactly what I was thinking I just don't like the pipe as much as I like commas and I think more people will be using them without presets than with presets so I kind of don't like forcing the majority of people to use a syntax that I don't like but I don't know how often handle it honestly so I think this is what we're stuck with because the alternative would be using pipes to different to differentiate that the parameters and I think that's very confusing couldn't use semicolon I actually originally thought about semicolon but I'm worried that semicolon is so similar to comma that it's gonna people aren't gonna remember to get it right so I do kind of think that pipe is better than semicolon just because it differentiates it a little bit better okay so let's I don't think it would terminate a command okay let's focus Matt and imagine that we're gonna build this so we need a preset not action but a preset option do we have a short of P I think we do yep path so we can't do a short on presets so I'm gonna put presets right next to paths so nobody ever accidentally comes back and tries to add a short of P and then we have a double so presets per am description equals and this is going to be call presets all right and so let's see do I have everything ready for these tests actually run correctly no I don't this is because I don't have my sequel on this this one so we said in our last stream we were going to fix tests to not fail on my sequel missing machines that was definitely to do in our last one so I definitely didn't get back to our two dues all right um so um class config does not exist and that is surprising to me John have you seen that one yeah this is definitely it's a lot for me to do this why am I getting that um oops cuz I want to not be breaking tests here but I also did not think to run the test before the stream class config does not exist and then we're getting a dot and error down somewhere else okay man y'all you know what I kind of really quickly want to fix these tests to run so I'm sorry but we're gonna do create database test and then it's called the method is why am I not seeing the method anywhere oh it creates in my sequel database and it throws an exception it creates a my sequel database and then this right here you know what for right now I'm just gonna say a mark test skipped Matt doesn't have my sequel installed locally and hopefully I won't ever actually merge this and then we can fix that another time and then what was the other one is it throws an exception if database creation fails again we'll deal with that later Marissa says class config does not exist whenever I can't connect to the database interesting John says mark test skipped I think that was exactly what I just said Deacon fit yeah okay that's totally oh yeah great so you're handling that one night right now so I'm actually gonna take it out of our two dues because John's fixing already thanks John okay so it looks like we're good so I think you are right Merced that was the problem all right folks so let's go back here and now let's do Lambo and see if we see our presets as a preset yep - - presets equals a : 1 2 pipe so this shows how to pass parameters and it also shows how to pass multiple presets call preset and I think I want to go into options and say call presets with optionally with parameters okay so now we want to go into the thing and actually make it that when you do that option it runs that so we will need to write a test for this but I don't know exactly how it's gonna work yet so this is gonna be test after test new project our new presets now write tests I can't write the tests when I don't know exactly I'm going to be testing okay so hmm where does it happen okay this is test we're not looking at tests right now I'm trying to remember where the primary action oh it's gonna be in command the new command okay so new command runs all the things here so what we're gonna do is allow the presets to run thanks for following DC blog so I think it's just gonna be like this run presets which doesn't exist yet so we can't import it so I should have created the action first-run presets run yeah I think run Oh el PHP I just realized I did not eat anything I was real I'm like I'm typoing because I'm shaking I'm shaking because I forgot to eat awesome I might turn off my video while I eat but for now let's see how far I can make it I literally had a thing in my um remove the brackets team that will be mad oh that's not a new that's a or did I put new somewhere else oh sheesh that's class I don't need that what's mukbang okay so run presets it's an action and what do they need to have they need to have a surprising amount of stuff actually we have this Lambo action thing and then interacts with Lambo config I don't yeah probably well actually there's Lambo action in here and that's why it's not being ported yeah okay cool and we'll we need the shell probably well actually I don't know if we'll need the shell let's blow it out until we know we need it thank you so much Chris I'm glad you like the shirt Len says to eat a snack first yeah literally oh mukbang yeah I remember that yeah my wife told me about that let's um it's actually really quickly go here go to my template the things I do before the checklist and ten minutes before eat a snack there now everyone in the future will have that in my to-do list because I'm when I get hungry I my brain stops really functioning very well I've blood sugar sensitivity so I'll eat in a sec okay run presets with invoke okay so right now let's just say presets yay oh except you know what I want it to run right now right at the top also I should probably import that so that we're not like creating things 10,000 times we're doing this whole like not doing TDD I don't TDD with CLI it I'm not there yet so right now all its gonna do is set the config and run the presets and then we're gonna exit here not creating real apps right now okay cool so if I were to do lambo presets equals and let's actually just go grab this right here parameters um oh my goodness yeah we're there okay eating in a second Lambo pre my project oh except it's gonna be new let's fix that all right so that's right there oh that pipe being highlighted a different color yep we can't use pipes because it's command line so if we were to use pipes we would have to surround the whole thing in quotes because otherwise it's gonna be piping all this in tune Nova duh Matt so let's try it with semicolons thanks sure and if we don't like that then we'll have to surround the whole thing in quotes so let's try this right here use a slash did you disable channel points I don't know what channel points are so I didn't disable them on purpose if I did nope semicolon is also must be a special thing so I think we're gonna I don't want to have to make them put them in quotes slash instead of a pipe like like that that that to me looks like de f / Nova yeah semicolon Z no no command I totally forgot about that man this is tough mmm still feels like a directory to me it kind of feels like we have to do quotes right now poop emoji time semicolon is that right there it's like bang bang but right now semicolon is the thing that's defining like the difference between the project itself and then its parameters and I think that semicolon definitely makes the most sense there so this is what we can do right now as much fun as poop emojis would be sorry for anybody who has trouble with hearing people I just was not functioning well hmm as much as I like the creativity I think that's a very non standard for how PHP projects normally do things sashing so I thank you I think it's a great idea but I don't think we're gonna be able to do it all right wait operation with the shortcut NRT exists we fixed that ages ago and I'm almost a 100% sure that I pulled the latest from master and then branched mes presets off of it rebuild on March 28 rebuild on March 28th why are we still having that problem what on earth how are we possibly still having that in problem yeah there's no N how on earth did we get that error an option with shortcut n aren't exists oh yeah you got a type dot slash beforehand so won't we're because that's running the global one which had that problem I'm gonna do hmm John that's kind of interesting it's very PHP II thanks real hot to many arguments expect the arguments command project name oh that presets got shrunk down into M - hmm okay so the parens is interesting I would do commas between them not colons but nope this one still feels more right but very creative alright let's let's write some code yeah all right so I'm now trying to remember it's been a while where do we get the stuff that was passed in we've got app mm and this is oh my Z show John do you remember me and I should it's it's crazy me how quickly this is all left my brain I want to pull in this presets thing do we pull it into configs maybe we probably put it into config yeah all right so we're gonna have a new one called presets and then we'll set a preset in here I guess we have a getter for every one of them so get three sets um we just not a boolean option value do we have get other option values got get option values but I don't think they're gonna be defined the same something presets it's going to be its own so let's take a look at get option value probably gonna copy it and then make our own thing I just started working with literatures and I'm not sure if I'm gonna stick with them or not so alright so this is gonna be I'm just gonna call it get preset value I don't think anything else is gonna be structured the same does it get presets where'd I name it get presets it's taking my brain a while to kind of get in this space so please forgive me everybody okay there we go so now we want to split it out by pipes so presets equals that and then we can just split it by pipes so explode pipe that and then for each presets as preset then we need to explode it into its uhm into its parameters I was sunny I was thinking about multiple preset things I think it's clean the problem is I think it's gonna take a lot more work for people to type which I don't love very much so Oh John says we sign the raw raw value and process it in the command interesting okay so then we can just use get option value right so let's pull this out I trust you because you wrote this John so you tell me to do that that's what I'm gonna do all right so I'm gonna do get option value presets all right so now we have access to that and config lambo dot store dot presets so now let's go into our run presets and it makes sense because we can test it in here better so I like that Thanks ligatures are when you do something like this and your font joins them together into a single one as it just mean has no sound I hope it's just you it says I have sound so I think it might just be Modesto but other people can tell me if they came here okay cool great alright so what we want to do is [Music] all right and then presets why is that an error should be no calls to doesn't um yeah I know that all right presets ei wait I thought no okay there we go so okay so I'm leaning in this direction for now - - P equals preset : params oof that's even worse though oh yeah the thing is the convention here is that if you are passing two hyphens then you're gonna get the full name and if you're passing one - you're gonna get the short name just like is always the case in most links things the problem is we already have one with the - P and so getting rid of that would be a little bit of a breaking change so yeah exactly Lynne okay so great so telescope : a DF so now we have to be able to track roof it's almost like there's a we need a class to represent a preset but for now I'm just gonna build all mature of race and John will laugh to hear that because we've been talking a lot about data structures lately alright so we have two types of presets those with and those without parameters so parameters equals string after that doesn't know string phpstorm but no string use gloom up what I just do illuminate support STR alright so now do you know after yep and what are my parameters subject and search so the subjects gonna be the preset and then the search is gonna be a colon and then I will explode that by commas and then hopefully at that point we now have up and then the preset name equals stir before preset comma and I got to make sure that if you don't pass parameters that doesn't break hundred messages today for me scream trap yay alright so we got our parameters correctly we got our command correctly now let's make sure we do that on one that doesn't it only has one parameter yep and then let's make sure it works for one that has no parameters and probably won't I'll probably have to set its default to an empty array yep exactly alright so the preset name worked correctly but the after didn't work correctly because if we don't have : I don't want it be ready to be telescope I want the array to be empty so there's probably a clever way to do this but the simplest thing to do would be if string contains haystack needles so that's gonna be preset and a colon then do it this way I think there's got to be a clever way to do this but for now we're just gonna do it like this and then else parameters is that and you know we can actually do that without else which is a little bit cleaner and I'm a little bit loath to wrap this all in this but I think I'm gonna do it anyway and then if I regret it later good okay so now that we're working just with this particular class I actually am interested in testing it which is why John said we should do in that test in that class so thank you so much John for your thoughtfulness there so I want to see one that's relatively simpler simple and make a test just like it um all right let's duplicate this one and we're gonna call it run presets tests because I'm doing this thing where you know I'm passing all these different parameters in let's just let's instead write a test for it okay so what we're saying is run presets test and our first method is going to be it parses current multiple parameters all right so we want to set our Lambo at startup presets to be equivalent to what was passed in which is going to be telescope : ABCDE F and then we're gonna run our run presets actually we're not gonna run it we're gonna we may end up being dependencies later as well well actually keep it like that so we create it and then this assert equals telescope action so what do our methods here presets pass okay so presets passed okay so we want to make sure there's only one preset past we want to make sure that so what's the structure that's going to look like it's going to be probably a key with array yep so it's gonna be an array a single array well no how do we want to structure that probably a key and parameters I think that's we're gonna our preset in parameter so I think I think we're gonna structure this as an array I think so so reset past equals reset presets past and then we want to assert that there's one preset past and then on the preset that's passed we want to assert that that preset passed let's just make them standard class objects like we're talking about before John and see how we feel about that so preset and then what version of lambo is using on its own our laravel it's their laravel zero six so that I've seen that's label six as well alright and then we want to make assertions against the parameters assert equals or no assert count to preset past parameters I think that's how we're gonna name it and then I don't know if we get we're able to do this this would I think we need to do it can contains yep ABC preset passed parameters [Music] and then DF right whoof or daimond dumping of course so let's build our thing here we do our good old build a temporary thing and then convert it to a collection later so let's build our temporary thing and then turn it in convection collection once it passes our tests so each of these are going to be returned an array with preset being preset name and then parameters being parameters okay so first let's just make sure this works trying to get Oh cuz it's not an object haha great that one works so now let's write the rest of our tests really quickly and then we can refactor it and then maybe we can get these presets actually doing something I'd love to at least create our first preset in the next 16 minutes unfortunately I have a call at 15 after so I can't go a little too long a path it parses a single parameter so this is gonna be sort of count 1 and it's gonna have ABC rate now we want to parse parameters when parses parameters with when multiple presets okay so telescope ABCDEF actually know let's start with it handles multiple presets all right so what we want to do is run assertions on each of them so the first one is going to be first preset and then [Music] okay and then the second one is gonna be Nova and then let's try it great and then what was the other thing I wanted to test I mean maybe that's enough for now we can handle all we could try a whole bunch of different configurations you know what we should at least make sure it handles the most complicated situations all right so it's gonna look more like the first one so let's just copy this one all right so we want to presets and here we're actually going to copy this more just kidding first preset second preset telescope Nova but in these they're gonna have two parameters and then we're going to assert contains and then parameter 1 and then parameter 2 and then parameter 3 and then change the name and then run tests OOP I suspect in function I'm sorry missed a semicolon in oh I missed a closing brace all right great we have tests around these now let's do a quick refactor and see if we can get them actually working so this is Adam Levin our refactoring the collection style I know I'm gonna head up but I like to do it one step at a time especially on streams all right so the first thing we're doing is map we're wrapping that array in a collection so we can now map it and for each of them we return what we want it to be set to be and so that should still work but then you notice we've got some duplication here we're returning this to array why don't we just do that return Presets map to array this is why tests are so great and then you say huh now this might make it too long so it's actually possible that we can't do this but I'd often like to do this how long is that that's column 94 so I like to keep everything between 1820 I think that's PSR 2 that says that so this is a little bit long but I don't know if I'm that mad about it and I want to see one last thing to see if there's a little bit of a there any cool reef actors we can do in here really quickly be calm I keep wanting to make this a turnery but it would make it too long there's gotta be a cleaner way to do this though I wish there was like some kind of after with a default or whatever you know these new lines new lines before the question mark in the Coleman turnery yeah so um I'm not sure if I like that but let's just try it parameters equals stir contains blah blah blah blah blah no maybe that it's better not sure instead of checking string contains : why not just apply explode because we'd still have to check if there's a second thing and if there's a no second thing we're still in we still end up in that same situation I think because I think in that point we still end up with something like parameters equals explode by a colon preset and then your your preset becomes for reset parameters and then let's see yeah maybe that works and then I think it's the same condition although oops this is um we're just gonna do this preset equals log preset preset and then so we know the first this is a little bit more obtuse so I kind of don't think I want to go in this direction thanks for falling brutal deluxe Oh nein hmm let me just try typing it and see if I like it so what we need to now do is say parameters equals and we're gonna be in that same kind of ternary that I fry it so we're just doing a different thing which is let's see count preset is greater than one if so then parameters is equal to preset it's really just that it's in the end we still kind of have actually have more code this way and I think it's less easy to follow so let's go back to but good idea good thinking on that let's go back to what do we have here and he goes this yay tests all right we're just gonna keep it with this this is it for now I um so we've now saved our presets each of these presets are gonna be standard class object there's gonna be array of standard class objects with preset and parameters and this is where you start asking a question of should this be a dto should we be doc locking it and the cotton answer is sometimes maybe hey crash 358 thanks for hanging out and falling out following following along and following okay so now once you invoke it we want to do something with each of the presets so for each this presets as preset now it's the goodies this is what we actually want to do so we need to figure out the structure that we're gonna use for presets so for right now I think what I want to do is have a loops presets directory called pre-made or something like that and then just create a min here so I'm gonna make one named telescope dot php' it's gonna be named space app presets a premade class telescope extends bass preset okay so it's gonna need to have a run method and then if we do it with that composer II way which I was talking about which I'm still not sure about you know else I'll also do this and maybe this starts becoming even more useful shell scripts well it's really gonna be shallow commands and so I think what we're gonna do hard part is should the shell commands be run before or after we might need both right it's starting to get a little bit janky but let's let's try this and see what we think all right so for each this before Shou commands as shell command and then this executes shell command [Music] oops and John I'm gonna be relying on you a little bit for what to write here so if you could kind of get your brain ready with what this execute shell command method it's gonna look like most simply I know we're gonna create a process and run it but I'm making all of these public because I don't really care I could make them protected I definitely want them to be extensible so I definitely don't want them private but for now I'm just gonna make them public because what they add the shell class and the constructor okay so let's do our constructor um so where do I want I'll probably put it here would be easy to have presets call other presets - that's an interesting idea maybe we could do something like presets preset dependencies or something like that that's a very interesting idea okay that base class thing should be ordered oh great Timlin has an opinion trait use public static property protected static property oh because it's protected so it has to go after the public's public all right so execute shell command is gonna be this shell thanks John exact in project what's the difference mean project and route I know I'm the one who originally planned that so exact in route runs on route ok what's the route path versus the project path blind Cuervo thanks for following oh I think route path is where you are running it from and project path is the directory I don't think I want anybody running anything in the route path and honestly we have to be very careful with these because we have to worry about people's safety when people have shell access to their machines so audit custom commands for safety and also put notices everywhere okay so I think we're relatively good there let's build out our telescope one and see how it feels so telescope reset right here it extends bass preset so it's got a run method telescope is I don't know if it has any install steps does it oh it probably does actually oops telescope so we definitely are gonna have a require it's gonna be whatever they're the recommended option is which is interesting because this will be different depending ono because it's always between the newest version of telescope so you don't have to worry about that alright this is what they're saying right now so we're just gonna say this tilde one dodo you and J max during the same time I know it's okay he didn't know that this is when I stream so somebody else called him on it alright and then you need to run these two and interestingly I don't know if I want to run PHP artisan migrate on these I kind of think about that I kind of think that I don't because we don't run migrate and the other ones do we or do we I don't think we don't Marisa says did the run in X prevent you from doing a CD / yeah that's a great question let's talk about that in terms of the audience make sure plug-in authors can't do things outside of project scope and they probably can honestly we might have to strip them to make them more safe or CD you know slash bar or something like that yep I don't know why that didn't turn into a code but okay alright um almost out of time it's 12:00 and everybody has to dip at 12 thank you so much for hanging out I'm gonna stick around for a couple minutes longer I just have my next meeting in 15 minutes so let's um what else needs to happen we need to do a after shell command and that's maybe it so we actually don't necessarily need a run command for all of them so we can't make an abstract because they don't necessarily have to implement it yeah exactly Marissa alright so is this it oh no we have to iterate over the the composer requires and preset dependencies okay the preset dependencies is gonna be interesting so let's actually just add that to our to you later filled out the preset dependencies idea whenever we touch when it's needs idea okay so that's gonna be later so let's just do composer requires so I think I want compose requires to happen after the before shell commands I think I think yes I'm gonna say yes so for each this composer requires as composer require and John is there a way we've done that in the past otherwise other than just making a shell command we should have we should have a migrate option that's honored by the presets I think it's a good idea okay so we just can do run a command script so I am gonna do a testable method for converting generate composer require command and then this is going to be a composer require I guess and right now composers requires going to be an array so this is going to be generate a command line string to require a package and then this is going to be something like key value I think it's a what is it gonna be it's gonna be a key - value actually package constraints I guess I'm gonna need this da clock now because it's gonna be a lot cleaner there okay I looked around a composer from within PHP it doesn't have such an API saw weird solutions can we not even wait can we even do composer require inside here like this John I hope so as a process but yeah I definitely want to run it within the PHP a good thinking there you're right alright so return um require no composer require and then this is gonna be s : s like that I think that's the best way to do it and then our first one's gonna be the package seconds gonna be they constraint and now we can run tests against this to make sure it does what we think so we're gonna make a preset class oh you have to exec in yeah yeah totally because that's what this is doing this shell exact so this is going to execute its shell command this generate compose or require command from composer require well hello alright so I was gonna make a test what has changed in this file yeah we got to figure out how to map these into the individual classes so let's get our bass preset tested really quickly um so we're gonna write a test for presets which is different than the run presets tests I should have just used artisan make I assume the artists and make tests exists in in layer mode 0 all right it's a preset test and then we're gonna do some tests on the bass preset class so it generates composer require strings alright so we don't have to do much of anything actually because we're just gonna be testing the bass preset class and I made everything public so we don't have to do a full integration test here this is more like a unit test on the preset the bass preset so bass preset equals new oh we can't make a bass preset alright so preset equals new telescope because it's abstracts we can't and I don't think telescope has any dependencies it does it as she'll and I'm really just using telescope because we can't new up bass preset so we're gonna say this assert equals and what we want is composure require laravel / telescope : tilde 1.0 like that oops and what its gonna come from is preset and we literally can just run this method right here because it's sitting there so why not and it's got two parameters laravel / telescope and tilde 1 0 so we can also do further integrated tests of that to make sure that like if it's set there okay great it does that so now we can a new test that says it what it executes items from here unfortunate 75 process component needs to compan pass there's an array of each space separated by the command awesome that's gonna be a lot of fun ok so it what was I just saying it requires all packages in composer requires array so this gonna be a little more complicated because we're actually going to have to have a preset that has that in there right now I'm just gonna allow us to assume that telescope has the presets that we know it has although later we might want to make this like an anonymous class we're actually setting it in here although you know what because it's public we could actually just set it here yeah we're just gonna set it here so just to you know make sure it's what we're actually expecting preset composer requires I don't remember how much of this I copied oh the whole thing oops equals this so we're it's actually set so now when we run it we can actually assert that it runs that exact same thing that we're expecting so we do want to mock the shell so I got to find a place where the shells macht so John if you know top your head we're at the mock the the shelves mock that'd be really nice because what I want to basically do is say assert that composure require laravel / telescope : tilde 1 . o was run that's really what I want to do um alright so let's see one in which we're mocking the shell ok here you go mock shell guess it's that simple so let's just do a shell equals this mock shell class instead of doing multiple requires in a row wouldn't it better be better to do that that's a fantastic point because I think composure handles that better that's I think it also handles dependency matching better unfortunately that means this test is wrong but you're right so let's do it oh I have so little time can we do it can we do it can we do it so that means we're not gonna for each instead we're going to basically this shall exec in project and it's going to be this build composer require string and then we don't need to pass anything well man we don't need to pass anything but I kind of want to pass it just because it's on the yeah we're we're gonna not pass anything alright so build composer well I have a meeting in six minutes require string that doesn't take any parameters and what we're gonna do is generate this so basically we've got our primary string and again we can refactor this collections later it's gonna be a composer require and then for each this composer requires as composer require we can append to the string string equals well it's that really how that that's a very interesting one and so what we want to now do is now build this which is just going to be you know basically package : constraint so what are they stored as key-value so so come so this gonna be packaged oops constraint so string equals and emeritus printf yes let's printf s : quote print s quote and then package constraint and then return string all right can we write a test for this before I run out of time oh don't worry about a MRSA your hundred percent right that's don't feel bad for it help me write better code all right so we want to instead tested this right here um on this one so this is going to be wrong although we could do this anyway so we're gonna preset equals oh no preset composer require is equals and we want two of them so we can assure assert that it joins them correctly so laravel telescope tilde one dot o and then tighten co t lint tilde one dot oh cool and so now we want this to be laravel telescope and then space titan co /t went colon quote tilde one dot o till don't want it oh and then this is gonna be the new command right here and then it doesn't need any parameters because it's generating it off of this right here man that would be cool did i not out of space thank you if i did not um you are absolutely right thanks John so let's go to our preset test and if this works I'm gonna save and go cuz I am gonna be oh you know what this test right here all right and then preset tests come on somebody oh if I was doing the two strings are equal okay so what do we get instead opposed require what's different between them composer space require space laravel slash telescope colon quote tilde one zero space titan KO / deland : oh there's a space after the last one yep so we can do an art trim on that and get rid of the die and dump I love how y'all come up with the solution right after probably before me but because of the lag it's always like Oh Matt figure it out and then everyone else figured out yep that was it okay great I got a run you all are amazing thank you so much for hanging out thank you so much for all of your help so next Friday at 11:00 a.m. Eastern we are going to start building out what it looks like for the run presets method to actually invoke these and how do we map that string that we passed in here whenever we were calling it a while ago that was just the string telescope how do we map telescope to this class right here is it going to be something about snake casing and all that kind of stuff is it going to be a map somewhere how are we gonna bring an external one so y'all think about those things so you can bring your brains with me next week thank you so much thanks Marissa
Info
Channel: Matt Stauffer
Views: 592
Rating: undefined out of 5
Keywords: development, education, live, livestream, matt stauffer livestream, php, programming, lambo, laravel zero, cli, cli tools, laravel cli, laravel tools, laravel new, filesystem, live stream, live coding, presets, cli tool, cli presets
Id: ZlBI7DfxsY4
Channel Id: undefined
Length: 73min 23sec (4403 seconds)
Published: Mon Apr 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.