@salesforce/templates
Version:
Salesforce JS library for templates
70 lines • 2.27 kB
JavaScript
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemplateService = exports.importGenerator = void 0;
const types_1 = require("../utils/types");
const i18n_1 = require("../i18n");
function importGenerator(templateType) {
const generator = types_1.generators.get(templateType);
if (!generator) {
throw new Error(i18n_1.nls.localize('templateTypeNotFound'));
}
return generator;
}
exports.importGenerator = importGenerator;
/**
* Template Service
*/
class TemplateService {
constructor(cwd = process.cwd()) {
this._cwd = cwd;
}
/**
* Get an instance of TemplateService
* @param cwd cwd of current environment. CLI: don't need to set explicitly. VS Code: it's typically the root workspace path
*/
static getInstance(cwd) {
if (!TemplateService.instance) {
TemplateService.instance = new TemplateService(cwd);
}
else if (cwd) {
TemplateService.instance.cwd = cwd;
}
return TemplateService.instance;
}
/**
* Getting cwd of current environment
*/
get cwd() {
return this._cwd;
}
/**
* Setting cwd of current environment
* In VS Code, it's typically the root workspace path
*/
set cwd(cwd) {
this._cwd = cwd;
}
/**
* Create using templates
* @param templateType template type
* @param templateOptions template options
* @param customTemplatesRootPathOrGitRepo custom templates root path or git repo. If not specified, use built-in templates
*/
create(templateType, templateOptions, customTemplatesRootPathOrGitRepo) {
const runOptions = {
cwd: this.cwd,
customTemplatesRootPathOrGitRepo,
};
const Generator = importGenerator(templateType);
const instance = new Generator(templateOptions);
return instance.run(runOptions);
}
}
exports.TemplateService = TemplateService;
//# sourceMappingURL=templateService.js.map
;