diff --git a/.secretstore.yml b/.secretstore.yml new file mode 100644 index 0000000..5b77f36 --- /dev/null +++ b/.secretstore.yml @@ -0,0 +1,9 @@ +version: 1 +projects: +- name: "meta" + directory: . +- name: "cli-auth-proxy" + directory: "projects/cli-auth-proxy" +commitInfo: + name: dotenv-tools + email: dotenv-tools@andreijiroh.xyz \ No newline at end of file diff --git a/tools/commands/projects/index.js b/tools/commands/projects/index.js new file mode 100644 index 0000000..b3fef3f --- /dev/null +++ b/tools/commands/projects/index.js @@ -0,0 +1,31 @@ +import {Command} from "commander" +import { config } from "../../lib/config.js" +import { logger } from "@dotenvx/dotenvx/src/shared/logger.js" +const Table = await import("cli-table3") +export const projectsCli = new Command("projects") + +projectsCli + .description("manage projects") + +projectsCli.command("add") + .description("add a new project") + .argument("project", "project name") + .alias("new") + +projectsCli.command("ls") + .action(function() { + const projectList = config.secretStore.projects; + if (!projectList) { + logger.error(`missing secretstore config, maybe try again in git root directory (hint: not the .git/ folder itself)`) + process.exit(1) + } + const table = new Table.default({ + head: ["Projects", "Directory (relative to root dir)"], + }); + + projectList.forEach(element => { + table.push([element["name"], element["directory"]]) + }); + + console.log(table.toString()) + }) \ No newline at end of file diff --git a/tools/lib/config.js b/tools/lib/config.js index 99c6027..e589907 100644 --- a/tools/lib/config.js +++ b/tools/lib/config.js @@ -1,35 +1,65 @@ import { loadConfig } from "c12" -import { getRootDir } from "./git" -import { pkgMetadata } from "./constants" +import { getRootDir } from "./git.js" +import { pkgMetadata } from "./constants.js" +import fs from "node:fs" +import { logger } from "@dotenvx/dotenvx/src/shared/logger.js" -const defaultRepoConfig = { - repoStore: pkgMetadata.repository.url, - project: "meta" +function checkIfExists(file) { + if (!fs.existsSync(file)) { + logger.debug(`${process.cwd()}/${file} doesn't exist`); + return false; + } + logger.debug(`${process.cwd()}/${file} exist`); + return true; } -const defaultSecretStoreRepoConfig = { +export const defaultRepoConfig = { + repoStore: { + url: pkgMetadata.repository.url, + cloneDirectory: ".secretstore", + }, + sourceProject: { + name: "meta", + rawUrlPrefix: `${pkgMetadata.repository.url}/raw/main/`, + }, + commitInfo: { + name: "dotenv-tools", + email: "dotenv-tools@andreijiroh.xyz", + }, +}; + +export const defaultSecretStoreRepoConfig = { projects: [ { name: "meta", - directory: "./" + directory: "." } - ] + ], + commitInfo: { + name: "dotenv-tools", + email: "dotenv-tools@andreijiroh.xyz" + } } -export const repoConfig = await loadConfig({ - cwd: await getRootDir(), - configFile: ".dotenv-tools.yml", - defaults: defaultRepoConfig, - dotenv: false, - globalRc: false -}) - -export const repoStoreConfig = await loadConfig({ - cwd: await getRootDir(), - configFile: ".secretstore.yml", - defaults: defaultSecretStoreRepoConfig, - dotenv: false, - globalRc: false +export const projectRepoConfig = await loadConfig({ + cwd: await getRootDir(), + name: "dotenv-tools", + configFile: ".envtools.yml", + rcFile: ".envtoolsrc", + dotenv: false, + globalRc: false }) +export const secretStoreConfig = await loadConfig({ + cwd: await getRootDir(), + name: "dotenvx-secretstore", + configFile: ".secretstore.yml", + rcFile: ".secretstorerc", + dotenv: false, + globalRc: false, +}); +export const config = { + secretStore: secretStoreConfig.config, + projectRepo: projectRepoConfig.config +} \ No newline at end of file diff --git a/tools/lib/git.js b/tools/lib/git.js index 451ead0..c0d08dc 100644 --- a/tools/lib/git.js +++ b/tools/lib/git.js @@ -11,7 +11,14 @@ export async function getRootDir() { export async function stageAndCommit(file, message, skipCommit) { let dir = await getRootDir(); - await git.add({ fs, directory, file }); + if (typeof file == "object") { + for (const targetFile of file) { + logger.info(`staging ${targetFile}`) + await git.add({ fs, directory, file: targetFile }); + } + } else { + await git.add({ fs, directory, file }); + } if (!skipCommit || skipCommit == false) { await git.commit({ fs, diff --git a/tools/template/.secretstore.yml b/tools/template/.secretstore.yml new file mode 100644 index 0000000..da457a2 --- /dev/null +++ b/tools/template/.secretstore.yml @@ -0,0 +1,7 @@ +version: 1 +projects: +- name: "meta" + directory: . +commitInfo: + name: dotenv-tools + email: dotenv-tools@andreijiroh.xyz \ No newline at end of file