add --help to CLI

This commit is contained in:
Rich Harris
2018-02-13 17:12:55 -05:00
parent 2be9dd1883
commit 55b60369f9
5 changed files with 81 additions and 5 deletions

32
package-lock.json generated
View File

@@ -4224,6 +4224,11 @@
"integrity": "sha512-Yh9y73JRljxW5QxN08Fner68eFLxM5ynNOAw2LbIB1YAGeQzZT8QFSUvkAz609Zf+IHhhaUxqZK8dG3W/+HEvg==",
"dev": true
},
"mri": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.0.tgz",
"integrity": "sha1-XAo/KcjM/7ux7JQdzsCdcfoy82o="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@@ -5768,6 +5773,33 @@
"integrity": "sha512-ErW5cFw5KY/qiyUlPDJ7iBhw51Iro/oyvxETupO85bMg5T7MLlFj3lEDzwjLTOxJAyzWQanUYj/LZHm6aLLm5w==",
"dev": true
},
"rollup-plugin-json": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-json/-/rollup-plugin-json-2.3.0.tgz",
"integrity": "sha512-W45nZH7lmXgkSR/DkeyF4ks0YWFrMysdjUT049gTuAg+lwUEDBKI2+PztqW8UDSMlXCAeEONsLzpDDyBy9m+9A==",
"dev": true,
"requires": {
"rollup-pluginutils": "2.0.1"
},
"dependencies": {
"estree-walker": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.3.1.tgz",
"integrity": "sha1-5rGlHPcpJSTnI3wxLl/mZgwc4ao=",
"dev": true
},
"rollup-pluginutils": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.0.1.tgz",
"integrity": "sha1-fslbNXP2VDpGpkYb2afFRFJdD8A=",
"dev": true,
"requires": {
"estree-walker": "0.3.1",
"micromatch": "2.3.11"
}
}
}
},
"rollup-plugin-typescript": {
"version": "0.8.1",
"resolved": "https://registry.npmjs.org/rollup-plugin-typescript/-/rollup-plugin-typescript-0.8.1.tgz",

View File

@@ -27,6 +27,7 @@
"glob": "^7.1.2",
"locate-character": "^2.0.5",
"mkdirp": "^0.5.1",
"mri": "^1.1.0",
"node-fetch": "^1.7.3",
"relative": "^3.0.2",
"require-relative": "^0.8.7",
@@ -52,6 +53,8 @@
"nightmare": "^2.10.0",
"npm-run-all": "^4.1.2",
"rollup": "^0.53.0",
"rollup-plugin-json": "^2.3.0",
"rollup-plugin-string": "^2.0.2",
"rollup-plugin-typescript": "^0.8.1",
"source-map-support": "^0.5.2",
"style-loader": "^0.19.1",

View File

@@ -1,4 +1,6 @@
import typescript from 'rollup-plugin-typescript';
import string from 'rollup-plugin-string';
import json from 'rollup-plugin-json';
import pkg from './package.json';
const external = [].concat(
@@ -12,6 +14,10 @@ const paths = {
};
const plugins = [
string({
include: '**/*.md'
}),
json(),
typescript({
typescript: require('typescript')
})

16
src/cli/help.md Normal file
View File

@@ -0,0 +1,16 @@
# sapper v<@version@>
https://sapper.svelte.technology
> sapper build
Creates a production-ready version of your app
> sapper export
If possible, exports your app as static files, suitable for hosting on
services like Netlify or Surge
> sapper --help
Shows this message

View File

@@ -1,15 +1,34 @@
import mri from 'mri';
import chalk from 'chalk';
import help from './help.md';
import build from './build.js';
import exporter from './export.js';
import { dest, entry, isDev, src } from '../config';
import { dest, entry, src } from '../config';
import * as pkg from '../../package.json';
process.env.NODE_ENV = 'production';
const opts = mri(process.argv.slice(2), {
alias: {
h: 'help'
}
});
if (opts.help) {
const rendered = help
.replace('<@version@>', pkg.version)
.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));
console.log(`\n${rendered}\n`);
process.exit(0);
}
const [cmd] = opts._;
const cmd = process.argv[2];
const start = Date.now();
const dev = isDev();
if (cmd === 'build') {
build({ dest, dev, entry, src })
build({ dest, dev: false, entry, src })
.then(() => {
const elapsed = Date.now() - start;
console.error(`built in ${elapsed}ms`); // TODO beautify this, e.g. 'built in 4.7 seconds'