diff --git a/cli/NPM_README.md b/cli/NPM_README.md new file mode 100644 index 0000000000..6ccf9084c5 --- /dev/null +++ b/cli/NPM_README.md @@ -0,0 +1,48 @@ +# cypress + +> Testing the way it should be + +## Install + +Requires Node version >= 0.12 + +```sh +npm install --save-dev cypress +``` + +## Open Cypress desktop GUI application + +To open Cypress app, there are two alternatives from the +command line + +```sh +./node_modules/.bin/cypress open +$(npm bin)/cypress open +``` + +or you can add new a script to your `package.json` + +```json +{ + "scripts": { + "open": "cypress open" + } +} +``` + +and then call `npm run open` + +## Run tests + +To run e2e tests in headless mode execute `$(npm bin)/cypress run` + +## Load Cypress as an NPM module + +```js +const cy = require('cypress') +// opens desktop GUI application and returns a promise +cy.open(options) +// runs e2e tests in headless browser +// and returns a promise with test results +cy.run(options).then(results, console.error) +``` diff --git a/cli/package.json b/cli/package.json index 6baac04677..0e4c4313e8 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,27 +1,23 @@ { "name": "cypress", - "version": "0.19.2", + "version": "0.0.0", "description": "dev build project for Cypress NPM package", - "main": "lib/index.js", + "main": "index.js", "bin": { "cypress": "bin/cypress" }, "private": true, - "engines": { - "node": ">=6.5.0" - }, "scripts": { + "pretest": "npm run lint && npm run test-dependencies", "test": "npm run test-unit", "test-unit": "mocha", "test-watch": "mocha --watch", + "test-dependencies": "deps-ok && dependency-check . --no-dev", "lint": "$(bin-up eslint) --fix *.js bin/* lib/*.js lib/**/*.js test/*.js test/**/*.js", - "pretest": "npm run lint && npm run test-dependencies", - "build": "babel lib -d build/lib && babel index.js -o build/index.js", - "prebuild": "npm run copy-bin", - "precopy-bin": "mkdir -p build/bin || true", - "copy-bin": "cp bin/cypress build/bin/cypress", - "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";", - "test-dependencies": "deps-ok && dependency-check . --no-dev" + "prebuild": "./scripts/build.sh", + "build": "node ./scripts/build.js", + "release": "cd build && releaser", + "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";" }, "dependencies": { "bluebird": "^3.4.5", @@ -46,8 +42,9 @@ "yauzl": "^2.8.0" }, "devDependencies": { - "babel-preset-es2015": "^6.24.1", + "@cypress/releaser": "^0.1.12", "babel-cli": "^6.24.1", + "babel-preset-es2015": "^6.24.1", "bin-up": "^1.0.1", "chai": "^3.5.0", "clear-module": "^2.1.0", @@ -61,7 +58,7 @@ }, "files": [ "bin", - "es5", + "lib", "index.js" ], "repository": { diff --git a/cli/scripts/build.js b/cli/scripts/build.js new file mode 100644 index 0000000000..f208d65b07 --- /dev/null +++ b/cli/scripts/build.js @@ -0,0 +1,37 @@ +const _ = require('lodash') +const path = require('path') +const Promise = require('bluebird') + +const fs = Promise.promisifyAll(require('fs-extra')) + +// grab the current version from the root monorepo package.json +const { version, description } = require('../../package.json') + +const packageJsonSrc = path.join('package.json') +const packageJsonDest = path.join('build', 'package.json') + +function preparePackageForNpmRelease (json) { + // modify the existing package.json + // to prepare it for releasing to npm + delete json.devDependencies + delete json['private'] + + _.extend(json, { + version, + description, + scripts: { + postinstall: 'node index.js --exec install', + size: 't=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";', + }, + }) + + return json +} + +fs.readJsonAsync(packageJsonSrc) +.then(preparePackageForNpmRelease) +.then((json) => { + return fs.outputJsonAsync(packageJsonDest, json, { + spaces: 2, + }) +}) diff --git a/cli/scripts/build.sh b/cli/scripts/build.sh new file mode 100755 index 0000000000..f7b0ca5449 --- /dev/null +++ b/cli/scripts/build.sh @@ -0,0 +1,9 @@ +## copy over binary +mkdir -p build/bin || true +cp bin/cypress build/bin/cypress + +## copy readme +cp NPM_README.md build/README.md + +## generate babel'd js index + lib +babel lib -d build/lib && babel index.js -o build/index.js diff --git a/package.json b/package.json index d760e6b2b7..9afb1a1a3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,11 @@ { "name": "cypress-monorepo", + "version": "0.19.4", + "description": "Cypress.io end to end testing tool", "private": true, + "engines": { + "node": ">=6.5.0" + }, "scripts": { "start": "node ./scripts/start.js", "watch": "npm run all watch",