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

Doesn't preprocess #22

Closed
nwmcsween opened this issue Oct 9, 2013 · 5 comments
Closed

Doesn't preprocess #22

nwmcsween opened this issue Oct 9, 2013 · 5 comments

Comments

@nwmcsween
Copy link

grep version node_modules/grunt-preprocess/package.json
"version": "3.0.1",

grep @if source/client/index.html
<!-- @if ENV='dev'>
<!-- @if ENV='rel'>
<!-- @if ENV='dev'>
<!-- @if ENV='rel'

grep -A 8 preprocess: Gruntfile.coffee
preprocess:
source:
files: [
expand: true
cwd: "#{config.hierarchy.source}"
src: '*/.html'
dest: "#{config.hierarchy.build}"
filter: 'isFile'
]

ENV='rel' grunt preprocess

Local Npm module "grunt-cli" not found. Is it installed?

Running "preprocess:source" (preprocess) task

Done, without errors.

grep "@if ENV='rel'" build/client/index.html
<!-- @if ENV='rel'>
<!-- @if ENV='rel'>

@jsoverson
Copy link
Owner

That is not the correct syntax for the directives.

<!-- @if ENV='dev' -->
foo
<!-- @endif -->

or conditional comment syntax

<!-- @if ENV='rel' !>
foo
<!-- @endif -->

This task also delegates to preprocess, so if you find this is still a problem, please open an issue there.

@nwmcsween
Copy link
Author

I fixed the syntax but I'm still hitting an issue on this, doing a ENV=rel grunt preprocess produces expected output but a ENV=rel grunt with preprocess in default taskset does not.

grunt.registerTask('build', ['preprocess', 'coffee', 'less'])
...
grunt.registerTask('default', ['build', 'optimize', 'install', 'check', 'test', 'test:e2e'])

@jsoverson
Copy link
Owner

Isolate the preprocess in the default list to make sure that works with grunt. If that does, then do you have anything overwriting the preprocessed files?

@nwmcsween
Copy link
Author

Nothing I can see and preprocess in default taskset does the same thing the env var ENV isn't being passed or is overwritten if invoked via grunt default vs grunt preprocess

config = hierarchy:
    build:  'build'
    source: 'source'
    client: 'client'
    server: 'server'
    static: 'static'

module.exports = (grunt) ->

#   config  = require('./config/config.coffee')
    md = require('matchdep')

    grunt.loadNpmTasks(p) for p in md.filter('grunt-*')

    grunt.registerTask('build', ['preprocess', 'coffee', 'less'])
    grunt.registerTask('optimize', ['imagemin', 'uglify'])
    grunt.registerTask('install', ['symlink', 'copy'])
    grunt.registerTask('check', ['lesslint', 'coffeelint', 'complexity'])
    grunt.registerTask('test', ['test:unit'])
    grunt.registerTask('test:unit', ['karma:unit'])
    grunt.registerTask('test:e2e', ['karma:e2e'])
    grunt.registerTask('default', [ 'build', 'optimize', 'install', 'check', 'test', 'test:e2e'])
    grunt.registerTask('dev', ['connect', 'watch'])

    grunt.registerTask('printenv', ->
        console.log(process.env))

    re = new RegExp("(#{config.hierarchy.source}|#{config.hierarchy.build}|#{config.hierarchy.static})")
    inBuild = (f) ->
        grunt.file.isFile(f.replace(re, "#{config.hierarchy.build}"))

    # Configuration
    grunt.initConfig

        clean: ["#{config.hierarchy.build}/**/*", "#{config.hierarchy.static}/**/*"]

        coffee:
            source:
                files: [
                    expand: true
                    cwd:    "#{config.hierarchy.source}"
                    src:    '**/*.coffee'
                    dest:   "#{config.hierarchy.build}"
                    ext:    '.js'
                    filter: 'isFile'
                ]

        coffeelint:
            options:
                indentation:
                    value: 4
            src: "#{config.hierarchy.source}/**/*.coffee"

        complexity:
            options:
                cyclomatic:         3
                halstead:           11
                maintainability:    100
            static:
                files: [
                    src:    ["#{config.hierarchy.static}/**/*.js",
                        "!#{config.hierarchy.static}/#{config.hierarchy.client}/vendor/**/*"]
                    filter: 'isFile'
                ]

        connect:
            server:
                options:
                    hostname: '*'
                    port:   8080
                    base:   "#{config.hierarchy.static}/#{config.hierarchy.client}"

        copy:
            source:
                files: [
                    expand: true
                    cwd:    "#{config.hierarchy.source}"
                    src:    ['**/*', '!**/*.{coffee,less}']
                    dest:   "#{config.hierarchy.static}"
                    filter: !inBuild
                ]

        imagemin:
            options:
                progressive:    false
                interlaced:     false
                pngquant:       false
            source:
                files: [
                    expand: true
                    cwd:    "#{config.hierarchy.source}"
                    src:    "**/*.{png,gif,jpg,jpeg}"
                    dest:   "#{config.hierarchy.build}"
                ]

        karma:
            source:
                client:
                    options:
                        configFile: 'config/karam.js'
                    background:
                        background: true
                        singleRun:  false
                    e2e:
                        browsers:   ['PhantomJS']
                        singleRun:  true
                    unit:
                        singleRun:  true

        less:
            source:
                files: [
                    expand: true
                    cwd:    "#{config.hierarchy.source}"
                    src:    '**/*.less'
                    dest:   "#{config.hierarchy.build}"
                    ext:    '.css'
                    filter: 'isFile'
                ]

        lesslint:
            options:
                csslint:
                    'adjoining-classes': false
            source:
                files: [
                    src:    "#{config.hierarchy.source}/**/*.less"
                    filter: 'isFile'
                ]

#       ngmin:
#           build:
#               expand: true
#               cwd:    "#{config.hierarchy.build}"
#               src:    "#{config.hierarchy.client}/**/*.js"
#               dest:   "#{config.hierarchy.build}"
#               filter: 'isFile'

        preprocess:
            source:
                files: [
                    expand: true
                    cwd:    "#{config.hierarchy.source}"
                    src:    '**/*.html'
                    dest:   "#{config.hierarchy.build}"
                    filter: 'isFile'
                ]


# TODO: sprtie-smith

        symlink:
            build:
                files: [
                    expand: true
                    cwd:    "#{config.hierarchy.build}"
                    src:    "**/*"
                    dest:   "#{config.hierarchy.static}"
                    filter: 'isFile'
                ]
            components:
                files: [
                    expand: true
                    cwd:    'bower_components'
                    src:    '**/*'
                    dest:   "#{config.hierarchy.static}/#{config.hierarchy.client}/vendor"
                    filter: 'isFile'
                ]

        uglify:
            options:
                compress:       true
                sequences:      true
                properties:     true
                dead_code:      true
                unsafe:         true
                conditionals:   true
                comparisons:    true
                evaluate:       true
                booleans:       true
                loop:           true
                unused:         true
                houst_funs:     true
                if_return:      true
                join_vars:      true
                cascade:        true
                warnings:       true
                negate_iife:    true
            source:
                files: [
                    expand: true
                    cwd:    "#{config.hierarchy.build}"
                    src:    '**/*.js'
                    dest:   "#{config.hierarchy.build}"
                ]

        watch:
            options:
                debounceDelay:  200
                livereload:     true
                nospawn:        true
            coffee:
                files: ["#{config.hierarchy.source}/**/*.coffee"]
                tasks: ['coffeelint', 'coffee']
            image:
                files: ["#{config.hierarchy.source}/**/*.{png,gif,jpg,jpeg}"]
                tasks: ['imagemin']
            js:
                files: ["#{config.hierarchy.build}/**/*.js"]
                tasks: ['uglify']
            less:
                files: ["#{config.hierarchy.source}/**/*.less"]
                tasks: ['lesslint', 'less']
            link:
                files: ["#{config.hierarchy.build}'**/*"]
                tasks: ['symlink']
            unit:
                files: ["#{config.hierarchy.static}/#{config.hierarchy.client}/tests/**/*"]
                tasks: ['karma:source:client:background:run']

@jsoverson
Copy link
Owner

Just double checked on my machine and all looks well, posting to confirm.

[joverson@joverson-riot:~/temp/pp]
[10:01:44] $ ENV=dev grunt && cat done.html
Running "preprocess:main" (preprocess) task

Done, without errors.
HTML START
----------
Only shows if dev
----------

[joverson@joverson-riot:~/temp/pp]
[10:01:47] $ ENV=rel grunt && cat done.html
Running "preprocess:main" (preprocess) task

Done, without errors.
HTML START
----------
Only shows if rel
----------

[joverson@joverson-riot:~/temp/pp]
[10:01:52] $ ENV=dev grunt preprocess && cat done.html
Running "preprocess:main" (preprocess) task

Done, without errors.
HTML START
----------
Only shows if dev
----------

[joverson@joverson-riot:~/temp/pp]
[10:01:59] $ ENV=rel grunt preprocess && cat done.html
Running "preprocess:main" (preprocess) task

Done, without errors.
HTML START
----------
Only shows if rel
----------

Gruntfile :

module.exports = function(grunt) {

  grunt.initConfig({
    preprocess : {
      main : { src : 'index.html', dest : 'done.html' }
    }
  });

  grunt.loadNpmTasks('grunt-preprocess')

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

};

index.html

HTML START
----------
<!-- @if ENV='dev' -->
Only shows if dev
<!-- @endif -->

<!-- @if ENV='rel' !>
Only shows if rel
<!-- @endif -->
----------

If you find out the issue, please update the ticket. There's not much I can do to troubleshoot from my end. I'd recommend limiting as much as possible to isolate the variables and then testing configurations to find out what is broken.

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

No branches or pull requests

2 participants