123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- var path = require('path')
- var fs = require('fs')
- var chalk = require('chalk')
- var mkdirp = require('mkdirp')
- // var glob = require('glob')
- var babelify = require('babelify')
- // var yoyoify = require('yo-yoify')
- var browserify = require('browserify')
- // var exec = require('child_process').exec
- var exorcist = require('exorcist')
- var distPath = './dist'
- var srcPath = './src'
- function handleErr (err) {
- console.error(chalk.red('✗ Error:'), chalk.red(err.message))
- }
- function buildUppyBundle (minify) {
- var src = path.join(srcPath, 'index.js')
- var bundleFile = minify ? 'uppy.min.js' : 'uppy.js'
- var b = browserify(src, { debug: true, standalone: 'Uppy' })
- if (minify) {
- b.plugin('minifyify', {
- map: bundleFile + '.map',
- output: path.join(distPath, bundleFile + '.map')
- })
- }
- // b.transform(yoyoify)
- b.transform(babelify)
- b.on('error', handleErr)
- return new Promise(function (resolve, reject) {
- if (minify) {
- b.bundle()
- .pipe(fs.createWriteStream(path.join(distPath, bundleFile), 'utf8'))
- .on('error', handleErr)
- .on('finish', function () {
- console.info(chalk.green('✓ Built Minified Bundle:'), chalk.magenta(bundleFile))
- resolve()
- })
- } else {
- b.bundle()
- .pipe(exorcist(path.join(distPath, 'uppy.js.map')))
- .pipe(fs.createWriteStream(path.join(distPath, bundleFile), 'utf8'))
- .on('error', handleErr)
- .on('finish', function () {
- console.info(chalk.green('✓ Built Bundle:'), chalk.magenta(bundleFile))
- resolve()
- })
- }
- })
- }
- // function copyLocales () {
- // var copyCommand = 'cp -R ' + path.join(srcPath, 'locales/') + ' ' + path.join(distPath, 'locales/')
- // return new Promise(function (resolve, reject) {
- // exec(copyCommand, function (error, stdout, stderr) {
- // if (error) {
- // handleErr(error)
- // reject(error)
- // return
- // }
- // console.info(chalk.green('✓ Copied locales to dist'))
- // resolve()
- // })
- // })
- // }
- // function buildLocale (file) {
- // return new Promise(function (resolve, reject) {
- // var fileName = path.basename(file, '.js')
- // browserify(file)
- // .transform(babelify)
- // .on('error', handleErr)
- // .bundle()
- // .pipe(fs.createWriteStream('./dist/locales/' + fileName + '.js', 'utf8'))
- // .on('error', handleErr)
- // .on('finish', function () {
- // console.info(chalk.green('✓ Built Locale:'), chalk.magenta(fileName + '.js'))
- // resolve()
- // })
- // })
- // }
- // function buildUppyLocales () {
- // mkdirp.sync('./dist/locales')
- // var localePromises = []
- // glob('./src/locales/*.js', function (err, files) {
- // if (err) console.log(err)
- // files.forEach(function (file) {
- // localePromises.push(buildLocale(file))
- // })
- // })
- // return Promise.all(localePromises)
- // }
- mkdirp.sync(distPath)
- Promise.all([buildUppyBundle(), buildUppyBundle(true)])
- .then(function () {
- console.info(chalk.yellow('✓ JS Bundle 🎉'))
- })
- // Promise.all([buildUppyBundle(), buildUppyBundle(true), buildUppyLocales()])
- // .then(function () {
- // console.info(chalk.yellow('✓ JS Bundle 🎉'))
- // })
|