Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Support for defining one script to run in watch mode #38

Merged
merged 4 commits into from
May 1, 2017

Conversation

marcel-ploch
Copy link

@marcel-ploch marcel-ploch commented Apr 27, 2017

Hey,

I added and Update so the people can define one script inside the task to run in watch mode.
This is a nice feature if you define more than just one task inside the "watch" Object and not want to run all at once.

Kind regards

Marcel Ploch


This change is Reviewable

Copy link
Owner

@M-Zuber M-Zuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks great!
Added a few comments, looking forwards to your response

cli.js Outdated
@@ -2,14 +2,17 @@
'use strict';
var path = require('path')

var windows = process.platform === 'win32'
var windows = process.platform === 'win32'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my / our company Formater reformarted a lot of stuff i will change it back.

cli.js Outdated
process.env[pathVarName] += path.delimiter + path.join(__dirname, 'node_modules', '.bin')
process.env[pathVarName] +=
path.delimiter +
path.join(__dirname, 'node_modules', '.bin')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please revert this formatting? It does not seem to add anything in this case

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly :)

cli.js Outdated

var watchPackage = require('./watch-package')
var watchPackage = require('./watch-package')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace

cli.js Outdated

var watcher = watchPackage(process.argv[2] || process.cwd(), process.exit)
var watcher = watchPackage(
process.argv[3] || process.cwd(), process.exit, process.argv[2])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra new line

watch-package.js Outdated
var pkg = require(path.join(pkgDir, 'package.json'))
var processes = {}

if (typeof taskName !== 'undefined' && taskName === '') {
console.info('No Task specified. Will go trough all possible tasks');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task should be lowercase.
trough -> through

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the correction.

var pkgDir = '';
var stdin = null;

module.exports = function watchPackage(_pkgDir, exit, taskName) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can taskName ever come in with only white-space?
if so, it should be trimmed as soon as possible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right it would be possible if anyone would call it "npm-watch ' '".
Not thought about it and will add the trim.

@@ -8,16 +8,24 @@ var through = require('through2')
var npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
var nodemon = process.platform === 'win32' ? 'nodemon.cmd' : 'nodemon';

module.exports = function watchPackage(pkgDir, exit) {
var pkgDir = '';
var stdin = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning for creating these variables?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Problem is that if i not create these variables in the Global scope i would need to pass them as parameter to the function. So in this case they are in the module scope and not can be refered from outside.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@M-Zuber
Copy link
Owner

M-Zuber commented Apr 27, 2017

Happens to be, this was on my to-do list of things to add. 😀
Thank you for taking the time to work on this

@marcel-ploch
Copy link
Author

Is nice that I could help you.
I needed the changes to get the changes on a NativeScript to work probably so it helped me too a lot.

Kind regards.

watch-package.js Outdated
@@ -36,11 +44,47 @@ module.exports = function watchPackage(pkgDir, exit) {
stdin.stderr = through()
stdin.stdout = through()

if (typeof taskName !== 'undefined' && taskName.trim() !== '') {
if (!pkg.scripts[taskName]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth while to do taskName = taskName.trim() before the if

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm but what if taskName is undefined cause there was no param on vargs[2] than it would crash cause we can not trim on undefined. Otherwise we can do a default action after the function definition. How you like best.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about in between lines 47&48 so after we already checked for undefined.
But I will have to pull down the code before deciding on this, so will get back to you after the weekend

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem.
Take your time.
Just updated it to be like an default param.

Copy link
Owner

@M-Zuber M-Zuber May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the default param implementation, so will leave it at that

@M-Zuber M-Zuber merged commit 74f083c into M-Zuber:master May 1, 2017
@M-Zuber
Copy link
Owner

M-Zuber commented May 1, 2017

🎉
Thank you for working on this!
bachelor-the-chris-soules-yCjr0U8WCOQM0

@marcel-ploch
Copy link
Author

Thanks for accepting my Pullrequest.
If you have any other Issue I can help with just tell me.

Kind regards

Marcel Ploch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants