All files / src/commands/add-marionette index.js

85% Statements 17/20
60% Branches 6/10
70% Functions 7/10
84.21% Lines 16/19

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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112                6x                   6x         6x       1x 1x 1x 1x 2x 2x   1x                             1x                                                                                     1x           1x 1x       1x         1x      
import {join} from 'path';
import {
    PackageJsonEditor,
    Scaffolder,
    allDoExist,
    install
} from '../../api';
 
const MARIONETTE_DEPENDENCIES = [
    'jquery',
    'backbone',
    'backbone.marionette',
    'backbone.radio',
    'marionette.approuter',
    'lit-html',
    'lodash-es',
    'redux'
];
const ALWAYS = async () => true;
/**
 * @type {task[]}
 * @see https://marionettejs.com/
 */
export const tasks = [
    {
        text: 'Copy Marionette.js boilerplate and assets',
        task: async ({assetsDirectory, overwrite, sourceDirectory, useParcel, useRollup, useSnowpack}) => {
            const inPlace = (useParcel || useSnowpack) ? '-in-place' : '';
            const index = `index${inPlace}${useRollup ? '-rollup' : ''}.html`;
            const fonts = `fonts${inPlace}.css`;
            const format = filename => {
                const [name, extension] = filename.split('.');
                return `${name}${useSnowpack ? '-snowpack' : ''}.${extension}`;
            };
            await (new Scaffolder(join(__dirname, 'templates')))
                .overwrite(overwrite)
                .target(sourceDirectory)
                .copy('main.js')
                .target(`${sourceDirectory}/components`)
                .copy('app.js')
                .copy('header.js')
                .copy(format('body.js'), 'body.js')
                .copy('footer.js')
                .target(`${sourceDirectory}/shims`)
                .copy('mn.renderer.shim.js')
                .target(`${sourceDirectory}/plugins`)
                .copy('mn.radio.logging.js')
                .copy('mn.redux.state.js')
                .commit();
            await (new Scaffolder(join(__dirname, '..', 'common', 'templates')))
                .overwrite(overwrite)
                .target('.')
                .copy('gitignore', '.gitignore')
                .target(`${assetsDirectory}`)
                .copy(index, 'index.html')
                .target(`${assetsDirectory}/css`)
                .copy(format('style.css'), 'style.css')
                .copy(fonts, 'fonts.css')
                .target(`${assetsDirectory}/images`)
                .copy('blank_canvas.png')
                .copy('preferences.png')
                .target(`${assetsDirectory}/fonts`)
                .copy('SansForgetica-Regular.eot')
                .copy('SansForgetica-Regular.svg')
                .copy('SansForgetica-Regular.ttf')
                .copy('SansForgetica-Regular.woff')
                .copy('SansForgetica-Regular.woff2')
                .target(`${assetsDirectory}/library`)
                .copy('.gitkeep')
                .target(`${assetsDirectory}/workers`)
                .copy('.gitkeep')
                .commit();
        },
        condition: ALWAYS
    },
    {
        text: 'Copy Rust boilerplate',
        task: async ({overwrite}) => {
            await (new Scaffolder(join(__dirname, '..', 'common', 'templates')))
                .overwrite(overwrite)
                .target('.')
                .copy('Cargo.toml')
                .target('rust-to-wasm')
                .copy('Cargo_crate.toml', 'Cargo.toml')
                .target('rust-to-wasm/src')
                .copy('lib.rs')
                .copy('utils.rs')
                .target('rust-to-wasm/tests')
                .copy('app.rs')
                .copy('web.rs')
                .commit();
        },
        condition: ({withRust}) => withRust,
        optional: ({withRust}) => withRust
    },
    {
        text: 'Set package.json "main" attribute',
        task: async ({sourceDirectory}) => {
            const main = `${sourceDirectory}/main.js`;
            await (new PackageJsonEditor())
                .extend({main})
                .commit();
        },
        condition: () => allDoExist('package.json')
    },
    {
        text: 'Install Marionette.js dependencies',
        task: ({skipInstall}) => install(MARIONETTE_DEPENDENCIES, {skipInstall}),
        condition: ({skipInstall}) => !skipInstall && allDoExist('package.json')
    }
];
export default tasks;