In this video we're gonna write out a little bit more config inside of our package that JS on file to
get started.
I want to find the main flag inside of here.
By default it is set to index dot J.S. This main path right here is defining exactly what file we import
whenever we attempt to import this overall module.
Let me give you an example.
Let's imagine that we install this module into our auth service inside of our service.
We're going to want to import some code of common at some point in time.
So you're going to want to write out something like say import middleware or something from SGI ticketing
slash common the main flag inside that package dot Jason File is going to say what file we tried to
reach into when we write out this import statement.
So for you and I we want to make sure that when ever we tried to import this module we import that index
not just file inside the build directory so for main we're going to write out dot slash build slash
index.
J.S. then very similar to that.
We're also gonna add in eight types setting.
This is used by TypeScript and it tells typescript what the main type definition file inside of our
project is.
So for you and I it is the index dot deed t s file inside of the bill directory.
So we'll write out build index that D dot t us one other setting inside of here.
We're gonna put in files
this file setting is going to tell NPM what set of files inside of our project we want to make sure
100 percent gets included inside the final published version of our package.
So we want to make sure that we publish everything inside of this bill directory.
So inside of files right here we'll put in a string of dot slash build da star slash star.
Well that is pretty much it for a package not just on file.
We're not gonna move onto another little piece of housekeeping right now if we tried to use get to commit
all the files inside of our project that would include the node modules and Bill directories and we
usually do not commit those directories to get so burnt that prevent that behavior.
I'm gonna create a new file inside the common directory I'm gonna give it a very special name of dot
get ignore and then inside there I'm going to write out the build folder in node modules folders.
So again that's just gonna make sure that we do not accidentally commit those directories to get.
Well let's not take a look at how we would somehow make a change to our project build it and then publish
it to NPM.
Let's first begin with making a very simple change.
So how about inside of our index dot.
Yes file.
Let's say that we want to actually make this color object available to other things inside of our projects
and maybe at the bottom we'll do an expert default color well then save this.
And now we probably want to somehow publish this change up to NPM or other services can actually make
use of it.
But here's what we would do.
Usually we would go over to our terminal we would find our common directory.
We could do a get status to take a look at everything we have changed and added inside their after reviewing
all those changes we could commit them by running a get add dot and then actually commit it with some
kind of message.
In this case we'll give it a message of how about something like additional config
after committing and then going to increment the version of my package to do so we can either go over
to our package not just on file and manually update the version number right there or alternatively
we can run some built in commands include with NPM stuff like NPM version patch if we run NPM version
patch and PMA is going to automatically open up our package that Jason File and update that little last
version number right there so if I run NPM version patch right now I get printed out at my terminal
one point 0 5 and if I go backward in Pakistan J's on file it says the same thing we always have to
increment the version number and each single time we make a change to our package when we want to publish
it now.
Which number right here you update comes down to versioning semantics or semantic versioning.
I'll let you do some separate research or reading on semantic versioning if you're really interested
in it or you and I.
For the purposes of this course we're just going to update this last version number right here.
Any time we make a change even if it is a breaking change we're not going to strictly follow semantic
versioning or anything like that once I've incremental version number we would then do an NPM run build
that's going to build all of our code and then we can publish it with NPM publish
and there we go it looks pretty good.
Now running all those commands.
In other words the get ad that commits the version and to publish.
We're gonna have to run those fairly frequently inside this course.
So just in the context of this course we're going to add a little script to our package dot Jason File
to automate that whole process for us.
You would not normally do this in a real project whatsoever.
So what we're going to add and swipe here we would normally not run in a real project.
We are only going to add it just to make our lives inside this course a little bit easier because we
are going to have to come back over to this coming module several times and make updates to it so let's
write out a little command to just make our lives a little bit more straightforward.
Got to add in a new script called pub talk publish any time I run this.
I want to add all the changes to get and then going to commit those changes.
I'm going to put in a dash M and then an escaped set of double quotes and I'll give it a very generic
update message like updates I'll then do a version patch I'll do a NPM run build and then add NPM publish
notice that publish is not NPM run publish is just NPM published that's it.
Now what's so bad about this command.
Well it's very simple.
We are adding all the changes in to get at the same time.
We're giving those changes a very generic commit message which is not good.
And we are also only ever updating the patch version number.
So these three first things right here not super ideal at all so we'd normally not do this in a real
project.
Again it's just to make our lives in this course a little bit easier.
Let's save this I'll then go back over which my index dot t yes file I'll make another little arbitrary
change inside of here so how about will change red to 20 I'll save the file and then let's imagine we
want to publish these changes.
So with that new script we just put together all we do is run NPM run up like some that's going to commit
version build publish all in one little command and after a brief pause Yeah there we go.
So there's my new version of my package.
All right.
This looks good.
That that's very much all the setup we have to do for right now inside this coming module.
Let's take a pause right here.
When we come back the next video we're gonna start to move over some of that reusable code from our
art project into the common module.