73 lines
1.6 KiB
TypeScript
73 lines
1.6 KiB
TypeScript
#!/usr/bin/env node
|
|
import type { WebbyAsyncOptions } from './index.js'
|
|
import { loadPackageJson } from 'package-json-from-dist'
|
|
|
|
const { version } = loadPackageJson(import.meta.url)
|
|
|
|
const runHelpForUsage = () => console.error('run `webby --help` for usage information')
|
|
|
|
export const help = `webby version ${version}
|
|
|
|
Usage: webby <path to webby.conf.js file>
|
|
Builds your website with the information from the webby.conf.js file.
|
|
|
|
Options:
|
|
-h --help Display this usage info
|
|
--version Display version
|
|
`
|
|
|
|
import { parse, relative, resolve } from 'path'
|
|
const cwd = process.cwd()
|
|
|
|
const main = async (...args: string[]) => {
|
|
if (process.env.__WEBBY_TESTING_BIN_FAIL__ === '1') {
|
|
throw new Error('simulated Webby failure')
|
|
}
|
|
|
|
const opt: WebbyAsyncOptions = {}
|
|
const paths: string[] = []
|
|
/*
|
|
let impl: (
|
|
path: string | string[],
|
|
opt?: WebbyAsyncOptions,
|
|
) => Promise<boolean> = webby
|
|
*/
|
|
|
|
for (const arg of args) {
|
|
if (arg === '-h' || arg === '--help') {
|
|
console.log(help)
|
|
return 0
|
|
} else if (arg === '--version') {
|
|
console.log(version)
|
|
return 0
|
|
} else {
|
|
console.error(`unknown option: ${arg}`)
|
|
runHelpForUsage()
|
|
return 1
|
|
}
|
|
}
|
|
|
|
if (!paths.length) {
|
|
console.error('webby: must provide a path to build')
|
|
runHelpForUsage()
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
main.help = help
|
|
main.version = version
|
|
|
|
export default main
|
|
|
|
if (process.env.__TESTING_WEBBY_BIN__ !== '1') {
|
|
const args = process.argv.slice(2)
|
|
main(...args).then(
|
|
code => process.exit(code),
|
|
er => {
|
|
console.error(er)
|
|
process.exit(1)
|
|
},
|
|
)
|
|
} |