2023-11-28 15:10:33 +00:00
|
|
|
import { CliffyCommand, Path, Colors } from "./deps.ts";
|
2020-07-28 17:43:58 +00:00
|
|
|
|
2021-04-28 10:16:50 +00:00
|
|
|
import { checkPermOrExit } from "./helper/permission.ts";
|
2020-08-16 17:41:28 +00:00
|
|
|
|
2021-04-28 10:16:50 +00:00
|
|
|
await checkPermOrExit("env", "Requires --allow-env");
|
|
|
|
await checkPermOrExit("read", "Requires --allow-read");
|
|
|
|
await checkPermOrExit("write", "Requires --allow-write");
|
2020-08-16 17:41:28 +00:00
|
|
|
|
2021-04-28 10:16:50 +00:00
|
|
|
import { init } from "./global.ts";
|
|
|
|
import { version } from "./version.ts";
|
2020-07-28 17:43:58 +00:00
|
|
|
import setupCMD from "./commands/setup.ts";
|
|
|
|
import initCMD from "./commands/init.ts";
|
|
|
|
import bumpCMD from "./commands/bump.ts";
|
|
|
|
import publishCMD from "./commands/publish.ts";
|
2020-08-02 21:40:12 +00:00
|
|
|
import deprecateCMD from "./commands/deprecate.ts";
|
2020-08-16 17:28:27 +00:00
|
|
|
import upgradeCMD from "./commands/upgrade.ts";
|
2021-04-28 09:47:52 +00:00
|
|
|
import runCMD from "./commands/run.ts";
|
2020-07-28 17:43:58 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
2023-11-28 15:10:33 +00:00
|
|
|
const flags = await new CliffyCommand.Command()
|
2020-07-28 17:43:58 +00:00
|
|
|
.name("denreg")
|
2020-08-16 17:37:09 +00:00
|
|
|
.version(version)
|
2020-07-28 17:43:58 +00:00
|
|
|
.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",
|
2023-11-28 15:10:33 +00:00
|
|
|
new CliffyCommand.Command()
|
2020-07-28 17:43:58 +00:00
|
|
|
.description("Configure cli")
|
|
|
|
.action(commandWrapper(setupCMD))
|
|
|
|
)
|
|
|
|
.command(
|
|
|
|
"publish",
|
2023-11-28 15:10:33 +00:00
|
|
|
new CliffyCommand.Command()
|
2020-07-28 17:43:58 +00:00
|
|
|
.description("Upload package")
|
|
|
|
.action(commandWrapper(publishCMD))
|
2020-08-16 09:39:56 +00:00
|
|
|
.option("-d, --dry [dry:boolean]", "Dry run", {
|
|
|
|
default: false,
|
|
|
|
})
|
2020-07-28 17:43:58 +00:00
|
|
|
)
|
|
|
|
.command(
|
|
|
|
"init",
|
2023-11-28 15:10:33 +00:00
|
|
|
new CliffyCommand.Command()
|
2020-07-28 17:43:58 +00:00
|
|
|
.description("Create meta.json")
|
|
|
|
.action(commandWrapper(initCMD))
|
|
|
|
)
|
|
|
|
.command(
|
|
|
|
"bump",
|
2023-11-28 15:10:33 +00:00
|
|
|
new CliffyCommand.Command()
|
2020-07-28 17:43:58 +00:00
|
|
|
.complete("major|minor|patch", () => ["major", "minor", "patch"])
|
|
|
|
.arguments("<major|minor|patch>")
|
|
|
|
.description("Change package version")
|
|
|
|
.action(commandWrapper(bumpCMD))
|
|
|
|
)
|
2020-08-02 21:40:12 +00:00
|
|
|
.command(
|
|
|
|
"deprecate",
|
2023-11-28 15:10:33 +00:00
|
|
|
new CliffyCommand.Command()
|
2020-08-02 21:40:12 +00:00
|
|
|
.description("Deprecate package")
|
|
|
|
.action(commandWrapper(deprecateCMD))
|
|
|
|
)
|
2020-08-16 17:28:27 +00:00
|
|
|
.command(
|
|
|
|
"upgrade",
|
2023-11-28 15:10:33 +00:00
|
|
|
new CliffyCommand.Command()
|
2020-08-16 17:28:27 +00:00
|
|
|
.description("Upgrade to latest version of denreg cli")
|
|
|
|
.action(commandWrapper(upgradeCMD))
|
|
|
|
)
|
2021-04-28 09:47:52 +00:00
|
|
|
.command(
|
|
|
|
"run",
|
2023-11-28 15:12:49 +00:00
|
|
|
new CliffyCommand.Command()
|
2021-04-28 09:47:52 +00:00
|
|
|
.arguments("<name>")
|
|
|
|
// .complete("name", ()=>) //TODO: add autocomplete?
|
|
|
|
.description("Run script from meta.json")
|
|
|
|
.action(commandWrapper(runCMD))
|
|
|
|
)
|
2023-11-28 15:10:33 +00:00
|
|
|
.command("completions", new CliffyCommand.CompletionsCommand())
|
|
|
|
.command("help", new CliffyCommand.HelpCommand().global())
|
2020-07-28 17:43:58 +00:00
|
|
|
.parse(Deno.args);
|
|
|
|
|
|
|
|
await init(flags.options);
|
|
|
|
|
|
|
|
if (command) {
|
2020-08-16 17:20:37 +00:00
|
|
|
try {
|
|
|
|
await Promise.resolve((command as CommandHandler)(...opts));
|
|
|
|
} catch (err) {
|
|
|
|
console.log(Colors.bold(Colors.red("An error occured:")), err.message);
|
|
|
|
}
|
2020-09-15 09:40:25 +00:00
|
|
|
} else {
|
2021-04-15 15:20:09 +00:00
|
|
|
flags.cmd.showHelp();
|
2020-07-28 17:43:58 +00:00
|
|
|
}
|