2020-07-31 17:45:14 +00:00
|
|
|
import { Cliffy, Path } from "./deps.ts";
|
2020-07-28 17:43:58 +00:00
|
|
|
import { init } from "./global.ts";
|
|
|
|
|
|
|
|
import setupCMD from "./commands/setup.ts";
|
|
|
|
import initCMD from "./commands/init.ts";
|
|
|
|
import bumpCMD from "./commands/bump.ts";
|
|
|
|
import publishCMD from "./commands/publish.ts";
|
|
|
|
|
|
|
|
const HOME_FOLDER = Deno.env.get("HOME") || Deno.env.get("USERPROFILE") || "";
|
|
|
|
|
|
|
|
type CommandHandler = (...opts: any[]) => void | Promise<void>;
|
|
|
|
|
|
|
|
let command: CommandHandler | undefined = undefined;
|
|
|
|
let opts: any[] = [];
|
|
|
|
// const debounce = (fnc: any) => (...args: any[]) => {
|
|
|
|
// new Promise((y) => setTimeout(y, 0)).then(() => fnc(...args));
|
|
|
|
// }; //Put function call into queue
|
|
|
|
|
|
|
|
const commandWrapper = (cmd: CommandHandler) => {
|
|
|
|
return (...params: any[]) => {
|
|
|
|
command = cmd;
|
|
|
|
opts = params;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const flags = await new Cliffy.Command()
|
|
|
|
.name("denreg")
|
|
|
|
.version("0.0.1")
|
|
|
|
.description("CLI for the Open Source DenReg package registry")
|
|
|
|
.option("-i, --interactive [interactive:boolean]", "Interactive mode", {
|
|
|
|
default: true,
|
|
|
|
global: true,
|
|
|
|
})
|
|
|
|
.option("-c, --config <config>", "Config file", {
|
|
|
|
default: Path.resolve(HOME_FOLDER, ".denreg"),
|
|
|
|
global: true,
|
|
|
|
})
|
2020-07-31 17:45:14 +00:00
|
|
|
.option("-v, --verbose [verbose:boolean]", "Verbose", {
|
2020-07-28 17:43:58 +00:00
|
|
|
default: false,
|
|
|
|
global: true,
|
|
|
|
})
|
|
|
|
.command(
|
|
|
|
"setup",
|
|
|
|
new Cliffy.Command()
|
|
|
|
.description("Configure cli")
|
|
|
|
.action(commandWrapper(setupCMD))
|
|
|
|
)
|
|
|
|
.command(
|
|
|
|
"publish",
|
|
|
|
new Cliffy.Command()
|
|
|
|
.description("Upload package")
|
|
|
|
.action(commandWrapper(publishCMD))
|
|
|
|
)
|
|
|
|
.command(
|
|
|
|
"init",
|
|
|
|
new Cliffy.Command()
|
|
|
|
.description("Create meta.json")
|
|
|
|
.action(commandWrapper(initCMD))
|
|
|
|
)
|
|
|
|
.command(
|
|
|
|
"bump",
|
|
|
|
new Cliffy.Command()
|
|
|
|
.complete("major|minor|patch", () => ["major", "minor", "patch"])
|
|
|
|
.arguments("<major|minor|patch>")
|
|
|
|
.description("Change package version")
|
|
|
|
.action(commandWrapper(bumpCMD))
|
|
|
|
)
|
|
|
|
.command("completions", new Cliffy.CompletionsCommand())
|
|
|
|
.parse(Deno.args);
|
|
|
|
|
|
|
|
await init(flags.options);
|
|
|
|
|
|
|
|
if (command) {
|
|
|
|
await Promise.resolve((command as CommandHandler)(...opts));
|
|
|
|
}
|