mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-05 22:19:46 -06:00
* appveyor build for this branch * don't force install ffmpeg on windows don't force install ffmpeg on windows * derp * fix * build in appveyor * oops * delete using del * use RMDIR instead of DEL * only build 32-bit * build for x64 and x86 windows * separate win32 and win64 * require lodash * make electron arch configurable * cross-compile 32, only run in 64-bit * force install ffmpeg if necessary * it's all win10 x64, but we can force it to build for ia32 in x32 mode * add windows util * who's idea was it to make whitespace meaningful? * pass arch to npm install, pass arch to uploader * add TARGET_PLATFORM * fun fact: appveyor titlecases env var names fun fact: appveyor titlecases env var names * fix: pass args * use process * cli: use arch package to send arch to server * pass TARGET_ARCH to all npm installs * run-all * always call getUploadNameByOs * use the precise version of node, enable both x64 and ia32 arch * quotes * uh wat * move console logs to script because windows * add yet another env var to install the right node arch * use x86, not x32 * give ia32 a try, why not * use platform env again * and also try x86 again * remove notion of target_arch since we're using the right node version with arch set correctly * more comprehensive checks to ensure the arch is correct * simplify building the binary, do not accept arch as options * build the binary and test it on this branch * remove arch, ensure that process.env.Platform is set to x86 * do build the binary unless this is a forked PR * attempt to verify that this is a 32bit or 64bit windows binary * remove unused dep * consolidate commands * don't install packages in windows - just build the binary - this avoids needing to reinstall all node_modules and build-js twice * build the binary on more branches * cd up appveyor * ugh * right logic for whether or not this is a forked PR * remove unused deps * fix undefined var * platformArch * set in options * turns out we do have to npm install before building the binary * options.platformArch * comment out appveyor build 32bit/64bit verification temporarily Co-authored-by: Brian Mann <brian.mann86@gmail.com>
246 lines
5.5 KiB
JavaScript
246 lines
5.5 KiB
JavaScript
/* eslint-disable no-console */
|
|
|
|
const log = require('debug')('cypress:run')
|
|
const _ = require('lodash')
|
|
const path = require('path')
|
|
const AsciiTable = require('ascii-table')
|
|
const glob = require('glob')
|
|
const chalk = require('chalk')
|
|
const Promise = require('bluebird')
|
|
const runAll = require('@cypress/npm-run-all')
|
|
const through = require('through')
|
|
const fs = require('fs')
|
|
const prefixedList = require('prefixed-list')
|
|
|
|
const globAsync = Promise.promisify(glob)
|
|
|
|
const packageNameFromPath = (fullPath) => {
|
|
return fullPath
|
|
.replace(`${process.cwd()}${path.sep}`, '')
|
|
.replace(`packages${path.sep}`, '')
|
|
}
|
|
|
|
const nonPackageDirs = ['cli/']
|
|
|
|
const getDirs = () => {
|
|
const logDirs = (dirs) => {
|
|
log('found packages\n%s', dirs.join('\n'))
|
|
|
|
return dirs
|
|
}
|
|
|
|
return globAsync('packages/*/')
|
|
.then(logDirs)
|
|
.then((dirs) => {
|
|
return dirs.concat(nonPackageDirs)
|
|
})
|
|
.map((dir) => {
|
|
return path.join(process.cwd(), dir).replace(/\/$/, '')
|
|
})
|
|
}
|
|
|
|
const packageNameInArray = (dir, packages) => {
|
|
const packageName = packageNameFromPath(dir)
|
|
|
|
return _.includes(packages, packageName)
|
|
}
|
|
|
|
const filterDirsByPackage = (dirs, filter) => {
|
|
if (!filter) return dirs
|
|
|
|
return dirs.filter((dir) => {
|
|
return packageNameInArray(dir, filter)
|
|
})
|
|
}
|
|
|
|
const rejectDirsByPackage = (dirs, rejected) => {
|
|
if (!rejected) return dirs
|
|
|
|
if (rejected && rejected.length) {
|
|
return _.reject(dirs, (dir) => {
|
|
return packageNameInArray(dir, rejected)
|
|
})
|
|
}
|
|
}
|
|
|
|
const filterDirsByCmd = (dirs, cmd) => {
|
|
switch (cmd) {
|
|
case 'install': case 'i': case 'prune':
|
|
return dirs
|
|
default:
|
|
return dirs.filter((dir) => {
|
|
const packageJson = require(path.resolve(dir, 'package'))
|
|
|
|
return !!packageJson.scripts && !!packageJson.scripts[cmd]
|
|
})
|
|
}
|
|
}
|
|
|
|
const checkDirsLength = (dirs, errMessage) => {
|
|
if (dirs.length) {
|
|
return dirs
|
|
}
|
|
|
|
const err = new Error(errMessage)
|
|
|
|
err.noPackages = true
|
|
throw err
|
|
}
|
|
|
|
const mapTasks = (cmd, packages) => {
|
|
const colors = 'green yellow blue magenta cyan white gray bgGreen bgBlue bgMagenta bgCyan bgYellow bgWhite'.split(' ')
|
|
|
|
let runCommand
|
|
|
|
const command = cmd.split(' ', 2)[0]
|
|
|
|
switch (command) {
|
|
case 'install':
|
|
case 'i':
|
|
case 'test':
|
|
case 't':
|
|
case 'prune':
|
|
runCommand = cmd
|
|
break
|
|
default:
|
|
runCommand = `run ${cmd}`
|
|
}
|
|
|
|
console.log('filtered packages:', prefixedList(packages))
|
|
|
|
return packages.map((dir, index) => {
|
|
const packageName = packageNameFromPath(dir)
|
|
|
|
return {
|
|
command: runCommand,
|
|
options: {
|
|
cwd: dir,
|
|
label: {
|
|
name: `${packageName.replace(/\/$/, '')}:${cmd}`,
|
|
color: colors[index],
|
|
},
|
|
},
|
|
}
|
|
})
|
|
}
|
|
|
|
let stderrOutput = ''
|
|
const collectStderr = through(function (data) {
|
|
stderrOutput += data.toString()
|
|
|
|
return this.queue(data)
|
|
})
|
|
|
|
collectStderr.pipe(process.stderr)
|
|
|
|
const noPackagesError = (err) => {
|
|
return err.noPackages
|
|
}
|
|
// only consider printing a list of errors
|
|
const resultsError = (err) => {
|
|
return Array.isArray(err.results)
|
|
}
|
|
const failProcess = () => {
|
|
return process.exit(1)
|
|
}
|
|
|
|
const printOtherErrors = (err) => {
|
|
console.error(err.message)
|
|
console.error('run with DEBUG=cypress:run ... to see more details')
|
|
log(err.stack)
|
|
throw err
|
|
}
|
|
|
|
function hasPackageJson (dir) {
|
|
const packagePath = path.join(dir, 'package.json')
|
|
|
|
return fs.existsSync(packagePath)
|
|
}
|
|
|
|
function keepDirsWithPackageJson (dirs) {
|
|
return dirs.filter(hasPackageJson)
|
|
}
|
|
|
|
module.exports = (cmd, options) => {
|
|
const packagesFilter = options.package || options.packages
|
|
const packagesReject = options['skip-package'] || options['skip-packages']
|
|
|
|
if (packagesFilter === 'none') return
|
|
|
|
return getDirs()
|
|
.then(keepDirsWithPackageJson)
|
|
.then((dirs) => {
|
|
return filterDirsByPackage(dirs, packagesFilter)
|
|
})
|
|
.then((dirs) => {
|
|
return rejectDirsByPackage(dirs, packagesReject)
|
|
})
|
|
.then((dirs) => {
|
|
return checkDirsLength(dirs, `No packages were found with the filter '${packagesFilter}'`)
|
|
})
|
|
.then((dirs) => {
|
|
return filterDirsByCmd(dirs, cmd)
|
|
})
|
|
.then((dirs) => {
|
|
let errMessage = `No packages were found with the task '${cmd}'`
|
|
|
|
if (packagesFilter) {
|
|
errMessage += ` and the filter '${packagesFilter}'`
|
|
}
|
|
|
|
return checkDirsLength(dirs, errMessage)
|
|
})
|
|
.then((dirs) => {
|
|
if (options.args) {
|
|
cmd += ` ${options.args}`
|
|
}
|
|
|
|
return mapTasks(cmd, dirs)
|
|
})
|
|
.then((tasks) => {
|
|
const runSerially = Boolean(options.serial)
|
|
|
|
if (runSerially) {
|
|
console.log('⚠️ running jobs serially')
|
|
}
|
|
|
|
const parallel = !runSerially
|
|
|
|
return runAll(tasks, {
|
|
parallel,
|
|
printLabel: tasks.length > 1,
|
|
stdout: process.stdout,
|
|
stderr: collectStderr,
|
|
})
|
|
})
|
|
.then(() => {
|
|
console.log(chalk.green('\nAll tasks completed successfully'))
|
|
})
|
|
// using Bluebird filtered catch
|
|
// http://bluebirdjs.com/docs/api/catch.html#filtered-catch
|
|
.catch(noPackagesError, (err) => {
|
|
console.error(chalk.red(`\n${err.message}`))
|
|
|
|
return failProcess()
|
|
})
|
|
.catch(resultsError, (err) => {
|
|
const results = AsciiTable.factory({
|
|
heading: ['package', 'exit code'],
|
|
rows: err.results.map((result) => {
|
|
return [result.name.replace(`:${cmd}`, ''), result.code]
|
|
}),
|
|
}).toString()
|
|
|
|
console.error(chalk.red(`\nOne or more tasks failed running 'npm run all ${cmd}'.`))
|
|
console.error('\nResults:\n')
|
|
console.error(results)
|
|
|
|
console.error('\nstderr:\n')
|
|
console.error(stderrOutput)
|
|
|
|
return failProcess()
|
|
})
|
|
.catch(printOtherErrors)
|
|
.catch(failProcess)
|
|
}
|