4

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

4
  • It believes that ./node_modules/.bin/lb-sdk doesn't exist. Can you confirm it definitely does? Commented Dec 16, 2017 at 14:50
  • Or more specifically, it can't find it in relation to your gulpfile, or the directory that you're running gulp itself from. The ENOENT is an error that relates to spawn not finding the file in question. I'm writing these as comments because I can't 100% say it's all the answer is down to, but let me know if it helps in some way and I'll see if I can form a more solid answer. Commented Dec 16, 2017 at 15:26
  • Can you be positive about ./node_modules/.bin/lb-sdk? Does it exist? Commented Dec 16, 2017 at 15:27
  • Yes if i run it stand alone it works onlyy that task Commented Dec 17, 2017 at 12:12

2 Answers 2

1
+50

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'});
});
Sign up to request clarification or add additional context in comments.

Comments

0
  1. Are you sure you've run npm install --save-dev @mean-expert/loopback-sdk-builder?
  2. Are you sure that gulpfile.js is in the same dir as package.json?
  3. Are you certain ./node_modules/.bin/lb-sdk exists?
  4. Have you tried reinstalling everything?

The answer to the error is simply that your spawn function can't find ./node_modules/.bin/lb-sdk. This is either because the file doesn't exist, or because the it can't be found relatively to your gulpfile.js

The ENOENT error in the console means "error: no entity". It comes from UNIX, rather than Node itself, and basically just translates to "file not found", but applies to a variety of generic things, not just files/directories.

Check that the file ./node_modules/.bin/lb-sdk definitely exists. Then check that your gulpfile is in the root relative to that directory.

4 Comments

As a note, I thought I would try out your code. I assume the binary is coming from loopback-sdk-builder. I got it to work fine, myself
I think so for one of my tasks i change ir using.process and inthink i need to change agin relative to this, how can i do that
Sorry, I don't understand your question
my question is , i am changing the directory paths for one of the tasks and watching over this sdk . do i need to check the directory again here and if not put the prompt in tghe corrrect position or how can i have a static path for my indivdual process

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.