Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

better CLI #170

Merged
merged 7 commits into from
Mar 5, 2018
Merged

better CLI #170

merged 7 commits into from
Mar 5, 2018

Conversation

Rich-Harris
Copy link
Member

Fixes #168 and #169, using another @lukeed jam (Sade) which gives us a much nicer CLI.

sapper dev, sapper start and sapper export will all now pick available ports as necessary, unless (for dev and start) you specify a --port or -p, in which case it will try to use that port and print a useful error if it can't.

It also emits stats following the build, and prints instructions on how to start the app.

src/utils.ts Outdated
@@ -0,0 +1,10 @@
import * as fs from 'fs';

export function exists(file: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Can just use fs.existsSync here

Copy link
Member Author

Choose a reason for hiding this comment

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

huh, I thought it was deprecated. Turns out that's just fs.exists. Nice!


const export_dir = opts._[1] || 'export';
const start = Date.now();
Copy link
Member

Choose a reason for hiding this comment

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

You can use process.hrtime if you want to be a little more exact. Roughly the same though

Copy link
Member Author

Choose a reason for hiding this comment

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

when pretty-ms is involved I don't think it'll make any difference. I generally avoid process.hrtime because, well, the signature is batshit

process.env.NODE_ENV = 'production';
process.env.SAPPER_DEST = '.sapper/.export';
Copy link
Member

Choose a reason for hiding this comment

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

More for my own curiosity, but why not set SAPPER_DEST from within export()? Especially since the dest is variable

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used by build first — it sends the webpack output to .sapper/.export, and then sapper export runs the code therein to generate the export directory. So it has to be set before either thing happens

src/cli/index.ts Outdated
.replace(/^(.+)/gm, (m: string, $1: string) => /[#>]/.test(m) ? $1 : ` ${$1}`)
.replace(/^# (.+)/gm, (m: string, $1: string) => chalk.bold.underline($1))
.replace(/^> (.+)/gm, (m: string, $1: string) => chalk.cyan($1));
prog.version(pkg.version);
Copy link
Member

Choose a reason for hiding this comment

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

Definitely personal preference, but I like to recommend assigning all global aspects into the initial assignment. New commands get their own blocks, and that consistent spacing helps separate things with larger CLIs.

const prog = sade('sapper').version(pkg.version);`

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, nice. I didn't realise it was chainable, I suppose that makes sense!

Copy link
Member

Choose a reason for hiding this comment

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

Aye. You can chain the whole thing if you want, but that'll get messy

Copy link
Member

@lukeed lukeed left a comment

Choose a reason for hiding this comment

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

Look good~! Glad you were able to come up with your own port utilities after all 😆

@Rich-Harris
Copy link
Member Author

This PR ended up including a bunch of changes to the tests. They weren't very well structured before, and it turned out they had certain assumptions (about the build directory etc) that weren't necessarily true — in fact, the dev tests weren't testing dev behaviour at all.

Getting dev tests working will require jumping through a few more hoops, so I've just commented them out for now. Everything else is a bit neater and more robust.

@Rich-Harris Rich-Harris merged commit 5925636 into master Mar 5, 2018
@Rich-Harris Rich-Harris deleted the gh-169 branch March 5, 2018 20:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants