UNPKG

8.42 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2002-2017 "Neo Technology,","
3 * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 *
5 * This file is part of Neo4j.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20var browserify = require('browserify');
21var source = require('vinyl-source-stream');
22var buffer = require('vinyl-buffer');
23var gulp = require('gulp');
24var through = require('through2');
25var gulpif = require('gulp-if');
26var uglify = require('gulp-uglify');
27var concat = require('gulp-concat');
28var gutil = require('gulp-util');
29var download = require("gulp-download");
30var shell = require('gulp-shell');
31var jasmine = require('gulp-jasmine');
32var jasmineBrowser = require('gulp-jasmine-browser');
33var reporters = require('jasmine-reporters');
34var babelify = require('babelify');
35var babel = require('gulp-babel');
36var watch = require('gulp-watch');
37var batch = require('gulp-batch');
38var replace = require('gulp-replace');
39var decompress = require('gulp-decompress');
40var fs = require("fs-extra");
41var runSequence = require('run-sequence');
42var path = require('path');
43var childProcess = require("child_process");
44var minimist = require('minimist');
45var cucumber = require('gulp-cucumber');
46var merge = require('merge-stream');
47var install = require("gulp-install");
48var os = require('os');
49var file = require('gulp-file');
50var semver = require('semver');
51
52gulp.task('default', ["test"]);
53
54gulp.task('browser', function(cb){
55 runSequence('build-browser-test', 'build-browser', cb);
56});
57
58/** Build all-in-one files for use in the browser */
59gulp.task('bu' +
60 'ild-browser', function () {
61 var browserOutput = 'lib/browser';
62 // Our app bundler
63 var appBundler = browserify({
64 entries: ['src/index.js'],
65 cache: {},
66 standalone: 'neo4j',
67 packageCache: {}
68 }).transform(babelify.configure({
69 presets: ['es2015', 'stage-3'], ignore: /external/
70 })).bundle();
71
72 // Un-minified browser package
73 appBundler
74 .on('error', gutil.log)
75 .pipe(source('neo4j-web.js'))
76 .pipe(gulp.dest(browserOutput));
77
78 return appBundler
79 .on('error', gutil.log)
80 .pipe(source('neo4j-web.min.js'))
81 .pipe(buffer())
82 .pipe(uglify())
83 .pipe(gulp.dest(browserOutput));
84});
85
86gulp.task('build-browser-test', function(){
87 var browserOutput = 'lib/browser/';
88 var testFiles = [];
89 return gulp.src('./test/**/*.test.js')
90 .pipe( through.obj( function( file, enc, cb ) {
91 if(file.path.indexOf('examples.test.js') < 0) {
92 testFiles.push( file.path );
93 }
94 cb();
95 }, function(cb) {
96 // At end-of-stream, push the list of files to the next step
97 this.push( testFiles );
98 cb();
99 }))
100 .pipe( through.obj( function( testFiles, enc, cb) {
101 browserify({
102 entries: testFiles,
103 cache: {},
104 debug: true
105 }).transform(babelify.configure({
106 presets: ['es2015', 'stage-3'], plugins: ['transform-runtime'], ignore: /external/
107 }))
108 .bundle(function(err, res){
109 cb();
110 })
111 .on('error', gutil.log)
112 .pipe(source('neo4j-web.test.js'))
113 .pipe(gulp.dest(browserOutput))
114 },
115 function(cb) {
116 cb()
117 }
118 ));
119});
120
121var buildNode = function(options) {
122 return gulp.src(options.src)
123 .pipe(babel({presets: ['es2015', 'stage-3'], plugins: ['transform-runtime'], ignore: ['src/external/**/*.js']}))
124 .pipe(gulp.dest(options.dest))
125};
126
127gulp.task('nodejs', function(){
128 return buildNode({
129 src: 'src/**/*.js',
130 dest: 'lib'
131 });
132});
133
134gulp.task('all', function(cb){
135 runSequence('nodejs', 'browser', cb);
136});
137
138// prepares directory for package.test.js
139gulp.task('install-driver-into-sandbox', ['nodejs'], function(){
140 var testDir = path.join(os.tmpdir(), 'sandbox');
141 fs.emptyDirSync(testDir);
142
143 var packageJsonContent = JSON.stringify({
144 "dependencies":{
145 "neo4j-driver" : __dirname
146 }
147 });
148
149 return file('package.json', packageJsonContent, {src:true})
150 .pipe(gulp.dest(testDir))
151 .pipe(install());
152});
153
154gulp.task('test', function(cb){
155 runSequence('test-nodejs', 'test-browser', 'run-tck', function (err) {
156 if (err) {
157 var exitCode = 2;
158 console.log('[FAIL] test task failed - exiting with code ' + exitCode);
159 return process.exit(exitCode);
160 }
161 return cb();
162 });
163});
164
165gulp.task('test-nodejs', ['install-driver-into-sandbox'], function () {
166 return gulp.src('test/**/*.test.js')
167 .pipe(jasmine({
168 // reporter: new reporters.JUnitXmlReporter({
169 // savePath: "build/nodejs-test-reports",
170 // consolidateAll: false
171 // }),
172 includeStackTrace: true
173 }));
174});
175
176gulp.task('test-boltkit', ['nodejs'], function () {
177 return gulp.src('test/**/*.boltkit.it.js')
178 .pipe(jasmine({
179 // reporter: new reporters.JUnitXmlReporter({
180 // savePath: "build/nodejs-test-reports",
181 // consolidateAll: false
182 // }),
183 includeStackTrace: true
184 }));
185});
186
187gulp.task('test-browser', function (cb) {
188 runSequence('all', 'run-browser-test', cb)
189});
190
191gulp.task('run-browser-test', function(){
192 return gulp.src('lib/browser/neo4j-web.test.js')
193 .pipe(jasmineBrowser.specRunner({console: true}))
194 .pipe(jasmineBrowser.headless())
195});
196
197gulp.task('watch', function () {
198 return watch('src/**/*.js', batch(function (events, done) {
199 gulp.start('all', done);
200 }));
201});
202
203gulp.task('watch-n-test', ['test-nodejs'], function () {
204 return gulp.watch(['src/**/*.js', "test/**/*.js"], ['test-nodejs'] );
205});
206
207var featureFiles = 'https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz';
208var featureHome = './build/tck';
209
210gulp.task('download-tck', function() {
211 return download(featureFiles)
212 .pipe(decompress({strip: 1}))
213 .pipe(gulp.dest(featureHome));
214});
215
216gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
217 return gulp.src(featureHome + "/*").pipe(cucumber({
218 'steps': 'test/v1/tck/steps/*.js',
219 'format': 'progress',
220 'tags' : ['~@fixed_session_pool', '~@db', '~@equality', '~@streaming_and_cursor_navigation']
221 }));
222});
223
224/** Set the project version, controls package.json and version.js */
225gulp.task('set', function() {
226 // Get the --version arg from command line
227 var version = minimist(process.argv.slice(2), { string: 'version' }).version;
228
229 if (!semver.valid(version)) {
230 throw 'Invalid version "' + version + '"';
231 }
232
233 // Change the version in relevant files
234 var versionFile = path.join('src', 'version.js');
235 return gulp.src([versionFile], {base: "./"})
236 .pipe(replace('0.0.0-dev', version))
237 .pipe(gulp.dest('./'));
238
239});
240
241
242var neo4jHome = path.resolve('./build/neo4j');
243var neorunPath = path.resolve('./neokit/neorun.py');
244var neorunStartArgsName = "--neorun.start.args"; // use this args to provide additional args for running neorun.start
245
246gulp.task('start-neo4j', function() {
247
248 var neorunStartArgs = '-p neo4j'; // default args to neorun.start: change the default password to neo4j
249 process.argv.slice(2).forEach(function (val) {
250 if(val.startsWith(neorunStartArgsName))
251 {
252 neorunStartArgs = val.split("=")[1];
253 }
254 });
255
256 neorunStartArgs = neorunStartArgs.match(/\S+/g) || '';
257
258 return runScript([
259 neorunPath, '--start=' + neo4jHome
260 ].concat( neorunStartArgs ) );
261});
262
263gulp.task('stop-neo4j', function() {
264 return runScript([
265 neorunPath, '--stop=' + neo4jHome
266 ]);
267});
268
269var runScript = function(cmd) {
270 var spawnSync = childProcess.spawnSync, child, code;
271 child = spawnSync('python', cmd);
272 console.log("Script Outputs:\n" + child.stdout.toString());
273 var error = child.stderr.toString();
274 if (error.trim() !== "")
275 console.log("Script Errors:\n"+ error);
276 code = child.status;
277 if( code !==0 )
278 {
279 throw "Script finished with code " + code
280 }
281};