Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed undefined destination filename, inc constellation with grunt-newer and grunt-contrib-watch #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

christian-beckmann
Copy link

With grunt build everything worked fine. But when I used grunt watch I get the error "Warning: Unable to write "undefined" file (Error code: undefined). Use --force to continue."
Because this.data.dest was not defined in this context. this.data.files alias this.files has the right destination filename. Inspired by grunt-contrib-coffee I wrote this bugfix and it "grunt watch" worked now correctly.

"grunt watch" gets an error: "Warning: Unable to write "undefined" file (Error code: undefined). Use --force to continue."
Therefore "this.data.dest" is undefined in an "grunt watch", use this.files instead.

"grunt build" is successful without errors.

Example configuration for this problem

package.json

{
    "name": "application-name",
    "version": "0.0.1",
    "dependencies": {
        "grunt": "~0.4.4",
        "grunt-contrib-clean": "~0.5.0",
        "grunt-contrib-copy": "~0.5.0",
        "grunt-contrib-watch": "~0.6.1",
        "grunt-mustache": "~0.1.6",
        "grunt-newer": "^0.7.0"
    }
}

Gruntfile.js

'use strict';
module.exports = function (grunt) {
    grunt.loadNpmTasks("grunt-mustache");
    grunt.loadNpmTasks("grunt-contrib-watch");
    grunt.loadNpmTasks("grunt-newer");
    grunt.loadNpmTasks("grunt-contrib-clean");
    grunt.loadNpmTasks("grunt-contrib-copy");

    var config, sourceDir, targetDir;
    sourceDir = 'src';
    targetDir = 'build';
    config = {};
    config.pkg = grunt.file.readJSON("package.json");
    config.clean = {
        dist: [targetDir]
    };
    config.copy = {
        app: {
            files: [
                {
                    cwd: sourceDir,
                    dest: targetDir,
                    src: "**/*.js",
                    expand: true
                }
            ]
        }
    };
    config.mustache = {
        app: {
            src: sourceDir + "/**/**.mustache",
            dest: targetDir + "/templates/templates.js",
            options: {
                prefix: 'window.templates = ',
                postfix: ';',
                verbose: true
            }
        }
    };
    config.watch = {
        all: {
            options: {
                atBegin: true,
                interval: 500
            },
            files: [sourceDir + "/**/**.js", sourceDir + "/**/**.mustache"],
            tasks: ["newer:mustache:app"]
        }
    };

    grunt.initConfig(config);
    grunt.registerTask("build", ["clean", "copy", "mustache:app"]);
    grunt.registerTask("view", ["mustache"]);
    return grunt.registerTask("default", "build");
};
@phun-ky
Copy link
Owner

phun-ky commented Feb 6, 2016

@christian-beckmann sorry for the delay here :S I've merged in the oldest PR, will that fix the current issue?

@phun-ky phun-ky self-assigned this Feb 6, 2016
@christian-beckmann
Copy link
Author

Hopefully it run's (did'nt test it). But at least I didn't have the project anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants