Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_l10nInit() {
const l10nData = [];
let l10nFiles;
try {
l10nFiles = lsSync(this.config.l10n, 0);
} catch (e) {
logger.fatal(`Unable to find the localization data file ${this.config.l10nFile}`);
return this;
}
l10nFiles.forEach(filepath => {
l10nData.push(loadYaml(filepath));
});
// Merge the objects in reverse order so that the first one loaded wins.
this._l10nData = deepExtend.apply(deepExtend, l10nData.reverse());
this._l10nFormatter = new MessageFormat(this.locale).compile(this._l10nData);
return this;
}
function parseName(tagInfo) {
// like '[foo]' or '[ foo ]' or '[foo=bar]' or '[ foo=bar ]' or '[ foo = bar ]'
// or 'foo=bar' or 'foo = bar'
if ( /^(\[)?\s*(.+?)\s*(\])?$/.test(tagInfo.name) ) {
tagInfo.name = RegExp.$2;
// were the "optional" brackets present?
if (RegExp.$1 && RegExp.$3) {
tagInfo.optional = true;
}
// like 'foo=bar' or 'foo = bar'
if ( /^(.+?)\s*=\s*(.+)$/.test(tagInfo.name) ) {
tagInfo.name = RegExp.$1;
tagInfo.defaultvalue = cast(RegExp.$2);
}
}
return tagInfo;
}
try {
env.opts = engine.parseFlags(env.args);
}
catch (e) {
props.shouldPrintHelp = true;
cli.exit(
1,
`${e.message}\n`
);
return cli;
}
try {
conf = config.loadSync(env.opts.configure);
env.conf = conf.config;
}
catch (e) {
cli.exit(
1,
`Cannot parse the config file ${conf.filepath}: ${e}\n${FATAL_ERROR_MESSAGE}`
);
return cli;
}
// look for options on the command line, then in the config
env.opts = _.defaults(env.opts, env.conf.opts);
return cli;
};
if (!sourceFilePaths.includes(sourcePath)) {
sourceFilePaths.push(sourcePath);
}
}
});
// update outdir if necessary, then create outdir
packageInfo = ( find({kind: 'package'}) || [] )[0];
if (packageInfo && packageInfo.name) {
outdir = path.join( outdir, packageInfo.name, (packageInfo.version || '') );
}
mkdirpSync(outdir);
// copy the template's static files to outdir
fromDir = path.join(templatePath, 'static');
staticFiles = lsSync(fromDir);
staticFiles.forEach(fileName => {
const toPath = sourceToDestination(fromDir, fileName, outdir);
mkdirpSync(path.dirname(toPath));
fs.copyFileSync(fileName, toPath);
});
// copy the fonts used by the template to outdir
staticFiles = lsSync(path.join(require.resolve('open-sans-fonts'), '..', 'open-sans'));
staticFiles.forEach(fileName => {
const toPath = path.join(outdir, 'fonts', path.basename(fileName));
if (FONT_NAMES.includes(path.parse(fileName).name)) {
mkdirpSync(path.dirname(toPath));
exports.load = filepath => {
let content;
let current;
const files = lsSync(filepath, {
depth: env.opts.recurse ? env.conf.recurseDepth : 0
});
let name;
let match;
let type;
// tutorials handling
files.forEach(file => {
match = file.match(finder);
// any filetype that can apply to tutorials
if (match) {
name = path.basename(match[1]);
content = fs.readFileSync(file, env.opts.encoding);
switch (match[2].toLowerCase()) {
}
mkdirpSync(outdir);
// copy the template's static files to outdir
fromDir = path.join(templatePath, 'static');
staticFiles = lsSync(fromDir);
staticFiles.forEach(fileName => {
const toPath = sourceToDestination(fromDir, fileName, outdir);
mkdirpSync(path.dirname(toPath));
fs.copyFileSync(fileName, toPath);
});
// copy the fonts used by the template to outdir
staticFiles = lsSync(path.join(require.resolve('open-sans-fonts'), '..', 'open-sans'));
staticFiles.forEach(fileName => {
const toPath = path.join(outdir, 'fonts', path.basename(fileName));
if (FONT_NAMES.includes(path.parse(fileName).name)) {
mkdirpSync(path.dirname(toPath));
fs.copyFileSync(fileName, toPath);
}
});
// copy the prettify script to outdir
PRETTIFIER_SCRIPT_FILES.forEach(fileName => {
const toPath = path.join(outdir, 'scripts', path.basename(fileName));
fs.copyFileSync(
path.join(require.resolve('code-prettify'), '..', fileName),
case Syntax.RestElement:
str = nodeToValue(node.argument);
break;
case Syntax.ThisExpression:
str = 'this';
break;
case Syntax.UnaryExpression:
// like -1. in theory, operator can be prefix or postfix. in practice, any value with a
// valid postfix operator (such as -- or ++) is not a UnaryExpression.
str = nodeToValue(node.argument);
if (node.prefix === true) {
str = cast(node.operator + str);
}
else {
// this shouldn't happen
throw new Error(`Found a UnaryExpression with a postfix operator: ${node}`);
}
break;
case Syntax.VariableDeclarator:
str = nodeToValue(node.id);
break;
default:
str = '';
}
return str;
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/** @module lib/template */
const _ = require('lodash');
const beautify = require('js-beautify').html;
const config = require('./config');
const deepExtend = require('deep-extend');
const handlebars = require('handlebars');
const handlebarsLayouts = require('handlebars-layouts');
const loader = require('./loader');
const { lsSync } = require('@jsdoc/core').fs;
const MessageFormat = require('messageformat');
const logger = require('jsdoc/util/logger');
const path = require('path');
const { readFileSync } = require('fs');
const yaml = require('js-yaml');
// Maximum file size that we'll try to beautify.
const MAX_BEAUTIFY_SIZE = 1024 * 128;
function loadYaml(filepath) {
let parsedObject;
try {
if (filepath) {
parsedObject = yaml.load(readFileSync(filepath, 'utf8'));
}
const filepath = path.resolve(process.cwd(), decodeURIComponent($));
try {
currentFile = statSync(filepath);
}
catch (e) {
logger.error('Unable to find the source file or directory %s', filepath);
return;
}
if ( currentFile.isFile() ) {
filePaths.push(filepath);
}
else {
filePaths = filePaths.concat(lsSync(filepath, depth));
}
});
this.config.views.partials.forEach(filepath => {
partials = partials.concat(lsSync(path.resolve(this.path, filepath), 0));
});
this._addPartials(partials.concat(layouts));