grunt-contrib-compress icon indicating copy to clipboard operation
grunt-contrib-compress copied to clipboard

Windows compression linefeed

Open andobolocco opened this issue 9 years ago • 4 comments

When on windows, if I compress a file which has LF (I've also set grunt.util.linefeed = "\n"; in my Gruntfile.js), it ends up having CRLF inside the final .zip file.

Any ideas? I'm not sure who's reposible for this, how can it be debugged?

andobolocco avatar Nov 30 '15 17:11 andobolocco

Here's Gruntfile.js

module.exports = function(grunt) {

    "use strict";

    // main configuration
    var path = require('path'),
        NOW = new Date(),
        RELEASE = NOW.getFullYear() + '' + NOW.getMonth() + '' + NOW.getDate() + '_' + NOW.getHours() + '' + NOW.getMinutes() + '' + NOW.getSeconds(),
        ENVS = ['development', 'staging', 'production', 'desktop'],
        ENVS_COMPRESSED = ['staging', 'production', 'desktop'],
        ENVS_ONLINE = ['development', 'staging', 'production'],
        REPOS = {
            'development': path.resolve('./build/repos/development/'),
            'staging': path.resolve('./build/repos/staging/'),
            'production': path.resolve('./build/repos/production/'),
            'desktop': path.resolve('./build/repos/desktop/')
        };

    grunt.config.set('REPOS', REPOS);
    grunt.config.set('RELEASE', RELEASE);
    grunt.config.set('ENVS', ENVS);
    grunt.config.set('ENVS_COMPRESSED', ENVS_COMPRESSED);
    grunt.config.set('ENVS_ONLINE', ENVS_ONLINE);

    grunt.util.linefeed = "\n";

    // load tasks
    require('time-grunt')(grunt);
    require('./build/config/clean')(grunt);
    require('./build/config/jshint')(grunt);
    require('./build/config/requirejs')(grunt);
    require('./build/config/less')(grunt);
    require('./build/config/watch')(grunt);
    require('./build/config/copy')(grunt);
    require('./build/config/env')(grunt);
    require('./build/config/preprocess')(grunt);
    require('./build/config/compress')(grunt);
    require('./build/config/prompt')(grunt);
    require('./build/config/shell')(grunt);

    // load custom tasks
    grunt.loadTasks('./build/tasks');
};

Here's build/config/compress.js:

module.exports = function(grunt) {

    grunt.config('compress', {

        'development': {
            options: {
                mode: 'zip',
                archive: 'build/deploys/development_<%= RELEASE %>.zip'
            },
            files: [{
                expand: true,
                cwd: 'build/repos/development/',
                dest: '/dist',
                src: ['**/*']
            },{
                expand: true,
                cwd: 'server/development/codedeploy/',
                src: ['scripts/*', 'appspec.yml']
            }]
        },

        'staging': {
            options: {
                mode: 'zip',
                archive: 'build/deploys/staging_<%= RELEASE %>.zip'
            },
            files: [{
                expand: true,
                cwd: 'build/repos/staging/',
                dest: '/dist',
                src: ['**/*']
            },{
                expand: true,
                cwd: 'server/staging/codedeploy/',
                src: ['scripts/*', 'appspec.yml']
            }]
        },

    'production': {
            options: {
                mode: 'zip',
                archive: 'build/deploys/production_<%= RELEASE %>.zip'
            },
            files: [{
                expand: true,
                cwd: 'build/repos/production/',
                dest: '/dist',
                src: ['**/*']
            },{
                expand: true,
                cwd: 'server/production/codedeploy/',
                src: ['scripts/*', 'appspec.yml']
            }]
        }

    });

    grunt.loadNpmTasks('grunt-contrib-compress');
};

My issue is specially with files under the server/production/codedeploy/scripts directory, they need to be executed on a remote machine after building the zip, for deploying the built zip (original files have LF line endings). After uploading the zip files AWS CodeDeploy tries to execute those files under /scripts and I get this error: /bin/bash^M: bad interpreter: No such file or directory this happens because the script file inside the zip has CRLF or "Windows" line endings instead of LF, when executing the grunt task in a Windows machine. If I mannually replace the file inside the .zip file with the original one, and retry the deploy, it works fine because it has proper LF.

andobolocco avatar Nov 30 '15 17:11 andobolocco

Why is some part of the process ignoring the grunt.util.linefeed property? Why don't that part of the process simply keep original LF?

andobolocco avatar Nov 30 '15 17:11 andobolocco

could you explain why are u closing this issue?

andobolocco avatar Mar 04 '16 22:03 andobolocco

Reopened, we should investigate the file processing in the created archive...

vladikoff avatar Mar 04 '16 23:03 vladikoff