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

Windows compression linefeed #169

Open
andobolocco opened this issue Nov 30, 2015 · 4 comments
Open

Windows compression linefeed #169

andobolocco opened this issue Nov 30, 2015 · 4 comments

Comments

@andobolocco
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

could you explain why are u closing this issue?

@vladikoff vladikoff reopened this Mar 4, 2016
@vladikoff
Copy link
Member

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

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