mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-21 06:30:49 -06:00
save wip on parallel script UI
current issues: - nodemon causes scrolling not to work (https://github.com/chjj/blessed/issues/235) - exiting doesn’t exit scripts (via npm-run-all) properly
This commit is contained in:
121
lib/index.coffee
121
lib/index.coffee
@@ -1,14 +1,23 @@
|
||||
blessed = require("blessed")
|
||||
|
||||
cp = require("child_process")
|
||||
path = require("path")
|
||||
glob = require("glob")
|
||||
chalk = require("chalk")
|
||||
Promise = require("bluebird")
|
||||
minimist = require("minimist")
|
||||
runAll = require("@cypress/npm-run-all")
|
||||
through = require("through")
|
||||
|
||||
globAsync = Promise.promisify(glob)
|
||||
|
||||
DEFAULT_DIR = path.resolve("packages", "*")
|
||||
|
||||
createStream = (onWrite) ->
|
||||
through (data) ->
|
||||
onWrite(data.toString())
|
||||
@queue(data)
|
||||
|
||||
module.exports = {
|
||||
getDirs: (dir) ->
|
||||
dir ?= DEFAULT_DIR
|
||||
@@ -20,30 +29,116 @@ module.exports = {
|
||||
|
||||
@getDirs()
|
||||
.then (dirs) ->
|
||||
exec = (str) =>
|
||||
execDir = (dir) ->
|
||||
new Promise (resolve, reject) ->
|
||||
args = str.split(" ")
|
||||
cmd = args.shift()
|
||||
screen = blessed.screen({
|
||||
smartCSR: true
|
||||
})
|
||||
|
||||
console.log("")
|
||||
console.log(chalk.green("Running:"), chalk.magenta(str), chalk.blue(dir))
|
||||
screen.title = "run:all:#{cmd}";
|
||||
|
||||
sp = cp.spawn(cmd, args, {cwd: dir, stdio: "inherit"})
|
||||
sp.on("error", reject)
|
||||
sp.on("close", resolve)
|
||||
screen.key ['escape', 'q', 'C-c'], (ch, key) ->
|
||||
process.exit(0)
|
||||
|
||||
Promise.map(dirs, execDir)
|
||||
packages = dirs.filter (dir) ->
|
||||
packageJson = require(path.resolve(dir, "package"))
|
||||
return packageJson.scripts[cmd]
|
||||
|
||||
Promise.each(cmds, exec)
|
||||
boxWidth = 100 / packages.length
|
||||
|
||||
logs = packages.map (dir, index) ->
|
||||
packageName = dir.replace(path.resolve("packages") + "/", "")
|
||||
|
||||
content = ""
|
||||
|
||||
box = blessed.log({
|
||||
border: 'line'
|
||||
content: content
|
||||
label: "#{packageName}:#{cmd}"
|
||||
left: "#{index * boxWidth}%"
|
||||
height: '100%'
|
||||
parent: screen
|
||||
top: 0
|
||||
width: "#{boxWidth}%"
|
||||
|
||||
scrollable: true
|
||||
keys: true
|
||||
vi: true
|
||||
alwaysScroll: true
|
||||
scrollbar: {
|
||||
ch: ' '
|
||||
inverse: true
|
||||
}
|
||||
})
|
||||
|
||||
box.key ['escape', 'q', 'C-c'], (ch, key) ->
|
||||
process.exit(0)
|
||||
|
||||
return {
|
||||
box: box,
|
||||
dir: dir,
|
||||
stdout: createStream (message) ->
|
||||
content += message
|
||||
box.setContent(content)
|
||||
screen.render()
|
||||
stderr: createStream (message) ->
|
||||
content += message
|
||||
box.setContent(content)
|
||||
screen.render()
|
||||
}
|
||||
|
||||
screen.render()
|
||||
|
||||
tasks = logs.map (log) ->
|
||||
return {
|
||||
command: cmd
|
||||
options: {
|
||||
cwd: log.dir
|
||||
stdout: log.stdout
|
||||
stderr: log.stderr
|
||||
}
|
||||
}
|
||||
|
||||
runAll(tasks, {
|
||||
continueOnError: true
|
||||
parallel: true
|
||||
# stdout: process.stdout
|
||||
# stderr: process.stderr
|
||||
})
|
||||
.catch (err) ->
|
||||
## TODO: handle this better
|
||||
console.log(err)
|
||||
|
||||
start: (argv = []) ->
|
||||
options = minimist(argv)
|
||||
|
||||
switch
|
||||
when e = options.exec
|
||||
when e = options.exec or options._[0]
|
||||
@exec(e)
|
||||
|
||||
else
|
||||
require("core-app").start(options)
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
|
||||
work out script running UX
|
||||
- stderr
|
||||
- report proper exit code
|
||||
- individual control of each pane/task
|
||||
work out build dependencies
|
||||
- e.g. runner waits on reporter
|
||||
- any other examples? if not, just deal with runner/reporter
|
||||
wire up interdependencies correctly
|
||||
- @cypress/core-runner -> core-runner
|
||||
handle deployment
|
||||
core-app -> core-server
|
||||
more some core-app stuff into root
|
||||
tests?
|
||||
- unit/integration in each package
|
||||
- e2e should be in root
|
||||
running all tests
|
||||
- needs to be sequential?
|
||||
- unit tests in parallel?
|
||||
- how are errors reporter?
|
||||
|
||||
###
|
||||
|
||||
@@ -6,15 +6,19 @@
|
||||
"postinstall": "node index.js --exec 'npm install, npm run build'",
|
||||
"start": "node index.js",
|
||||
"dev": "node index.js --exec 'npm run dev'",
|
||||
"test": "node index.js --exec 'npm test'"
|
||||
"test": "node index.js --exec 'npm test'",
|
||||
"all": "node index.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@cypress/npm-run-all": "^3.1.0",
|
||||
"blessed": "^0.1.81",
|
||||
"bluebird": "^3.4.5",
|
||||
"coffee-script": "^1.11.1",
|
||||
"eslint": "^3.7.1",
|
||||
"lodash": "^4.16.3"
|
||||
"lodash": "^4.16.3",
|
||||
"through": "^2.3.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"app-module-path": "^1.1.0",
|
||||
|
||||
@@ -56,6 +56,6 @@
|
||||
"react-dom": "^15.1.0",
|
||||
"react-loader": "^2.4.0",
|
||||
"react-router": "^2.4.1",
|
||||
"zunder": "3.4.13"
|
||||
"zunder": "^3.4.16"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user