MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/snap.cafsinfotech.in/node_modules/laravel-mix-serve/src/plugin/ServePlugin.js
const mix = require('laravel-mix')
const {spawn} = require("child_process");

const VerbosePlugin = require('./VerbosePlugin');

class ServePlugin {
    spawned = false

    modes = {
        prod: mix.inProduction(),
        dev: !mix.inProduction(),
        watch: false
    }

    constructor(config) {
        this.config = config
    }

    apply(compiler) {
        this.watchStatus(compiler);

        compiler.hooks[this.config.hook]
            .tap('ServePlugin', () =>
                this.spawnConditions(() =>
                    this.determineSpawn()));
    }

    watchStatus(compiler) {
        compiler.hooks.watchRun
            .tap('ServePlugin', () =>
                this.modes.watch = true);
    }

    spawnConditions(callback){
        if (this.spawned) return;

        for (const mode in this.modes) {
            if(this.modes[mode] === true && this.config[mode] === false) {
                if(mode === 'dev' && this.modes.watch === true) continue;

                return;
            }
        }

        callback()
    }

    determineSpawn() {
        this.config.verbose
            ? this.runSpawnVerbose()
            : this.runSpawn()
    }

    runSpawn() {
        return this.spawned = spawn(this.config.cmd, this.config.args, {shell: true})
    }

    runSpawnVerbose() {
        return new VerbosePlugin(this.runSpawn(), this.config)
    }
}

module.exports = ServePlugin;