Link to home
Start Free TrialLog in
Avatar of Leo Torres
Leo TorresFlag for United States of America

asked on

Grunt No Clean Targets

I dont under stand what is happening here with running my Gruntfile.js I am run at from a MACOS and Windows server 2012 both gave me exact error

This is my Gruntfile.js
'use strict';

module.exports = function (grunt) {

// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);

// Automatically load required Grunt tasks
require('jit-grunt')(grunt, {
  useminPrepare: 'grunt-usemin'
});

    // Define the configuration for all the tasks
    grunt.initConfig({
      pkg: grunt.file.readJSON('package.json'),


        // Make sure code styles are up to par and there are no obvious mistakes
  jshint: {
    options: {
      jshintrc: '.jshintrc',
      reporter: require('jshint-stylish')
    },
    all: {
      src: [
        'Gruntfile.js',
        'app/scripts/{,*/}*.js'
      ]
    }

 },
  useminPrepare: {
      html: 'app/menu.html',

      useminPrepare: {
          html: 'app/menu.html',
          options: {
              dest: 'dist'
          }
      },

      // Concat
      concat: {
          options: {
              separator: ';'
          },

          // dist configuration is provided by useminPrepare
          dist: {}
      },

      // Uglify
      uglify: {
          // dist configuration is provided by useminPrepare
          dist: {}
      },

      cssmin: {
          dist: {}
      },

      // Filerev
      filerev: {
          options: {
              encoding: 'utf8',
              algorithm: 'md5',
              length: 20
          },

          release: {
              // filerev:release hashes(md5) all assets (images, js and css )
              // in dist directory
              files: [{
                  src: [
                    'dist/scripts/*.js',
                    'dist/styles/*.css',
                  ]
              }]
          }
      },

      // Usemin
      // Replaces all assets with their revved version in html and css files.
      // options.assetDirs contains the directories for finding the assets
      // according to their relative paths
      usemin: {
          html: ['dist/*.html'],
          css: ['dist/styles/*.css'],
          options: {
              assetsDirs: ['dist', 'dist/styles']
          }
      },


      copy: {
          dist: {
              cwd: 'app',
              src: ['**', '!styles/**/*.css', '!scripts/**/*.js'],
              dest: 'dist',
              expand: true
          },

          fonts: {
              files: [
                {
                    //for bootstrap fonts
                    expand: true,
                    dot: true,
                    cwd: 'bower_components/bootstrap/dist',
                    src: ['fonts/*.*'],
                    dest: 'dist'
                }, {
                    //for font-awesome
                    expand: true,
                    dot: true,
                    cwd: 'bower_components/font-awesome',
                    src: ['fonts/*.*'],
                    dest: 'dist'
                }
              ]
          }
      },

      clean: {
          build: {
              src: ['dist/']
          }
      }
  }
 });



grunt.registerTask('build', [
  'clean',
  'jshint',
  'useminPrepare',
  'concat',
  'cssmin',
  'uglify',
  'copy',
  'filerev',
  'usemin'
]);


    grunt.registerTask('default',['build']);

};

Open in new window


Below is my output
PS V:\ProgramData\Coursera\AngularJS\Week2vs\conFusion> grunt -v
Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ build, default

No tasks specified, running default tasks.
Running tasks: default

Running "default" task

Running "build" task

Loading "grunt-contrib-clean" plugin

Registering "V:\ProgramData\Coursera\AngularJS\Week2vs\conFusion\node_modules\grunt-contrib-clean\tasks" tasks.
Loading "clean.js" tasks...OK
+ clean

Running "clean" task
>> No "clean" targets found.
Warning: Task "clean" failed. Use --force to continue.

Aborted due to warnings.


Execution Time (2016-10-21 23:44:36 UTC-4)
loading tasks                971ms  ███████████████████████████████████████████████████████ 75%
loading grunt-contrib-clean  332ms  ███████████████████ 25%
Total 1.3s

PS V:\ProgramData\Coursera\AngularJS\Week2vs\conFusion>

Open in new window



Here is a list of the directory
PS V:\ProgramData\Coursera\AngularJS\Week2vs\conFusion> ls


    Directory: V:\ProgramData\Coursera\AngularJS\Week2vs\conFusion


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        10/21/2016  11:43 PM            node_modules
d----        10/16/2016  11:11 PM            img
d----        10/18/2016   1:22 AM            app
d----        10/16/2016  11:11 PM            css
d----        10/16/2016  11:11 PM            bower_components
d----        10/16/2016  11:11 PM            js
d----        10/21/2016  12:44 AM            dist
d----        10/16/2016  11:11 PM            __MACOSX
d----        10/16/2016  11:11 PM            fonts
-a---        10/21/2016  11:48 PM       3223 Gruntfile.js
-a---         7/14/2016  11:05 PM      14624 aboutus.html
-a---         7/19/2016  11:14 PM        426 bower.json
-a---          7/4/2016   9:30 AM      12505 contactus.html
-a---         7/21/2016   7:54 AM      22837 index.html
-a---        10/21/2016  11:43 PM        588 package.json
-a---        10/20/2016  11:05 PM       3933 Gruntfile_new2.js
-a---        10/19/2016  11:12 PM       2904 Gruntfile_new.js


PS V:\ProgramData\Coursera\AngularJS\Week2vs\conFusion>

Open in new window

As you can see the dist folder is present line #15. I have been at this for a week now.
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leo Torres

ASKER

The task are run at the bottom by build

I finally got it to work. The open and closed braces were incorrectly placed.

'use strict';

module.exports = function (grunt) {

// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);

// Automatically load required Grunt tasks
require('jit-grunt')(grunt, {
  useminPrepare: 'grunt-usemin'
});

    // Define the configuration for all the tasks
    grunt.initConfig({
      pkg: grunt.file.readJSON('package.json'),


        // Make sure code styles are up to par and there are no obvious mistakes
  jshint: {
    options: {
      jshintrc: '.jshintrc',
      reporter: require('jshint-stylish')
    },
    all: {
      src: [
        'Gruntfile.js',
        'app/scripts/{,*/}*.js'
      ]
    }
  },
 useminPrepare: {
      html: 'app/menu.html',

      useminPrepare: {
          html: 'app/menu.html',
          options: {
              dest: 'dist'
          }
      },

      // Concat
      concat: {
          options: {
              separator: ';'
          },

          // dist configuration is provided by useminPrepare
          dist: {}
      },

      // Uglify
      uglify: {
          // dist configuration is provided by useminPrepare
          dist: {}
      },

      cssmin: {
          dist: {}
      },

 },
      // Filerev
      filerev: {
          options: {
              encoding: 'utf8',
              algorithm: 'md5',
              length: 20
          },

          release: {
              // filerev:release hashes(md5) all assets (images, js and css )
              // in dist directory
              files: [{
                  src: [
                    'dist/scripts/*.js',
                    'dist/styles/*.css',
                  ]
              }]
          }
      },

      // Usemin
      // Replaces all assets with their revved version in html and css files.
      // options.assetDirs contains the directories for finding the assets
      // according to their relative paths
      usemin: {
          html: ['dist/*.html'],
          css: ['dist/styles/*.css'],
          options: {
              assetsDirs: ['dist', 'dist/styles']
          }
      },
 
        

copy: {
  dist: {
    cwd: 'app',
    src: [ '**','!styles/**/*.css','!scripts/**/*.js' ],
    dest: 'dist',
    expand: true
  },
  
  fonts: {
    files: [
      {
        //for bootstrap fonts
        expand: true,
        dot: true,
        cwd: 'bower_components/bootstrap/dist',
        src: ['fonts/*.*'],
        dest: 'dist'
      }, {
        //for font-awesome
        expand: true,
        dot: true,
        cwd: 'bower_components/font-awesome',
        src: ['fonts/*.*'],
        dest: 'dist'
      }
    ]
  }
},

watch: {
  copy: {
    files: [ 'app/**', '!app/**/*.css', '!app/**/*.js'],
    tasks: [ 'build' ]
  },
  
  scripts: {
    files: ['app/scripts/app.js'],
    tasks:[ 'build']
  },
  
  styles: {
    files: ['app/styles/mystyles.css'],
    tasks:['build']
  },
  
  livereload: {
    options: {
      livereload: '<%= connect.options.livereload %>'
    },
    
    files: [
      'app/{,*/}*.html',
      '.tmp/styles/{,*/}*.css',
      'app/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
    ]
  }
},

connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729
  },
  
  dist: {
    options: {
      open: true,
      base:{
        path: 'dist',
        options: {
          index: 'menu.html',
          maxAge: 300000
        }
      }
    }
  }
},        
        

clean: {
  build: {
    src: [ 'dist/']
  }
},
      
        
 



 });



grunt.registerTask('build', [
  'clean',
  'jshint',
  'useminPrepare',
  'concat',
  'cssmin',
  'uglify',
  'copy',
  'filerev',
  'usemin'
]);

    grunt.registerTask('serve',['build','connect:dist','watch']);

    grunt.registerTask('default',['build']);

};

Open in new window

I got the answer. Will keep yours as an alternative approach.
I copied your file and looked for grunt.load which I did not find. The registerTask calls at the end just declare the tasks which can consist of other internal tasks as an external task. The Grunt functionality is held in the grunt.loadNpmTask()  calls. These, as far as I can remember can be external, but if you git everything and distrubte it elsewhere it is a good idea to encapsulate everything internally (I git my entire project grunt file, package.json and so on, which makes it easy to reinstall.

There is a good little book which I highly recommend "Automate with Grunt" by Brian Hogan
https://www.amazon.com/Automate-Grunt-Build-Tool-JavaScript/dp/1941222110/ref=sr_1_1?ie=UTF8&qid=1477227096&sr=8-1&keywords=automate+with+grunt
which for around 10 bucks is not bad.
Great I will look into the book.

On another note.  I can start a new thread but I cant understand why grunt works on my MACOS but not windows server 2012.


Folder sits on a share runs fine on Mac Windows gives error below. And yes Powershell and Command line were opened as ADMIN.
Writing dist\styles\main.css...Warning: Unable to create directory "V:\ProgramData\AngularJS\Week2vs\conFusion\dist" (Error code: EEXIST). Use --force
to continue.

Open in new window


Would you like a new thread?
Well this time no. My clean clears out build and dist :

 clean: ['build', 'dist'
		],

Open in new window


and as far as I remember it deletes both. Which means that they'll be recreated on build. Why do you have a funny directory structure build/src/dist?

I must admit to having set up my directory structure with Yeoman. It also generated all the relevant files as well.