Problems with gulp and gulp-diff - angularjs

I'm wanting my gulpfile.js to compare what is in my angular concatenated file before it has ng-annotate run and after so I can see what injections it made. I can't quite get the syntax. I keep getting different versions of the error which says gulp can not stat my file.
The code that I'm stuck on is below. I'd be happy to do it in one pass but had no success with that either.
gulp.task('scripts', function () {
gulp.src(['public/app/**/*.js'])
.pipe(concat('main-noanotate.js'))
.pipe(rename({suffix: '.noannotate.js'}))
.pipe(gulp.dest('public/dist'));
return gulp.src(['public/app/**/*.js'])
.pipe(concat('main.js'))
.pipe(ngAnnotate())
.pipe(diff('main.noannotate.js'))
.pipe(diff.reporter({ fail: true }))
.pipe(gulp.dest('public/dist'))
});

gulp-diff is trying to diff against the original source file, but there is no original source file on disk as you're working with the result of a concatenation of multiple files. I recommend splitting out your gulp tasks and writing to a temporary .build directory.
Here is an example of clearing a build workspace.
To set things up, create a new directory and run:
npm install del gulp gulp-concat gulp-diff gulp-header; mkdir -p src; echo "foo" > src/foo.txt; echo "bar" > src/bar.txt
Then create this gulpfile.js:
'use strict';
var gulp = require('gulp');
var diff = require('gulp-diff');
var header = require('gulp-header');
var concat = require('gulp-concat');
var del = require('del');
gulp.task('default', ['clean']);
gulp.task('clean', ['build'], function(cb) {
del(['.build'], cb);
});
gulp.task('build', ['concat'], function() {
return gulp.src('.build/all.txt')
.pipe(header('//stream test\n'))
.pipe(diff())
.pipe(diff.reporter())
.pipe(gulp.dest('./dist'));
});
gulp.task('concat', function() {
return gulp.src('src/*.txt')
.pipe(concat('all.txt'))
.pipe(gulp.dest('.build'));
});
Then try running gulp. It should concat the file and put the output into the temporary .build directory. That file is then used to diff against. In the above example header is doing the job of amending the file (this might be where you apply ngAnnotate instead).

Related

SpawnSync doesn't work when using electron-builder

I am writing an react-electron application and I noticed that when I used electron-builder to build it the binary was stuck when calling "spawn".
With "yarn start" the application can be executed without problems. Only with electron-builder it gets stuck.
Can you help ?
Thanks,
Update
It seems that the C++ binary included as part of the program can't be executed within electron. If I give the hardcoded full path to the binary it works but if I give the path from __dirname I get an error
const GetLocalPath = () => {
const path = __dirname + "/../cpp_program/"
return {
helloWorld: path+ "helloWorld",
helloWorldRepeat: path+ "helloWorldRepeat"
}
}
export function helloWorld(){
// let dir = "/Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/cpp_program";
let comm = GetLocalPath().helloWorld;
The error message
internal/child_process.js:403 Uncaught (in promise) Error: spawn ENOTDIR
at ChildProcess.spawn (internal/child_process.js:403)
at Object.spawn (child_process.js:562)
at helloWorldRepeat (/Users/ricky/proje…ar/build/Lib.js:113)
at Object.<anonymous> (/Users/ricky/proje…sar/build/Lib.js:49)
at Generator.next (<anonymous>)
at /Users/ricky/proje…asar/build/Lib.js:9
at new Promise (<anonymous>)
at __awaiter (/Users/ricky/proje…asar/build/Lib.js:5)
at Object.handleInitialize (/Users/ricky/proje…sar/build/Lib.js:35)
at TestStateMachine.transition (/Users/ricky/proje…tStateMachine.js:56)
This is pretty odd because it works just fine with "yarn start", which is "tsc && electron"
package.json is shown below
"scripts": {
"start": "tsc && electron ."
},
"build": {
"appId": "com.example.myapp",
"productName": "MyApp",
"files": [
"build/**/*",
"public/**/*",
"src/images/**/*"
]
},
Update ver 2
Per Alexander's suggestion I have included
"asar": false
inside package.json
When I excute it I get a different error
Uncaught Error: spawn /Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/dist/mac/MyApp.app/Contents/Resources/app/build/../cpp_program/helloWorldRepeat ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269)
at onErrorNT (internal/child_process.js:465)
at processTicksAndRejections (internal/process/task_queues.js:80)
errnoException # internal/errors.js:510
ChildProcess._handle.onexit # internal/child_process.js:269
onErrorNT # internal/child_process.js:465
processTicksAndRejections # internal/process/task_queues.js:80
Now the error is that there is no "helloWorldRepeat" file inside /Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/dist/mac/MyApp.app/Contents/Resources/app/build/../cpp_program/.
The binary is in fact located at
/Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/build/../cpp_program/helloWorldRepeat
Do I have to manually create this folder and paste the binary files ?
By default, Electron Builder compiles your application and packs all resources into one large archive file (think of it as a ZIP file) which can be read just fine because Electron brings support for this format known as "ASAR".
When running the built program, the code will be read from the archive. This means that __dirname will point to a directory inside the archive. The operating system, however, cannot read from the archive. Since you did not actually include the piece of code calling child_process.spawn (), I can only speculate on why you get ENOTDIR, which hints that a given path is not a directory when it was expected to be one, but I assume this is because you point to a path inside the ASAR file.
When relying on external binaries, it is a good idea to keep them outside the ASAR archive and programmatically find the path to them (which is quite complex) or by preventing Electron Builder from compiling your app into an ASAR file. However, you would also have to ask Electron Builder to include the executable in the built version of your app. This can be done by modifying your package.json:
{
...
"build": {
"appId": "com.example.myapp",
"productName": "MyApp",
"files": [
"build/**/*",
"public/**/*",
"src/images/**/*"
],
"extraResources": [
"cpp_program/*"
]
"asar": false
},
}
(Replace "cpp_program/*" by whatever path pattern matches your desired directory, possibly even replacing /* with /**/* if there are subdirectories.)
This way, the directory cpp_program will be copied to your app's resources directory upon build. This path, according to Electron Builder's documentation, is Contents/Resources/ on MacOS. Thus, you will have to modify your path (__dirname + "../" will not work because it will point to Contents/Resources/app, but __dirname + "../../" should; if not, experimenting will lead to the correct path)*. Remember to run Electron Builder every time your C++ executable changes, as the files in the .app folder are not linked to their counterparts outside the built app.
* You can switch between development paths (__dirname + "../") and production paths (__dirname + "../../" or whatever) by checking if __dirname.includes (".app/")

Gradle: How to designate a output directory for C/C++ object files?

I have a fairly simple build.gradle file which builds a zlib directory. Unfortunately, the resulting *.o file are sprinkled into individual directories. e.g.
build/objs/zlib/shared/zlibC/xvtb7xzcn488esep2yp1v714/uncompr.o
build/objs/zlib/shared/zlibC/2osjpf8p443huii37rw8g7o7d/zutil.o
[...]
build/objs/zlib/shared/zlibC/bkho3m4h5simvpsegapx51g54/trees.o
build/objs/zlib/shared/zlibC/2zicemubjlmw82yi1ysriaup4/inflate.o
How do you set the output directory to be build/zlib for all the resulting *.o files (minus the unique-id directories)?
apply plugin: 'c'
FileCollection zlibfiles = files(
'adler32',
[...]
'trees',
'zutil')
model {
components {
zlib(NativeLibrarySpec) {
sources {
c {
source {
srcDir "."
include '*.c'
}
exportedHeaders {
srcDir '.'
}
}
}
}
}
binaries {
withType(SharedLibraryBinarySpec) {
if (targetPlatform.operatingSystem.linux) {
cppCompiler.args '-c', '-g', '-fPIC'
// relative paths are ignored by Gradle
// only fully qualified paths are recognized
// cppCompiler.args '-I', '../..'
cppCompiler.args '-I', "${rootDir}/zlib"
linker.args '-pthread'
}
}
}
}
I have a find-copy task, but the goal here is use Gradle properly. I would rather use Gradle's version of gcc/g++ '-o' option.
task zlibcopy (type: Copy) {
configurations {
conf
}
dependencies {
conf fileTree(dir: "${buildDir}/objs/zlib/shared/zlibC/")
}
from configurations.conf.getAsFileTree()
into "${rootDir}/build/client/ps/common/zlib"
}
Gradle: 4.7
CentOS: 7.4
Java: 1.8.0_144
Apparently, Gradle does not allow native code to be outputted to a designated output directory. You can find the *.o's in uniquely identified output directories, the *.so in a "shared" directory, and *.a in a "static" directory. Darn.
Try that, the unique directories won't be included.
task zlibcopy (type: Copy) {
zlibfiles.each { File file ->
println file.name
from ("${buildDir}/objs/zlib/shared/zlibC/") {
include "**/${file.name}*"
}
includeEmptyDirs = false
eachFile {
def (id, name) = it.path.split('/')
it.relativePath = RelativePath.parse(true, name)
}
into "${rootDir}/build/zlib"
}
}
the last six *.o files are never copied
Maybe these six files are not included in zlibfiles and by consequence, never included ?

Gradle command syntax for executing TESTNG tests as a group

I have some tests as below:
#Test(groups={"smoke"})
public void Test1(){...}
#Test(groups={"smoke", "regression"})
public void Test2(){...}
#Test(groups={"regression"})
public void Test3(){...}
In build.gradle file I have below:
task smoketests(type: Test){
useTestNG() {
suites "src/test/resources/testng.xml"
includeGroups "smoke"
}
}
I need to have a gradle syntax to run the smoke/regression tests only using commandline.
I have tried this:
./gradlew clean test -P testGroups="smoke"
if I run that, build is successful as below:
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
BUILD SUCCESSFUL
Total time: 42.253 secs
But it never execute actual tests. Need help
You have created a custom test task, so you need to use that instead of test in your command line:
gradlew clean smoketests

Gulp Build fails on Yeoman gulp-angular

I've been running through the gulp-angular generator.
Tried other answers by doing a complete uninstall of npm bower etc and reinstalling.
I do not get any errors when going through the generator but as soon as I try running 'gulp build', I keep getting this error
gulp build
[09:16:28] Using gulpfile ~/app/gulpfile.js
[09:16:28] Starting 'scripts'...
[09:16:28] Starting 'styles'...
[09:16:29] Starting 'partials'...
[09:16:29] Starting 'fonts'...
[09:16:29] Starting 'other'...
[09:16:29] gulp-inject 2 files into index.scss.
[09:16:30] Finished 'partials' after 1.28 s
[09:16:30] gulp-ruby-sass: directory
[09:16:30] gulp-ruby-sass: write index.css
write index.css.map
[09:16:30] all files 13.84 kB
[09:16:30] Finished 'scripts' after 2.08 s
[09:16:31] Finished 'styles' after 2.03 s
[09:16:31] Starting 'inject'...
[09:16:31] gulp-inject 1 files into index.html.
[09:16:31] Finished 'other' after 1.61 s
[09:16:31] Finished 'fonts' after 1.68 s
[09:16:31] gulp-inject 10 files into index.html.
[09:16:31] Finished 'inject' after 142 ms
[09:16:31] Starting 'html'...
[09:16:31] gulp-inject 1 files into index.html.
[09:16:31] dist/ maps/styles/app-070ae8ae0a.css.map 13.48 kB
[09:16:32] dist/ maps/styles/vendor-2a1d35e48e.css.map 273.03 kB
[09:16:33] dist/ maps/scripts/app-6e2669f540.js.map 14.81 kB
events.js:142
throw er; // Unhandled 'error' event
^
Error: scripts/vendor-70aa324478.js: error: couldn't process source due to parse error
Unexpected token (49992:4)
I thought it's in that file, script/vendor ... but I figured out that it was generated by gulp.
Here is my Gulp file.
/**
* Welcome to your gulpfile!
* The gulp tasks are splitted in several files in the gulp directory
* because putting all here was really too long
*/
'use strict';
var gulp = require('gulp');
var wrench = require('wrench');
/**
* This will load all js or coffee files in the gulp directory
* in order to load all gulp tasks
*/
wrench.readdirSyncRecursive('./gulp').filter(function(file) {
return (/\.(js|coffee)$/i).test(file);
}).map(function(file) {
require('./gulp/' + file);
});
/**
* Default task clean temporaries directories and launch the
* main optimization build task
*/
gulp.task('default', ['clean'], function () {
gulp.start('build');
});
Any guidance would be appreciated!
Thank you in advance

How can I save protractor test results

Is there a way to output protractor test results to a file to be viewed outside of the command line after a test is run, including seeing detailed failures?
I found a nice clean way of saving the test results in a orderly fashion using Jasmine reporter.
How to install and configure Jasmine reporter:
Install Jasmine reporter:
npm install -g jasmine-reporters
Add the following to the protractor-config.js file:
onPrepare: function() {
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter('outputxmldir', true, true));
}
Create the outputxmldir folder (This is where all the test outputs will be placed).
Run protractor and now the results will be exported to an XML file in the outputxmldir folder.
Just the test output is enough?
protractor conf.js > test.log
Cheers.
You can also set the resultJsonOutputFile option in the config file:
export.config = {
(...)
// If set, protractor will save the test output in json format at this path.
// The path is relative to the location of this config.
resultJsonOutputFile:'./result.json',
(...)
}
More details about the config file can be found at:
https://raw.githubusercontent.com/angular/protractor/master/docs/referenceConf.js

Resources