From fb23f6fd8b5c4f625524a86e2378aa2b503458a8 Mon Sep 17 00:00:00 2001 From: jank Date: Thu, 19 Jun 2025 13:48:36 +0200 Subject: [PATCH 1/2] feat: Add basic project creation --- configuration/configuration.ts | 37 +++++++++++++++++++++++ index.ts | 54 +++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/configuration/configuration.ts b/configuration/configuration.ts index 2c35e86..9219138 100644 --- a/configuration/configuration.ts +++ b/configuration/configuration.ts @@ -4,8 +4,36 @@ import * as toml from "@std/toml"; export const configPath = os.homedir() + "/.config/project-cli/"; +export interface Project { + name: string; +} + export interface Configuration { projectsDirectory: string; + cloningCommand: string; +} + +export function getProjects(): Project[] { + const projectsString = fs + .readFileSync(configPath + "projects.json") + .toString(); + return JSON.parse(projectsString) as Project[]; +} + +export function getConfiguration(): Configuration { + return toml.parse( + fs.readFileSync(configPath + "config.toml").toString(), + ) as unknown as Configuration; +} + +export function addProject(project: Project) { + let projects = getProjects(); + if (projects.length == undefined) { + saveProjects([project]); + } else { + projects.push(project); + saveProjects(projects); + } } export function generateDefaultConfig() { @@ -14,10 +42,19 @@ export function generateDefaultConfig() { const defaultConfig: Configuration = { projectsDirectory: os.homedir() + "/projects", + cloningCommand: "git clone %s %n", }; const configString = toml.stringify( defaultConfig as unknown as Record, ); fs.writeFileSync(configPath + "config.toml", configString); + + const projects: Project[] = []; + saveProjects(projects); +} + +function saveProjects(projects: Project[]) { + const projectsString = JSON.stringify(projects); + fs.writeFileSync(configPath + "projects.json", projectsString); } diff --git a/index.ts b/index.ts index 62c0d0d..d067790 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,15 @@ import fs from "fs"; -import { confirm } from "@inquirer/prompts"; +import { confirm, select, input } from "@inquirer/prompts"; import { exit } from "process"; import { + addProject, configPath, generateDefaultConfig, + getConfiguration, + getProjects, + type Project, } from "./configuration/configuration"; +import { execSync } from "child_process"; if (!fs.existsSync(configPath + "config.toml")) { const createConfig = await confirm({ @@ -21,3 +26,50 @@ if (!fs.existsSync(configPath + "config.toml")) { } } +if ( + !getProjects() || + getProjects().length == 0 || + getProjects().length == undefined +) { + const anwser = await select({ + message: "Create a new Project", + choices: ["Clone a project with git", "Create a new empty Project"], + }); + if (anwser == "Clone a project with git") { + const repoUrl = await input({ message: "What is the url of the repo?" }); + const wantsCustomName = await confirm({ + message: "Would you like to give this project a custom name?", + default: false, + }); + let customName = ""; + if (wantsCustomName) { + customName = await input({ + message: "What would you like the custom name to be?", + }); + } + + execSync( + "cd " + + getConfiguration().projectsDirectory + + " && " + + getConfiguration() + .cloningCommand.replace("%s", repoUrl) + .replace("%n", customName), + ); + + const newProject: Project = { + name: customName, + }; + addProject(newProject); + } else if (anwser == "Create a new empty Project") { + const name = await input({ + message: "What would you like to call the project?", + }); + fs.mkdirSync(getConfiguration().projectsDirectory + "/" + name); + const newProject: Project = { + name: name, + }; + addProject(newProject); + } +} +console.log(getProjects()); From 0ec25d16936b65885495958a9e3258dad8b3ee40 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 19 Jun 2025 11:49:48 +0000 Subject: [PATCH 2/2] chore(release): 0.2.0 [skip ci] ## [0.2.0](https://git.kjan.de/jank/project-cli/compare/v0.1.1...v0.2.0) (2025-06-19) ### Features * Add basic project creation ([fb23f6f](https://git.kjan.de/jank/project-cli/commit/fb23f6fd8b5c4f625524a86e2378aa2b503458a8)) --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0f63a1..640fcaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.2.0](https://git.kjan.de/jank/project-cli/compare/v0.1.1...v0.2.0) (2025-06-19) + +### Features + +* Add basic project creation ([fb23f6f](https://git.kjan.de/jank/project-cli/commit/fb23f6fd8b5c4f625524a86e2378aa2b503458a8)) + ## [0.1.1](https://git.kjan.de/jank/project-cli/compare/v0.1.0...v0.1.1) (2025-06-19) ### Chores diff --git a/package-lock.json b/package-lock.json index c516e8c..f36ff4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "proj-cli", - "version": "0.1.1", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "proj-cli", - "version": "0.1.1", + "version": "0.2.0", "dependencies": { "@saithodev/semantic-release-gitea": "^2.1.0", "@semantic-release/changelog": "^6.0.3", diff --git a/package.json b/package.json index 91db27e..4540066 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "proj-cli", - "version": "0.1.1", + "version": "0.2.0", "module": "index.ts", "type": "module", "devDependencies": {