@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
73 lines (72 loc) • 3.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.execDotenvCommand = exports.checkGitignoreContainsDotenvFiles = void 0;
const chalk_1 = __importDefault(require("chalk"));
const log_1 = require("diginext-utils/dist/xconsole/log");
const fs_1 = require("fs");
const lodash_1 = require("lodash");
const path_1 = __importDefault(require("path"));
const yargs_1 = __importDefault(require("yargs"));
const dotenv_download_1 = require("./dotenv-download");
const dotenv_upload_1 = require("./dotenv-upload");
const checkGitignoreContainsDotenvFiles = async (options = {}) => {
const { targetDir = process.cwd() } = options;
const globby = require("globby");
const allDotenvFiles = await globby(targetDir + "/.env*");
const fileNames = allDotenvFiles.map((filePath) => (0, lodash_1.last)(filePath.split("/")));
const gitignoreFile = path_1.default.resolve(targetDir, ".gitignore");
if (!(0, fs_1.existsSync)(gitignoreFile)) {
(0, log_1.logWarn)(`".gitignore" file not found.`);
return;
}
const gitignoreContent = (0, fs_1.readFileSync)(gitignoreFile, "utf8");
let isContainAll = true;
const results = fileNames
.filter((dotenvName) => dotenvName !== ".env.sample" && dotenvName !== ".env.example" && dotenvName !== ".env.template")
.map((dotenvName) => {
if (gitignoreContent.indexOf(dotenvName) === -1)
isContainAll = false;
const isContained = gitignoreContent.indexOf(dotenvName) > -1;
if (!isContained) {
(0, log_1.logWarn)(`⚠️ "${dotenvName}" should be added to ".gitignore":`, chalk_1.default.cyan("https://salferrarello.com/add-env-to-gitignore/"));
}
return { name: dotenvName, isContained };
});
return { isContainAll, results };
};
exports.checkGitignoreContainsDotenvFiles = checkGitignoreContainsDotenvFiles;
const execDotenvCommand = async (options) => {
const { secondAction, env, filePath, targetDirectory = process.cwd() } = options;
switch (secondAction) {
// take down the whole project & all of its apps
case "push":
case "up":
case "upload":
try {
await (0, dotenv_upload_1.uploadDotenvFile)(env, { targetDir: targetDirectory, fileName: filePath, isDebugging: options === null || options === void 0 ? void 0 : options.isDebugging });
}
catch (e) {
(0, log_1.logError)(e);
}
break;
// take down the whole app & all of its environments
case "pull":
case "down":
case "download":
try {
await (0, dotenv_download_1.downloadDotenv)(env, { targetDir: targetDirectory, fileName: filePath, isDebugging: options === null || options === void 0 ? void 0 : options.isDebugging });
}
catch (e) {
(0, log_1.logError)(e);
}
break;
// show help
default:
yargs_1.default.showHelp();
break;
}
};
exports.execDotenvCommand = execDotenvCommand;