|
@@ -1,7 +1,8 @@
|
|
|
const fs = require('fs')
|
|
|
const path = require('path')
|
|
|
const chalk = require('chalk')
|
|
|
-const { exec } = require('child_process')
|
|
|
+const { spawn } = require('child_process')
|
|
|
+const readline = require('readline')
|
|
|
const YAML = require('js-yaml')
|
|
|
const { promisify } = require('util')
|
|
|
const gzipSize = require('gzip-size')
|
|
@@ -9,6 +10,7 @@ const prettierBytes = require('@transloadit/prettier-bytes')
|
|
|
const browserify = require('browserify')
|
|
|
const touch = require('touch')
|
|
|
const glob = require('glob')
|
|
|
+const { minify } = require('terser')
|
|
|
|
|
|
const webRoot = __dirname
|
|
|
const uppyRoot = path.join(__dirname, '../packages/uppy')
|
|
@@ -80,7 +82,7 @@ async function getMinifiedSize (pkg, name) {
|
|
|
const b = browserify(pkg)
|
|
|
|
|
|
const packageJSON = fs.readFileSync(path.join(pkg, 'package.json'))
|
|
|
- const version = JSON.parse(packageJSON).version
|
|
|
+ const { version } = JSON.parse(packageJSON)
|
|
|
|
|
|
if (name !== '@uppy/core' && name !== 'uppy') {
|
|
|
b.exclude('@uppy/core')
|
|
@@ -90,9 +92,8 @@ async function getMinifiedSize (pkg, name) {
|
|
|
if (excludes[name]) {
|
|
|
b.exclude(excludes[name])
|
|
|
}
|
|
|
- b.plugin('tinyify')
|
|
|
|
|
|
- const bundle = await promisify(b.bundle).call(b)
|
|
|
+ const { code:bundle } = await promisify(b.bundle).call(b).then(buf => minify(buf.toString(), { toplevel: true }))
|
|
|
const gzipped = await gzipSize(bundle)
|
|
|
|
|
|
return {
|
|
@@ -104,7 +105,7 @@ async function getMinifiedSize (pkg, name) {
|
|
|
|
|
|
async function injectSizes (config) {
|
|
|
console.info(chalk.grey('Generating bundle sizes…'))
|
|
|
- const padTarget = packages.reduce((max, cur) => Math.max(max, cur.length), 0) + 2
|
|
|
+ const padTarget = Math.max(...packages.map((cur) => cur.length)) + 2
|
|
|
|
|
|
const sizesPromise = Promise.all(
|
|
|
packages.map(async (pkg) => {
|
|
@@ -115,35 +116,43 @@ async function injectSizes (config) {
|
|
|
`${prettierBytes(result.minified)} min`.padEnd(10)
|
|
|
} / ${prettierBytes(result.gzipped)} gz`
|
|
|
))
|
|
|
- return Object.assign(result, {
|
|
|
+ return [pkg, {
|
|
|
+ ...result,
|
|
|
prettyMinified: prettierBytes(result.minified),
|
|
|
prettyGzipped: prettierBytes(result.gzipped),
|
|
|
- })
|
|
|
- })
|
|
|
- ).then((list) => {
|
|
|
- const map = {}
|
|
|
- list.forEach((size, i) => {
|
|
|
- map[packages[i]] = size
|
|
|
+ }]
|
|
|
})
|
|
|
- return map
|
|
|
- })
|
|
|
+ ).then(Object.fromEntries)
|
|
|
|
|
|
config.uppy_bundle_kb_sizes = await sizesPromise
|
|
|
}
|
|
|
|
|
|
+const sourceUppy = path.join(webRoot, '/themes/uppy/source/uppy/')
|
|
|
+const sourceUppyLocales = path.join(sourceUppy, 'locales')
|
|
|
async function injectBundles () {
|
|
|
+ await Promise.all([
|
|
|
+ fs.promises.mkdir(sourceUppy, { recursive:true }),
|
|
|
+ fs.promises.mkdir(sourceUppyLocales, { recursive:true }),
|
|
|
+ ])
|
|
|
const cmds = [
|
|
|
- `mkdir -p ${path.join(webRoot, '/themes/uppy/source/uppy')}`,
|
|
|
- `mkdir -p ${path.join(webRoot, '/themes/uppy/source/uppy/locales')}`,
|
|
|
- `cp -vfR ${path.join(uppyRoot, '/dist/*')} ${path.join(webRoot, '/themes/uppy/source/uppy/')}`,
|
|
|
- `cp -vfR ${path.join(robodogRoot, '/dist/*')} ${path.join(webRoot, '/themes/uppy/source/uppy/')}`,
|
|
|
- `cp -vfR ${path.join(localesRoot, '/dist/*')} ${path.join(webRoot, '/themes/uppy/source/uppy/locales')}`,
|
|
|
+ `cp -vfR ${path.join(uppyRoot, '/dist/*')} ${sourceUppy}`,
|
|
|
+ `cp -vfR ${path.join(robodogRoot, '/dist/*')} ${sourceUppy}`,
|
|
|
+ `cp -vfR ${path.join(localesRoot, '/dist/*')} ${sourceUppyLocales}`,
|
|
|
].join(' && ')
|
|
|
|
|
|
- const { stdout } = await promisify(exec)(cmds)
|
|
|
- stdout.trim().split('\n').forEach((line) => {
|
|
|
- console.info(chalk.green('✓ injected: '), chalk.grey(line))
|
|
|
- })
|
|
|
+ const cp = spawn(cmds, { stdio:['ignore', 'pipe', 'inherit'], shell: true })
|
|
|
+ await Promise.race([
|
|
|
+ new Promise((resolve, reject) => cp.on('error', reject)),
|
|
|
+ (async () => {
|
|
|
+ const stdout = readline.createInterface({
|
|
|
+ input: cp.stdout,
|
|
|
+ })
|
|
|
+
|
|
|
+ for await (const line of stdout) {
|
|
|
+ console.info(chalk.green('✓ injected: '), chalk.grey(line))
|
|
|
+ }
|
|
|
+ })(),
|
|
|
+ ])
|
|
|
}
|
|
|
|
|
|
// re-enable after rate limiter issue is fixed
|
|
@@ -233,7 +242,7 @@ function injectLocaleList () {
|
|
|
|
|
|
async function readConfig () {
|
|
|
try {
|
|
|
- const buf = await promisify(fs.readFile)(configPath, 'utf8')
|
|
|
+ const buf = await fs.promises.readFile(configPath, 'utf8')
|
|
|
return YAML.safeLoad(buf)
|
|
|
} catch (err) {
|
|
|
return {}
|
|
@@ -254,7 +263,7 @@ async function inject () {
|
|
|
await injectSizes(config)
|
|
|
|
|
|
const saveConfig = { ...defaultConfig, ...config }
|
|
|
- await promisify(fs.writeFile)(configPath, YAML.safeDump(saveConfig), 'utf-8')
|
|
|
+ await fs.promises.writeFile(configPath, YAML.safeDump(saveConfig), 'utf-8')
|
|
|
console.info(chalk.green('✓ rewritten: '), chalk.grey(configPath))
|
|
|
|
|
|
try {
|