# All files / src/cli linker.js

42.86% Statements 12/28
0% Branches 0/6
0% Functions 0/4
34.78% Lines 8/23

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
    481x
    1x
    1x
    1x

    1x

    1x

    1x

    1x
     import path from 'path';
    import fs from 'fs';
    import { logTask, logWarning } from '../common';
    import { copyFolderContentsRecursiveSync } from '../systemTools/fileutils';

    const LINK = 'link';

    // ##########################################
    // PUBLIC API
    // ##########################################

    const run = (c) => {
        logTask('run');

        switch (c.command) {
        case LINK:
            return _link(c);
        default:
            return Promise.reject(`cli:linker: Command ${c.command} not supported`);
        }
    };

    // ##########################################
    // PRIVATE
    // ##########################################

    const _link = c => new Promise((resolve) => {
        if (fs.existsSync(c.paths.project.npmLinkPolyfill)) {
            const l = JSON.parse(fs.readFileSync(c.paths.project.npmLinkPolyfill).toString());
            Object.keys(l).forEach((key) => {
                // console.log('COPY', key, l[key]);
                const source = path.resolve(l[key]);
                const nm = path.join(source, 'node_modules');
                const dest = path.join(c.paths.project.nodeModulesDir, key);
                if (fs.existsSync(source)) {
                    copyFolderContentsRecursiveSync(source, dest, false, [nm]);
                } else {
                    logWarning(`Source: ${source} doesn't exists!`);
                }
            });
        } else {
            logWarning(`${c.paths.project.npmLinkPolyfill} file not found. nothing to link!`);
            resolve();
        }
    });

    export default run;