UNPKG

salesforcedx-templates

Version:

Salesforce CLI scaffolding commands for different types of Force.com metadata

47 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* * Copyright (c) 2019, 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 */ const core_1 = require("@salesforce/core"); const fs = require("fs"); const path = require("path"); core_1.Messages.importMessagesDirectory(__dirname); const messages = core_1.Messages.loadMessages('salesforcedx-templates', 'messages'); /* tslint:disable:no-unused-expression */ class CreateUtil { static checkInputs(flagValue) { const alphaRegExp = /^\w+$/; if (!alphaRegExp.test(flagValue)) { throw new Error(messages.getMessage('AlphaNumericNameError')); } const letterStartRegExp = /^[A-Za-z]/; if (!letterStartRegExp.test(flagValue)) { throw new Error(messages.getMessage('NameMustStartWithLetterError')); } const endUnderscore = /_$/; if (endUnderscore.test(flagValue)) { throw new Error(messages.getMessage('EndWithUnderscoreError')); } const dblUnderscore = /__/; if (dblUnderscore.test(flagValue)) { throw new Error(messages.getMessage('DoubleUnderscoreError')); } return ''; } // TODO: switch filetype to a string instead of regex static getCommandTemplatesForFiletype(filetype, command) { const files = fs .readdirSync(path.resolve(__dirname, '..', 'templates', command)) .filter(file => filetype.test(file)) .map(file => { return file.split('.', 1).toString(); }); return files; } } exports.CreateUtil = CreateUtil; //# sourceMappingURL=createUtil.js.map