Nativescript: Graphical installer for Windows

Created on 16 Aug 2016  Â·  3Comments  Â·  Source: NativeScript/NativeScript

Create a GUI installer for the CLI dependencies.

Steps (credits to @dtopuzov):

  1. Initial steps

Welcome screen, explain what installer will do:
Setup {N} and all {N} dependencies.
Installer will reuse current dependencies if available.

Installer should prompt for dependencies root folder.
It should be he folder where not existing dependencies will be installed by default.
Default location of this folder should be short because later we may hit 255 symbols limitations in Windows.
For example: c:NativeScriptTools or c:DevTools or c:Tools or c:NativeScriptTools
We can use structure like this:
c:NativeScript -> root
c:NativeScriptdependencies -> dependencies
c:NativeScriptdemos -> here installer can close some repos like hello-world
c:NativeScriptdocs -> stand alone version of docs or other resources
c:NativeScriptcomponents -> RichUI components (pro version). Valid only for RichUI installer.
c:NativeScripttns.bat
-> We can place a shortcut to tns (just to have something in the root folder).
-> We may also place "The {N} shell" there (for sandboxed installations).

Next version options:
Checkbox "Install in sandboxed environment".

  • There is an idea for a separate shell.
  • In this case all dependencies will be force installed in specified dependencies folder.
  • Installer will not try to detect existing version and prompt if you want to reuse them.

    1. JDK

      Check if JAVA_HOME exist

      Yes -> Check if version is 1.8+

      Yes -> Use it

      No -> Install JDK 1.8+

      No -> Check if Java exists

      Yes -> Just set JAVA_HOME

      No -> Install JDK 1.8+

    2. NodeJS

      Minimal NodeJS: 4

      Recommended NodeJS: 6

      Check node and npm versions:

      < 4.0 -> Error "{N} is not compatible with this NodeJS vesrions." Install NodeJS 6.

      4._, 5_, 6* -> Do nothing

      7+ -> Warning "{N} is not verified agains this version of NodeJS. Proceed on your own risk!" and suggest installing Node6 (but Node6 should not be mandatory if you already have 7)

    3. Android

      Check if ANDROID_HOME exist

      Yes ->

      prompt "Android SDK already exists. {N} will reuse it."

      ask "Do you want {N} to add Android SDK features it needs."

      Yes -> Go to step 4

      No -> Warning "Proceed on your onw risk!"

      No -> Download and extract SDK zip.

    4. Setup Android

      Just run some commands (see details in draft).

    5. Create Emulators

      Ask for HAXM (if possible detect if CPU is compatible with HAXM in future releases):

      Yes -> Install HAXM and x86 Android 6.0 Emulator

      No -> Install arm Android 6.0 Emulator

    6. Install tns

      Check if current version is available:

      Yes -> Check if latest on npm is newer:

      Yes -> Suggest installing latest

      No -> Do nothing

      No -> Install latest

    7. Final steps

      Open nativescript docs.

Draft, notes, more info:

  1. Java
    if JAVA_HOME exists:
    # c:>"%JAVA_HOME%binjava" -version
    # java version "1.8.0_91"
    # Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
    # Java HotSpot(TM) 64-Bit Server VM (build 25.91-b15, mixed mode)
    if (""%JAVA_HOME%binjava -version" is 1.8+):
    pass
    # Installer can prompt -> Java detected, will reuse it.
    else:
    Install Java 1.8+
    # http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#jdk-silent-installation
    # http://stackoverflow.com/questions/15292464/how-to-silently-install-java-jdk-into-a-specific-directory-on-windows
    else:
    # c:>where javac
    # C:ToolsJavajdk1.8.0_20binjavac.exe
    # c:>where javac
    # C:ToolsJavajdk1.8.0_20binjavac.exe
    # C:ToolsJavajdk1.8.0_20binjavac.exe -version
    # javac 1.8.0_20
    if (java exists, and it is 1.8+, but JAVA_HOME is not set):
    set JAVA_HOME (no need to install it)
    # Installer can prompt "Java 1.8+ detected on this location, do you want to set it in JAVA_HOME"
    # If cancel setting java home then we can fallback to new JDK installation.
    else:
    Install Java 1.8+
    # http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#jdk-silent-installation
    # http://stackoverflow.com/questions/15292464/how-to-silently-install-java-jdk-into-a-specific-directory-on-windows

Notes:
Download JDK might be a bit challenging, see https://gist.github.com/P7h/9741922

  1. NodeJS
    if (npm and node are available):
    # c:Gitnativescript-cli-tests>npm -v
    #2.15.8
    # c:Gitnativescript-cli-tests>node -v
    # v4.4.7
    # both should return some versions
    # Possible checks:
    # If version is < 4.0:
    # Show warning that we recommend latest LTS release of NodeJS.
    # May be even prompt "Do you want latest LTS" and install it.
    # If version is 4._:
    # pass (this is the best case)
    # If version is 5._:
    # Prompt "Your version is not LTS, do you want to install latest LTS release?"
    # If version is 6._:
    # pass
    # Now LTS is 4, but after 4 next LTS will be 6. We work on 6 (but to be honest we do not use it on CI).
    # So if node is 6._ => Do nothing and hope it work (most likely it will).
    pass
    else:
    Install latest LTS from here: https://nodejs.org/en/

Notes:
Not sure how we can get link that always get latest msi, but is is not a big problem to hardcode some LTS version.

  1. Install Android SDK
    if (%ANDROID_HOME%Toolsandroid exists):
    prompt "Android SDK already exists. {N} will reuse it."
    ask "Do you want {N} to add Android SDK features it needs."
    if yes:
    go to step 4
    else:
    do nothing (hope this user knows what to do)
    else:
    Download and extract SDK zip.
  2. Configure Android SDK

Run:
%ANDROID_HOME%Toolsandroid update sdk --filter "platform-tools" --all --no-ui
%ANDROID_HOME%Toolsandroid update sdk --filter "tools" --all --no-ui
%ANDROID_HOME%Toolsandroid update sdk --filter "android-23" --all --no-ui
%ANDROID_HOME%Toolsandroid update sdk --filter "build-tools-24.0.1" --all --no-ui
%ANDROID_HOME%Toolsandroid update sdk --filter "extra-android-m2repository" --all --no-ui
%ANDROID_HOME%Toolsandroid update sdk --filter "extra-google-m2repository" --all --no-ui

Reference:
https://github.com/NativeScript/nativescript-cli/blob/master/setup/native-script.ps1

  1. Create emulators:
    I think there is no need to prompt here, just run it.
    Even if user has some emulators, it will add one more.

if ((Read-Host "Do you want to install HAXM (Hardware accelerated Android emulator)?") -eq 'y') {
echo y | $ANDROID_HOME/tools/android update sdk --filter extra-intel-Hardware_Accelerated_Execution_Manager --all --no-ui

 $haxmSilentInstaller = [io.path]::combine($env:ANDROID_HOME, "extras", "intel", "Hardware_Accelerated_Execution_Manager", "silent_install.bat")
 cmd /c "$haxmSilentInstaller"

 echo y | $ANDROID_HOME/tools/android update sdk --filter sys-img-x86-android-23 --all --no-ui
 echo no | $ANDROID_HOME/tools/android create avd -n NativeScript-Emulator-Api23 -t android-23 --abi default/x86 -c 32M -f

} else {
echo y | $ANDROID_HOME/tools/android update sdk --filter sys-img-armeabi-v7a-android-23 --all --no-ui
echo no | $ANDROID_HOME/tools/android create avd -n NativeScript-Emulator-Api23 -t android-23 --abi default/armeabi-v7a -c 32M -f
}

Ides for next versions:

  • Detect if CPU support HAXM.
    If CPU suport HAXM and HAXM is not install it -> install it.
    Crete x86 emulators
  • If CPU does not support HAXM -> prompt with some message like
    "Your CPU does not support hardware accelerated emulators. Please be patient..."
    Create arm emulators.

    1. Nativescript

      if nativescript exists:

      # c:>tns --version (check local version)

      #2.2.0

      # c:>npm view nativescript version (check latest on npm)

      #2.2.1

      if (latest version on npm > available version):

      prompt "There is newer version of nativescript. Do you want to update?"

      if yes:

      "npm install -g nativescript -f" (force isntall latest)

      else:

      "npm install -g nativescript"

    2. Final steps (Optional): Open {N} documentation - http://docs.nativescript.org/angular/start/introduction.html.

Notes:
If getting JDK and SDK from internet is hard then we may install them with chocolaty.
This approach is used in setup scripts and it works:
https://github.com/NativeScript/nativescript-cli/blob/master/setup/native-script.ps1

feature

Most helpful comment

The algorithm looks good to me generally. Some suggestions:

  • after checking that JAVA_HOME and ANDROID_HOME exist, check that they point to_valid_ installations. Sometimes they get stalled, happened more than once.
  • Writing to c: require UAC elevation. Depending on the chosen installation method, this may be tricky
  • Writing to places like %LocalAppData% is safe and should not hit the dreaded MAX_PATH limit, you may consider it instead of C:
  • Android sdk executable sometimes prints an EULA and asks interactively the user to accept it. Make sure you handle this
  • Emulators are very costly in disk space – up to 1 GB per emulator. If the user has a small SSD they definitely won’t be happy if we take this space without prompting first. I strongly suggest to prompt.

All 3 comments

The algorithm looks good to me generally. Some suggestions:

  • after checking that JAVA_HOME and ANDROID_HOME exist, check that they point to_valid_ installations. Sometimes they get stalled, happened more than once.
  • Writing to c: require UAC elevation. Depending on the chosen installation method, this may be tricky
  • Writing to places like %LocalAppData% is safe and should not hit the dreaded MAX_PATH limit, you may consider it instead of C:
  • Android sdk executable sometimes prints an EULA and asks interactively the user to accept it. Make sure you handle this
  • Emulators are very costly in disk space – up to 1 GB per emulator. If the user has a small SSD they definitely won’t be happy if we take this space without prompting first. I strongly suggest to prompt.

Node 6 LTS is now must!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings