jetup
Version:
Jetup: JavaScript Project Setup! Jetting-up your next JS project in seconds with one command, using fully modular, customizable presets, instantly ready to code!.
72 lines • 3.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseModule = void 0;
const utils_1 = require("../../utils");
const config_1 = require("../config");
const logger_1 = require("../logger");
class BaseModule {
constructor() {
this.cwd = (0, utils_1.cwd)();
this.autoInstallDeps = false;
}
get name() {
const name = this.constructor.name.replace('Module', '');
return name.charAt(0).toLowerCase() + name.substring(1);
}
setCWD(cwd) {
this.cwd = cwd;
}
setRegistry(registry) {
if (!this.registry)
throw new Error(`${this.name}.registry is not configured`);
registry.register(this.registry, this);
const configModule = registry.get(config_1.ConfigModule);
const config = configModule.get(this.name);
this.config = config;
const loggerModule = registry.get(logger_1.LoggerModule);
this.logger = loggerModule;
}
async isInstalled() {
let depsExists = this.config.installedIfDepsExists.length === 0;
let filesOrFoldersExists = this.config.installedIfFilesOrFoldersExists.length === 0;
this.logger.info(`checking whether ${this.name} module is already installed...`);
depsExists = this.config.installedIfDepsExists.every(deps => {
const dep = (0, utils_1.getPackageName)(deps);
const exists = (0, utils_1.hasJsonProperty)((0, utils_1.cwd)('package.json'), `devDependencies.${dep}`);
this.logger.info(`Dependency "${dep}" ${exists ? 'found' : 'not found'} in package.json devDependencies`);
return exists;
});
filesOrFoldersExists = this.config.installedIfFilesOrFoldersExists.every(filesOrFolders => {
const exists = (0, utils_1.isFolderExists)((0, utils_1.cwd)(filesOrFolders)) || (0, utils_1.isFileExists)((0, utils_1.cwd)(filesOrFolders));
this.logger.info(`File/folder "${filesOrFolders}" ${exists ? 'found' : 'not found'}`);
return exists;
});
if (depsExists && filesOrFoldersExists) {
this.logger.info(`module "${this.name}" is already installed! Skipping setup...`);
return true;
}
this.logger.info(`module "${this.name}" is not yet installed! Continuing setup...`);
return false;
}
async setup() {
throw new Error(`setup for class ${this.constructor.name} is not implemented`);
}
async installDeps() {
if (this.autoInstallDeps && this.config.installedIfDepsExists.length > 0) {
this.logger.info(`auto installing dev dependencies of "${this.name}" module...`);
const depsExists = this.config.installedIfDepsExists.every(deps => {
const dep = (0, utils_1.getPackageName)(deps);
const exists = (0, utils_1.hasJsonProperty)((0, utils_1.cwd)('package.json'), `devDependencies.${dep}`);
this.logger.info(`Dependency "${dep}" ${exists ? 'found' : 'not found'} in package.json devDependencies`);
return exists;
});
if (!depsExists) {
this.logger.info(`installing [${this.config.installedIfDepsExists.join(', ')}] as devDependencies`);
await (0, utils_1.packageInstallDev)(this.config.installedIfDepsExists.join(' '));
}
this.logger.info(`dependencies installation of "${this.name}" module completed!`);
}
}
}
exports.BaseModule = BaseModule;
//# sourceMappingURL=base.js.map