javanile / yamlinc

Compose multiple YAML files into one with $include tag. Split Swagger/OpenAPI into multiple YAML files.
MIT License
114 stars 22 forks source link

Question about watching #17

Closed helitik closed 5 years ago

helitik commented 5 years ago

Hi,

I'm wondering how the watch works.

I'm trying : yamlinc --watch doc/src/index.yaml

But I get a spawn error:

{PROJECT_PATH}/node_modules/yamlinc/src/helpers.js:69
        wrapper.stdout.on('data', (data) => {
                       ^

TypeError: Cannot read property 'on' of undefined
    at Object.spawn ({PROJECT_PATH}/node_modules/yamlinc/src/helpers.js:69:24)
    at Object.spawnLoop ({PROJECT_PATH}/node_modules/yamlinc/src/yamlinc.js:335:17)
    at Timeout.setTimeout [as _onTimeout] ({PROJECT_PATH}/node_modules/yamlinc/src/yamlinc.js:304:18)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

Any idea how I can fix that ?

francescobianco commented 5 years ago

Hi @helitik

the --watch works with command that eat the YAML files (es. cat)

you can run

yamlinc --watch cat doc/src/index.yaml

in this way every-time, the file change a cat can be repeated. is useful when you start a service and need re-restart if configuration changes

helitik commented 5 years ago

Hi @francescobianco ,

Thank you for your answer!

I've found sourcey/spectacle but this is not compatible with openapi 3.0.

I use widdershins with cli api2html and i'm watching yaml files with yamlinc:

yamlinc --watch "api2html -o doc/dist/index.html -l shell,http,php,javascript" doc/src/index.yaml

I have to write quotes otherwise the -o option of api2html is in conflict with yamlinc (yamlinc write yaml in doc/dist/index.html).

But I get an error with quotes:

Error: spawn api2html -o doc/dist/index.html -l shell,http,php,javascript ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
    at onErrorNT (internal/child_process.js:407:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)
    at onErrorNT (internal/child_process.js:407:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)

I've fixed helpers.js line 66:

let wrapper = spawn(cmd, args, { shell: true });

And it works perfectly.

I also found a bug in yamlinc.js line 280:

let match = [];
for (let i in this.extensions) {
  match.push('./**/*.*');
}

I've fixed by:

let match = [];
for (let i in this.extensions) {
  match.push('./**/*.' + this.extensions[i]);
}

If you are interested, I can make a pull request.

francescobianco commented 5 years ago

@helitik Thanks for your supports... let start with pull-request.

francescobianco commented 5 years ago

@helitik In order to make this project grow, I invite all those who contribute to becoming official collaborators. Check out for the invitation on email

helitik commented 5 years ago

Done by #18

francescobianco commented 5 years ago

Hi @helitik your patch is online on the new version https://www.npmjs.com/package/yamlinc/v/0.1.9 Thanks