From 61d1a7e70ccf545b45f87307137f5ef5e92f80d6 Mon Sep 17 00:00:00 2001 From: Abdul Rehman Talat Date: Sun, 29 Sep 2019 17:27:51 +0500 Subject: [PATCH] feat(expo): Adds supports of expo cli flags on start command --- packages/expo/README.md | 37 ++++++--- packages/expo/package.json | 2 +- packages/expo/src/commands/expo/start.ts | 101 ++++++++++++++++++++--- 3 files changed, 117 insertions(+), 23 deletions(-) diff --git a/packages/expo/README.md b/packages/expo/README.md index 934af2d8..130c929e 100644 --- a/packages/expo/README.md +++ b/packages/expo/README.md @@ -27,7 +27,7 @@ $ npm install -g @bluebase/cli-expo $ bluebase COMMAND running command... $ bluebase (-v|--version|version) -@bluebase/cli-expo/0.0.29 darwin-x64 node-v12.10.0 +@bluebase/cli-expo/0.0.30 darwin-x64 node-v12.10.0 $ bluebase --help [COMMAND] USAGE $ bluebase COMMAND @@ -62,7 +62,7 @@ EXAMPLE $ bluebase expo:build ``` -_See code: [src/commands/expo/build.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.29/src/commands/expo/build.ts)_ +_See code: [src/commands/expo/build.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.30/src/commands/expo/build.ts)_ ## `bluebase expo:build:android` @@ -82,7 +82,7 @@ EXAMPLE $ bluebase expo:build:android ``` -_See code: [src/commands/expo/build/android.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.29/src/commands/expo/build/android.ts)_ +_See code: [src/commands/expo/build/android.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.30/src/commands/expo/build/android.ts)_ ## `bluebase expo:build:ios` @@ -102,7 +102,7 @@ EXAMPLE $ bluebase expo:build:ios ``` -_See code: [src/commands/expo/build/ios.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.29/src/commands/expo/build/ios.ts)_ +_See code: [src/commands/expo/build/ios.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.30/src/commands/expo/build/ios.ts)_ ## `bluebase expo:init` @@ -122,7 +122,7 @@ EXAMPLE $ bluebase expo:init ``` -_See code: [src/commands/expo/init.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.29/src/commands/expo/init.ts)_ +_See code: [src/commands/expo/init.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.30/src/commands/expo/init.ts)_ ## `bluebase expo:start` @@ -133,14 +133,31 @@ USAGE $ bluebase expo:start OPTIONS - --appJsPath=appJsPath [default: ./bluebase/expo/App] Path to App.js file relative to the root directory - --assetsDir=assetsDir [default: ./assets/expo] Path to assets directory relative to the root directory - --buildDir=buildDir [default: ./build/expo] Path to build directory relative to the root directory - --configDir=configDir [default: ./bluebase/expo] Path to config directory relative to the root directory + -a, --android Opens your app in Expo on a connected Android device + -c, --clear Clear the React Native packager cache + -i, --ios Opens your app in Expo in a currently running iOS simulator on your computer + -s, --send-to=send-to An email address to send a link to + -w, --web Opens your app in a web browser + --appJsPath=appJsPath [default: ./bluebase/expo/App] Path to App.js file relative to the root directory + --assetsDir=assetsDir [default: ./assets/expo] Path to assets directory relative to the root directory + --buildDir=buildDir [default: ./build/expo] Path to build directory relative to the root directory + --configDir=configDir [default: ./bluebase/expo] Path to config directory relative to the root directory + --dev Turns dev flag on + --host=(lan|tunnel|localhost) [default: lan] Maximum number of tasks to allow Metro to spawn. + --https To start webpack with https protocol + --lan Same as --host lan + --localhost Same as --host localhost + --max-workers=max-workers Maximum number of tasks to allow Metro to spawn. + --minify Turns minify flag on + --no-dev Turns dev flag off + --no-https To start webpack with http protocol + --no-minify Turns minify flag off + --offline Allows this command to run while offline + --tunnel Same as --host tunnel EXAMPLE $ bluebase expo:start ``` -_See code: [src/commands/expo/start.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.29/src/commands/expo/start.ts)_ +_See code: [src/commands/expo/start.ts](https://github.com/BlueBaseJS/cli/blob/v0.0.30/src/commands/expo/start.ts)_ diff --git a/packages/expo/package.json b/packages/expo/package.json index a56f2860..79e9cf79 100644 --- a/packages/expo/package.json +++ b/packages/expo/package.json @@ -1,7 +1,7 @@ { "name": "@bluebase/cli-expo", "description": "An Expo plugin for BlueBaseJS CLI", - "version": "0.0.29", + "version": "0.0.30", "author": "BlueEast Team ", "bugs": "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/BlueBaseJS/cli/issues", "main": "./lib", diff --git a/packages/expo/src/commands/expo/start.ts b/packages/expo/src/commands/expo/start.ts index 443dc480..36492148 100755 --- a/packages/expo/src/commands/expo/start.ts +++ b/packages/expo/src/commands/expo/start.ts @@ -1,6 +1,6 @@ +import { Command, flags } from '@oclif/command'; import { ExpoFlagDefs, ExpoFlags } from '../../flags'; -import { Command } from '@oclif/command'; import { Utils } from '@bluebase/cli-core'; import { createBundle } from '../../scripts'; import fromRoot from '../../scripts/fromRoot'; @@ -8,17 +8,94 @@ import path from 'path'; import { spawn } from 'child_process'; export default class ExpoStart extends Command { - static description = 'Starts or restarts a local server for your app and gives you a URL to it.'; + static description = + 'Starts or restarts a local server for your app and gives you a URL to it.'; - static examples = [ - `$ bluebase expo:start`, - ]; + static examples = [`$ bluebase expo:start`]; - static flags = ExpoFlagDefs; + static flags = { + ...ExpoFlagDefs, + + 'send-to': flags.string({ + char: 's', + description: 'An email address to send a link to', + }), + + clear: flags.boolean({ + char: 'c', + description: 'Clear the React Native packager cache', + }), + + 'max-workers': flags.integer({ + description: 'Maximum number of tasks to allow Metro to spawn.', + }), + + android: flags.boolean({ + char: 'a', + description: 'Opens your app in Expo on a connected Android device', + }), + + ios: flags.boolean({ + char: 'i', + description: + 'Opens your app in Expo in a currently running iOS simulator on your computer', + }), + + web: flags.boolean({ + char: 'w', + description: 'Opens your app in a web browser', + }), + + host: flags.enum({ + default: 'lan', + description: 'Maximum number of tasks to allow Metro to spawn.', + options: ['lan', 'tunnel', 'localhost'], + }), + + tunnel: flags.boolean({ + description: 'Same as --host tunnel', + }), + + lan: flags.boolean({ + description: 'Same as --host lan', + }), + + localhost: flags.boolean({ + description: 'Same as --host localhost', + }), + + dev: flags.boolean({ + description: 'Turns dev flag on', + }), + + 'no-dev': flags.boolean({ + description: 'Turns dev flag off', + }), + + minify: flags.boolean({ + description: 'Turns minify flag on', + }), + + 'no-minify': flags.boolean({ + description: 'Turns minify flag off', + }), + + https: flags.boolean({ + description: 'To start webpack with https protocol', + }), + + 'no-https': flags.boolean({ + description: 'To start webpack with http protocol', + }), + + offline: flags.boolean({ + description: 'Allows this command to run while offline', + }), + }; async run() { const parsed = this.parse(ExpoStart); - const flags = parsed.flags as ExpoFlags; + const inputFlags = parsed.flags as ExpoFlags; Utils.logger.log({ label: '@bluebase/cli/expo', @@ -27,10 +104,10 @@ export default class ExpoStart extends Command { }); // Absolute path of build dir - const buildDir = Utils.fromProjectRoot(flags.buildDir); - const configDir = Utils.fromProjectRoot(flags.configDir); - const assetsDir = Utils.fromProjectRoot(flags.assetsDir); - const appJsPath = Utils.fromProjectRoot(flags.appJsPath); + const buildDir = Utils.fromProjectRoot(inputFlags.buildDir); + const configDir = Utils.fromProjectRoot(inputFlags.configDir); + const assetsDir = Utils.fromProjectRoot(inputFlags.assetsDir); + const appJsPath = Utils.fromProjectRoot(inputFlags.appJsPath); ///////////////////////////// ///// Transpile & Build ///// @@ -58,7 +135,7 @@ export default class ExpoStart extends Command { const appJsonPath = path.join(buildDir, 'app.json'); const child = spawn( fromRoot('./node_modules/.bin/expo'), - ['start', '--config', Utils.fromProjectRoot(appJsonPath)], + ['start', '--config', Utils.fromProjectRoot(appJsonPath), ...this.argv], { shell: true, env: process.env, stdio: 'inherit' } ) .on('close', (_code: number) => process.exit(0))