Improve upgrade script
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e5829d9a4f
commit
3cda4ee8c8
@ -2,6 +2,7 @@ import { Colors, Path, FS, Compress, Base64 } from "../deps.ts";
|
|||||||
import { getMeta, IMeta, log, getConfig } from "../global.ts";
|
import { getMeta, IMeta, log, getConfig } from "../global.ts";
|
||||||
import { runHooks } from "../helper/run_script.ts";
|
import { runHooks } from "../helper/run_script.ts";
|
||||||
import { ServerError } from "../helper/server_error.ts";
|
import { ServerError } from "../helper/server_error.ts";
|
||||||
|
import { checkPermOrExit } from "../helper/permission.ts";
|
||||||
|
|
||||||
export default async function publish(options: { dry: boolean }) {
|
export default async function publish(options: { dry: boolean }) {
|
||||||
const originalMeta = await getMeta();
|
const originalMeta = await getMeta();
|
||||||
@ -62,6 +63,8 @@ export default async function publish(options: { dry: boolean }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!options.dry) {
|
if (!options.dry) {
|
||||||
|
await checkPermOrExit("net", "Net permission required for publishing");
|
||||||
|
|
||||||
log("Uploading new package version");
|
log("Uploading new package version");
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { Cliffy, Colors } from "../deps.ts";
|
import { Cliffy, Colors } from "../deps.ts";
|
||||||
import { version } from "../version.ts";
|
import { version } from "../version.ts";
|
||||||
|
import { requestPermOrExit } from "../helper/permission.ts";
|
||||||
|
|
||||||
export default async function upgrade() {
|
export default async function upgrade() {
|
||||||
|
await requestPermOrExit(
|
||||||
|
"net",
|
||||||
|
"Net permission required to fetch new version"
|
||||||
|
);
|
||||||
const meta = await fetch(
|
const meta = await fetch(
|
||||||
"https://deno.hibas123.de/raw/@denreg-cli/meta.json"
|
"https://deno.hibas123.de/raw/@denreg-cli/meta.json"
|
||||||
).then((e) => e.json());
|
).then((e) => e.json());
|
||||||
@ -20,15 +25,23 @@ export default async function upgrade() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
const process = Deno.run({
|
const cmd = [
|
||||||
cmd: [
|
|
||||||
"deno",
|
"deno",
|
||||||
"install",
|
"install",
|
||||||
"-A",
|
"-A",
|
||||||
"--unstable",
|
"--unstable",
|
||||||
"-f",
|
"-f",
|
||||||
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/denreg.ts`,
|
`https://deno.hibas123.de/raw/@denreg-cli@${meta.version}/denreg.ts`,
|
||||||
],
|
];
|
||||||
|
|
||||||
|
await requestPermOrExit(
|
||||||
|
"run",
|
||||||
|
"Run permission required to install new version. Or run it manually: " +
|
||||||
|
cmd.join(" ")
|
||||||
|
);
|
||||||
|
|
||||||
|
const process = Deno.run({
|
||||||
|
cmd,
|
||||||
});
|
});
|
||||||
|
|
||||||
const s = await process.status();
|
const s = await process.status();
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
import { Cliffy, Path, Colors } from "./deps.ts";
|
import { Cliffy, Path, Colors } from "./deps.ts";
|
||||||
|
|
||||||
|
import { checkPermOrExit } from "./helper/permission.ts";
|
||||||
|
|
||||||
|
await checkPermOrExit("env", "Requires --allow-env");
|
||||||
|
await checkPermOrExit("read", "Requires --allow-read");
|
||||||
|
await checkPermOrExit("write", "Requires --allow-write");
|
||||||
|
|
||||||
import { init } from "./global.ts";
|
import { init } from "./global.ts";
|
||||||
|
|
||||||
import { version } from "./version.ts";
|
import { version } from "./version.ts";
|
||||||
|
|
||||||
import setupCMD from "./commands/setup.ts";
|
import setupCMD from "./commands/setup.ts";
|
||||||
import initCMD from "./commands/init.ts";
|
import initCMD from "./commands/init.ts";
|
||||||
import bumpCMD from "./commands/bump.ts";
|
import bumpCMD from "./commands/bump.ts";
|
||||||
|
26
cli/helper/permission.ts
Normal file
26
cli/helper/permission.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Colors } from "../deps.ts";
|
||||||
|
|
||||||
|
export const checkPermOrExit = (name: string, err: string) =>
|
||||||
|
Deno.permissions.query({ name: name as any }).then((res) => {
|
||||||
|
if (res.state !== "granted") {
|
||||||
|
console.log(Colors.bold(Colors.red(err)));
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const requestPermOrExit = (name: string, err: string) => {
|
||||||
|
Deno.permissions
|
||||||
|
.query({ name: name as any })
|
||||||
|
.then((res) => {
|
||||||
|
if (res.state === "prompt") {
|
||||||
|
return Deno.permissions.request({ name: name as any });
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (res.state !== "granted") {
|
||||||
|
console.log(Colors.bold(Colors.red(err)));
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
@ -1,6 +1,11 @@
|
|||||||
import { Colors } from "../deps.ts";
|
import { Colors } from "../deps.ts";
|
||||||
|
import { checkPermOrExit } from "../helper/permission.ts";
|
||||||
|
|
||||||
export async function runScript(script: string) {
|
export async function runScript(script: string) {
|
||||||
|
await checkPermOrExit(
|
||||||
|
"run",
|
||||||
|
"Requires --allow-run to run scripts and hooks"
|
||||||
|
);
|
||||||
console.log(Colors.bold(Colors.blue("Running script:")), script);
|
console.log(Colors.bold(Colors.blue("Running script:")), script);
|
||||||
const runPerm = await Deno.permissions.query({
|
const runPerm = await Deno.permissions.query({
|
||||||
name: "run",
|
name: "run",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@denreg-cli",
|
"name": "@denreg-cli",
|
||||||
"version": "0.3.0",
|
"version": "0.3.2",
|
||||||
"description": "CLI for the DenReg package registry",
|
"description": "CLI for the DenReg package registry",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
"contributors": [],
|
"contributors": [],
|
||||||
|
0
cli/test.ts
Normal file
0
cli/test.ts
Normal file
@ -1 +1 @@
|
|||||||
export const version = "0.3.0"
|
export const version = "0.3.2"
|
Loading…
Reference in New Issue
Block a user