Kent sets up the next exercise with a little pseudo code before turning it over to the group. In this exercise you will create the index.js file, install the unique-random-array module, and add the node_modules directory to the .gitignore file.
(flute and synthesizer music) - This next one, we're actually going to check out a different branch. We're going to skip over a branch, and I'll show you why here in a second. Once you check that out, it's git checkout -f FEM/03.0-add-data And for this one, what it did was, not only did it blow away all of your changes, so we don't have that test anymore, and if you put your own name, it changed it to mine.
We'll change that later. But it also added a source directory with a Star Wars names JSON file in here, that has almost 100 names of random Star Wars characters, including Yoda, and I'm not even going to begin to try and say some of these people's names, 'cause it will reveal that I'm not as much of a Star Wars nerd as I should be. So, but yeah, bunch of Star Wars names. So let me explain the purpose of the library that we're building.
We are going to build a module that will allow you to get a random Star Wars name, like a random Star Wars character's name. And so like when you say require('starwars-names').random() that will give you back a string of a random Star Wars character name. And then there'll also be an .all property that will have that entire list that you can look at. So that's what we're trying to accomplish here, and that's what we're going to write in this next step.
So we're going to create the lib. This is for microlibs especially, this is the easy part. And often when you're open sourcing something, it's something that you've already built internally. You want to take that and open source it. So often you might think of this as the easy part, especially for smaller libraries, 'cause managing and maintaining open source can be challenging in itself. So this is what we're going to do for our exercises, if you want to, you can pull up the slides and look at this git diff.
And this is exactly what we what we're going to do I'm actually going to leave this as an exercise, not because it's totally ... There are a couple of things that you'll learn about managing open source and making open source libraries by doing this. But it's also just kind of fun. So I'm going to leave this to you. All that I care about I'll give you a little bit of pseudocode. You're going to need to have an index.js file in here.
And you need to have a module that exports an .all property that's going to have the array of Star Wars names there. And a random property that will be a function. So function some function here and some array here. And as a protip, or like as the way that we're going to solve this, is you'll use unique-random-array to actually so you'll require the JSON file.
That's like totally a thing that Node can do. It can just require in JSON files to get the array of Star Wars names. And then you'll use the unique-random-array to create your random function. So if you want to, you can reference the git diff, but like this is kind of the fun part, so go hog wild.
Note: This course was created by Frontend Masters. It was originally released on 08/09/2016. We're pleased to host this training in our library.
- Creating an open-source library
- Linting and testing
- Code coverage
- Installing and configuring Babel
- Peer dependencies
- Forking and renaming
- Continuous integration and automating releases