Skip to content

Commit d8bd174

Browse files
committed
Generate rtd doc embed js without creating a module
1 parent 816201d commit d8bd174

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed

gulpfile.js

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ var gulp = require('gulp'),
1717
// picking up dependencies of the primary entry points and putting any
1818
// limitations on directory structure for entry points.
1919
var sources = {
20-
builds: ['js/detail.js'],
21-
core: [
22-
'js/readthedocs-doc-embed.js',
23-
'js/autocomplete.js',
24-
'js/projectimport.js',
25-
],
26-
projects: ['js/tools.js'],
27-
gold: ['js/gold.js'],
28-
donate: ['js/donate.js']
20+
builds: {'js/detail.js': {}},
21+
core: {
22+
'js/readthedocs-doc-embed.js': {create_module: false},
23+
'js/autocomplete.js': {},
24+
'js/projectimport.js': {},
25+
},
26+
projects: {'js/tools.js': {}},
27+
gold: {'js/gold.js': {}},
28+
donate: {'js/donate.js': {}}
2929
};
3030

3131
// Standalone application to create vendor bundles for. These can be imported
@@ -36,56 +36,68 @@ var standalone = ['jquery', 'knockout', 'jquery-migrate', 'jquery-ui'];
3636
// application. This is called by build and dev tasks.
3737
function build_app_sources (application, minify) {
3838
// Normalize file glob lists
39-
var app_sources = sources[application].map(function (n) {
40-
return path.join(pkg_config.name, application, 'static-src', '**', n)
39+
var bundles = Object.keys(sources[application]).map(function (n) {
40+
var bundle_path = path.join(
41+
pkg_config.name, application, 'static-src', '**', n),
42+
bundle_config = sources[application][n] || {},
43+
bundle;
44+
45+
if (/\.js$/.test(bundle_path)) {
46+
// Javascript sources
47+
bundle = gulp
48+
.src(bundle_path)
49+
.pipe(es.map(function (file, cb) {
50+
return browserify_stream(file, bundle_config, cb);
51+
}));
52+
53+
if (minify) {
54+
bundle = bundle
55+
.pipe(vinyl_buffer())
56+
.pipe(uglify())
57+
.on('error', function (ev) {
58+
gulp_util.beep();
59+
gulp_util.log('Uglify error:', ev.message);
60+
});
61+
}
62+
}
63+
else if (/\.less$/.test(bundle_path)) {
64+
// CSS sources
65+
bundle = gulp.src(bundle_path)
66+
.pipe(less({}))
67+
.on('error', function (ev) {
68+
gulp_util.beep();
69+
gulp_util.log('LESS error:', ev.message);
70+
});
71+
}
72+
73+
return bundle;
4174
});
42-
var app_js_sources = app_sources.filter(function (elem, n, arr) {
43-
return /\.js$/.test(elem);
44-
});
45-
var app_css_sources = app_sources.filter(function (elem, n, arr) {
46-
return /\.less$/.test(elem);
47-
});
48-
49-
// Javascript sources
50-
var app_js = gulp
51-
.src(app_js_sources)
52-
.pipe(es.map(browserify_stream));
5375

54-
if (minify) {
55-
app_js = app_js
56-
.pipe(vinyl_buffer())
57-
.pipe(uglify())
58-
.on('error', function (ev) {
59-
gulp_util.beep();
60-
gulp_util.log('Uglify error:', ev.message);
61-
});
62-
}
63-
64-
// CSS sources
65-
var app_css = gulp.src(app_css_sources)
66-
.pipe(less({}))
67-
.on('error', function (ev) {
68-
gulp_util.beep();
69-
gulp_util.log('LESS error:', ev.message);
70-
});
71-
72-
return es.merge(app_js, app_css)
76+
return es.merge(bundles)
7377
.pipe(gulp.dest(path.join(pkg_config.name, application, 'static')));
7478
}
7579

7680
// Browserify build
77-
function browserify_stream (file, cb_output) {
81+
function browserify_stream (file, config, cb_output) {
7882
bower_resolve.offline = true;
7983
bower_resolve.init(function () {
80-
var bundle_stream = browserify(),
81-
module_name = path.basename(file.path, '.js');
84+
var bundle_stream = browserify();
8285

8386
standalone.map(function (module) {
8487
bundle_stream = bundle_stream.external(module);
8588
});
8689

90+
if (config.create_module === false) {
91+
bundle_stream.add(file.path)
92+
}
93+
else {
94+
var module_name = config.expose || path.basename(file.path, '.js');
95+
bundle_stream = bundle_stream.require(
96+
file.path,
97+
{expose: module_name})
98+
}
99+
87100
bundle_stream
88-
.require(file.path, {expose: module_name})
89101
.transform('debowerify', {ignoreModules: standalone})
90102
.bundle()
91103
.on('error', function (ev) {

readthedocs/core/static-src/core/js/readthedocs-doc-embed.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ var sponsorship = require('./sponsorship'),
33
grokthedocs = require('./doc-embed/grokthedocs-client'),
44
mkdocs = require('./doc-embed/mkdocs'),
55
rtddata = require('./doc-embed/rtd-data'),
6-
sphinx = require('./doc-embed/sphinx'),
7-
$ = require('jquery');
6+
sphinx = require('./doc-embed/sphinx');
87

98
$(document).ready(function () {
109
footer.init();

readthedocs/core/static-src/core/js/sponsorship.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* Read the Docs - Documentation promotions */
22

3-
var $ = require('jquery');
4-
53
module.exports = {
64
Promo: Promo
75
};

readthedocs/core/static/core/js/readthedocs-doc-embed.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)