Search code examples
notificationsgulp

How to show native popup using Gulp


I am working on Gulp build process for automation. I have created a Gulp task for creating signed APK of android. Now I want to show a notification popup so that I can come to know my android APK is built.

Is there any way to show native popup in Gulp process?

I have done research and found node-notifier and gulp-notify modules but both are not working for me. Please help

As per posted answer,

I have tried with following, but no help... I am not getting notification. Does it requires Windows Toaster Support... I am using Windows 8.1 Pro.

gulp.task('notifier', function(){
    notify('Running from notifier task', 'Everything looks good');
});

function notify(title, message) {
    // Load dependencies
    var path = require('path');
    var notifier = require('node-notifier');
    var notifyOptions = {
        title: title,
        message: message,
        //icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
        sound: true, // Only Notification Center or Windows Toasters
        wait: true // Wait with callback, until user action is taken against notification
    };

    // start notifier
    notifier.notify(notifyOptions);
}

Solution

  • This is too late after asking the question, but I thought it's good to record my solutions here. So there are different commands to show a native popup for different OS.

    1. Windows

    Use the command msg * <Your_Message_Here>, for example, msg * Hello World. This popup closes automatically after 1 minute.

    2.iOS

    Use the command

    osascript -e 'tell app \"System Events\" to display dialog \"<Your_Message>\" with title \"<Your_Title>\"'"

    and then you can execute these commands using node exec,

    var WINDOWS_POPUP = "msg * MESSAGE";
    var MAC_POPUP = "osascript -e 'tell app \"System Events\" to display dialog \"MESSAGE\" with title \"SUCCESS\"'";
    
    function execCMD(cmd, cb) {
        exec(cmd,
        {
            cwd: './',
            maxBuffer: 2048 * 2048
        },
        function (err, stdout, stderr) {
            plugins.util.log(stdout);
            plugins.util.log(stderr);
            if (err) {
                cb(err);
            } else {
                cb(null,stdout);
            }
        });
    }
    /**
     * Rename android apk
     */
    gulp.task('copyAPK', function () {
        return gulp.src(APK_PATH)
            .pipe(plugins.if(args.signedAPK, plugins.rename(APK_NAME)))
            .pipe(gulp.dest(releaseDirName + '/Android/'))
            .on('end', function () {
                plugins.util.log(plugins.util.colors.green('Good Job! Your APK is ready at following location : ') + plugins.util.colors.cyan(releaseDirName + '/Android/' + APK_NAME))
                execCMD(WINDOWS_POPUP.replace('MESSAGE', 'Good Job! Your APK is ready at following location : ' + releaseDirName + '/Android/' + APK_NAME), function () {
                })
            });
    });
    
    /**
     * Copy generated IPA
     */
    gulp.task('copyIPA', function () {
        return gulp.src(IPA_PATH)
            .pipe(plugins.rename(IPA_NAME))
            .pipe(gulp.dest(releaseDirName + '/iOS/'))
            .on('end', function () {
                plugins.util.log(plugins.util.colors.green('Good Job! Your IPA is ready at following location : ') + plugins.util.colors.cyan(releaseDirName + '/iOS/' + IPA_NAME))
                execCMD(MAC_POPUP.replace('MESSAGE', 'Good Job! Your IPA is ready at following location : ' + releaseDirName + '/iOS/' + IPA_NAME), function () {
                })
            });
    })
    

    Hope this will help someone in scripting :).