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

86.67% Statements 13/15
75% Branches 3/4
83.33% Functions 5/6
85.71% Lines 12/14

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      6x           6x         6x         6x       2x                         2x 2x 2x 2x           2x       2x               2x      
import {join} from 'path';
import {PackageJsonEditor, Scaffolder, allDoExist, install} from '../../api';
 
const DEPENDENCIES = [
    'electron',
    'electron-context-menu',
    'electron-debug',
    'electron-is-dev'
];
const DEV_DEPENDENCIES = [
    'electron-reloader',
    'npm-run-all',
    'spectron'
];
const ALWAYS = () => true;
/**
 * @type {task[]}
 * @see https://electronjs.org/
 */
export const tasks = [
    {
        text: 'Copy electron application files',
        task: async ({overwrite}) => {
            await (new Scaffolder(join(__dirname, 'templates')))
                .overwrite(overwrite)
                .target('.')
                .copy('index.js')
                .target('bin')
                .copy('preload.js')
                .commit();
        },
        condition: ALWAYS
    },
    {
        text: 'Configure metadata and add tasks to package.json',
        task: async ({useParcel}) => {
            const description = `Native Desktop application built with Electron`;
            const main = 'index.js';
            const name = 'tomo-native-app';
            const scripts = {
                'build:electron': 'npm-run-all build:es build:css',
                'prestart:electron': 'npm run build:electron',
                'start:electron': 'electron index --enable-logging',
                dev: `npm-run-all --parallel watch:es${useParcel ? '' : ' watch:css'} start:electron`
            };
            await (new PackageJsonEditor())
                .extend({description, main, name, scripts})
                .commit();
        },
        condition: () => allDoExist('package.json')
    },
    {
        text: 'Install electron dependencies',
        task: async ({skipInstall}) => {
            await install(DEPENDENCIES, {skipInstall});
            await install(DEV_DEPENDENCIES, {dev: true, skipInstall});
        },
        condition: ({skipInstall}) => !skipInstall && allDoExist('package.json')
    }
];
export default tasks;