2023-11-28 15:10:33 +00:00
|
|
|
import { CliffyPrompt, 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();
|
2023-11-28 15:10:33 +00:00
|
|
|
} catch (err) { }
|
2020-07-28 17:43:58 +00:00
|
|
|
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()) {
|
2023-11-28 15:10:33 +00:00
|
|
|
meta.name = await CliffyPrompt.Input.prompt({
|
2020-07-28 17:43:58 +00:00
|
|
|
message: "What's the name of your package?",
|
|
|
|
default: meta.name,
|
|
|
|
});
|
2023-11-28 15:10:33 +00:00
|
|
|
meta.description = await CliffyPrompt.Input.prompt({
|
2020-07-28 17:43:58 +00:00
|
|
|
message: "What's the description of your package?",
|
|
|
|
default: meta.description,
|
|
|
|
});
|
2023-11-28 15:10:33 +00:00
|
|
|
meta.author = await CliffyPrompt.Input.prompt({
|
2020-07-28 17:43:58 +00:00
|
|
|
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"))) {
|
2023-11-28 15:10:33 +00:00
|
|
|
const res = await CliffyPrompt.Confirm.prompt({
|
2020-07-31 17:45:14 +00:00
|
|
|
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);
|
|
|
|
}
|