-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a372f8
commit 5e9f53b
Showing
4 changed files
with
845 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env node | ||
|
||
import sade from 'sade' | ||
import { register as esbuild } from 'esbuild-register/dist/node' | ||
|
||
import pkg from '../package.json' | ||
import { | ||
PrestaEnv, | ||
defaultJSConfigFilepath, | ||
findAndParseConfigFile, | ||
mergeConfig, | ||
PrestaCliArgs, | ||
Presta, | ||
} from './index.beta' | ||
|
||
esbuild() | ||
|
||
const program = sade('presta') | ||
|
||
program | ||
.version(pkg.version) | ||
// do not provide default config here | ||
.option('--config, -c', `Path to a config file. (default ${defaultJSConfigFilepath})`) | ||
.option('--output, -o', `Specify output directory for built files. (default ./build)`) | ||
.option('--assets, -a', `Specify static asset directory. (default ./public)`) | ||
.option('--debug, -d', `Enable debug mode (prints more logs)`) | ||
.example(`dev index.jsx -o dist`) | ||
.example(`dev 'pages/*.tsx' -o static`) | ||
.example(`'pages/*.tsx'`) | ||
.example(`-c site.json`) | ||
.example(`serve -p 8080`) | ||
|
||
program | ||
.command('build', 'Build project to output directory.', { default: true }) | ||
.example(``) | ||
.example(`files/**/*.js`) | ||
.example(`-c ${defaultJSConfigFilepath}`) | ||
.action(async (cliArgs: PrestaCliArgs) => { | ||
process.env.PRESTA_ENV = PrestaEnv.Production | ||
process.env.PRESTA_DEBUG = cliArgs.debug ? 'debug' : '' | ||
console.clear() | ||
const configFile = findAndParseConfigFile(cliArgs.config) | ||
const config = await mergeConfig(cliArgs, configFile) | ||
await new Presta(config, { cliArgs }).build() | ||
}) | ||
|
||
program | ||
.command('dev', 'Start Presta dev server and watch files', { alias: 'watch' }) | ||
.option('--port, -p', `Port to run the local server. (default 4000)`) | ||
.option('--no-serve, -n', `Do not run local dev server. (default false)`) | ||
.describe('Watch project and build to output directory.') | ||
.example(`dev`) | ||
.example(`dev ./files/**/*.js`) | ||
.example(`dev ./files/**/*.js -o ./out`) | ||
.example(`dev -c ${defaultJSConfigFilepath}`) | ||
.action(async (cliArgs: PrestaCliArgs) => { | ||
process.env.PRESTA_ENV = PrestaEnv.Development | ||
process.env.PRESTA_DEBUG = cliArgs.debug ? 'debug' : '' | ||
console.clear() | ||
const configFile = findAndParseConfigFile(cliArgs.config) | ||
const config = await mergeConfig(cliArgs, configFile) | ||
new Presta(config, { cliArgs }).watch() | ||
}) | ||
|
||
program | ||
.command('serve') | ||
.option('--port, -p', `Port to run the local server. (default 4000)`) | ||
.describe('Serve built files, lambdas, and static assets.') | ||
.example(`serve`) | ||
.example(`serve -o ./out -p 8080`) | ||
.example(`serve -c ${defaultJSConfigFilepath}`) | ||
.action(async (cliArgs: PrestaCliArgs) => { | ||
process.env.PRESTA_ENV = PrestaEnv.Development | ||
process.env.PRESTA_DEBUG = cliArgs.debug ? 'debug' : '' | ||
console.clear() | ||
const configFile = findAndParseConfigFile(cliArgs.config) | ||
const config = await mergeConfig(cliArgs, configFile) | ||
new Presta(config, { cliArgs }).serve() | ||
}) | ||
|
||
program.parse(process.argv) |
Oops, something went wrong.