Skip to content

Commit

Permalink
fix(action): only use action.value is onAction is missing. Don't run …
Browse files Browse the repository at this point in the history
…set-env-var if not changed.
  • Loading branch information
johnlindquist committed Dec 3, 2024
1 parent ec5b4bb commit e02c115
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 448 deletions.
2 changes: 1 addition & 1 deletion build/build-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ await dec
console.log("Install deps")
// await exec('npx pnpm node -p "process.execPath"', options)

await exec(`npx pnpm i --prod`, options)
await exec(`pnpm i --prod`, options)
// await exec(`npx pnpm dedupe --check`, options)
// await exec(`npx pnpm dedupe`, options)

Expand Down
721 changes: 368 additions & 353 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions src/api/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,9 @@ export let getFlagsFromActions = (
return flags
}

global.setActions = (actions: Action[], options = {}) => {
global.setActions = async (actions: Action[], options = {}) => {
let flags = getFlagsFromActions(actions)
setFlags(flags, options)
await setFlags(flags, options)
}

global.openActions = async () => {
Expand Down Expand Up @@ -1270,7 +1270,15 @@ export let actions: Action[] = [
let loggedIn = userJson?.login
let helpActions: Action[] = [
...(loggedIn
? []
? [
{
name: "Sign Out",
description: "Sign out of Script Kit",
onAction: async () => {
await deauthenticate()
},
},
]
: [
{
name: "Sign In",
Expand Down Expand Up @@ -2398,6 +2406,19 @@ export let authenticate = async (): Promise<Octokit> => {
return octokit
}

export let deauthenticate = async () => {
await setUserJson({})
await replace({
files: kenvPath(".env"),
from: /GITHUB_SCRIPTKIT_TOKEN=.*/g,
to: "",
disableGlobs: true
})
process.env.GITHUB_SCRIPTKIT_TOKEN = env.GITHUB_SCRIPTKIT_TOKEN = ``

await mainScript()
}

global.createGist = async (
content: string,
{
Expand Down
22 changes: 13 additions & 9 deletions src/cli/set-env-var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import { kitDotEnvPath } from "../core/utils.js"
let envKey = await arg("env key:")
let envValue = await arg("env value:")
let envFile = kenvPath(".env")
let updateEnv = async (envKey, envValue) => {
if (env?.[envKey] !== envValue) {
let regex = new RegExp("^" + envKey + "=.*$")
sed("-i", regex, envKey + "=" + envValue, envFile)
env[envKey] = envValue
process.env[envKey] = envValue
}
let updateEnv = (envKey: string, envValue: string) => {
if (env?.[envKey] === envValue) { return }

let regex = new RegExp("^" + envKey + "=.*$")
sed("-i", regex, envKey + "=" + envValue, envFile)
env[envKey] = envValue
process.env[envKey] = envValue
}
let writeNewEnv = async (envKey, envValue) => {
let writeNewEnv = async (envKey: string, envValue: string) => {
if (env?.[envKey] === envValue) { return }

await appendFile(envFile, `\n${envKey}=${envValue}`)
env[envKey] = envValue
process.env[envKey] = envValue
}
let removeEnv = async envKey => {
let removeEnv = (envKey: string) => {
if (!env?.[envKey]) { return }

let regex = new RegExp("^" + envKey + "=.*$", "gm")
sed("-i", regex, "", envFile)
delete env[envKey]
Expand Down
Loading

0 comments on commit e02c115

Please sign in to comment.