feat: Add new cli-tool for creating and building webby projects
This commit is contained in:
parent
dd0e2b67d5
commit
6fe3d90a17
73
src/bin.mts
Normal file
73
src/bin.mts
Normal file
@ -0,0 +1,73 @@
|
||||
#!/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)
|
||||
},
|
||||
)
|
||||
}
|
19
src/index.ts
19
src/index.ts
@ -1 +1,18 @@
|
||||
console.log("This is Webby - A small static website builder written in TypeScript for learning purposes.")
|
||||
import { Dirent, Stats } from 'fs'
|
||||
import { GlobOptions } from 'glob'
|
||||
|
||||
export interface WebbyAsyncOptions {
|
||||
preserveRoot?: boolean
|
||||
tmp?: string
|
||||
maxRetries?: number
|
||||
retryDelay?: number
|
||||
backoff?: number
|
||||
maxBackoff?: number
|
||||
signal?: AbortSignal
|
||||
glob?: boolean | GlobOptions
|
||||
filter?:
|
||||
| ((path: string, ent: Dirent | Stats) => boolean)
|
||||
| ((path: string, ent: Dirent | Stats) => Promise<boolean>)
|
||||
}
|
||||
|
||||
//console.log("This is Webby - A small static website builder written in TypeScript for learning purposes.")
|
Loading…
x
Reference in New Issue
Block a user