如何使用gulp从以下配置自动化构建 [英] How to automate the build from the following configuration using gulp

查看:211
本文介绍了如何使用gulp从以下配置自动化构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个loopback和Angular应用程序,Loopback给出了使用服务器模型和api以及使用它的sdk我们能够获得客户服务。

现在我打算使用gulp自动执行以下构建过程。
如果模型中有任何更改,则运行sdk命令并重新启动服务器/其次,当角度文件发生任何更改时,运行sdk文件并从角度dist文件夹获取文件,服务器为重新启动和尽可能我们可以使用实时重新加载浏览器。



这是我试过的,这似乎从来没有工作过这个好几天。



更新



我能够自动执行大部分内容('browser-sync',function(){
browserSync.init(null,{

pre $ gulp.task
代理:'http:// localhost:3000 / home',
browser:'google chrome',
port:7000,
});
gulp。 (['client / src / app / *。ts'],browserSync.reload);
let watcher = gulp.watch(['./ common / models / **。js','./server /**.js','gulpfile.js'],['sdk','server']);
watcher.on('change',fu nction(event){
console.log('File'+ event.path +'是'+ event.type +',正在运行的任务...'); //这个观察者
});
});

gulp.task('sdk',function(){
spawn('./ node_modules / .bin / lb-sdk',['server / server.js','。 / client / src / app / shared / sdk','-q'],{stdio:'inherit'});
});

该观察者重新启动服务器并运行sdk,但在sdk中失败



堆栈跟踪请通过远程处理帮助

 。这个范围的Angular代码不会生成。 
[19:29:37]开始'sdk'...
[19:29:37] 11 ms后完成'sdk'
[19:29:37]启动'server '...
[19:29:37] 17 ms后完成'server'
events.js:163
throw er; // unhandled'error'事件
^

错误:产生./node_modules/.bin/lb-sdk ENOENT
在exports._errnoException(util.js:1050:11 )
在Process.ChildProcess._handle.onexit(internal / child_process.js:193:32)
在onErrorNT(internal / child_process.js:367:16)
在_combinedTickCallback(内部/ process / next_tick.js:80:11)
at process._tickCallback(internal / process / next_tick.js:104:9)

更新

我有多个gulp任务,其中一个是 ng build -w 在同一个新目录中发生,我改变 process.chdir 来改变路径,我也保留这个sdk的tab我需要再次检查她的路径。我如何检查或给我的产卵绝对路径。如果这是失败的可能原因之一

解决方案

考虑到您的更新



可能发生的情况是,一旦您使用 process.chdir 更改您的目录以执行分离任务,并且您还一直在观看在所有的任务上。路径设置为上一个路径,吞吐任务无法找到sdk i:e spawn('./ node_modules / .bin / lb-sdk',['server / server.js ','./client/src/app/shared/sdk','-q'],{stdio:'inherit'}); 在相应的路径中。



要解决这个问题,您可以在 sdk任务中添加以下检查



<$ p $如果(process.cwd()!= __dirname){//这将检查当前路径
进程。 chdir(< change path>); //如果剂量符合您的基本路径,请在此更改
}
spawn('./ node_modules / .bin / lb-sdk',['server / server .js','./client/src/app/shared/sdk','-q'],{stdio:'inherit'});
});


Backdrop

I have a loopback and Angular app, Loopback gives use the server models and api's and using its sdk we are able to get client services.

Now i am planning to automate the following build process using gulp. If any changes in the model is made then the sdk command is run and also the server is restarted/ and secondly when any changes to the angular files the sdk files are run and files are fetched from angular dist folder and server is restarted and best possible we can use live reload of browser.

Here is what i have tried and this never seems to work have been working on this for days.

Update

I was able to automate most of the stuff the one place where it fails is

gulp.task('browser-sync', function() {
  browserSync.init(null, {
    proxy: 'http://localhost:3000/home',
    browser: 'google chrome',
    port: 7000,
  });
  gulp.watch(['client/src/app/*.ts'], browserSync.reload);
  let watcher = gulp.watch(['./common/models/**.js', './server/**.js', 'gulpfile.js'], ['sdk', 'server']);
  watcher.on('change', function(event) {
    console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); // this watcher
  });
});

gulp.task('sdk', function() {
  spawn('./node_modules/.bin/lb-sdk', ['server/server.js', './client/src/app/shared/sdk', '-q'], {stdio: 'inherit'});
});

This watcher restarts the server and runs the sdk but it is failing in the sdk

The stack trace please help

via remoting. The Angular code for this scope won't be generated.
[19:29:37] Starting 'sdk'...
[19:29:37] Finished 'sdk' after 11 ms
[19:29:37] Starting 'server'...
[19:29:37] Finished 'server' after 17 ms
events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: spawn ./node_modules/.bin/lb-sdk ENOENT
    at exports._errnoException (util.js:1050:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Update

I have multiple gulp task and one such is ng build -w which happens in a new directory for the same i change the process.chdir to change path and i also keep tab of this sdk so do i need to check the path again her . How can i check or give absolute paths in my spawn . if this is one of the probable causes of failure

解决方案

Taking into account your update

What might be happening is that once you change your directory using process.chdir for a sepearate task and also you have kept watch on all the tasks . The path is set to the previous path and the gulp task is not able to find the sdk i:e spawn('./node_modules/.bin/lb-sdk', ['server/server.js', './client/src/app/shared/sdk', '-q'], {stdio: 'inherit'}); in that respective path .

To fix this you can add the following check in the sdk task

gulp.task('sdk', function() {
  if (process.cwd() != __dirname) { // this checks for the current path 
    process.chdir(<change path>); // if it dosent match your base path change it here
  }
  spawn('./node_modules/.bin/lb-sdk', ['server/server.js', './client/src/app/shared/sdk', '-q'], {stdio: 'inherit'});
});

这篇关于如何使用gulp从以下配置自动化构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆