Skip to content

Commit

Permalink
fix(env): support numbers. install multiple packages at once
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Feb 28, 2025
1 parent bdd16e7 commit db976ba
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 81 deletions.
25 changes: 25 additions & 0 deletions build/build-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,31 @@ if (packageJsonChanged) {
console.error('Error installing dependencies:', error)
process.exit(1)
}
} else {
// Verify node_modules exists even if package.json hasn't changed
const nodeModulesPath = kitPath('node_modules')
if (!existsSync(nodeModulesPath) || !existsSync(path.join(nodeModulesPath, '.pnpm'))) {
console.log('node_modules directory missing or incomplete. Installing dependencies...')
try {
console.log('Downloading and installing pnpm...')
await downloadAndInstallPnpm()
console.log('pnpm installation completed')

const pnpmPath = kitPath('pnpm')
console.log(`Installing production dependencies using ${pnpmPath}...`)
await exec(`"${pnpmPath}" i --prod`, options)
console.log('Production dependencies installed successfully')

console.log('Installing development tools (esbuild, vite, tsx)...')
await exec(`"${pnpmPath}" i esbuild vite tsx`, options)
console.log('Development tools installed successfully')
} catch (error) {
console.error('Error installing dependencies:', error)
process.exit(1)
}
} else {
console.log('node_modules directory exists. Skipping dependency installation.')
}
}

console.log('Download docs')
Expand Down
5 changes: 3 additions & 2 deletions src/api/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ export let getGroupedScripts = async (fromCache = true) => {
kitPath('cli', 'new-theme.js'),
kitPath('cli', 'share.js'),
kitPath('cli', 'find.js'),
kitPath('main', 'docs.js'),
// kitPath('main', 'docs.js'),
kitPath('main', 'kit.js'),
kitPath('cli', 'processes.js'),
kitPath('cli', 'kenv-manage.js'),
Expand All @@ -1601,6 +1601,7 @@ export let getGroupedScripts = async (fromCache = true) => {
}

kitScripts = kitScripts.concat([
kitPath("main", "docs.js"),
// kitPath("main", "api.js"),
// kitPath("main", "guide.js"),
// kitPath("main", "tips.js"),
Expand All @@ -1611,7 +1612,7 @@ export let getGroupedScripts = async (fromCache = true) => {
kitPath('main', 'app-launcher.js'),
// kitPath("main", "account.js"),
kitPath('main', 'dev.js'),
kitPath('main', 'hot.js'),
// kitPath('main', 'hot.js'),
kitPath('main', 'snippets.js'),
kitPath('main', 'term.js'),
kitPath('main', 'sticky.js'),
Expand Down
9 changes: 6 additions & 3 deletions src/cli/download-md.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
let downloadMarkdown = async (fileName: string) => {
try {
let url = `https://raw.githubusercontent.com/johnlindquist/kit-docs/main/${fileName}`
console.log(`Downloading ${url}...`)
process.send?.(`Downloading ${url}...`)
let buffer = await download(url, undefined, {
rejectUnauthorized: false,
})
await writeFile(kitPath(fileName), buffer)
process.send?.(`Successfully downloaded ${fileName}`)
} catch (error) {
log(`Error downloading ${fileName}`)
process.send?.(`Error downloading ${fileName}`)
}
}

await downloadMarkdown("API.md")
await downloadMarkdown("ANNOUNCEMENTS.md")
await downloadMarkdown("API-GENERATED.md")
await downloadMarkdown("SCRIPTLETS.md")
await downloadMarkdown("GUIDE.md")
await downloadMarkdown("KIT.md")
await downloadMarkdown("TIPS.md")
Expand Down
3 changes: 2 additions & 1 deletion src/cli/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ let packages = await arg(
}
)

let installNames = [...packages.split(" ")]
let installNames = [...packages.split(" "), ...args];
args = [];
if (process?.send) global.setChoices([])

await install([...installNames, ...argOpts])
Expand Down
3 changes: 3 additions & 0 deletions src/cli/set-env-var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Usage: set-env-var [env key:] [env value:]
throw new Error("Environment value cannot be null or undefined.")
}

// Ensure envValue is a string
envValue = String(envValue)

const envFilePath = kenvPath(".env")
const dotEnvPath = kitDotEnvPath()

Expand Down
87 changes: 25 additions & 62 deletions src/main/announcements.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,37 @@
// Name: Annoucements
// Description: Browse Annoucements
// Name: Announcements
// Description: Script Kit Announcements
// Keyword: announcements
// Pass: true
// Cache: true
// Enter: Open Announcements

let noChoices = false
let onNoChoices = async input => {
noChoices = true
setPanel(
md(`# No Examples Found for "${input}"
import { createGuideConfig } from "./main-helper.js"

- Share one! ❤️ [Share on GitHub Discussions](https://github.com/johnlindquist/kit/discussions/categories/share)
- Request one 💡 [Request on GitHub Discussions](https://github.com/johnlindquist/kit/discussions/categories/ideas)
`)
)
}

let getHot = async () => {
let hotPath = kitPath("data", "hot.json")
if (await isFile(hotPath)) {
return await readJson(hotPath)
}

return []
}

let loadHotChoices = async () => {
try {
let hot = await getHot()

return hot
.filter(choice => choice?.category?.name !== "Share")
.map(choice => {
choice.preview = async () => {
if (choice?.body) {
return await highlight(choice?.body)
}

return ""
}
return choice
})
} catch (error) {
return [error.message]
}
}

let choices = await loadHotChoices()

let url = await arg(
{
let selectedDoc = await docs(
kitPath("ANNOUNCEMENTS.md"),
createGuideConfig({
name: "Announcements",
placeholder: `Announcements`,
input: arg?.input,
guidePath: kitPath("ANNOUNCEMENTS.md"),
itemHeight: PROMPT.ITEM.HEIGHT.SM,
input: arg?.input || arg?.input || "",
placeholder: "Browse Announcements",
enter: `Open ANNOUNCEMENTS.md`,
preventCollapse: true,
onNoChoices,
onChoiceFocus: () => {
noChoices = false
onNoChoices: async input => {
setPanel(
md(`# Expected ${input} in the Announcements?
This guide is constantly evolving. If you're missing something, [suggest an edit](https://github.com/johnlindquist/kit-docs/blob/main/ANNOUNCEMENTS.md) to the guide or open an issue on GitHub.
`)
)
},
shortcuts: [],
enter: "Open in Browser",
},
choices
})
)

if (noChoices) {
browse(
`https://github.com/johnlindquist/kit/discussions/categories/share`
)
// if selected docs is a url, then open it
if (selectedDoc.startsWith("http")) {
open(selectedDoc)
} else {
browse(url)
await run(kitPath("cli", selectedDoc))
await mainScript("", "Announcements")
}

export {}
4 changes: 2 additions & 2 deletions src/main/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import { createGuideConfig } from "./main-helper.js"

let selectedDoc = await docs(
kitPath("API.md"),
kitPath("API-GENERATED.md"),
createGuideConfig({
name: "API",
guidePath: kitPath("API.md"),
guidePath: kitPath("API-GENERATED.md"),
itemHeight: PROMPT.ITEM.HEIGHT.SM,
input: arg?.input || arg?.pass || "",
placeholder: "Browse API",
Expand Down
10 changes: 5 additions & 5 deletions src/main/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Description: Script Kit Docs
// Enter: Open Docs
// Keyword: docs
// Pass: true
// Index: 0

delete arg?.pass
delete arg?.keyword
Expand All @@ -12,6 +12,10 @@ onTab("API", async (input = "") => {
await main("api", "--input", input)
})

onTab("Scriptlets", async (input = "") => {
await main("scriptlets", "--input", input)
})

onTab("Guide", async (input = "") => {
await main("guide", "--input", input)
})
Expand All @@ -20,10 +24,6 @@ onTab("Tips", async (input = "") => {
await main("tips", "--input", input)
})

onTab("Community Scripts", async (input = "") => {
await main("community", "--input", input)
})

onTab("Announcements", async (input = "") => {
await main("announcements", "--input", input)
})
1 change: 1 addition & 0 deletions src/main/index-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Main {
tips: Promise<typeof import("./tips")>
community: Promise<typeof import("./community")>
announcements: Promise<typeof import("./announcements")>
scriptlets: Promise<typeof import("./scriptlets")>
}

interface MainModuleLoader {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Choice } from "../types/core"
import { CLI } from "../cli"
import { addPreview, findDoc } from "../cli/lib/utils.js"
import { addPreview } from "../cli/lib/utils.js"

let otherOptions: Choice<keyof CLI>[] = [
{
Expand Down
33 changes: 31 additions & 2 deletions src/main/main-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export let createGuideConfig =

let shortcuts: Shortcut[] = [
{
name: `Playground`,
name: `Create Script`,
key: `${cmd}+p`,
bar: "right",
visible: true,
Expand All @@ -47,7 +47,7 @@ export let createGuideConfig =
// remove any emoji
name = name.replace(/:.+?:/g, "")

name = `playground-${name}`
name = `docs-generated-${name}`

// comment out every line of contents that has text
contents = contents
Expand Down Expand Up @@ -119,6 +119,35 @@ ${contents}`
} as PromptConfig
}

export let createScriptletsConfig =
(
config: Partial<PromptConfig> & { guidePath?: string }
) =>
async (sections: GuideSection[]) => {
let getCodeblocks =
global.getCodeblocksFromSections(sections)

return {
...config,
shortcuts: [
{
name: "Copy Scriptlet",
key: `${cmd}+c`,
bar: "right",
visible: true,
onPress: async (input, { focused }) => {
let codeBlocks = getCodeblocks(focused?.name)
await copy(codeBlocks)
toast("Copied to Clipboard!")
},
},
],
onSubmit: async (input, { focused }) => {
await edit(kenvPath("scriptlets", "scriptlets.md"))
},
} as PromptConfig
}

export let createTipsConfig =
(
config: Partial<PromptConfig> & { guidePath?: string }
Expand Down
31 changes: 31 additions & 0 deletions src/main/scriptlets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Name: Scriptlets
// Description: Docs for Script Kit Scriptlets
// Keyword: scriptlets
// Pass: true
// Enter: Open Scriptlets

import { createScriptletsConfig } from "./main-helper.js"

let scriptletsPath = kitPath("SCRIPTLETS.md")

await docs(
scriptletsPath,
createScriptletsConfig({
name: "Scriptlets",
guidePath: scriptletsPath,
itemHeight: PROMPT.ITEM.HEIGHT.SM,
input: arg?.input || "",
placeholder: "Browse Scriptlets",
enter: `Create Script`,
preventCollapse: true,
onNoChoices: async input => {
setPanel(
md(`# Expected ${input} in the Tips?
Tips are constantly evolving. If you're missing something, [suggest an edit](https://github.com/johnlindquist/kit-docs/blob/main/TIPS.md) to the tips.
`)
)
},
})
)

export {}
2 changes: 1 addition & 1 deletion src/setup/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ try {
await ensureDir(kitPath("data"))
await run(kitPath("hot", "download-hot.js"))
await run(kitPath("emoji", "download-emoji.js"))
if (!arg.dev) await run(kitPath("cli", "download-md.js"))
await run(kitPath("cli", "download-md.js"))
if (!arg.dev) {
await run(kitPath("setup", "update-examples.js"))
}
Expand Down
6 changes: 4 additions & 2 deletions src/target/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,7 @@ export let appInstallMultiple = async (
)

let i = 0
let confirmedPackages = []
for await (let packageName of adjustedPackageNames) {
let placeholder = `${packageName} is required for this script`
setDescription(placeholder)
Expand Down Expand Up @@ -2329,13 +2330,14 @@ export let appInstallMultiple = async (
}

i++
confirmedPackages.push(packageName)
}

setHint(
`Installing ${adjustedPackageNames.join(", ")}...`
`Installing ${confirmedPackages.join(", ")}...`
)

await global.cli("install", ...adjustedPackageNames)
await global.cli("install", ...confirmedPackages)
console.clear()
}

Expand Down

0 comments on commit db976ba

Please sign in to comment.