countinmultiples
This repo contains the source code for an interactive JavaScript web tool to practise counting in multiples.
See the README for some background.
Development
Note that the following instructions apply only if you would like to contribute to the code.
Pre-requisites
countinmuliples uses npm for its build system. See Downloading and installing Node.js and npm for installation instructions.
Then use npm
to install development dependencies:
$ npm install
This should install all dependencies from the lock file.
Dependencies
autoprefixer
browser-sync
clean-jsdoc-theme
copyfiles
cssnano
dotenv-run-script
eslint
eslint-plugin-jsdoc
jsdoc
npm-run-all
postcss-cli
sass
terser
The .env file
- In the root of your project directory, create a dotenv file (called '.env').
- Specify two environment variables:
DEPLOY_PATH="</path/to/local/deployment/dir>"
[required]
The deployment path.BROWSER="<browser-for-previews>"
[optional]
E.g.BROWSER="firefox"
The browser to use for previewing the site. IfBROWSER
is not specified, orBROWSER
is empty, running thepreview:*
scripts will start up a local server but not open a browser.
The package.json file
Usage:npm run <script-name>
(runs the specified script)
Note that some scripts in package.json
are platform dependent as they are linux bash scripts.
Scripts in package.json
Available scripts:
with-env
Makes variables in the dotenv file '.env' available for use within a script.lint
Uses eslint (with configuration .eslintrc.json) to run the linter on all .js files in src/js.copy:assets
Copies assets (e.g. images) from src/assets/ to build/assets/.copy:css
Copies css files from src/css/ to build/css/.copy:js
Copies .js files which have already been minified from src/minjs/ to build/js/.copy:html
Copies html files from src/ to build/.copy:md
Copies markdown (.md) files from src/ to build/.copy:build
Runs allcopy:*
scripts.build.sass
Uses sass to compile sass files, with no source map, from src/sass/ to build/css/.build.js
Runs the linux bash script tools/minify-exploded.sh which uses terser to create minified (compressed) versions of the .js files in src/js/, saving them to src/minjs (i.e. under the source tree).build.jsdoc
Uses jsdocs (with configuration jsdoc.json) to generate documentation and save it to build/docs/.dev:build
Note that this task is identical tobuild
except thatbuild
also has a pre-hook (prebuild
).
Executes the following steps:- Runs script
clean
- Runs all
build:*
scripts - Runs script
copy
- Runs script
dev:sass
Uses sass to initiate watching of sass files in src/sass/. These get compiled (in expanded form, with a source map) to src/css/.clean
Deletes all files in build/.prebuild
Pre-hook for thebuild
script. Runs the linux bash script tools/check-log-level.sh which checks that debugging is disabled prior to build and deployment. It does this by checking ifLOGLEV
is set to anything other thanLevel.None
in .js files in src/js/.build
Note that this task is identical todev:build
except thatdev:build
does not have a pre-hook like thebuild
script does.
Executes the following steps:- Runs script
clean
- Runs all
build:*
scripts - Runs script
copy
- Runs script
postbuild
Post-hook for thebuild
script. Uses postcss-cli to run postcss on files in build/css/, updating them in place with no source map. Runs plugins:- autoprefixer to add vendor prefixes to CSS rules using values from Can I Use
- cssnano to compress css files
jsdoc:clean
Deletes all files in build/docs/.jsdoc:refresh
Executes the following steps:- Runs script
jsdoc:clean
- Runs script
build:jsdoc
- Runs script
deploy:clean
To run from the command line:npm run with-env deploy:clean
.
Deletes all files (except git and node_js files, including package*.json files if they exist) in the local deployment destination.
This script will fail if the environment variableDEPLOY_PATH
is not set.
Requires:- A dotenv file '.env' with
DEPLOY_PATH="</path/to/deployment/dir>"
- The dotenv file to be loaded for the deployment path.
- A dotenv file '.env' with
deploy:copy
To run from the command line:npm run with-env deploy:copy
.
Copies site files from the build directory to the (local) deployment directory.
This script will fail if the environment variableDEPLOY_PATH
is not set.
Requires:- A dotenv file '.env' with
DEPLOY_PATH="</path/to/local/deployment/dir>"
- The dotenv file to be loaded for the deployment path.
- A dotenv file '.env' with
deploy:build
To run from the command line:npm run with-env deploy:build
.
This script will fail if the environment variableDEPLOY_PATH
is not set.
Runs scriptsbuild
,deploy:clean
anddeploy:copy
to build the site, clean out any previously deployed files and copy the newly-built files to the (local) deployment directory.
Requires:- A dotenv file '.env' with
DEPLOY_PATH="</path/to/local/deployment/dir>"
- The dotenv file to be loaded for the deployment path.
- A dotenv file '.env' with
deploy
Loads the dotenv file '.env' and runs scriptdeploy:build
.browser:debug
To run from the command line:npm run with-env browser:debug
.
Uses browser-sync to serve files in src/, on port 8020. Run this script to attach to a browser (which must be chrome or edge) from within vscode for debugging.
Note NB: Requires:- The chrome/chromium or edge browser installed on the system
- The dotenv file to be loaded for the deployment path.
- An appropriate launch.json configuration to be specified in .vscode/launch.json, for example:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch chrome on localhost",
"url": "http://localhost:8020",
"webRoot": "${workspaceFolder}/src"
}
]
}
browser:noopen
Uses browser-sync to serve files in src/, not opening any browser for preview. After running this script, navigate to the server's URL from within a browser of your choice.browser:dev
To run from the command line:npm run with-env browser:dev
.
Uses browser-sync to serve files in src/, opening the browser specified in environment variableBROWSER
. If no validBROWSER
is specified, starts up a local server but does not open a browser. This enables real-time syncing of changes during development for viewing in a browser.
Note NB: Requires:- A dotenv file '.env' with
BROWSER="<exe-for-your-choice-of-browser>"
- The specified browser to be installed on the system
- The dotenv file to be loaded to open the specified browser.
- A dotenv file '.env' with
browser:build
To run from the command line:npm run with-env browser:build
.
Uses browser-sync to serve files in build/, opening the browser specified in environment variableBROWSER
. If no valid BROWSER is specified, starts up a local server but does not open a browser.
Note NB: Requires:- A dotenv file '.env' with
BROWSER="<exe-for-your-choice-of-browser>"
- The specified browser to be installed on the system
- The dotenv file to be loaded to open the specified browser.
- A dotenv file '.env' with
debug
Loads the dotenv file '.env' and runs scriptbrowser:debug
.preview:dev
Loads the dotenv file '.env' and runs scriptbrowser:dev
.preview:build
Loads the dotenv file '.env' and runs scriptbrowser:build
.