Open Projects folder [Win]

Open dev-project in Script Kit

// Preview: docs
// Menu: Open Project
// Description: Opens a project in vscode
// Shortcut: command shift .
import "@johnlindquist/kit";
import * as fs from "fs"
const envPath = await env('PROJECT_DIR');
const projectDir = home(envPath);
const unfilteredProjectList = await readdir(projectDir);
const projectList = unfilteredProjectList.filter(value => !value.includes('.'));
let { projects, write } = await db("projects", {
projects: projectList,
})
projects.forEach(async val => {
if (val.includes('.')) {
projects.pop(val);
await write()
}
})
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()))
let del = await arg(`Delete project dir: ${project}?`, ["yes", "no"])
if (del === "yes") {
fs.rmSync(path.resolve(projectDir, project), { recursive: true, force: true });
}
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) => {
const dir = path.resolve(projectDir, input)
const exists = await isDir(dir);
if (exists) {
return `${input} already exists`;
} else {
const { code, stderr, stdout } = mkdir(dir);
if(stderr){
throw stderr;
}
}
const initorNot = await arg("Create git repo?", ["yes", "no"])
if (initorNot === "yes") {
cd(dir);
execLog("git init");
}
edit('', dir)
return true;
}
},
)
projects.push(project)
mkdir(path.resolve(projectDir, project))
await write()
}
})
// Test gitpush