本文整理匯總了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();
});
};