All files / src/commands add-esdoc.js

81.82% Statements 18/22
57.14% Branches 4/7
66.67% Functions 8/12
81.82% Lines 18/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90                6x                             6x           6x     6x         6x       2x 2x   2x         2x           2x 2x   2x         2x         2x           1x 1x 1x                 2x        
import {
    PackageJsonEditor,
    allDoExist,
    allDoNotExist,
    createJsonEditor,
    install
} from '../api';
 
const ESDOC_CONF = {
    source: './src',
    destination: './docs',
    plugins: [
        {
            name: 'esdoc-standard-plugin'
        },
        {
            name: 'esdoc-ecmascript-proposal-plugin',
            option: {
                all: true
            }
        }
    ]
};
const ESDOC_DEPENDENCIES = [
    'esdoc',
    'esdoc-jsx-plugin',
    'esdoc-ecmascript-proposal-plugin',
    'esdoc-standard-plugin'
];
const ESDOC_REACT_PLUGINS = [
    'esdoc-jsx-plugin'
];
const EsdocJsonEditor = createJsonEditor('esdoc.conf.json', ESDOC_CONF);
/**
 * @type {task[]}
 * @see https://esdoc.org/
 */
export const addEsdoc = [
    {
        text: 'Create esdoc configuration file',
        task: async () => {
            const cfg = new EsdocJsonEditor();
            await cfg.create().commit();
        },
        condition: () => allDoNotExist('esdoc.conf.json', '.esdoc.json')
    },
    {
        text: 'Add documentation tasks to package.json',
        task: async () => {
            const scripts = {
                'lint:docs': `eslint . --no-eslintrc --rule valid-jsdoc:error --parser babel-eslint`,
                predocs: 'npm run lint:docs',
                docs: `esdoc -c esdoc.conf.json`,
                postdocs: 'open-cli ./docs/index.html'
            };
            const pkg = new PackageJsonEditor();
            await pkg.extend({scripts}).commit();
        },
        condition: () => allDoExist('package.json')
    },
    {
        text: 'Install esdoc dependencies',
        task: ({skipInstall}) => install([...ESDOC_DEPENDENCIES, 'open-cli'], {dev: true, skipInstall}),
        condition: ({skipInstall}) => !skipInstall && allDoExist('package.json')
    },
    {
        text: 'Install esdoc React plugins',
        task: ({skipInstall}) => install(ESDOC_REACT_PLUGINS, {dev: true, skipInstall}),
        condition: ({skipInstall, useReact}) => !skipInstall && useReact && allDoExist('package.json'),
        optional: ({useReact}) => useReact
    },
    {
        text: 'Add esdoc React plugin to configuration file',
        task: async () => {
            const {plugins} = ESDOC_CONF;
            const cfg = new EsdocJsonEditor();
            await cfg
                .extend({
                    plugins: [...plugins, {
                        name: 'esdoc-jsx-plugin',
                        options: {enable: true}
                    }]
                })
                .commit();
        },
        condition: ({useReact}) => useReact && allDoExist('esdoc.conf.json'),
        optional: ({useReact}) => useReact
    }
];
export default addEsdoc;