Skip to content

Commit

Permalink
initial cli-tools module
Browse files Browse the repository at this point in the history
  • Loading branch information
rotemmiz committed Mar 13, 2017
1 parent 9c2b266 commit 6f81e04
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
61 changes: 61 additions & 0 deletions detox-cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node

'use strict';

const fs = require('fs');
const path = require('path');
const exec = require('child_process');
const execSync = require('child_process').execSync;
//const chalk = require('chalk');
//const prompt = require('prompt');
//const semver = require('semver');
/**
* Used arguments:
* -v --version - to print current version of react-native-cli and react-native dependency
* if you are in a RN app folder
* init - to create a new project and npm install it
* --verbose - to print logs while init
* --version <alternative react-native package> - override default (https://registry.npmjs.org/react-native@latest),
* package to install, examples:
* - "0.22.0-rc1" - A new app will be created using a specific version of React Native from npm repo
* - "https://registry.npmjs.org/react-native/-/react-native-0.20.0.tgz" - a .tgz archive from any npm repo
* - "/Users/home/react-native/react-native-0.22.0.tgz" - for package prepared with `npm pack`, useful for e2e tests
*/

const options = require('minimist')(process.argv.slice(2));

const CLI_MODULE_PATH = () => {
return path.resolve(process.cwd(), 'node_modules', 'detox', 'cli.js');
};

const DETOX_PACKAGE_JSON_PATH = () => {
return path.resolve(process.cwd(), 'node_modules', 'detox', 'package.json');
};

if (options._.length === 0) {
printVersionsAndExit(DETOX_PACKAGE_JSON_PATH());
} else {
var cli;
var cliPath = CLI_MODULE_PATH();
if (fs.existsSync(cliPath)) {
cli = require(cliPath);
//exec.execSync(`node ${cliPath}`);

}

var commands = options._;
if (cli) {
//cli.run();
}
process.exit();
}

function printVersionsAndExit(reactNativePackageJsonPath) {
console.log('detox-cli: ' + require('./package.json').version);
try {
console.log('detox: ' + require(reactNativePackageJsonPath).version);
} catch (e) {
console.log('detox: n/a - detox is not installed in this project');
}
}

40 changes: 40 additions & 0 deletions detox-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "detox-cli",
"version": "0.0.1",
"description": "detox CLI tool wrapper",
"main": "index.js",
"scripts": {
"test": "jest"
},
"bin": {
"detox": "./index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wix/detox.git"
},
"keywords": [
"detox",
"cli"
],
"author": "Rotem Meidan <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/wix/detox/issues"
},
"dependencies": {
"minimist": "^1.2.0",
"commander": "^2.9.0"
},
"devDependencies": {
"babel-jest": "*",
"babel-plugin-transform-async-to-generator": "^6.5.0",
"babel-polyfill": "*",
"babel-preset-es2015": "*",
"jest": "*"
},
"homepage": "https://github.com/wix/detox#readme",
"jest": {
"verbose": true
}
}
11 changes: 11 additions & 0 deletions detox/cli-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env node

const log = require('npmlog');
const program = require('commander');

program
.arguments('<process>')
.parse(process.argv);

//console.log('server');
log.verbose('server');
23 changes: 23 additions & 0 deletions detox/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env node

const log = require('npmlog');
const program = require('commander');

program
.arguments('<process>')
.command('server', 'starts the detox server')
.option('-v, --verbose', 'verbose log ?', false)
.option('--loglevel <level>', 'log level', /^(silly|verbose|info|warn|error)$/i, 'info')
.parse(process.argv);

log.level = setLogLevel();

function setLogLevel() {
if (program.verbose) {
return 'verbose';
}

return program.loglevel;
}

log.verbose('cli');

0 comments on commit 6f81e04

Please sign in to comment.