How to automate the build from the following configuration using gulp

INFOSYS

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

Rahul Singh

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'});
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to automate configuration of the Linux kernel build

How to build the following dictionary, from a list using regex?

How to script make menuconfig to automate Linux kernel build configuration?

How to Automate a Report from Namely using API

how to build the following dictionary from a json file?

How to automate the build of codenameone project (using only command line)?

How to automate Linux server configuration?

How to automate the process of using outputs from R as inputs in another software?

How to create Excel rows from Dataverse using Power Automate?

Automate the installation and configuration of Jenkins using puppet

Updating serviceworker configuration using gulp

how to generate .xap file using Visual Studio Team Services and how to automate the build generation process

How to publish an NPM package from the CI build pipeline and still automate versioning?

How to automate TFS to build xamarin.iOS

How to Automate Build and Deployment in Visual Studio TFS?

How to automate encryption using AES

How to automate this object using JavaScript?

How automate using sh scripting

How to build the following sql query

How to build the following dynamic query?

Data from Mongo in Gulp using Gulp Data

How to NOT download artifacts from previous stages for build configuration?

How to include/exclude source files from the project depending on the build configuration?

How to extract 'hello' from the following nested dictionary using indexing?

How to extract only the URL from the following strings using regular expressions?

To build a flow using Power Automate to download linked csv report in gmail

how do I correctly access karma.config object in gulp configuration to watch files, then run karma, and finally build if karma passes?

Setting up build server using Node and Gulp

Build this node project using only gulp or webpack