@salesforce/templates
Version:
Salesforce JS library for templates
69 lines • 3.06 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.SfdxGenerator = void 0;
const fs = require("fs");
const path = require("path");
const Generator = require("yeoman-generator");
const templateService_1 = require("../service/templateService");
/**
* Base class for generators
*/
class SfdxGenerator extends Generator {
/**
* The constructor for the SFDXGenerator.
*
* @param args arguments to pass to the yeoman generator constructor.
* @param options SFDXGenerator specific options.
* @param features The yeoman GeneratorFeatures. Defaults to a customInstallTask of false in order to skip the automatic npm/yarn install. Override to true if you need to run the package manager install.
*/
constructor(args, options,
// custom install task set to true keeps us from getting a warning message about a missing package.json file.
// Note for generators that need an npm install it should be set to false.
features = {
customInstallTask: true,
}) {
var _a, _b;
super(args, options, features);
this.apiversion =
(_a = options.apiversion) !== null && _a !== void 0 ? _a : templateService_1.TemplateService.getDefaultApiVersion();
this.outputdir = (_b = options.outputdir) !== null && _b !== void 0 ? _b : process.cwd();
this.validateOptions();
}
/**
* Set source root to built-in templates or custom templates root if available.
* @param partialPath the relative path from the templates folder to templates root folder.
*/
sourceRootWithPartialPath(partialPath) {
this.builtInTemplatesRootPath = path.join(__dirname, '..', 'templates', partialPath);
const { customTemplatesRootPath } = templateService_1.TemplateService.getInstance();
if (!customTemplatesRootPath) {
this.sourceRoot(path.join(this.builtInTemplatesRootPath));
}
else {
if (fs.existsSync(path.join(customTemplatesRootPath, partialPath))) {
this.sourceRoot(path.join(customTemplatesRootPath, partialPath));
}
}
}
templatePath(...paths) {
// The template paths are relative to the generator's source root
// If we have set a custom template root, the source root should have already been set.
// Otherwise we'll fallback to the built-in templates
const customPath = super.templatePath(...paths);
if (fs.existsSync(customPath)) {
return customPath;
}
else {
// files that are builtin and not in the custom template folder
return super.templatePath(path.join(this.builtInTemplatesRootPath, ...paths));
}
}
}
exports.SfdxGenerator = SfdxGenerator;
//# sourceMappingURL=sfdxGenerator.js.map