2020-07-31 17:45:14 +00:00
|
|
|
import { Ini, FS, Colors } from "./deps.ts";
|
2020-07-28 17:43:58 +00:00
|
|
|
import setupCMD from "./commands/setup.ts";
|
|
|
|
|
|
|
|
export interface IMeta {
|
|
|
|
name: string;
|
|
|
|
version: string;
|
|
|
|
description?: string;
|
|
|
|
author?: string;
|
|
|
|
contributors?: string[];
|
2020-08-02 21:40:12 +00:00
|
|
|
deprecated?: boolean;
|
2020-07-28 17:43:58 +00:00
|
|
|
files: string[];
|
2020-10-14 14:34:18 +00:00
|
|
|
root?: string;
|
2020-08-16 17:20:37 +00:00
|
|
|
hooks?: {
|
|
|
|
prepublish?: string | string[];
|
|
|
|
postpublish?: string | string[];
|
|
|
|
};
|
2020-07-28 17:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let verbose = false;
|
|
|
|
|
|
|
|
export function log(...args: any) {
|
|
|
|
if (verbose) console.log(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
let config: any = {};
|
|
|
|
let configLocation = "";
|
|
|
|
let configInitialized = false;
|
|
|
|
|
|
|
|
export function getConfig(name: string) {
|
|
|
|
if (!configInitialized) throw new Error("Not initialized!");
|
|
|
|
return config[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setConfig(name: string, value: string) {
|
|
|
|
if (!configInitialized) throw new Error("Not initialized!");
|
|
|
|
config[name] = value;
|
|
|
|
|
|
|
|
const data = Ini.encode(config);
|
|
|
|
|
|
|
|
await Deno.writeFile(configLocation, new TextEncoder().encode(data), {
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getMeta() {
|
|
|
|
log("Reading meta.json");
|
|
|
|
return (await FS.readJson("meta.json")) as IMeta;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setMeta(meta: IMeta): Promise<void> {
|
|
|
|
log("Saving meta.json");
|
|
|
|
return FS.writeJson("meta.json", meta, {
|
|
|
|
spaces: " ",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let interactive = true;
|
|
|
|
|
|
|
|
export function isInteractive() {
|
|
|
|
return interactive;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function init(globalOptions: any) {
|
|
|
|
configLocation = globalOptions.config;
|
|
|
|
interactive = globalOptions.interactive;
|
|
|
|
verbose = globalOptions.verbose;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const data = Deno.readFileSync(configLocation);
|
|
|
|
config = Ini.decode(new TextDecoder().decode(data));
|
|
|
|
} catch (err) {
|
|
|
|
log("Error loading config:");
|
|
|
|
log(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
configInitialized = true;
|
|
|
|
|
|
|
|
if (!config.username || !config.registry || !config.password) {
|
|
|
|
if (!isInteractive()) {
|
|
|
|
console.error(
|
|
|
|
Colors.red("Run setup or set necessary value in " + configLocation)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
await setupCMD();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|