uppy/bin/build-lib.js
Kevin van Zonneveld 764c2ccada
Update Linter (#2796)
* relocate .vscode

* Switch to transloadit linter

* Update .eslintrc.json

* autofix code

* unlink and install eslint-config-transloadit@1.1.1

* Change 0 to "off"

* Don't change 'use strict'

* Do not vertically align

* disable key-spacing

* add import/no-extraneous-dependencies per package

* add more react/a11y warnings

* Revert "autofix code"

This reverts commit 14c8a8cde8.

* add import/no-extraneous-dependencies per example and main package

* autofix code (2)

* Allow devDependencies in ./bin

* Change import/no-extraneous-dependencies to warn again

* upgrade linter

* Set import/no-extraneous-dependencies to warn
2021-03-15 16:25:17 +00:00

64 lines
1.9 KiB
JavaScript

const chalk = require('chalk')
const babel = require('@babel/core')
const { promisify } = require('util')
const glob = promisify(require('glob'))
const mkdirp = promisify(require('mkdirp'))
const fs = require('fs')
const path = require('path')
const transformFile = promisify(babel.transformFile)
const writeFile = promisify(fs.writeFile)
const stat = promisify(fs.stat)
const SOURCE = 'packages/{*,@uppy/*}/src/**/*.js'
// Files not to build (such as tests)
const IGNORE = /\.test\.js$|__mocks__|svelte|companion\//
// Files that should trigger a rebuild of everything on change
const META_FILES = [
'babel.config.js',
'package.json',
'package-lock.json',
'bin/build-lib.js',
]
function lastModified (file) {
return stat(file).then((s) => s.mtime)
}
async function buildLib () {
const metaMtimes = await Promise.all(META_FILES.map((filename) =>
lastModified(path.join(__dirname, '..', filename))))
const metaMtime = Math.max(...metaMtimes)
const files = await glob(SOURCE)
for (const file of files) {
if (IGNORE.test(file)) continue
const libFile = file.replace('/src/', '/lib/')
// on a fresh build, rebuild everything.
if (!process.env.FRESH) {
const srcMtime = await lastModified(file)
const libMtime = await lastModified(libFile)
.catch(() => 0) // probably doesn't exist
// Skip files that haven't changed
if (srcMtime < libMtime && metaMtime < libMtime) {
continue
}
}
const { code, map } = await transformFile(file, { sourceMaps: true })
await mkdirp(path.dirname(libFile))
await Promise.all([
writeFile(libFile, code),
writeFile(`${libFile}.map`, JSON.stringify(map)),
])
console.log(chalk.green('Compiled lib:'), chalk.magenta(libFile))
}
}
console.log('Using Babel version:', require('@babel/core/package.json').version)
buildLib().catch((err) => {
console.error(err.stack)
process.exit(1)
})