mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-23 07:34:00 -05:00
convert run scripts to JS and prep for require-able cypress module
This commit is contained in:
@@ -4,5 +4,84 @@
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6
|
||||
},
|
||||
"rules": {
|
||||
"array-bracket-spacing": ["error", "never"],
|
||||
"arrow-parens": ["error", "always"],
|
||||
"arrow-spacing": "error",
|
||||
"block-spacing": "error",
|
||||
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"comma-spacing": "error",
|
||||
"curly": ["error", "multi-line", "consistent"],
|
||||
"constructor-super": "error",
|
||||
"default-case": "error",
|
||||
"eol-last": "error",
|
||||
"eqeqeq": ["error", "allow-null"],
|
||||
"indent": ["error", 2, { "SwitchCase": 1 }],
|
||||
"key-spacing": "error",
|
||||
"keyword-spacing": "error",
|
||||
"no-case-declarations": "error",
|
||||
"no-class-assign": "error",
|
||||
"no-cond-assign": "error",
|
||||
"no-console": "error",
|
||||
"no-const-assign": "error",
|
||||
"no-constant-condition": "error",
|
||||
"no-control-regex": "error",
|
||||
"no-debugger": "error",
|
||||
"no-delete-var": "error",
|
||||
"no-dupe-class-members": "error",
|
||||
"no-dupe-keys": "error",
|
||||
"no-dupe-args": "error",
|
||||
"no-duplicate-case": "error",
|
||||
"no-duplicate-imports": "error",
|
||||
"no-empty": "error",
|
||||
"no-empty-character-class": "error",
|
||||
"no-empty-pattern": "error",
|
||||
"no-ex-assign": "error",
|
||||
"no-extra-boolean-cast": "error",
|
||||
"no-extra-semi": "error",
|
||||
"no-fallthrough": "error",
|
||||
"no-func-assign": "error",
|
||||
"no-inner-declarations": "error",
|
||||
"no-invalid-regexp": "error",
|
||||
"no-irregular-whitespace": "error",
|
||||
"no-mixed-spaces-and-tabs": "error",
|
||||
"no-multiple-empty-lines": ["error", { "max": 2 }],
|
||||
"no-negated-in-lhs": "error",
|
||||
"no-new-symbol": "error",
|
||||
"no-obj-calls": "error",
|
||||
"no-octal": "error",
|
||||
"no-redeclare": "error",
|
||||
"no-regex-spaces": "error",
|
||||
"no-self-assign": "error",
|
||||
"no-spaced-func": "error",
|
||||
"no-sparse-arrays": "error",
|
||||
"no-this-before-super": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-undef": "error",
|
||||
"no-unexpected-multiline": "error",
|
||||
"no-unreachable": "error",
|
||||
"no-unused-labels": "error",
|
||||
"no-unused-vars": "error",
|
||||
"no-useless-concat": "error",
|
||||
"no-useless-constructor": "error",
|
||||
"no-var": "error",
|
||||
"no-whitespace-before-property": "error",
|
||||
"object-curly-spacing": ["error", "always"],
|
||||
"object-shorthand": "error",
|
||||
"one-var": ["error", "never"],
|
||||
"prefer-rest-params": "error",
|
||||
"prefer-spread": "error",
|
||||
"prefer-template": "error",
|
||||
"semi-spacing": "error",
|
||||
"space-before-blocks": "error",
|
||||
"space-before-function-paren": "error",
|
||||
"space-in-parens": ["error", "never"],
|
||||
"space-infix-ops": "error",
|
||||
"space-unary-ops": "error",
|
||||
"template-curly-spacing": "error",
|
||||
"use-isnan": "error",
|
||||
"valid-typeof": "error"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Cypress.io, LLC
|
||||
Copyright (c) 2016 Cypress.io, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
// http://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another#answer-8396318
|
||||
|
||||
const { snakeCase } = require('lodash')
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
require("app-module-path").addPath(__dirname)
|
||||
require("coffee-script/register")
|
||||
|
||||
module.exports = require("./lib").start(process.argv.slice(2))
|
||||
module.exports = require('./lib/cypress')
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
_ = require("lodash")
|
||||
path = require("path")
|
||||
AsciiTable = require("ascii-table")
|
||||
glob = require("glob")
|
||||
chalk = require("chalk")
|
||||
Promise = require("bluebird")
|
||||
runAll = require("@cypress/npm-run-all")
|
||||
through = require("through")
|
||||
|
||||
globAsync = Promise.promisify(glob)
|
||||
|
||||
setTerminalTitle = (title) ->
|
||||
process.stdout.write(
|
||||
String.fromCharCode(27) + "]0;" + title + String.fromCharCode(7)
|
||||
)
|
||||
|
||||
packageNameFromPath = (fullPath) ->
|
||||
fullPath.replace(path.resolve("packages") + "/", "")
|
||||
|
||||
getDirs = () ->
|
||||
packagesDir = path.resolve("packages", "*")
|
||||
globAsync(packagesDir)
|
||||
|
||||
filterDirsByPackage = (dirs, packages) ->
|
||||
return dirs unless packages
|
||||
|
||||
return dirs.filter (dir) ->
|
||||
packageName = packageNameFromPath(dir)
|
||||
return _.includes(packages, packageName)
|
||||
|
||||
filterDirsByCmd = (dirs, cmd) ->
|
||||
switch cmd
|
||||
when "install", "i"
|
||||
return dirs
|
||||
else
|
||||
dirs.filter (dir) ->
|
||||
packageJson = require(path.resolve(dir, "package"))
|
||||
return !!packageJson.scripts[cmd]
|
||||
|
||||
checkDirsLength = (dirs, errMessage) ->
|
||||
return dirs if dirs.length
|
||||
|
||||
err = new Error(errMessage)
|
||||
err.noPackages = true
|
||||
throw err
|
||||
|
||||
mapTasks = (cmd, packages) ->
|
||||
colors = "green yellow blue magenta cyan white gray bgGreen bgYellow bgBlue bgMagenta bgCyan bgWhite".split(" ")
|
||||
|
||||
runCommand = switch cmd
|
||||
when "install", "i", "test", "t" then cmd
|
||||
else "run #{cmd}"
|
||||
|
||||
packages.map (dir, index) ->
|
||||
packageName = packageNameFromPath(dir)
|
||||
return {
|
||||
command: runCommand
|
||||
options: {
|
||||
cwd: dir
|
||||
label: {
|
||||
name: "#{packageName}:#{cmd}"
|
||||
color: colors[index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stderrOutput = ""
|
||||
collectStderr = through (data) ->
|
||||
stderrOutput += data.toString()
|
||||
@queue(data)
|
||||
|
||||
collectStderr.pipe(process.stderr)
|
||||
|
||||
noPackagesError = (err) -> err.noPackages
|
||||
resultsError = (err) -> !!err.results
|
||||
|
||||
module.exports = (cmd, options) ->
|
||||
setTerminalTitle("run:all:#{cmd}")
|
||||
|
||||
packagesFilter = options.package or options.packages
|
||||
|
||||
getDirs()
|
||||
.then (dirs) ->
|
||||
filterDirsByPackage(dirs, packagesFilter)
|
||||
.then (dirs) ->
|
||||
checkDirsLength(dirs, "No packages were found with the filter '#{packagesFilter}'")
|
||||
.then (dirs) ->
|
||||
filterDirsByCmd(dirs, cmd)
|
||||
.then (dirs) ->
|
||||
errMessage = "No packages were found with the task '#{cmd}'"
|
||||
if packagesFilter
|
||||
errMessage += " and the filter '#{packagesFilter}'"
|
||||
checkDirsLength(dirs, errMessage)
|
||||
.then (dirs) ->
|
||||
mapTasks(cmd, dirs)
|
||||
.then (tasks) ->
|
||||
runAll(tasks, {
|
||||
parallel: if options.serial then false else true
|
||||
stdout: process.stdout
|
||||
stderr: collectStderr
|
||||
})
|
||||
|
||||
.then ->
|
||||
console.log(chalk.green("\nAll tasks completed successfully"))
|
||||
|
||||
.catch noPackagesError, (err) ->
|
||||
console.error(chalk.red("\n#{err.message}"))
|
||||
process.exit(1)
|
||||
|
||||
.catch resultsError, (err) ->
|
||||
results = AsciiTable.factory({
|
||||
heading: ["package", "exit code"]
|
||||
rows: err.results.map (result) ->
|
||||
[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)
|
||||
|
||||
process.exit(1)
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
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 globAsync = Promise.promisify(glob)
|
||||
|
||||
const setTerminalTitle = (title) => {
|
||||
process.stdout.write(
|
||||
`${String.fromCharCode(27)}]0${title}${String.fromCharCode(7)}`
|
||||
)
|
||||
}
|
||||
|
||||
const packageNameFromPath = (fullPath) => {
|
||||
return fullPath.replace(`${path.resolve('packages')}/`, '')
|
||||
}
|
||||
|
||||
const getDirs = () => {
|
||||
const packagesDir = path.resolve('packages', '*')
|
||||
return globAsync(packagesDir)
|
||||
}
|
||||
|
||||
const filterDirsByPackage = (dirs, packages) => {
|
||||
if (!packages) return dirs
|
||||
|
||||
return dirs.filter((dir) => {
|
||||
const packageName = packageNameFromPath(dir)
|
||||
return _.includes(packages, packageName)
|
||||
})
|
||||
}
|
||||
|
||||
const filterDirsByCmd = (dirs, cmd) => {
|
||||
switch (cmd) {
|
||||
case 'install': case 'i':
|
||||
return dirs
|
||||
default:
|
||||
return dirs.filter((dir) => {
|
||||
const packageJson = require(path.resolve(dir, 'package'))
|
||||
return !!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 bgYellow bgBlue bgMagenta bgCyan bgWhite'.split(' ')
|
||||
|
||||
let runCommand
|
||||
|
||||
switch (cmd) {
|
||||
case 'install':
|
||||
case 'i':
|
||||
case 'test':
|
||||
case 't':
|
||||
runCommand = cmd
|
||||
break
|
||||
default:
|
||||
runCommand = `run ${cmd}`
|
||||
}
|
||||
|
||||
return packages.map((dir, index) => {
|
||||
const packageName = packageNameFromPath(dir)
|
||||
return {
|
||||
command: runCommand,
|
||||
options: {
|
||||
cwd: dir,
|
||||
label: {
|
||||
name: `${packageName}:${cmd}`,
|
||||
color: colors[index],
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let stderrOutput = ''
|
||||
const collectStderr = through((data) => {
|
||||
stderrOutput += data.toString()
|
||||
return this.queue(data)
|
||||
})
|
||||
|
||||
collectStderr.pipe(process.stderr)
|
||||
|
||||
const noPackagesError = (err) => err.noPackages
|
||||
const resultsError = (err) => !!err.results
|
||||
|
||||
module.exports = (cmd, options) => {
|
||||
setTerminalTitle(`run:all:${cmd}`)
|
||||
|
||||
const packagesFilter = options.package || options.packages
|
||||
|
||||
return getDirs()
|
||||
.then((dirs) => filterDirsByPackage(dirs, packagesFilter))
|
||||
.then((dirs) => checkDirsLength(dirs, `No packages were found with the filter '${packagesFilter}'`))
|
||||
.then((dirs) => 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) => mapTasks(cmd, dirs))
|
||||
.then((tasks) =>
|
||||
runAll(tasks, {
|
||||
parallel: options.serial ? false : true,
|
||||
stdout: process.stdout,
|
||||
stderr: collectStderr,
|
||||
}))
|
||||
.then(() => {
|
||||
console.log(chalk.green('\nAll tasks compconsted successfully'))
|
||||
})
|
||||
.catch(noPackagesError, (err) => {
|
||||
console.error(chalk.red(`\n${err.message}`))
|
||||
return process.exit(1)
|
||||
})
|
||||
.catch(resultsError, (err) => {
|
||||
const results = AsciiTable.factory({
|
||||
heading: ['package', 'exit code'],
|
||||
rows: err.results.map((result) => [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 process.exit(1)
|
||||
})
|
||||
}
|
||||
@@ -1,20 +1,22 @@
|
||||
minimist = require("minimist")
|
||||
runAll = require("./run-all")
|
||||
require('app-module-path').addPath(__dirname)
|
||||
require('coffee-script/register')
|
||||
|
||||
module.exports = {
|
||||
start: (argv = []) ->
|
||||
options = minimist(argv)
|
||||
const minimist = require('minimist')
|
||||
const runAll = require('./run-all')
|
||||
|
||||
switch
|
||||
when cmd = options._[0]
|
||||
runAll(cmd, options)
|
||||
const options = minimist(process.argv.slice(2))
|
||||
|
||||
else
|
||||
require("packages/core-app").start()
|
||||
const cmd = options._[0]
|
||||
|
||||
if (cmd) {
|
||||
runAll(cmd, options)
|
||||
} else {
|
||||
require('packages/core-app').start()
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
/**
|
||||
TODO
|
||||
|
||||
starting app
|
||||
deployment
|
||||
@@ -31,4 +33,4 @@ work out script running UX
|
||||
- bring back panes
|
||||
* need to be able to scroll
|
||||
|
||||
###
|
||||
*/
|
||||
@@ -1,3 +1,5 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
// http://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another#answer-8396318
|
||||
|
||||
const { snakeCase } = require('lodash')
|
||||
|
||||
+2
-2
@@ -4,13 +4,13 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"postinstall": "npm run all install",
|
||||
"start": "node index.js",
|
||||
"start": "node lib/run.js",
|
||||
"watch-dev": "npm run all watch-dev",
|
||||
"test-once": "npm run all test-once -- --serial",
|
||||
"test-unit-once": "npm run all test-unit-once -- --serial",
|
||||
"test-integration-once": "npm run all test-integration-once -- --serial",
|
||||
"test-e2e-once": "npm run all test-e2e-once -- --serial",
|
||||
"all": "node index.js"
|
||||
"all": "node lib/run.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
|
||||
Reference in New Issue
Block a user