-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cli): migrate to
citty
(#498)
- Loading branch information
Showing
3 changed files
with
34 additions
and
30 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,36 +1,40 @@ | ||
import { resolve } from "node:path"; | ||
import mri from "mri"; | ||
import { defineCommand, runMain } from "citty"; | ||
import { listen } from "listhen"; | ||
import { createStorage } from "./storage"; | ||
import { createStorageServer } from "./server"; | ||
import fsDriver from "./drivers/fs"; | ||
|
||
async function main() { | ||
const arguments_ = mri(process.argv.splice(2)); | ||
const main = defineCommand({ | ||
meta: { | ||
name: "unstorage", | ||
description: "Unstorage CLI", | ||
}, | ||
args: { | ||
dir: { | ||
type: "string", | ||
description: "project root directory", | ||
}, | ||
_dir: { | ||
type: "positional", | ||
default: ".", | ||
description: "project root directory (prefer using `--dir`)", | ||
}, | ||
}, | ||
async run(args) { | ||
const rootDir = resolve(args.args.dir || args.args._dir); | ||
|
||
if (arguments_.help) { | ||
console.log("Usage: npx unstorage [rootDir]"); | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
process.exit(0); | ||
} | ||
const storage = createStorage({ | ||
driver: fsDriver({ base: rootDir }), | ||
}); | ||
|
||
const rootDir = resolve(arguments_._[0] || "."); | ||
const storageServer = createStorageServer(storage); | ||
|
||
const storage = createStorage({ | ||
driver: fsDriver({ base: rootDir }), | ||
}); | ||
|
||
const storageServer = createStorageServer(storage); | ||
|
||
await listen(storageServer.handle, { | ||
name: "Storage server", | ||
port: 8080, | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line unicorn/prefer-top-level-await | ||
main().catch((error) => { | ||
console.error(error); | ||
// eslint-disable-next-line unicorn/no-process-exit | ||
process.exit(1); | ||
await listen(storageServer.handle, { | ||
name: "unstorage server", | ||
port: 8080, | ||
}); | ||
}, | ||
}); | ||
|
||
runMain(main); |