diff --git a/bin/test.js b/bin/test.js new file mode 100644 index 00000000..a0152020 --- /dev/null +++ b/bin/test.js @@ -0,0 +1,52 @@ +const shell = require('shelljs'); + +const WATCH_SRC = require('path').resolve('./lib'); +const WATCH_OUT = require('path').resolve('./tests/firebase'); + +/* + "tests-watch-init": "wml add $(node --eval \"console.log(require('path').resolve('./lib'));\") $(node --eval \"console.log(require('path').resolve('./tests/firebase'));\")", + "tests-watch-start": "watchman watch $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml start", + "tests-watch-stop": "watchman watch-del $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml stop" + */ + +if (process.argv.includes('watch')) { + if (!shell.which('wml')) { + shell.echo(''); + shell.echo('---------------------------------------------------'); + shell.echo(' Missing required npm global from library wix/wml. '); + shell.echo('---------------------------------------------------'); + shell.echo(''); + shell.exit(1); + } + + if (!shell.which('watchman')) { + shell.echo(''); + shell.echo('---------------------------------------------------'); + shell.echo(' Missing required executable: watchman '); + shell.echo('---------------------------------------------------'); + shell.echo(''); + shell.exit(1); + } + + if (process.argv.includes('init')) { + console.log(`wml add ${WATCH_SRC} ${WATCH_OUT}`); + if (shell.exec(`wml add ${WATCH_SRC} ${WATCH_OUT}`).code !== 0) { + shell.echo('Error setting up watched location via WML.'); + shell.exit(1); + } + } + + if (process.argv.includes('start')) { + console.log(`watchman watch ${WATCH_SRC} && wml start`); + const watcher = shell.exec(`watchman watch ${WATCH_SRC} && wml start`, { async: true }); + watcher.stdout.on('data', console.log); + watcher.stderr.on('data', console.error); + } + + if (process.argv.includes('stop')) { + console.log(`watchman watch-del ${WATCH_SRC} && wml stop && wml rm all`); + const watcher = shell.exec(`watchman watch-del ${WATCH_SRC} && wml stop && wml rm all`, { async: true }); + watcher.stdout.on('data', console.log); + watcher.stderr.on('data', console.error); + } +} diff --git a/package.json b/package.json index bc9cbe0f..2ec2a431 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "build": "./node_modules/.bin/babel --source-maps=true --out-dir=dist .", "publish_pages": "gh-pages -d public/", "docs-serve-local": "docsify serve docs", + "test-cli": "node ./bin/test.js", "tests-packager": "cd tests && npm run start", "tests-npm-install": "cd tests && npm install", "tests-pod-install": "cd tests && npm run ios:pod:install", - "tests-watch-init": "wml add $(node --eval \"console.log(require('path').resolve('./lib'));\") $(node --eval \"console.log(require('path').resolve('./tests/firebase'));\")", - "tests-watch-start": "watchman watch $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml start", - "tests-watch-stop": "watchman watch-del $(node --eval \"console.log(require('path').resolve('./lib'));\") && wml stop" + "tests-watch-start": "npm run test-cli watch init start", + "tests-watch-stop": "npm run test-cli watch stop" }, "repository": { "type": "git", @@ -74,6 +74,7 @@ "react": "^15.3.0", "react-dom": "^15.3.0", "react-native": "^0.44.0", + "shelljs": "^0.7.8", "wml": "0.0.82" }, "dependencies": {