Composer and NPM

From OpenEMR Project Wiki
Revision as of 07:17, 1 September 2018 by Bradymiller (talk | contribs) (→‎NPM)

Overview

Introduction

Composer provides the following key functions for OpenEMR:
  1. A tool for dependency management of packages for OpenEMR in 'vendor' directory.
  2. An autoloader of libraries including OpenEMR classes.
NPM provide the following key functions for OpenEMR:
  1. A tool for dependency management of packages for OpenEMR in 'public/assets' directory.
  2. A tool for building css theme files for OpenEMR in 'public/themes' directory.
  3. A open door to do lots of cool stuff in the future.

Installation

Composer

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

NPM

Instructions are under construction.

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

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

composer install

When Composer has finished its install you’ll be ready to install OpenEMR after you run the following commands to bring in npm packages and build css scripts and optimize composer autoloading:

npm install
npm run build
composer dump-autoload -o

Dependencies

Composer

Always included

  1. adldap2/adldap2
  2. adodb/adodb-php
  3. doctrine/common
  4. doctrine/couchdb
  5. doctrine/orm
  6. dompdf/dompdf
  7. ezyang/htmlpurifier (Sherwin plans to use to html escape editors that need to allow html code)
  8. knplabs/knp-snappy
  9. mobiledetect/mobiledetectlib (Ray is using this for an ongoing project that should get into codebase into the future)
  10. mpdf/mpdf
  11. phpmailer/phpmailer
  12. phpoffice/phpspreadsheet (Sherwin plans to use this; note Kim was planning to use a prior deprecated package phpoffice/phpexcel for allscripts rx module and will instead need to use phpspreadsheet now)
  13. phpseclib/phpseclib
  14. rospdf/pdf-php
  15. smarty/smarty
  16. stripe/stripe-php (Sherwin requested this for incorporating payment collection via stripe)
  17. symfony/config
  18. symfony/dependency-injection
  19. symfony/event-dispatcher
  20. symfony/http-foundation
  21. symfony/yaml
  22. twig/twig
  23. vlucas/phpdotenv
  24. zendframework/zendframework

Optional

  1. openemr/wkhtmltopdf-openemr - Used by institutional billing (ub04) to create the pdf's. Very large (240MB) so unable to include in main codebase. Install via following command in the openemr directory:
    • composer require openemr/wkhtmltopdf-openemr

Global

This section is for developers, and these are packages that should be installed globally:
  1. phing/phing (this is used by mechanism for cleaning out stuff when bring in new composer/npm packages)

Work in Progress

  1. html2pdf - spipu/html2pdf (also need to include setasign/fpdi-tcpdf) (PENDING REMOVAL - migrating to mPDF)
  2. TCPDF - tecnickcom/tcpdf (PENDING REMOVAL - migrating to mPDF)
  3. FPDF - setasign/fpdf (UNABLE to do this since there is a needed minor modification to work with PDF_Label; there is no way around this since certain variables are set as protected and the prior version of FPDF that would work is not compatible with PHP7)(only plan to use FPDF for PDF_Label anyways, so not a huge deal)(is stored at library/classes/fpdf)
  4. FPDI - setasign/fpdi (COMPLETED; this was brought in by mPDF; will try to remove other copy when get rid of html2pdf/TCPDF stuff)

NPM

Always included

  1. AnythingSlider-1-9-4
  2. angular-1-5-8
  3. angular-sanitize-1-5-8
  4. angular-summernote-0-8-1
  5. backbone-1-3-3
  6. bootstrap-3-3-4
  7. bootstrap-rtl-3-3-4
  8. Chart.js-2-1-3
  9. checklist-model-0-10-0
  10. ckeditor-4-7-0 (Sherwin plans to use to modernize forms)
    • Brought in 'full' version
  11. datatables.net-1-10-13
  12. datatables.net-bs-1-10-13
    • This is the bootstrap styling for datatables-1-10-13.
  13. datatables.net-dt-1-10-13
    • This is the generic styling for datatables-1-10-13.
  14. datatables.net-jqui-1-10-13
    • This is the jquery-ui styling for datatables-1-10-13.
  15. datatables.net-colreorder-1-3-2
    • This is an extension for datatables-1-10-13.
  16. datatables.net-colreorder-dt-1-3-2
    • This is the generic styling for datatables.net-colreorder-dt-1-3-2.
  17. datatables.net-scroller-1-4-2
    • This is an extension for datatables-1-10-13.

datatables.net-scroller-jqui-1-4-2=

  • This is the jquery-ui styling for datatables.net-scroller-1-4-2.

dropzone-4-3-0

dwv-0-21-0

emodal-1-2-65

  • To support modern jquery versions, we needed to make the following changes in this asset:
  • In future, when a new version is out that addresses this issue, will bring in the new version. And if there is not a new version that addresses this issue, then plan to fork it and maintain it.

flot-0-8-3

font-awesome-4-6-3

i18next-9-0-1

i18next-browser-languagedetector-2-0-0

i18next-xhr-backend-1-4-3

jquery-creditcardvalidator-1-1-0

jquery-datetimepicker-2-5-4

Use the files in build directory (and do NOT use build/jquery.datetimepicker.min.js)

jquery.gritter-1-7-4

jquery-min-*

  • Contain the jquery library files. This is brought in via bower by direct html download since the old versions are not available in repo (need to be built) and only 1 file is needed for these numerous different versions of jquery.
  • jquery-min-1-10-2 is used by datatables.net-1-10-13

jquery-panelslider-0-1-1

jquery-ui-1-10-4

jquery-ui-1-11-4

jquery-ui-1-12-1

jquery-validation-1-13-0

jscolor-1-4-5

  • Need to keep this version until update where it is used (not compatible with more recent jscolor version).

jscolor-2-0-4

jszip-3-1-5

knockout-3-4-0

konva-1-6-8

literallycanvas-0-4-13

magic-wand-js

modernizr-3-5-0

After collect via bower, need to do the following to create the dist/modernizr-build.js script:
  • cd public/assets/modernizr-3-5-0
  • npm install
  • grunt build
  • rm -fr node_modules

moment-2-13-0

numeral-1-5-3 (requested by Matrix, but not used yet)

pure-0-5-0

qtip2-2-2-1

qtip2-3-0-3 (requested by MD Support, but not used yet)

react-15-1-0

select2

select2-bootstrap-theme

shortcut.js-2-01-B

  • Not supported by bower, so brought in manually to the manual-added-packages sub-directory.
  • In future, can likely bring this in via bower via http method.

summernote-0-8-2

  • Note this has a plugin system that is not supported by bower and need to manually copy in the plugins into the asset. Here are the plugin(s) that were placed manually:
  • The Nugget plugin was placed at summernote-0-8-2/dist/plugin/nugget/*

underscore-1-8-3

undone.js-0-0-1

validate.js-0-10-0 (requested by Matrix, but not used yet)=

Migrating

  1. Add package/vendor to the composer.json file
  2. run composer install
    1. (if this isn't bringing in requested package, then will need to remove the composer.lock file before running the command)
  3. Remove unused files(if they are present) from the installed package (eg. git, .gitignore, tests, docs) - You must update build.xml to include directory(s). This step will require a composer global install of phing and then use the path to phing below in the call.
    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
      • (btw, if need to clean up public/assets for bower stuff, then run ./vendor/bin/phing assets-clean )
  4. run composer dump-autoload -o

Autoloader

Ongoing Work

Working on using the autoloader to modernize the OpenEMR codebase. Steps:
  1. Place the central libraries that are always called in OpenEMR into the autoloader. (COMPLETED)
  2. Place the OpenEMR classes into the classmap autoloader.(IN PROGRESS)
    • Done with library/classes with following exceptions that plan to work on:
    • Prescription.class.php, /ClinicalTypes, /rulesets, and /smtp.
  3. Convert libraries into classes and also bring these in via the classmap autoloader.
  4. Above steps will allow then to do the following:
    • Remove globals from within classes.
    • Write phpunit tests.
  5. Place new "modernized" OpenEMR classes into the PSR-4 autoloader.(IN PROGRESS)

Update Autoloader

If updating classes within OpenEMR to work with the autoloader, then just need to run the following command:
  • run composer dump-autoload -o

Forum