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

Commit f6b26f1

Browse files
authored
Merge pull request #119 from sveltejs/better-cli
Better CLI
2 parents 2be9dd1 + 55b6036 commit f6b26f1

File tree

5 files changed

+81
-5
lines changed

5 files changed

+81
-5
lines changed

package-lock.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"glob": "^7.1.2",
2828
"locate-character": "^2.0.5",
2929
"mkdirp": "^0.5.1",
30+
"mri": "^1.1.0",
3031
"node-fetch": "^1.7.3",
3132
"relative": "^3.0.2",
3233
"require-relative": "^0.8.7",
@@ -52,6 +53,8 @@
5253
"nightmare": "^2.10.0",
5354
"npm-run-all": "^4.1.2",
5455
"rollup": "^0.53.0",
56+
"rollup-plugin-json": "^2.3.0",
57+
"rollup-plugin-string": "^2.0.2",
5558
"rollup-plugin-typescript": "^0.8.1",
5659
"source-map-support": "^0.5.2",
5760
"style-loader": "^0.19.1",

rollup.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import typescript from 'rollup-plugin-typescript';
2+
import string from 'rollup-plugin-string';
3+
import json from 'rollup-plugin-json';
24
import pkg from './package.json';
35

46
const external = [].concat(
@@ -12,6 +14,10 @@ const paths = {
1214
};
1315

1416
const plugins = [
17+
string({
18+
include: '**/*.md'
19+
}),
20+
json(),
1521
typescript({
1622
typescript: require('typescript')
1723
})

src/cli/help.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# sapper v<@version@>
2+
3+
https://sapper.svelte.technology
4+
5+
> sapper build
6+
7+
Creates a production-ready version of your app
8+
9+
> sapper export
10+
11+
If possible, exports your app as static files, suitable for hosting on
12+
services like Netlify or Surge
13+
14+
> sapper --help
15+
16+
Shows this message

src/cli/index.ts

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1+
import mri from 'mri';
2+
import chalk from 'chalk';
3+
import help from './help.md';
14
import build from './build.js';
25
import exporter from './export.js';
3-
import { dest, entry, isDev, src } from '../config';
6+
import { dest, entry, src } from '../config';
7+
import * as pkg from '../../package.json';
48

5-
process.env.NODE_ENV = 'production';
9+
const opts = mri(process.argv.slice(2), {
10+
alias: {
11+
h: 'help'
12+
}
13+
});
14+
15+
if (opts.help) {
16+
const rendered = help
17+
.replace('<@version@>', pkg.version)
18+
.replace(/^(.+)/gm, (m: string, $1: string) => /[#>]/.test(m) ? $1 : ` ${$1}`)
19+
.replace(/^# (.+)/gm, (m: string, $1: string) => chalk.bold.underline($1))
20+
.replace(/^> (.+)/gm, (m: string, $1: string) => chalk.cyan($1));
21+
22+
console.log(`\n${rendered}\n`);
23+
process.exit(0);
24+
}
25+
26+
const [cmd] = opts._;
627

7-
const cmd = process.argv[2];
828
const start = Date.now();
9-
const dev = isDev();
1029

1130
if (cmd === 'build') {
12-
build({ dest, dev, entry, src })
31+
build({ dest, dev: false, entry, src })
1332
.then(() => {
1433
const elapsed = Date.now() - start;
1534
console.error(`built in ${elapsed}ms`); // TODO beautify this, e.g. 'built in 4.7 seconds'

0 commit comments

Comments
 (0)