How to use @jsdoc/core - 10 common examples

To help you get started, we’ve selected a few @jsdoc/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hegemonic / jsdoc-baseline / lib / template.js View on Github external
_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;
    }
github jsdoc / jsdoc / packages / jsdoc / lib / jsdoc / tag / type.js View on Github external
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;
}
github jsdoc / jsdoc / packages / jsdoc / cli.js View on Github external
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;
    };
github jsdoc / jsdoc / packages / jsdoc / templates / default / publish.js View on Github external
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));
github jsdoc / jsdoc / packages / jsdoc / lib / jsdoc / tutorial / resolver.js View on Github external
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()) {
github jsdoc / jsdoc / packages / jsdoc / templates / default / publish.js View on Github external
}
    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),
github jsdoc / jsdoc / packages / jsdoc / lib / jsdoc / src / astnode.js View on Github external
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;
github hegemonic / jsdoc-baseline / lib / template.js View on Github external
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'));
        }
github jsdoc / jsdoc / packages / jsdoc / lib / jsdoc / src / scanner.js View on Github external
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));
            }
        });
github hegemonic / jsdoc-baseline / lib / template.js View on Github external
this.config.views.partials.forEach(filepath => {
            partials = partials.concat(lsSync(path.resolve(this.path, filepath), 0));
        });
        this._addPartials(partials.concat(layouts));

@jsdoc/core

Core functionality for JSDoc.

Apache-2.0
Latest version published 7 months ago

Package Health Score

70 / 100
Full package analysis