From 8134508b071593914a6f4969b071135bfff6d853 Mon Sep 17 00:00:00 2001 From: "n.lyubchich" Date: Tue, 28 Jul 2015 15:50:33 +0300 Subject: [PATCH] Still working on --- bower.json | 5 +- gulpfile.js | 113 +++++++++--------- package.json | 9 +- project/static/src/js/feed.js | 2 +- .../js/main}/bootstrap-image-gallery.js | 8 +- project/static/src/js/mainpage.js | 3 + project/static/src/js/vacancy.js | 4 +- project/static/src/js/vendor.js | 4 - project/templates/pages/mainpage.html | 6 +- 9 files changed, 83 insertions(+), 71 deletions(-) rename project/static/{js => src/js/main}/bootstrap-image-gallery.js (94%) create mode 100644 project/static/src/js/mainpage.js delete mode 100644 project/static/src/js/vendor.js diff --git a/bower.json b/bower.json index 51b8410..d089a25 100644 --- a/bower.json +++ b/bower.json @@ -25,6 +25,9 @@ "blueimp-bootstrap-image-gallery": "~3.1.3", "jquery": "~2.1.4", "react": "~0.13.3", - "underscore": "~1.8.3" + "underscore": "~1.8.3", + "blueimp-gallery": "~2.15.4", + "react-mini-router": "~1.1.7", + "react-select": "~0.5.5" } } diff --git a/gulpfile.js b/gulpfile.js index 5558192..22c81b8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,6 +1,8 @@ var gulp = require('gulp'); var pkginfo = require('./package.json'); - +var path = require('path'); +var es = require('event-stream'); +var glob = require('glob'); var browserify = require('browserify'); var buffer = require('vinyl-buffer'); var del = require('del'); @@ -10,79 +12,82 @@ var source = require('vinyl-source-stream'); var stylus = require('gulp-stylus'); var uglify = require('gulp-uglify'); var _ = require('lodash'); +var fs = require('vinyl-fs'); var bowerResolve = require('bower-resolve'); +var debug = gutil.env.type === 'production'; +var bowerPackages = _.keys(require('./bower.json').dependencies) || []; +gulp.task('default', ['build:scripts', 'build:styles']); -gulp.task('build', ['build:scripts', 'build:styles']); +gulp.task('build:scripts', ['build:scripts:app', 'build:scripts:vendor']); +gulp.task('build:scripts:app', function (done) { + glob(pkginfo.assets.scripts.entries, function (err, files) { -gulp.task('build:scripts:vendor', function() { - var b = browserify({ - // generate source maps in non-production environment - debug: true - }); + if (err) done(err); + var tasks = files.map(function (file) { - getBowerPackageIds().forEach(function (id) { + var b = browserify({ + debug: debug, + entries: [file] + }); - var resolvedPath = bowerResolve.fastReadSync(id); + bowerPackages.forEach(function (lib) { + var resolvedPath = bowerResolve.fastReadSync(lib); + b.external(resolvedPath, {expose: lib}) + }); - b.require(resolvedPath, { - expose: id - }); + return b + .bundle() + .pipe(source(path.basename(file))) + .pipe(rename({ + extname: ".bundle.js" + })) + .pipe(buffer()) + .pipe(debug ? uglify() : gutil.noop()) + .pipe(gulp.dest(pkginfo.dist)); + }); + es.merge(tasks).on('end', done); }); +}); - var stream = b.bundle() +gulp.task('build:scripts:vendor', function () { + var b = browserify({ + debug: debug + }); + bowerPackages.forEach(function (id) { + var resolvedPath = bowerResolve.fastReadSync(id); + console.log(resolvedPath); + //console.log(id); + b.require(resolvedPath, { + expose: id + }); + }); + return b.bundle() .pipe(source('vendor.js')) .pipe(gulp.dest(pkginfo.dist)); - - return stream; }); -gulp.task('build:scripts', function() { - browserify({ - entries: pkginfo.assets.scripts.entries, - paths: pkginfo.assets.scripts.paths - }).bundle() - .pipe(source('bundle.js')) - .pipe(buffer()) - .pipe(gutil.env.type === 'production' ? uglify() : gutil.noop()) - .pipe(gulp.dest(pkginfo.dist)); -}); - -gulp.task('build:styles', function() { - gulp.src(pkginfo.assets.styles.entries).pipe(stylus({ - compress: true, - 'include css': true, - include: pkginfo.stylus.includes - })) - .pipe(rename('bundle.css')) - .pipe(gulp.dest(pkginfo.dist)); +gulp.task('build:styles', function () { + gulp.src(pkginfo.assets.styles.entries).pipe(stylus({ + compress: true, + 'include css': true, + include: pkginfo.stylus.includes + })) + .pipe(rename('bundle.css')) + .pipe(gulp.dest(pkginfo.dist)); }); -gulp.task('watch', ['build'], function() { - gulp.watch(pkginfo.assets.scripts.watches, ['build:scripts']); - gulp.watch(pkginfo.assets.styles.watches, ['build:styles']); +gulp.task('watch', ['build'], function () { + gulp.watch(pkginfo.assets.scripts.watches, ['build:scripts']); + gulp.watch(pkginfo.assets.styles.watches, ['build:styles']); }); -gulp.task('clean', function(callback) { - glob = pkginfo.dist + '/*'; - del([glob, '!.gitignore'], callback); +gulp.task('clean', function (callback) { + glob = pkginfo.dist + '/*'; + del([glob, '!.gitignore'], callback); }); - - - -function getBowerPackageIds() { - // read bower.json and get dependencies' package ids - var bowerManifest = {}; - try { - bowerManifest = require('./bower.json'); - } catch (e) { - // does not have a bower.json manifest - } - return _.keys(bowerManifest.dependencies) || []; - -} diff --git a/package.json b/package.json index f75b5ba..a7c4314 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,10 @@ "vinyl-source-stream": "^1.1.0", "browserify": "~11.0.0", "bower-resolve": "~2.2.1", - "lodash": "~3.10.0" + "lodash": "~3.10.0", + "glob": "~5.0.14", + "event-stream": "~3.3.1", + "vinyl-fs": "~1.0.0" }, "stylus": { "includes": [ @@ -54,9 +57,7 @@ }, "assets": { "scripts": { - "entries": [ - "./project/static/src/js/main.js" - ], + "entries": "./project/static/src/js/*.js", "watches": [ "./project/static/src/js/**/*.js", "./project/static/src/js/**/*.jsx" diff --git a/project/static/src/js/feed.js b/project/static/src/js/feed.js index 69f4868..ed5ea9d 100644 --- a/project/static/src/js/feed.js +++ b/project/static/src/js/feed.js @@ -2,5 +2,5 @@ var React = require('react'); var $ = require('jquery'); -var feed = React.createFactory(require('./index.jsx')); +var feed = React.createFactory(require('./feed/index.js')); React.render(feed(), document.getElementById("vacancies")); diff --git a/project/static/js/bootstrap-image-gallery.js b/project/static/src/js/main/bootstrap-image-gallery.js similarity index 94% rename from project/static/js/bootstrap-image-gallery.js rename to project/static/src/js/main/bootstrap-image-gallery.js index 800387d..e3ea9fe 100644 --- a/project/static/js/bootstrap-image-gallery.js +++ b/project/static/src/js/main/bootstrap-image-gallery.js @@ -18,7 +18,13 @@ 'jquery', './blueimp-gallery' ], factory); - } else { + } else if (typeof require === 'function') { + factory( + require('jquery'), + require('blueimp-gallery') + ) + } + else { factory( window.jQuery, window.blueimp.Gallery diff --git a/project/static/src/js/mainpage.js b/project/static/src/js/mainpage.js new file mode 100644 index 0000000..234a965 --- /dev/null +++ b/project/static/src/js/mainpage.js @@ -0,0 +1,3 @@ +//require('./main/bootstrap-image-gallery.js'); +//require('blueimp-gallery'); +require('blueimp-gallery'); \ No newline at end of file diff --git a/project/static/src/js/vacancy.js b/project/static/src/js/vacancy.js index 4be76a2..abdb79c 100644 --- a/project/static/src/js/vacancy.js +++ b/project/static/src/js/vacancy.js @@ -1,5 +1,5 @@ var node = document.getElementById('attached-form'); var securityToken = node.dataset['securityToken']; -var ApplyForm = require("vacancy_form/form.js"); +var ApplyForm = require("./vacancy_form/form.js"); -React.render(, node); +React.render(React.createElement(ApplyForm, {securityToken: securityToken}), node); \ No newline at end of file diff --git a/project/static/src/js/vendor.js b/project/static/src/js/vendor.js deleted file mode 100644 index ec6d216..0000000 --- a/project/static/src/js/vendor.js +++ /dev/null @@ -1,4 +0,0 @@ -var $ = require("jquery"); -var gallery = require("blueimp-bootstrap-image-gallery"); -var React = require("react"); -var _ = require("underscore"); \ No newline at end of file diff --git a/project/templates/pages/mainpage.html b/project/templates/pages/mainpage.html index 0fd2332..98ab79c 100644 --- a/project/templates/pages/mainpage.html +++ b/project/templates/pages/mainpage.html @@ -1,10 +1,8 @@ {% extends "base.html" %} {% block meta %} - - -{# #} -{# #} + + {% endblock %}