wp-setup
Version:
Easily create replicable local WordPress environments with Docker
84 lines • 3.58 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { execSync } from 'child_process';
import { exit } from 'process';
import { getExternalVolumeFiles } from '../helpers/docker.js';
export default class AbstractCommand {
constructor(config) {
this.config = {};
this.parsedConfig = false;
this.mode = 'silent';
this.setUser = () => {
if (process.env.UID && process.env.GID) {
return;
}
const uid = execSync('id -u', { stdio: 'pipe' }).toString().trim();
const gid = execSync('id -g', { stdio: 'pipe' }).toString().trim();
process.env.UID = uid;
process.env.GID = gid;
};
this.getConfig = () => __awaiter(this, void 0, void 0, function* () {
if (this.parsedConfig) {
return this.config;
}
const [plugins, themes, volumes] = yield Promise.all(['plugins', 'themes', 'volumes'].map((type) => __awaiter(this, void 0, void 0, function* () {
var _a;
const volumes = ((_a = this.config[type]) !== null && _a !== void 0 ? _a : []);
const singularType = type.slice(0, -1);
const beforeCallback = (fileName, tmpFile) => {
this.info(`Downloading ${singularType}: ${fileName} on ${tmpFile}...`);
};
return getExternalVolumeFiles(volumes, type, beforeCallback);
})));
this.config.plugins = plugins;
this.config.themes = themes;
this.config.volumes = volumes;
this.parsedConfig = true;
return this.config;
});
this.print = (message, type = 'log') => {
switch (type) {
case 'error':
return console.log('\x1b[31m%s\x1b[0m', message);
case 'warn':
return console.log('\x1b[33m%s\x1b[0m', message);
case 'info':
return console.log('\x1b[34m%s\x1b[0m', message);
case 'success':
return console.log('\x1b[32m%s\x1b[0m', message);
default:
return console.log(message);
}
};
this.log = (message) => {
this.print(message);
};
this.info = (message) => {
this.print(message, 'info');
};
this.error = (message, shouldExit = true) => {
this.print(message, 'error');
if (shouldExit) {
exit(1);
}
};
this.success = (message = null, shouldExit = true) => {
if (message) {
this.print(message, 'success');
}
if (shouldExit) {
exit(0);
}
};
this.config = config;
this.setUser();
}
}
//# sourceMappingURL=abstractCommand.js.map