Create and run scripts from the package

In the previous section you started to dig into the scripts entry of the package.json file.

This entry represents a JavaScript literal object with one default property called test. This object is a way to extend the commands set of npm.

Go back to the opened Terminal window and type the following command:

npm test

You can use the scripts object to start an Android emulator. To do this add the following property to the scripts object (Go to section Setup Android Emulator for the details on how to setup this Android emulator):

"Nexus5" : "$ANDROID_HOME/tools/emulator -netdelay none -netspeed full -avd Nexus_5_API_25"

The package.json file should look like :

Save the package.json file.

To run your custom android emulator type the following command in the Terminal window:

npm run Nexus5

The scripts content is fully described at https://docs.npmjs.com/misc/scripts.

Create a script to run an iPhone emulator

You can use the scripts object to start an IPhone emulator. To do this add the following property to the scripts object:

"iPhone6" : "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceID 8528838E-4B47-4F0E-B415-E87F8C8A6163"

The CurrentDeviceID comes from the result of the following command:

xcrun simctl list

This command will display the IDs for each knowns devices:

== Devices ==
-- iOS 10.2 --
    iPhone 5 (DAC97D5B-7BBA-4799-AD18-5D09EF888565) (Shutdown)
    iPhone 5s (CCD365A7-50EB-4378-B91B-2F1CA20DD602) (Shutdown)
    iPhone 6 (8528838E-4B47-4F0E-B415-E87F8C8A6163) (Shutdown)
    iPhone 6 Plus (6DC829A9-D2EE-492D-B1FC-D22FBB5AD587) (Shutdown)
    iPhone 6s (1F4BF9E0-D2C8-47CF-B210-EFB97505CD8B) (Shutdown)
    iPhone 6s Plus (4C7C5F53-3516-41B0-832D-E78DA377E970) (Shutdown)
    iPhone 7 (2FDBFF1B-5525-475A-AC37-FE53C49E2317) (Shutdown)
    iPhone 7 Plus (520BC035-F348-40F5-83EF-BC7F3609B7EC) (Shutdown)
    iPhone SE (27293068-6192-463A-9FC9-A35CD20881CC) (Shutdown)
    iPad Retina (A1CA6D93-2A94-416C-A05B-2A3311FEE5DB) (Shutdown)
    iPad Air (D3D4D745-3091-4DCB-8BF9-7E743B5F9420) (Shutdown)
    iPad Air 2 (441070C1-A5CB-461A-B8FF-63958137ABAA) (Shutdown)
    iPad Pro (9.7 inch) (BD0F1E11-50A9-4B08-8543-A4AFEE0F9BBA) (Shutdown)
    iPad Pro (12.9 inch) (AE34B33C-0D72-43F7-9937-CC51B679B5E5) (Shutdown)

The package.json file should look like :

Save the package.json file.

To run your iPhone emulator type the following command in the Terminal window:

npm run iPhone6

How to open a Terminal Window from Visual Studio Code?

In Visual Studio Code open the Command Palette by typing ⌘⇧P. Then start typing the following text:

open New

Then select Open New Terminal from the suggestion list.

Notice that you may also use the following shortcut : ⌘⇧C

In the newly opened Terminal Window, type the following command:

pwd

The working directory that is setup in this Terminal Window is the project's directory.

References

http://stackoverflow.com/questions/31179706/how-can-i-launch-the-ios-simulator-from-terminal

results matching ""

    No results matching ""