mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-18 17:16:00 +00:00
a bad result from adding the examples as dependencies of the root repository is that they now don't have access to the npm binaries they need to run in their own folder, because they are installed into the root repository instead. this works around that issue. we may need to consider undoing that change and making the examples work as standalone projects again, that's easier to understand. fixes #2024 for now.
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Lerna installs all the example dependencies into the root `node_modules`.
|
|
* To run the examples they need to have access to executables from npm dependencies in their $PATH.
|
|
* If you run `npm start` in a dependency folder, the root `node_modules/.bin` is not in the $PATH.
|
|
*
|
|
* This proxy executable can be run from the repository root using `npm run example`, so the root
|
|
* `node_modules/.bin` will be in the $PATH. It then runs `npm start` in the specific example folder,
|
|
* which will inherit the $PATH, so the example has access to executables from npm dependencies in both
|
|
* its own and in the root `node_modules`.
|
|
*/
|
|
|
|
const path = require('path')
|
|
const { execSync } = require('child_process')
|
|
const exampleName = process.argv[2]
|
|
|
|
if (!exampleName) {
|
|
console.error('Usage: npm run example "name-of-example"')
|
|
process.exit(1)
|
|
}
|
|
|
|
const exampleDir = path.join(__dirname, '../examples', exampleName)
|
|
const pkg = require(path.join(exampleDir, 'package.json'))
|
|
if (pkg.scripts && pkg.scripts.build) {
|
|
execSync('npm run build', { cwd: exampleDir, stdio: 'inherit' })
|
|
}
|
|
|
|
execSync('npm start', { cwd: exampleDir, stdio: 'inherit' })
|