Is there a way to get gulp to pass along error messages/position? - gulp

I've created a less task:
var gulp = require('gulp'),
less = require('gulp-less');
gulp.task('dktest-less', function () {
gulp.src('dktest/**/*.less')
.pipe(less());
});
and when I run it I get:
(dev) c:\work\dev\dkjs>gulp dktest-less
[16:07:46] Using gulpfile c:\work\dev\dkjs\gulpfile.js
[16:07:46] Starting 'dktest-less'...
[16:07:46] Finished 'dktest-less' after 4.22 ms
events.js:72
throw er; // Unhandled 'error' event
^
Error: Invalid HEX color code
at error (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:248:17)
at Object.Parser.parser.parsers.parsers.entities.color (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:966:29)
at Object.Parser.parser.parsers.parsers.operand (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1984:34)
at Object.Parser.parser.parsers.parsers.multiplication (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1882:26)
at Object.Parser.parser.parsers.parsers.addition (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1911:26)
at Object.Parser.parser.parsers.parsers.expression (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:2006:30)
at Object.Parser.parser.parsers.parsers.value (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1851:30)
at Object.Parser.parser.parsers.parsers.rule (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1575:60)
at Object.Parser.parser.parsers.parsers.primary (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:731:76)
at Object.Parser.parser.parsers.parsers.block (c:\work\dev\dkjs\node_modules\gulp-less\node_modules\less\lib\less\parser.js:1492:51)
which isn't very useful (how do you search for an invalid hex value..? ..and where?)
If I run lessc manually it gives me:
(dev) c:\work\dev\dkjs\dktest>lessc diffview.less
SyntaxError: Invalid HEX color code in c:\work\dev\dkjs\dktest\diffview.less on line 821, column 48:
820
821 .white .beautify .data em.s16 { color: #880s }
822
What do I need to do to get this wonderfully informative error message through gulp?

Try adding an error handler function to your code like this:
var gulp = require('gulp'),
less = require('gulp-less');
gulp.task('dktest-less', function () {
gulp.src('dktest/**/*.less')
.pipe(less().on('error', errorHandler));
});
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}

Related

Run Octave function form shell

It is possible to write a function directly in the octave shell?
A=147;
B=26.3;
C=5.4;
d=0.35*A;
function S=function_test(A,B,C,d)
S=2*A*B*C*d;
end
I tried this but if I wanted to know the value of "S", this error appears:
error: 'S' undefined near line 1, column 1
Yes it is possible. You does it correctly. But you missed indicating how you call the function. For me, no error occurs:
≫ function_test(1,2,3,4)
ans = 48
≫ res = function_test(1,2,3,4)
res = 48
≫ S = function_test(-1,3,5,7)
S = -210
≫

Joining 2 strings in my Gulp file gives a non-sensical error?

Using node 16.2.0 on OSX. I new to Gulp.
I want to update the version in my package.json file that will contain the Git hash if on a feature branch, so I have this in my Gulp file
// pkg is defined somewhere else to be my Gulp file
// I have a "semVer" key in my package.json file
const {src, dest} = require('gulp');
const semver = require('semver');
...
const semVer = semver.parse(pkg.semVer);
// Functions getBranch() and getHash() are defined somewhere else,
// and they return the Git branch and hash respectively.
function manageVersion() {
var newVersion = semver.inc(semVer, 'patch');
var hash = "";
if (getBranch().includes('feature')) {
hash = getHash().toString();
newVersion = [newVersion, hash].join('-');
}
src(['../package*.json'])
.pipe(gulp_bump({
version: newVersion
}))
.pipe(dest('./'));
}
exports.manageVersion = manageVersion
I then do this, and get the non-sensical error
$ gulp manageVersion -f gulpfiles/version.js
[16:20:20] Working directory changed to /path/gulpfiles
[16:20:20] Using gulpfile /path/gulpfiles/version.js
[16:20:20] Starting 'manageVersion'...
[16:20:20] Finished 'manageVersion' after 99 ms
/path/node_modules/semver/semver.js:564
if (v1[key] !== v2[key]) {
^
TypeError: Cannot read property 'major' of null
at Function.diff (/path/node_modules/semver/semver.js:564:27)
at /path/node_modules/bump-regex/index.js:66:26
at String.replace (<anonymous>)
at module.exports (/path/node_modules/bump-regex/index.js:54:23)
at DestroyableTransform._transform (/path/node_modules/gulp-bump/index.js:29:5)
at DestroyableTransform.Transform._read (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_transform.js:172:83)
at doWrite (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:428:64)
at writeOrBuffer (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:417:5)
at DestroyableTransform.Writable.write (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:334:11)
I've checked ALL my values for newVersion and hash and they're valid strings. What am I missing?
Turns out I had to trim the string from the getHash() function
hash = getHash().trim();

Fatal error: Uncaught TypeError: Argument 1 passed to Mage_Core_Model_Design_Package::getPackageByUserAgent()

I was getting a 500 error once I moved my magento 1.9 install from an old server to a new server. The old server was running php5 and this one is on 7. I am now getting the following error and I know I have to change some of the code, but I am not sure what:
Fatal error: Uncaught TypeError: Argument 1 passed to Mage_Core_Model_Design_Package::getPackageByUserAgent() must be of the type array, object given, called in /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php on line 576 and defined in /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php:586 Stack trace: #0 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(576): Mage_Core_Model_Design_Package::getPackageByUserAgent(Object(Zend_Log), 'design/theme/te...') #1 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(262): Mage_Core_Model_Design_Package->_checkUserAgentAgainstRegexps('design/theme/te...') #2 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(287): Mage_Core_Model_Design_Package->getTheme('template') #3 /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php(420): Mage_Core_Model_Design_Package->updateParamDefaults(Array) #4 /home1/acapps/flagstuff.com/app/code/core in /home1/acapps/flagstuff.com/app/code/core/Mage/Core/Model/Design/Package.php on line 586
This is the code that starts on line 586 of Package.php
public static function getPackageByUserAgent(array $rules, $regexpsConfigPath = 'path_mock')
{
foreach ($rules as $rule) {
if (!empty(self::$_regexMatchCache[$rule['regexp']][$_SERVER['HTTP_USER_AGENT']])) {
self::$_customThemeTypeCache[$regexpsConfigPath] = $rule['value'];
return $rule['value'];
}
$regexp = '/' . trim($rule['regexp'], '/') . '/';
if (#preg_match($regexp, $_SERVER['HTTP_USER_AGENT'])) {
self::$_regexMatchCache[$rule['regexp']][$_SERVER['HTTP_USER_AGENT']] = true;
self::$_customThemeTypeCache[$regexpsConfigPath] = $rule['value'];
return $rule['value'];
}
}
return false;
}
Turns out I needed to change this:
public static function getPackageByUserAgent(array $rules, $regexpsConfigPath = 'path_mock')
to this
public static function getPackageByUserAgent($rules, $regexpsConfigPath = 'path_mock')
after that, it worked like a charm

Gulp: Recursively copy a file to every sub-directory

I have a file called foo and I want to copy it to every sub-directory.
For example if the current directory structure is:
- files
- A/
- B/
- C/
- D/
- D1/
- D2/
Then after the operation, it should be:
-files
- foo
- A/
- foo
- B/
- foo
- C/
- foo
- D/
- foo
- D1/
- foo
- D2/
- foo
How can I do this using Gulp
Note that I do not know what the sub-directories will be before hand, so it needs to be done dynamically, and the paths cannot be hard-coded.
You can accomplish this using the gulp-multi-dest and glob packages:
const gulp = require('gulp'),
multiDest = require('gulp-multi-dest'),
glob = require('glob');
function copyToAll(done) {
glob('files/**/', (err, matches) => {
if (err) {
console.log('Error', err);
} else {
gulp.src('files/foo').pipe(multiDest(matches));
}
done();
});
}
exports.default = copyToAll;

ES6: Tests pass in browser, fail with phantomJS, "Can't find variable: Reflect"

I am doing an ES6 rewrite for a js library.
class VerbalExpression extends RegExp {
// snipped for brevity
}
/**
* Alias for the constructor
* #return {VerbalExpression} new instance of VerbalExpression
*/
function instantiate() {
return new VerbalExpression();
}
// UMD (Universal Module Definition)
// https://github.com/umdjs/umd
if (typeof module !== 'undefined' && module.exports) { // CommonJS
module.exports = instantiate;
} else if (typeof define === 'function' && define.amd) { // AMD Module
define('VerEx', [], () => VerbalExpression);
} else { // Browser
this.VerEx = instantiate;
}
When I run the tests in my browser, they all pass.
However, when I run the tests in the terminal, I get errors.
❯ npm test
verbal-expressions#0.3.0 test /Users/shreyasminocha/dev/open source/JSVerbalExpressions
grunt test
Running "qunit:files" (qunit) task
Testing test/index.html FFFFFFFFFFFFFFFFFFFF
>> something
>> Message: Died on test #1 global code#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:7:5: Can't find variable: Reflect
>> Actual: null
>> Expected: undefined
>> ExtendableBuiltin#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:11:31
>> VerbalExpression#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:59:130
>> instantiate#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/dist/verbalexpressions.js:588:32
>> somethingTest#file:///Users/shreyasminocha/dev/open%20source/JSVerbalExpressions/test/tests.js:8:26
...
Warning: 20 tests completed with 20 failed, 0 skipped, and 0 todo.
20 assertions (in 91ms), passed: 0, failed: 20 Use --force to continue.
Note: I am running the tests on compiled es6 code, that is, I run babel before running the tests.
I am guessing this is something to do with PhantomJS. How do I get the tests to pass in the terminal? Am I missing something? Any workarounds?
Stable PhantomJS doesn't support ES6 and is no longer in development, if possible migrate to puppeteer which is heavily inspired by PhantomJS.