@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
96 lines • 3.06 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const globby_1 = __importDefault(require("@sprucelabs/globby"));
const WriterFactory_1 = __importDefault(require("../writers/WriterFactory"));
const feature_utilities_1 = __importDefault(require("./feature.utilities"));
class AbstractFeature {
dependencies = [];
packageDependencies = [];
optionsSchema;
fileDescriptions = [];
installOrderWeight = 0;
cwd;
scripts = {};
actionsDir;
actions;
templates;
emitter;
features;
ui;
serviceFactory;
storeFactory;
writers;
apiClientFactory;
actionExecuter;
actionCodes;
constructor(options) {
this.cwd = options.cwd;
this.serviceFactory = options.serviceFactory;
this.templates = options.templates;
this.actions = options.actionFactory;
this.storeFactory = options.storeFactory;
this.writers = new WriterFactory_1.default({
templates: this.templates,
ui: options.ui,
settings: this.Service('settings'),
linter: this.Service('lint'),
});
this.emitter = options.emitter;
this.features = options.featureInstaller;
this.ui = options.ui;
this.apiClientFactory = options.apiClientFactory;
this.actionExecuter = options.actionExecuter;
}
Action(featureCode, actionCode) {
return this.actionExecuter.Action(featureCode, actionCode);
}
async beforePackageInstall(_options) {
return {};
}
async afterPackageInstall(_options) {
return {};
}
Service(type, cwd) {
return this.serviceFactory.Service(cwd ?? this.cwd, type);
}
Writer(code, options) {
return this.writers.Writer(code, {
fileDescriptions: this.fileDescriptions,
linter: this.Service('lint'),
...options,
});
}
getFeature(code) {
return this.features.getFeature(code);
}
async getAvailableActionCodes() {
if (!this.actionsDir) {
return [];
}
if (!this.actionCodes) {
const matches = await (0, globby_1.default)(path_1.default.join(this.actionsDir, '**/*Action.js'));
const codes = [];
for (const match of matches) {
const generatedCode = feature_utilities_1.default.filePathToActionCode(match);
codes.push(generatedCode);
}
this.actionCodes = codes;
}
return this.actionCodes;
}
Store(code, options) {
return this.storeFactory.Store(code, {
cwd: this.cwd,
...options,
});
}
async connectToApi(options) {
return this.apiClientFactory(options);
}
}
exports.default = AbstractFeature;
//# sourceMappingURL=AbstractFeature.js.map