diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000000..8351c19397 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +14 diff --git a/docs/tutorials/creating-your-first-adf-application.md b/docs/tutorials/creating-your-first-adf-application.md index 2b388a7f70..16dbb75f7b 100644 --- a/docs/tutorials/creating-your-first-adf-application.md +++ b/docs/tutorials/creating-your-first-adf-application.md @@ -11,7 +11,7 @@ The first thing to do is to check the prerequisites and the requirements to run More in particular check that you have: - Alfresco Content Services (alias ACS) Enterprise edition up and running (identify the URL that will be required as configuration). -- The latest lts version of [NodeJs](https://nodejs.org/en/ "https://nodejs.org/en/"). +- The latest lts version of [NodeJs](https://nodejs.org/en/ "https://nodejs.org/en/"). For more convenient Node.js version management please check out [Node Version Management](./docs/tutorials/nvm.md). - A recent (and supported) version of a browser (see [here](https://github.com/Alfresco/alfresco-ng2-components#browser-support "https://github.com/Alfresco/alfresco-ng2-components#browser-support") for further details). All the Angular development is done using the [Typescript](https://www.typescriptlang.org/ "https://www.typescriptlang.org/") language. With this in mind, it is highly suggested to adopt a good text editor to help you in this task. We recommend [Visual Studio Code](http://code.visualstudio.com/ "http://code.visualstudio.com/") a free, lightweight, and _very_ powerful tool from Microsoft that works well with Angular development and has a [big ecosystem of plugins](https://marketplace.visualstudio.com/VSCode "https://marketplace.visualstudio.com/VSCode") to make the developer experience even better. @@ -101,4 +101,4 @@ In case of problems raise a question into the [Alfresco Forum](https://hub.alfre # Other types of ADF based applications -In this tutorial you learned how to create an ADF based application from scratch, running against an existing instance of Alfresco Content Services. Using the [ADF Yeoman Generator](https://github.com/Alfresco/generator-alfresco-adf-app "https://github.com/Alfresco/generator-alfresco-adf-app"), more in particular during the creation of the ADF based application, you can decide to use a different application blueprint (content only, content and process and process only). The tasks described above don’t really change except for the fact that you have to update the URLs of the backend services accordingly. \ No newline at end of file +In this tutorial you learned how to create an ADF based application from scratch, running against an existing instance of Alfresco Content Services. Using the [ADF Yeoman Generator](https://github.com/Alfresco/generator-alfresco-adf-app "https://github.com/Alfresco/generator-alfresco-adf-app"), more in particular during the creation of the ADF based application, you can decide to use a different application blueprint (content only, content and process and process only). The tasks described above don’t really change except for the fact that you have to update the URLs of the backend services accordingly. diff --git a/docs/tutorials/nvm.md b/docs/tutorials/nvm.md new file mode 100644 index 0000000000..00678d06a5 --- /dev/null +++ b/docs/tutorials/nvm.md @@ -0,0 +1,116 @@ +--- +Title: Node Version Manager +--- + +# Node Version Manager + +Nvm is a version manager for Node.js. You can use it to install and switch to correct Node.js version. + +## Installation + +To install nvm you can run following: + +```sh +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash +``` +for other installation options and troubleshooting instructions please follow [nvm installation docs](https://github.com/nvm-sh/nvm#install--update-script). + +## Usage + +To use nvm run following command: + +```sh +nvm use +``` + +which automatically use Node.js version specified in .nvmrc file. If given Node.js version is not installed you need to run: + +```sh +nvm install +``` + +with version provided in .nvmrc file. Additionally if you want to install a new version of Node.js and migrate npm packages from a previous version run: + +```sh +nvm install node --reinstall-packages-from=node +``` + +where 'node' is an alias for the latest version. For more details please refer to: [nvm usage](https://github.com/nvm-sh/nvm#usage). + +## Automatically call nvm use + +To automatically call nvm use put the following at the end of `$HOME/.bashrc`: + +```sh +cdnvm() { + command cd "$@" || return $? + nvm_path=$(nvm_find_up .nvmrc | tr -d '\n') + + # If there are no .nvmrc file, use the default nvm version + if [[ ! $nvm_path = *[^[:space:]]* ]]; then + + declare default_version; + default_version=$(nvm version default); + + # If there is no default version, set it to `node` + # This will use the latest version on your machine + if [[ $default_version == "N/A" ]]; then + nvm alias default node; + default_version=$(nvm version default); + fi + + # If the current version is not the default version, set it to use the default version + if [[ $(nvm current) != "$default_version" ]]; then + nvm use default; + fi + + elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then + declare nvm_version + nvm_version=$(<"$nvm_path"/.nvmrc) + + declare locally_resolved_nvm_version + # `nvm ls` will check all locally-available versions + # If there are multiple matching versions, take the latest one + # Remove the `->` and `*` characters and spaces + # `locally_resolved_nvm_version` will be `N/A` if no local versions are found + locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]') + + # If it is not already installed, install it + # `nvm install` will implicitly use the newly-installed version + if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then + nvm install "$nvm_version"; + elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then + nvm use "$nvm_version"; + fi + fi +} +alias cd='cdnvm' +cd "$PWD" +``` + +or if you're using zsh put this into your `$HOME/.zshrc`: + +```sh +# place this after nvm initialization! +autoload -U add-zsh-hook +load-nvmrc() { + local nvmrc_path="$(nvm_find_nvmrc)" + + if [ -n "$nvmrc_path" ]; then + local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") + + if [ "$nvmrc_node_version" = "N/A" ]; then + nvm install + elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then + nvm use + fi + elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then + echo "Reverting to nvm default version" + nvm use default + fi +} +add-zsh-hook chpwd load-nvmrc +load-nvmrc +``` + +For more details visit [nvm shell integration](https://github.com/nvm-sh/nvm#deeper-shell-integration).