1

I'm trying to automatize the process of prepare a machine to start developing with Cordova but i have many problems with CLI.

var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    jade = require('gulp-jade'),
    shell = require('gulp-shell'),
    coffee = require('gulp-coffee'),
    runSequence = require('run-sequence'),
    sass = require('gulp-ruby-sass');

gulp.task('build', function () {
    gulp.src(['app/**/*.*'])
        .pipe(gulp.dest('cordova/www/'));
});

gulp.task('sass', function () {
    gulp.src(['app/styles/main.scss'])
        .pipe(sass())
        .pipe(gulp.dest('app/styles/'));
});

gulp.task('cordova', function () {
    return gulp.src('/', {read: false})
        .pipe(shell([
            'npm install cordova'
        ]));
});

gulp.task('folder', function () {
    return gulp.src('/', {read: false})
        .pipe(shell([
            'mkdir -m 777 app'
        ]));
});

gulp.task('project', function () {
    return gulp.src('/')
        .pipe(shell([
            'cordova create . com.rvallespin.app app',
            //'cordova platform add ios',
            'cordova platform add android'
        ], {cwd: '/app'}));
});

gulp.task('plugins', function () {
    return gulp.src('/')
        .pipe(shell([
                'cordova plugin add https://github.com/apache/cordova-plugin-statusbar & ' +
                'cordova plugin add https://github.com/apache/cordova-plugin-device & ' +
                'cordova plugin add https://github.com/apache/cordova-plugin-network-information & ' +
                'cordova plugin add https://github.com/apache/cordova-plugin-battery-status &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-device-motion &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-device-orientation &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-geolocation &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-camera &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-media &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-media-capture &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-file &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-file-transfer &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-dialogs &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-vibration &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-contacts &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-globalization &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-splashscreen &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser &' +
                'cordova plugin add https://github.com/apache/cordova-plugin-console'
        ], {cwd: '/app'}));
});

gulp.task('install', function () {
    runSequence('cordova', 'folder', 'project', 'plugins');
});

gulp.task('default', function () {
    gulp.watch("app/styles/main.scss", function (event) {
        gulp.run('sass');
    });
});

When i run "project" or "plugins" gulp always returns me an error with this message:

Error in plugin 'gulp-shell' Message: spawn ENOENT Details: code: ENOENT errno: ENOENT syscall: spawn

What am i doing wrong here? Thanks

Raul Vallespin
  • 1,323
  • 2
  • 11
  • 16
  • I notice that you are making the project in a ROOT only folder: {cwd: '/app'}. Consider changing that to ./app – SteveLacy Jan 18 '15 at 21:57

1 Answers1

2

I had the same problem and I've been able to track it down. In my case the node_modules folder was owned by root, but since I wasn't logged in with root I didn't have sufficient rights to access the installed npm modules. So my fault was to install node modules using sudo.

My solution: Shell commands: sudo rm -r node_modules/ npm install

If the problem still persists: If your npm installation complains about insufficient rights, you should fix the ownership of your ~/.npm folder. In my case I fixed it this way:

sudo chown -R ~/.npm

If that still wasn't enough this can help too: https://stackoverflow.com/a/27955349/1646019

EDIT: Another, maybe better solution might be this procedure: npm / yeoman install generator-angular without sudo

Community
  • 1
  • 1
tmuecksch
  • 6,222
  • 6
  • 40
  • 61