本文整理汇总了TypeScript中latest-version类的典型用法代码示例。如果您正苦于以下问题:TypeScript latest-version类的具体用法?TypeScript latest-version怎么用?TypeScript latest-version使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了latest-version类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: latestVersion
(async () => {
const current = pkg.version as string;
console.log("current:", current);
const latest = await latestVersion("mirakurun");
console.log("latest:", latest);
if (current === latest) {
console.log("already up to date.");
process.exit(0);
}
if (current.split(".")[0] !== latest.split(".")[0]) {
console.error("updater has aborted cause major version outdated.");
process.exit(0);
}
console.log("updating...");
const npm = spawnNpmInstall(latest);
npm.on("exit", (code) => {
if (code === 0) {
console.log("updated successfully.");
process.exit(0);
} else {
console.error("failed! reverting...");
const npm = spawnNpmInstall(current);
npm.on("exit", () => process.exit(1));
}
});
})();
示例2: async
export const get: Operation = async (req, res) => {
const version: Version = {
current: pkg.version,
latest: await latestVersion("mirakurun")
};
api.responseJSON(res, version);
};
示例3: async
export const put: Operation = async (req, res) => {
if (!req.query.force && !process.env.pm_uptime && !process.env.USING_WINSER) {
api.responseError(res, 500);
return;
}
const latest = await latestVersion("mirakurun");
if (!req.query.force && current === latest) {
api.responseError(res, 409, "Update Nothing");
return;
}
res.setHeader("Content-Type", "text/plain; charset=utf-8");
res.status(202);
res.write("Updating...\n");
const path = join(tmpdir(), "Mirakurun_Updating.log");
if (existsSync(path) === true) {
unlinkSync(path);
}
const out = openSync(path, "a");
const err = openSync(path, "a");
res.write(`> node lib/updater\n\n`);
const npm = spawn("node", ["lib/updater"], {
detached: true,
stdio: ["ignore", out, err]
});
npm.unref();
const tail = new Tail(path);
tail.on("line", data => res.write(data + "\n"));
req.once("close", () => {
tail.removeAllListeners("line");
tail.unwatch();
});
};