|
| 1 | +var path = require('path'); |
| 2 | +var fs = require('fs-extra'); |
| 3 | +var exec = require('child_process').exec; |
| 4 | +var runSeries = require('run-series'); |
| 5 | + |
| 6 | +var common = require('./util/common'); |
| 7 | +var constants = require('./util/constants'); |
| 8 | +var pkg = require('../package.json'); |
| 9 | + |
| 10 | +var packagesSpecs = constants.partialBundlePaths |
| 11 | + .map(function(d) { |
| 12 | + return { |
| 13 | + name: 'plotly.js-' + d.name + '-dist', |
| 14 | + main: 'plotly-' + d.name + '.js', |
| 15 | + dist: d.dist, |
| 16 | + desc: 'Ready-to-use plotly.js ' + d.name + ' distributed bundle', |
| 17 | + }; |
| 18 | + }) |
| 19 | + .concat([{ |
| 20 | + name: 'plotly.js-dist', |
| 21 | + main: 'plotly.js', |
| 22 | + dist: constants.pathToPlotlyDist, |
| 23 | + desc: 'Ready-to-use plotly.js distributed bundle', |
| 24 | + }]); |
| 25 | + |
| 26 | +packagesSpecs.forEach(function(d) { |
| 27 | + var pkgPath = path.join(constants.pathToBuild, d.name); |
| 28 | + |
| 29 | + function initDirectory(cb) { |
| 30 | + if(!common.doesDirExist(pkgPath)) { |
| 31 | + fs.mkdir(pkgPath, cb); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + function writePackageJSON(cb) { |
| 36 | + var cnt = { |
| 37 | + name: d.name, |
| 38 | + version: pkg.version, |
| 39 | + description: d.desc, |
| 40 | + license: pkg.license, |
| 41 | + main: d.main, |
| 42 | + repository: pkg.repository, |
| 43 | + bugs: pkg.bugs, |
| 44 | + author: pkg.author, |
| 45 | + keywords: pkg.keywords |
| 46 | + }; |
| 47 | + |
| 48 | + fs.writeFile( |
| 49 | + path.join(pkgPath, 'package.json'), |
| 50 | + JSON.stringify(cnt, null, 2), |
| 51 | + cb |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + function writeREADME(cb) { |
| 56 | + var cnt = [ |
| 57 | + '# ' + d.name, |
| 58 | + '', |
| 59 | + d.desc, |
| 60 | + '', |
| 61 | + 'For more info on plotly.js, go to https://github.com/plotly/plotly.js', |
| 62 | + '', |
| 63 | + '## Copyright and license', |
| 64 | + '', |
| 65 | + 'Code and documentation copyright 2018 Plotly, Inc.', |
| 66 | + '', |
| 67 | + 'Code released under the [MIT license](https://github.com/plotly/plotly.js/blob/master/LICENSE).', |
| 68 | + '', |
| 69 | + 'Docs released under the [Creative Commons license](https://github.com/plotly/documentation/blob/source/LICENSE).', |
| 70 | + '' |
| 71 | + ]; |
| 72 | + |
| 73 | + fs.writeFile( |
| 74 | + path.join(pkgPath, 'README.md'), |
| 75 | + cnt.join('\n'), |
| 76 | + cb |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + function copyDist(cb) { |
| 81 | + fs.copy(d.dist, path.join(pkgPath, d.main), cb); |
| 82 | + } |
| 83 | + |
| 84 | + function publishToNPM(cb) { |
| 85 | + exec('npm publish', {cwd: pkgPath}, cb).stdout.pipe(process.stdout); |
| 86 | + } |
| 87 | + |
| 88 | + // TODO |
| 89 | + // - add minified file? |
| 90 | + // - what to do with dist/topojson/ |
| 91 | + // - what to do with mathjax/ |
| 92 | + |
| 93 | + runSeries([ |
| 94 | + initDirectory, |
| 95 | + writePackageJSON, |
| 96 | + writeREADME, |
| 97 | + copyDist, |
| 98 | + publishToNPM |
| 99 | + ], function(err) { |
| 100 | + if(err) throw err; |
| 101 | + }); |
| 102 | +}); |
0 commit comments