Difference between revisions of "Composer and NPM"

From OpenEMR Project Wiki
Line 126: Line 126:
:# Add package/vendor to the composer.json file
:# Add package/vendor to the composer.json file
:# run composer install
:# run composer install
:# Remove .gitignore and .gitattributes files(if they are present) from the installed package.
:# Remove unused files(if they are present) from the installed package (eg. git, .gitignore, tests, docs) - You must update build.xml to include directorys.
:## Windows - From the command line run <code>call vendor/bin/phing vendor-clean</code>
:## Linux - From the command line run <code>./vendor/bin/phing vendor-clean</code>


=Forum=
=Forum=
:*[https://sourceforge.net/p/openemr/discussion/202506/thread/0d878640/ Composer]
:*[https://sourceforge.net/p/openemr/discussion/202506/thread/0d878640/ Composer]

Revision as of 01:34, 22 July 2016

Overview

Introduction

Composer is a command line tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

End Goal

  1. Centralize and organize all PHP libraries/dependancies into a single directory.
    • Use Composer to collect and organize the PHP libraries/dependancies.
    • Migrate all the PHP libraries/dependancies.
  2. Setup composer to use PSR-4 autoloading.

More Details

  • Composer creates a vendor directory in the root folder. This is where all the external dependencies are kept.
  • Commit the vendor directory to the codebase initially until we get composer to work with demo and build scripts.
  • The workaround is to add a .gitig nore line that removes all .git directories within your vendor directory. So add this line to the .gitignore file at the same level as composer.json and vendor/: vendor/.git
  • Get the demo and build scripts to bring in composer dependencies and package them up and test.
  • Make sure documentation on how to use composer is upto date and developers are aware of upcoming changes
  • Once this is done we can remove vendor directory from the codebase

Installation

Windows

This is the easiest way to get Composer set up on your machine.

The installer will download composer for you and set up your PATH environment variable so you can simply call composer from any directory. Download and run Composer-Setup.exe - it will install the latest composer version whenever it is executed. See: https://getcomposer.org/doc/00-intro.md/

To test your installation, open up your favourite Command Line Interface (CLI) and run:

composer

And you should get output similar to this:

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.1.2 2016-05-31 19:48:11

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Linux & MacOS

The first step is to download Composer, which will effectively create a Phar (PHP Archive) file called composer.phar. From your terminal, run the following command:

curl -sS https://getcomposer.org/installer | php

The resulting file will be called composer.phar, a PHP Archive that can be executed directly via PHP. However, in our case, we want Composer to be accessible globally by simply typing composer. To do this, move it to /usr/bin/ and create an alias:

sudo mv composer.phar /usr/local/bin/
vim ~/.bash_profile

Add this to your .bash_profile. It may be empty or non-existent, so go ahead and create it:

alias composer="php /usr/local/bin/composer.phar"

Now, relaunch your terminal and you'll be able to access Composer simply by calling composer
See: https://www.abeautifulsite.net/installing-composer-on-os-x

To test your installation, open up your favourite Command Line Interface (CLI) and run:

composer

And you should get output similar to this:

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.1.2 2016-05-31 19:48:11

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Usage

  1. clone the OpenEMR development version from github: https://github.com/openemr/openemr.git
git clone https://github.com/openemr/openemr.git
  1. Once it’s done run the following command to move into the OpemEMR root directory and checkout the master branch.
cd openemr
git checkout master

In order to work with Composer a project must have a composer.json file within its root directory. If you take a look at the file you’ll see a list of OpenEMR package dependencies.

  1. require: a list of packages (and versions) required by OpenEMR. OpenEMR will not install if any of those package dependencies are not met.
  2. require-dev: a list of packages required by OpenEMR for development.

To run Composer for the first time and install your packages simply run:

composer install

When Composer has finished its install you’ll be ready to install OpenEMR.

Be aware that development requirements are always installed by default, Composer doesn’t magically know when it is being run on your production server. If you want to exclude development requirements you will need to run:

composer install --no-dev

Dependencies to migrate

  1. ADODB - adodb/adodb-php
  2. html2pdf - spipu/html2pdf (also need to include setasign/fpdi-tcpdf)
  3. TCPDF - tecnickcom/tcpdf
  4. FPDF - setasign/fpdf
  5. FPDI - setasign/fpdi
  6. Smarty - smarty/smarty
  7. adLDAP - adldap/adldap
  8. JSON (Old JSON Wrapper, maybe replace with hampel/json?)
  9. phpseclib - phpseclib/phpseclib
  10. PhpMyAdmin - phpmyadmin/phpmyadmin (Should we even include this? The only people using this are developers? )
  11. phpgacl - (should move this to its own repo)

Migrating

  1. Add package/vendor to the composer.json file
  2. run composer install
  3. Remove unused files(if they are present) from the installed package (eg. git, .gitignore, tests, docs) - You must update build.xml to include directorys.
    1. Windows - From the command line run call vendor/bin/phing vendor-clean
    2. Linux - From the command line run ./vendor/bin/phing vendor-clean

Forum