我试图自动化准备机器以开始使用Cordova进行开发的过程,但我遇到了很多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');
});
});
当我跑步"项目"或者"插件" gulp总是在这条消息中给我一个错误:
插件错误' gulp-shell'信息: 产卵ENOENT细节: 代码:ENOENT 错误:ENOENT 系统调用:spawn
我在这里做错了什么? 感谢
答案 0 :(得分:2)
我有同样的问题,我已经能够追踪它了。在我的情况下,node_modules
文件夹由root拥有,但由于我没有使用root登录,因此我没有足够的权限访问已安装的npm模块。所以我的错是使用sudo
安装节点模块。
我的解决方案:
Shell命令:
sudo rm -r node_modules/
npm install
如果问题仍然存在:
如果您的npm安装抱怨权限不足,则应修复~/.npm
文件夹的所有权。
在我的情况下,我这样修复它:
sudo chown -R ~/.npm
如果仍然不够,这也可以提供帮助:https://stackoverflow.com/a/27955349/1646019
修改强> 另一个可能更好的解决方案可能就是这个程序:npm / yeoman install generator-angular without sudo