Skip to content

Commit 5e04f37

Browse files
committed
lint: group stats in sub-routines
1 parent 7040e49 commit 5e04f37

File tree

1 file changed

+102
-87
lines changed

1 file changed

+102
-87
lines changed

tasks/stats.js

Lines changed: 102 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var falafel = require('falafel');
55
var gzipSize = require('gzip-size');
66
var prettySize = require('prettysize');
77

8+
var common = require('./util/common');
89
var constants = require('./util/constants');
910
var pkg = require('../package.json');
1011

@@ -16,97 +17,111 @@ var ENC = 'utf-8';
1617
var JS = '.js';
1718
var MINJS = '.min.js';
1819

20+
// main
21+
var content = getContent();
22+
common.writeFile(pathDistREADME, content.join('\n'));
23+
24+
function getContent() {
25+
return []
26+
.concat(getInfoContent())
27+
.concat(getMainBundleInfo())
28+
.concat(getPartialBundleInfo())
29+
.concat(getFooter());
30+
}
1931

2032
// general info about distributed files
21-
var infoContent = [
22-
'# Using distributed files',
23-
'',
24-
'All plotly.js dist bundles inject an object `Plotly` into the global scope.',
25-
'',
26-
'Import plotly.js as:',
27-
'',
28-
'```html',
29-
'<script type="text/javascript" src="plotly.min.js"></script>',
30-
'```',
31-
'',
32-
'or the un-minified version as:',
33-
'',
34-
'```html',
35-
'<script type="text/javascript" src="plotly.js" charset="utf-8"></script>',
36-
'```',
37-
'',
38-
'To support IE9, put:',
39-
'',
40-
'```html',
41-
'<script>if(typeof window.Int16Array !== \'function\')document.write("<scri"+"pt src=\'extras/typedarray.min.js\'></scr"+"ipt>");</script>',
42-
'```',
43-
'',
44-
'before the plotly.js script tag.',
45-
'',
46-
'To add MathJax, put',
47-
'',
48-
'```html',
49-
'<script type="text/javascript" src="mathjax/MathJax.js?config=TeX-AMS-MML_SVG"></script>',
50-
'```',
51-
'',
52-
'before the plotly.js script tag. You can grab the relevant MathJax files in `./dist/extras/mathjax/`.',
53-
''
54-
];
55-
56-
// add bundle content/size info
57-
var mainSizes = findSizes({
58-
dist: constants.pathToPlotlyDist,
59-
distMin: constants.pathToPlotlyDistMin,
60-
withMeta: constants.pathToPlotlyDistWithMeta
61-
});
62-
var bundleInfo = [
63-
'# Bundle information',
64-
'',
65-
'The main plotly.js bundle includes all the official (non-beta) trace modules.',
66-
'',
67-
'It be can imported as minified javascript',
68-
'- using dist file `dist/plotly.min.js`',
69-
'- using CDN URL ' + cdnRoot + 'plotly-latest.min.js OR ' + cdnRoot + 'plotly-' + pkg.version + MINJS,
70-
'',
71-
'or as raw javascript:',
72-
'- using dist file `dist/plotly.js`',
73-
'- using CDN URL ' + cdnRoot + 'plotly-latest.js OR ' + cdnRoot + 'plotly-' + pkg.version + JS,
74-
'- using CommonJS with `require(\'plotly.js\')`',
75-
'',
76-
'If you would like to have access to the attribute meta information ' +
77-
'(including attribute descriptions as on the [schema reference page](https://plot.ly/javascript/reference/)), ' +
78-
'use dist file `dist/plotly-with-meta.js`',
79-
'',
80-
'The main plotly.js bundle weights in at:',
81-
'',
82-
'| plotly.js | plotly.min.js | plotly.min.js + gzip | plotly-with-meta.js |',
83-
'|-----------|---------------|----------------------|---------------------|',
84-
'| ' + mainSizes.raw + ' | ' + mainSizes.minified + ' | ' + mainSizes.gzipped + ' | ' + mainSizes.withMeta + ' |',
85-
'',
86-
'## Partial bundles',
87-
'',
88-
'Starting in `v1.15.0`, plotly.js also ships with several _partial_ bundles:',
89-
'',
90-
constants.partialBundlePaths.map(makeBundleHeaderInfo).join('\n'),
91-
''
92-
]
93-
.concat(
94-
constants.partialBundlePaths.map(makeBundleInfo)
95-
);
33+
function getInfoContent() {
34+
return [
35+
'# Using distributed files',
36+
'',
37+
'All plotly.js dist bundles inject an object `Plotly` into the global scope.',
38+
'',
39+
'Import plotly.js as:',
40+
'',
41+
'```html',
42+
'<script type="text/javascript" src="plotly.min.js"></script>',
43+
'```',
44+
'',
45+
'or the un-minified version as:',
46+
'',
47+
'```html',
48+
'<script type="text/javascript" src="plotly.js" charset="utf-8"></script>',
49+
'```',
50+
'',
51+
'To support IE9, put:',
52+
'',
53+
'```html',
54+
'<script>if(typeof window.Int16Array !== \'function\')document.write("<scri"+"pt src=\'extras/typedarray.min.js\'></scr"+"ipt>");</script>',
55+
'```',
56+
'',
57+
'before the plotly.js script tag.',
58+
'',
59+
'To add MathJax, put',
60+
'',
61+
'```html',
62+
'<script type="text/javascript" src="mathjax/MathJax.js?config=TeX-AMS-MML_SVG"></script>',
63+
'```',
64+
'',
65+
'before the plotly.js script tag. You can grab the relevant MathJax files in `./dist/extras/mathjax/`.',
66+
''
67+
];
68+
}
69+
70+
// info about main bundle
71+
function getMainBundleInfo() {
72+
var mainSizes = findSizes({
73+
dist: constants.pathToPlotlyDist,
74+
distMin: constants.pathToPlotlyDistMin,
75+
withMeta: constants.pathToPlotlyDistWithMeta
76+
});
77+
78+
return [
79+
'# Bundle information',
80+
'',
81+
'The main plotly.js bundle includes all the official (non-beta) trace modules.',
82+
'',
83+
'It be can imported as minified javascript',
84+
'- using dist file `dist/plotly.min.js`',
85+
'- using CDN URL ' + cdnRoot + 'plotly-latest.min.js OR ' + cdnRoot + 'plotly-' + pkg.version + MINJS,
86+
'',
87+
'or as raw javascript:',
88+
'- using dist file `dist/plotly.js`',
89+
'- using CDN URL ' + cdnRoot + 'plotly-latest.js OR ' + cdnRoot + 'plotly-' + pkg.version + JS,
90+
'- using CommonJS with `require(\'plotly.js\')`',
91+
'',
92+
'If you would like to have access to the attribute meta information ' +
93+
'(including attribute descriptions as on the [schema reference page](https://plot.ly/javascript/reference/)), ' +
94+
'use dist file `dist/plotly-with-meta.js`',
95+
'',
96+
'The main plotly.js bundle weights in at:',
97+
'',
98+
'| plotly.js | plotly.min.js | plotly.min.js + gzip | plotly-with-meta.js |',
99+
'|-----------|---------------|----------------------|---------------------|',
100+
'| ' + mainSizes.raw + ' | ' + mainSizes.minified + ' | ' + mainSizes.gzipped + ' | ' + mainSizes.withMeta + ' |',
101+
'',
102+
'## Partial bundles',
103+
'',
104+
'Starting in `v1.15.0`, plotly.js also ships with several _partial_ bundles:',
105+
'',
106+
constants.partialBundlePaths.map(makeBundleHeaderInfo).join('\n'),
107+
''
108+
];
109+
}
110+
111+
// info about partial bundles
112+
function getPartialBundleInfo() {
113+
return constants.partialBundlePaths.map(makeBundleInfo);
114+
}
96115

97116
// footer info
98-
var footer = [
99-
'----------------',
100-
'',
101-
'_This file is auto-generated by `npm run stats`. ' +
102-
'Please do not edit this file directly._'
103-
];
104-
105-
var content = infoContent.concat(bundleInfo).concat(footer);
106-
107-
fs.writeFile(pathDistREADME, content.join('\n'), function(err) {
108-
if(err) throw err;
109-
});
117+
function getFooter() {
118+
return [
119+
'----------------',
120+
'',
121+
'_This file is auto-generated by `npm run stats`. ' +
122+
'Please do not edit this file directly._'
123+
];
124+
}
110125

111126
function makeBundleHeaderInfo(pathObj) {
112127
var name = pathObj.name;

0 commit comments

Comments
 (0)