Now updated to use DB and add paths, create folders.

Open for any improvements ^^

Open dev-project in Script Kit

// Preview: docs
// Menu: Open Project
// Description: Opens a project in vscode
// Shortcut: cmd shift .
import "@johnlindquist/kit";
const envPath = await env('PROJECT_DIR');
const projectDir = home(envPath);
const projectList = await readdir(projectDir);
let { projects, write } = await db("projects", {
projects: projectList,
})
projectList.forEach(async value => {
if (!projects.includes(value)) {
projects.push(value);
await write()
}
})
onTab("Open", async () => {
let project = await arg("Open project:", projects.map(project => project.split('\\').pop()))
edit('', path.resolve(projectDir, project))
})
onTab("Add Path", async () => {
while (true) {
let project = await arg(
"Add path to project:",
md(projects.map(project => `* ${project.split('\\').pop()}`).join("\n"))
)
projects.push(project)
await write()
}
})
onTab("Remove", async () => {
while (true) {
let project = await arg("Open project:", projects.map(project => project.split('\\').pop()))
project.split(':').length > 1 ? await rm(path.resolve(project)) : await rm(path.resolve(projectDir, project))
let indexOfProject = projects.indexOf(project)
projects.splice(indexOfProject, 1)
await write()
}
})
onTab("New Project", async () => {
while (true) {
let project = await arg(
{
placeholder: "Create new project:", debounceInput: 400,
enter: "Create", validate: async (input) => {
let exists = await isDir(path.resolve(projectDir, input));
if (exists) {
return `${input} already exists`;
}
return true;
}
},
)
projects.push(project)
mkdir(path.resolve(projectDir, project))
await write()
}
})