Table of Contents

Web - Gulp Builder

About

Gulp is a task orchestrator that can:

Code snippet

Copy File

import gulpfile from 'gulp'
function serverCopy() {
    return gulpfile.src([
        dist + '/client/index.html',
        dist + '/client/.vite/ssr-manifest.json',
        dist + '/server/entry-server.js'
    ])
        .pipe(gulpfile.dest(serverDestination));
}

Delete File/Directory

import {deleteAsync} from 'del'
export function clean() {
    return deleteAsync([
        dist,
        hostingDestination + '/*',
        serverDestination + '/*'
    ])
}

Execute Command (Yarn build)

import {spawn} from 'child_process';
function build(cb) {

    // We use spawn (and not exec) to get live feedback on the std streams (
    // https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
    // without the shell option, we get ENOENT (yarn is not found)
    const cmd = spawn('yarn', ['build'], {shell: true});
    cmd.stdout.on('data', (data) => {
        // process.stdout and not console.log to not add a new line
        process.stdout.write(data);
    });
    cmd.stderr.on('data', (data) => {
        // process.stderr and not console.err to not add a new line
        process.stderr.write(data);
    });
    cmd.on('close', function (code) {
        if (code !== 0) {
            process.stderr.write(`Error on yarn build. The process exited with the code ${code}`);
        } else {
            process.stdout.write('Yarn build was successful');
        }
        cb(code);
    });

}

Documentation / Reference