1 | var path = require('path')
|
2 | var fs = require('fs')
|
3 | var chalk = require('chalk')
|
4 | var mkdirp = require('mkdirp')
|
5 | var babelify = require('babelify')
|
6 | var tinyify = require('tinyify')
|
7 | var browserify = require('browserify')
|
8 | var exorcist = require('exorcist')
|
9 |
|
10 | var distPath = './dist'
|
11 | var srcPath = './src'
|
12 |
|
13 | function handleErr (err) {
|
14 | console.error(chalk.red('✗ Error:'), chalk.red(err.message))
|
15 | }
|
16 |
|
17 | function buildUppyBundle (minify) {
|
18 | var src = path.join(srcPath, 'index.js')
|
19 | var bundleFile = minify ? 'uppy.min.js' : 'uppy.js'
|
20 |
|
21 | var b = browserify(src, { debug: true, standalone: 'Uppy' })
|
22 | if (minify) {
|
23 | b.plugin(tinyify)
|
24 | }
|
25 | b.transform(babelify)
|
26 | b.on('error', handleErr)
|
27 |
|
28 | return new Promise(function (resolve, reject) {
|
29 | b.bundle()
|
30 | .pipe(exorcist(path.join(distPath, bundleFile + '.map')))
|
31 | .pipe(fs.createWriteStream(path.join(distPath, bundleFile), 'utf8'))
|
32 | .on('error', handleErr)
|
33 | .on('finish', function () {
|
34 | if (minify) {
|
35 | console.info(chalk.green('✓ Built Minified Bundle:'), chalk.magenta(bundleFile))
|
36 | } else {
|
37 | console.info(chalk.green('✓ Built Bundle:'), chalk.magenta(bundleFile))
|
38 | }
|
39 | resolve()
|
40 | })
|
41 | })
|
42 | }
|
43 |
|
44 | // function copyLocales () {
|
45 | // var copyCommand = 'cp -R ' + path.join(srcPath, 'locales/') + ' ' + path.join(distPath, 'locales/')
|
46 | // return new Promise(function (resolve, reject) {
|
47 | // exec(copyCommand, function (error, stdout, stderr) {
|
48 | // if (error) {
|
49 | // handleErr(error)
|
50 | // reject(error)
|
51 | // return
|
52 | // }
|
53 | // console.info(chalk.green('✓ Copied locales to dist'))
|
54 | // resolve()
|
55 | // })
|
56 | // })
|
57 | // }
|
58 |
|
59 | // function buildLocale (file) {
|
60 | // return new Promise(function (resolve, reject) {
|
61 | // var fileName = path.basename(file, '.js')
|
62 | // browserify(file)
|
63 | // .transform(babelify)
|
64 | // .on('error', handleErr)
|
65 | // .bundle()
|
66 | // .pipe(fs.createWriteStream('./dist/locales/' + fileName + '.js', 'utf8'))
|
67 | // .on('error', handleErr)
|
68 | // .on('finish', function () {
|
69 | // console.info(chalk.green('✓ Built Locale:'), chalk.magenta(fileName + '.js'))
|
70 | // resolve()
|
71 | // })
|
72 | // })
|
73 | // }
|
74 |
|
75 | // function buildUppyLocales () {
|
76 | // mkdirp.sync('./dist/locales')
|
77 | // var localePromises = []
|
78 | // glob('./src/locales/*.js', function (err, files) {
|
79 | // if (err) console.log(err)
|
80 | // files.forEach(function (file) {
|
81 | // localePromises.push(buildLocale(file))
|
82 | // })
|
83 | // })
|
84 | // return Promise.all(localePromises)
|
85 | // }
|
86 |
|
87 | mkdirp.sync(distPath)
|
88 |
|
89 | Promise.all([buildUppyBundle(), buildUppyBundle(true)])
|
90 | .then(function () {
|
91 | console.info(chalk.yellow('✓ JS Bundle 🎉'))
|
92 | })
|
93 |
|
94 | // Promise.all([buildUppyBundle(), buildUppyBundle(true), buildUppyLocales()])
|
95 | // .then(function () {
|
96 | // console.info(chalk.yellow('✓ JS Bundle 🎉'))
|
97 | // })
|