DenReg/cli/commands/init.ts

55 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-07-31 17:45:14 +00:00
import { Cliffy, Path, FS } from "../deps.ts";
2020-07-28 17:43:58 +00:00
import {
getMeta,
setMeta,
IMeta,
getConfig,
isInteractive,
} from "../global.ts";
export default async function init() {
let existing = {};
try {
existing = await getMeta();
} catch (err) {}
let meta: IMeta = {
name: Path.basename(Deno.cwd()).toLowerCase().replace(/\s+/g, "-"),
version: "0.0.1",
description: "",
author: getConfig("author"),
contributors: [],
2020-07-31 17:45:14 +00:00
files: ["**/*.ts", "**/*.js", "README.md"],
2020-07-28 17:43:58 +00:00
...existing,
};
if (isInteractive()) {
meta.name = await Cliffy.Input.prompt({
message: "What's the name of your package?",
default: meta.name,
});
meta.description = await Cliffy.Input.prompt({
message: "What's the description of your package?",
default: meta.description,
});
meta.author = await Cliffy.Input.prompt({
message: "Who's the author of your package?",
default: meta.author,
});
2020-07-31 17:45:14 +00:00
if (!(await FS.exists("README.md"))) {
const res = await Cliffy.Confirm.prompt({
message: "Autogenerate README?",
default: true,
});
if (res) {
await Deno.writeFile(
"README.md",
new TextEncoder().encode(meta.description || "")
);
}
}
2020-07-28 17:43:58 +00:00
}
await setMeta(meta);
}