feat: Add config generation
This commit is contained in:
parent
c12b784b50
commit
418cced407
5 changed files with 52 additions and 1 deletions
1
.npmrc
Normal file
1
.npmrc
Normal file
|
@ -0,0 +1 @@
|
|||
@jsr:registry=https://npm.jsr.io
|
5
bun.lock
5
bun.lock
|
@ -4,6 +4,7 @@
|
|||
"": {
|
||||
"name": "project-cli",
|
||||
"dependencies": {
|
||||
"@std/toml": "npm:@jsr/std__toml",
|
||||
"@types/commander": "^2.12.5",
|
||||
"@types/inquirer": "^9.0.8",
|
||||
"commander": "^14.0.0",
|
||||
|
@ -46,6 +47,10 @@
|
|||
|
||||
"@inquirer/type": ["@inquirer/type@3.0.7", "", { "peerDependencies": { "@types/node": ">=18" }, "optionalPeers": ["@types/node"] }, "sha512-PfunHQcjwnju84L+ycmcMKB/pTPIngjUJvfnRhKY6FKPuYXlM4aQCb/nIdTFR6BEhMjFvngzvng/vBAJMZpLSA=="],
|
||||
|
||||
"@jsr/std__collections": ["@jsr/std__collections@1.1.1", "https://npm.jsr.io/~/11/@jsr/std__collections/1.1.1.tgz", {}, "sha512-bS4Y5f80IUeDUf+0BgVVWValgBeGcJ/UwFYTC5PBIJtrFqwEmU8IohDBwFLJILyUtiAB1jbJewl0K+REEQ9kQQ=="],
|
||||
|
||||
"@std/toml": ["@jsr/std__toml@1.0.8", "https://npm.jsr.io/~/11/@jsr/std__toml/1.0.8.tgz", { "dependencies": { "@jsr/std__collections": "^1.1.1" } }, "sha512-rnMoiySl30TrsdnfKcroYEWIBlmPvdNoA8fn/Njy3rsZR9C8k5nUeo9kWP/D/PhxYlUaYPtmQ31YhNqGpmEZ3Q=="],
|
||||
|
||||
"@types/bun": ["@types/bun@1.2.16", "", { "dependencies": { "bun-types": "1.2.16" } }, "sha512-1aCZJ/6nSiViw339RsaNhkNoEloLaPzZhxMOYEa7OzRzO41IGg5n/7I43/ZIAW/c+Q6cT12Vf7fOZOoVIzb5BQ=="],
|
||||
|
||||
"@types/commander": ["@types/commander@2.12.5", "", { "dependencies": { "commander": "*" } }, "sha512-YXGZ/rz+s57VbzcvEV9fUoXeJlBt5HaKu5iUheiIWNsJs23bz6AnRuRiZBRVBLYyPnixNvVnuzM5pSaxr8Yp/g=="],
|
||||
|
|
23
configuration/configuration.ts
Normal file
23
configuration/configuration.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import fs from "fs";
|
||||
import os from "os";
|
||||
import * as toml from "@std/toml";
|
||||
|
||||
export const configPath = os.homedir() + "/.config/project-cli/";
|
||||
|
||||
export interface Configuration {
|
||||
projectsDirectory: string;
|
||||
}
|
||||
|
||||
export function generateDefaultConfig() {
|
||||
fs.mkdirSync(configPath, { recursive: true });
|
||||
fs.mkdirSync(configPath + "templates/", { recursive: true });
|
||||
|
||||
const defaultConfig: Configuration = {
|
||||
projectsDirectory: os.homedir() + "/projects",
|
||||
};
|
||||
|
||||
const configString = toml.stringify(
|
||||
defaultConfig as unknown as Record<string, unknown>,
|
||||
);
|
||||
fs.writeFileSync(configPath + "config.toml", configString);
|
||||
}
|
23
index.ts
23
index.ts
|
@ -1,2 +1,23 @@
|
|||
console.log("Hello via Bun!");
|
||||
import fs from "fs";
|
||||
import { confirm } from "@inquirer/prompts";
|
||||
import { exit } from "process";
|
||||
import {
|
||||
configPath,
|
||||
generateDefaultConfig,
|
||||
} from "./configuration/configuration";
|
||||
|
||||
if (!fs.existsSync(configPath + "config.toml")) {
|
||||
const createConfig = await confirm({
|
||||
message: "No cofig has been found. Would you like to generate a new one?",
|
||||
});
|
||||
|
||||
if (createConfig) {
|
||||
generateDefaultConfig();
|
||||
} else {
|
||||
console.log(
|
||||
"This project can not run without the config. Either create it yourself or generate the default.",
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@std/toml": "npm:@jsr/std__toml",
|
||||
"@types/commander": "^2.12.5",
|
||||
"@types/inquirer": "^9.0.8",
|
||||
"commander": "^14.0.0",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue