Skip to content

Commit

Permalink
add package releases update
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Mar 18, 2024
1 parent aae5e1b commit 2fc1463
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/cmd-fns/dev/get-dev-server-axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const getDevServerAxios = ({ serverUrl }: { serverUrl: string }) => {
const devServerAxios = defaultAxios.create({
baseURL: serverUrl,
})

// https://github.com/oven-sh/bun/issues/267
devServerAxios.defaults.headers.common["Accept-Encoding"] = "gzip"

devServerAxios.interceptors.response.use(
(res) => res,
(err) => {
Expand Down
2 changes: 2 additions & 0 deletions lib/cmd-fns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export { packageFilesUploadDirectory } from "./package-files-upload-directory"
export { packageReleasesList } from "./package-releases-list"
export { packageReleasesGet } from "./package-releases-get"
export { packageReleasesCreate } from "./package-releases-create"
export { packageReleasesUpdate } from "./package-releases-update"
export { packageFilesList } from "./package-files-list"
export { packageFilesGet } from "./package-files-get"
export { packageFilesDownload } from "./package-files-download"
Expand All @@ -33,3 +34,4 @@ export { uninstallCmd as uninstall } from "./uninstall"
export { devServerUpload } from "./dev-server-upload"
export { configClear } from "./config-clear"
export { openCmd as open } from "./open"
export { versionCmd as version } from "./version"
45 changes: 45 additions & 0 deletions lib/cmd-fns/package-releases-update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { AppContext } from "../util/app-context"
import { z } from "zod"
import kleur from "kleur"

export const packageReleasesUpdate = async (ctx: AppContext, args: any) => {
const params = z
.object({
packageNameWithVersion: z.string().optional(),
packageName: z.string().optional(),
version: z.string().optional(),
isLatest: z.boolean().optional(),
isLocked: z.boolean().optional(),
})
.refine((d) => {
if (d.packageNameWithVersion) return true
if (d.packageName && d.version) return true
return false
}, "Either packageNameWithVersion or packageName and version must be provided")
.parse(args)

let { packageNameWithVersion, packageName, version } = params

if (!packageNameWithVersion) {
packageNameWithVersion = `${packageName}@${version}`
}

const delta: {
is_latest?: boolean
is_locked?: boolean
} = {}

if (params.isLatest !== undefined) {
delta.is_latest = params.isLatest
}
if (params.isLocked !== undefined) {
delta.is_locked = params.isLocked
}

await ctx.axios.post("/package_releases/update", {
package_name_with_version: packageNameWithVersion,
...delta,
})

console.log(`Package release updated!`)
}
11 changes: 9 additions & 2 deletions lib/get-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import * as CMDFN from "lib/cmd-fns"
export const getProgram = (ctx: AppContext) => {
const cmd = new Command("tsci")

cmd.version(packageJson.version)

const authCmd = cmd.command("auth")
authCmd.command("login").action((args) => CMDFN.authLogin(ctx, args))
authCmd.command("logout").action((args) => CMDFN.authLogout(ctx, args))
Expand Down Expand Up @@ -96,6 +94,15 @@ export const getProgram = (ctx: AppContext) => {
.option("--package-name <package_name>", "Package name")
.option("--release-version <release_version>", "Version to publish")
.action((args) => CMDFN.packageReleasesCreate(ctx, args))
packageReleases
.command("update")
.option(
"-p, --package-name-with-version <package_name_with_version>",
"Package name and version"
)
.option("--is-latest", "Make package release the latest version")
.option("--is-locked", "Lock the release")
.action((args) => CMDFN.packageReleasesUpdate(ctx, args))

const packageFiles = cmd.command("package_files")

Expand Down
3 changes: 3 additions & 0 deletions lib/util/create-context-and-run-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export const createContextAndRunProgram = async (process_args: any) => {
},
})

// https://github.com/oven-sh/bun/issues/267
axios.defaults.headers.common["Accept-Encoding"] = "gzip"

if (global_config.get("log_requests")) {
console.log(`Using registry_url: ${registry_url}`)
axios.interceptors.request.use((req) => {
Expand Down

0 comments on commit 2fc1463

Please sign in to comment.