|
1 |
| -# samaritans-patterns |
| 1 | +# samaritans-patterns |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This repository provides the pattern library code and assets for Samaritans, as used on samaritans.org. |
| 6 | + |
| 7 | +- _project_styleguide_: this contains all template code, structured to follow Atomic Design principles. Since the samaritans.org site uses [Wagtail](https://wagtail.io/), these templates use the [Django template language](https://docs.djangoproject.com/en/2.2/ref/templates/). |
| 8 | + - Please note that these templates are provided for reference and cannot be used as a drop-in implementation for other Wagtail/Django sites, due to the use of custom template tags that can't included here. |
| 9 | +- _static_src_: this contains the code for building the pattern library's CSS and Javascript, as well as static assets such as images and fonts. |
| 10 | + |
| 11 | + |
| 12 | +## Front end tooling |
| 13 | + |
| 14 | +This set of tooling can form the basis for any new projects using the Samaritans styles & patterns. |
| 15 | + |
| 16 | +### What's required |
| 17 | + |
| 18 | +The tooling makes heavy use of Node.js/npm. To install node on the host machine we recommend using [`nvm`](https://github.com/creationix/nvm). Once you have `nvm` installed simply run `nvm install` to install and activate the version of node required for the project. Refer to the [`nvm` documentation](https://github.com/creationix/nvm#usage) for more details about available commands. |
| 19 | + |
| 20 | + |
| 21 | +### Getting started |
| 22 | + |
| 23 | +* From inside the `static_src` directory, run `npm install`. |
| 24 | +* This will create: |
| 25 | + - a set of files inside `node_modules` which should be excluded from version control |
| 26 | + - a `package-lock.json` file, which will record the exact version of node packages used. |
| 27 | +* It's advisable to commit the package-lock.json file to your version control, to ensure consistency between the packages used when different developers are working on the same project |
| 28 | +* It may be advisable to upgrade the packages to their latest versions (see Using npm below) |
| 29 | + |
| 30 | + |
| 31 | +### What's included |
| 32 | + |
| 33 | +* [SASS](http://sass-lang.com/) CSS with [auto-prefixing](https://github.com/postcss/autoprefixer). |
| 34 | +* [Webpack](https://webpack.js.org/) and [Babel](https://babeljs.io) for ES2015 support with module loading. |
| 35 | +* Consideration for images, currently copying the directory only - to avoid slowdowns and non-essential dependancies. We encourage using SVG for UI vectors and pre-optimised UI photograph assets. |
| 36 | +* [Build commands](#build-scripts) for generating testable or deployable assets only |
| 37 | +* Sass linting with `sass-lint` |
| 38 | +* JS linting with `eslint` |
| 39 | + |
| 40 | +### Developing with it |
| 41 | + |
| 42 | +* To start the development environment, run `npm start` - to stop this process press `ctrl + c`. |
| 43 | +* Source files for developing your project are in `static_src` and the distribution folder for the compiled assets is `static_compiled`. Don't make direct changes to the `static_compiled` directory as they will be overwritten. |
| 44 | + |
| 45 | +Note that the build, debug and start commands will all rebuild node-sass before running the watch commands. This is because of differences between the way node-sass is installed when running vagrant up and when running `npm install` on the host machine. |
| 46 | + |
| 47 | +#### Using npm |
| 48 | + |
| 49 | +* Install all packages from `package.json`: `npm install` |
| 50 | +* Add new packages that are only required for development, e.g. tooling: `npm install --save-dev package_name` (this will add it to `package.json` and `package-lock.json` too) |
| 51 | +* Add new packages required in production, e.g. react: `npm install --save-prod package_name` |
| 52 | +* To upgrade packages run `npm update package_name` or `npm update` to update them all. |
| 53 | + |
| 54 | +### Deploying it |
| 55 | + |
| 56 | +#### Build scripts |
| 57 | + |
| 58 | +To only build assets for either development or production you can use |
| 59 | + |
| 60 | + * `npm run build` To build development assets |
| 61 | + * `npm run build:prod` To build assets with minification and vendor prefixes |
| 62 | + |
| 63 | +#### Debug script |
| 64 | + |
| 65 | +To test production, minified and vendor prefixed assets you can use |
| 66 | + |
| 67 | + * `npm run debug` To develop with a simple http server, no browsersync and production assets |
| 68 | + |
| 69 | +### Further details of the packages included |
| 70 | +- **autoprefixer** - adds vendor prefixes as necessary for the browsers defined in `browserslist` in the npm config https://www.npmjs.com/package/autoprefixer |
| 71 | +- **babel-core** - transpiler for es6 / react https://www.npmjs.com/package/babel-core |
| 72 | +- **babel-eslint** - add-on for extra linting of experimental features (may not be necessary for all projects) https://www.npmjs.com/package/babel-eslint |
| 73 | +- **babel-loader** - use babel with webpack - https://www.npmjs.com/package/babel-loader |
| 74 | +- **babel-preset-env** - babel preset for the latest version of es6, es2015 |
| 75 | + etc. https://www.npmjs.com/package/babel-preset-env https://babeljs.io/env/ |
| 76 | +https://babeljs.io/docs/plugins/ |
| 77 | +- **eslint** - lint your javascript https://www.npmjs.com/package/eslint |
| 78 | +- **node-sass** - compiles Sass to CSS https://www.npmjs.com/package/node-sass |
| 79 | +- **npm-run-all** - run more than one npm script concurrently - used by some of our npm scripts https://www.npmjs.com/package/npm-run-all |
| 80 | +- **onchange** - watches for changes in a set of files - used by our watch scripts https://www.npmjs.com/package/onchange |
| 81 | +- **postcss-cli** - required by `autoprefixer` - https://www.npmjs.com/package/postcss-cli |
| 82 | +- **postcss-custom-properties** - polyfill for CSS custom properties - https://www.npmjs.com/package/postcss-custom-properties |
| 83 | +- **sass-lint** - Linting for Sass files - https://www.npmjs.com/package/sass-lint |
| 84 | +- **webpack** - Bundler for js files (can do much more too) - https://www.npmjs.com/package/webpack https://webpack.js.org/concepts/ |
| 85 | +- **webpack-cli** - The webpack command calls this behind the scenese (as of webpack v 4) https://www.npmjs.com/package/webpack-cli |
0 commit comments