Skip to content
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

Getting started cleanup #59

Merged
merged 5 commits into from
Jun 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions lib/content/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ git add --all
git commit -m "Initial commit"
```

On running `npx hpal new paldo-riddles`, you'll be prompted with the [`npm init`](https://docs.npmjs.com/cli/init) dialog, where you can enter details about your project that will go into its `package.json` file. Feel free to take the time to fill-out the details, or just "enter" all the way through—either is fine for the purposes of this tutorial.
On running `npm init @hapipal paldo-riddles`, you'll be prompted with the [`npm init`](https://docs.npmjs.com/cli/init) dialog, where you can enter details about your project that will go into its `package.json` file. Feel free to take the time to fill-out the details, or just "enter" all the way through—either is fine for the purposes of this tutorial.

You now have a base pal project directory ready to go!

`npx hpal new paldo-riddles` calls hapi pal's command line utility [hpal](https://www.npmjs.com/package/@hapipal/hpal) to bootstrap a new project in a directory titled `paldo-riddles` in our current working directory (the argument to `new` is a path).
`npm init @hapipal paldo-riddles` calls hapi pal's command line utility [hpal](https://www.npmjs.com/package/@hapipal/hpal) to bootstrap a new project in a directory titled `paldo-riddles` in our current working directory (the argument to `new` is a path).

We'll cover more on `hpal` in just a bit.

Expand Down Expand Up @@ -93,7 +93,7 @@ Debug: start
Server started at http://localhost:3000
```

If you then visit that address in your browser or cURL it (`curl http://localhost:3000`), you should receive the following:
If you then visit that address [in your browser](http://localhost:3000) or cURL it (`curl http://localhost:3000`), you should receive the following:

```json
{
Expand Down Expand Up @@ -207,8 +207,8 @@ module.exports = {
slug: 'no-body',
question: 'I have a head & no body, but I do have a tail. What am I?',
answer: 'A coin'
},
// etc.
}
// etc.
];

// And we reply randomly
Expand All @@ -224,7 +224,7 @@ module.exports = {

Be sure to restart your server in order to pick-up this new code.

If you cURL our new route (`curl http://localhost:3000/riddle-random`) or visit it [in your browser](http://localhost:3000/riddle-random), you'll see one of Paldo's riddles. We're up and running!
If you cURL our new route (`curl http://localhost:3000/riddle-random`) or visit it [in your browser](http://localhost:3000/riddle-random), we'll see one of Paldo's riddles. We're up and running!

Now, let's setup letting people get answers if (well, when :)), they get stumped. We'll rely on Paldo's friends supplying the `slug` of the riddle they're stuck on (for now) to know which answer to supply.

Expand Down Expand Up @@ -318,11 +318,7 @@ module.exports = {
};
```

Now, passing any riddle's `slug`s here returns its answer.
```sh
# Use a slug from your project
curl http://localhost:3000/riddle-answer/no-body
```
After restarting your server, we may cURL our new route with a `slug` (`curl http://localhost:3000/riddle-answer/no-body`) or visit it [in your browser](http://localhost:3000/riddle-answer/no-body) and we'll see the answer associated with the `slug`.

## Aside: Linting

Expand Down Expand Up @@ -370,7 +366,7 @@ If you used the hpal CLI to start your project as described above, run:
git cherry-pick objection
```

If you cloned the pal repo (rather than using `npx hpal new ...`), you'll need to fetch the tagged commits first:
If you cloned the pal repo (rather than using `npm init @hapipal paldo-riddles`), you'll need to fetch the tagged commits first:

```sh
git fetch pal --tags
Expand Down Expand Up @@ -447,6 +443,7 @@ The main takeaway from here is that, out of the box, we get an in-memory databas
>
> In fact, there's already a sqlite database, prepopulated with a handful of riddles, [available in the example application repo](https://github.com/hapipal/examples/blob/master/paldo-riddles/riddles.db). As an exercise for the reader, try setting `filename` with an environment variable (as would usually be done in a production deployment (and how the examples repo is setup))
>
> NOTE: using the prepopulated database may error because the migration scripts likely don't exist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point: the migration directory will seem corrupt to knex when the user hasn't simply cloned the example repo, since it's expected the exact same migrations (i.e. by their timestamped filename) will exist. Something to think on, hmm! CC @zemccartney in case you have any ideas.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled off an issue to track this so that we can land the rest of these updates: #60

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, bummer. Sorry, y'all, thanks for catching @openam! Immediate idea is doing away with the prepopulated db and setting up some sort of seeding script — maybe an onPreStart extension? — in the example repo. So we could point people to that extension from the getting started tutorial to copy into their project if they so choose, assuming they were creating the example app manually vs. cloning the example repo. People might find it nice that they can see and edit the riddles content, too. I dunno, I'll mull it over a bit more




Expand Down Expand Up @@ -588,7 +585,6 @@ If all's gone well, you should see:

```sh
Batch 1 run: 1 migrations
/your/local/path/paldo-riddles/lib/migrations/20180226173134_add-riddles.js
```

At long last, we're ready to start working with our data.
Expand Down