Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade node #1117

Draft
wants to merge 33 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b80cb45
added sass compile and lint
will-byrne Jan 24, 2022
16a3a4e
replace img tasks with node versions elifesciences/issues#7190
will-byrne Jan 25, 2022
bc5065a
fix accidental rf in sass clean elifesciences/issues#7190
will-byrne Jan 25, 2022
411ae85
replace font task elifesciences/issues#7191
will-byrne Jan 25, 2022
5f49b18
replace JS tasks elifesciences/issues#7192
will-byrne Feb 2, 2022
b749838
wip for pairing
will-byrne Feb 22, 2022
7f0ecfd
replace mocha test targets
will-byrne Feb 28, 2022
439d166
replace build tasks in bin/dev for serve tasks elifesciences/issues#7195
will-byrne Mar 7, 2022
8848ab3
replace watch tasks with nodemon elifesciences/issues#7194
will-byrne Mar 7, 2022
54b8f3e
chore: update nvmrc file to node 16
Mar 16, 2022
c1a51b2
chore: add intial makefile
Mar 16, 2022
dd572fb
fix: various issues with makefile
Mar 16, 2022
4943eda
chore: start work on adding tests to makefile
Mar 16, 2022
ce6a9c8
chore: rename test
Mar 17, 2022
d2863a9
feat: initial working tests
Mar 17, 2022
7738303
chore: test targets working with some minor issues
Mar 17, 2022
9802c5d
chore: cleanup makefile
Mar 17, 2022
c0a4dbd
feat: update makefile to generate images
Mar 17, 2022
6ca7a4e
fix dockerfiles to build with new systems
will-byrne Mar 21, 2022
1496419
comment out selenium test for now and point tests at make
will-byrne Mar 21, 2022
11c7978
fix build issues with unit tests
will-byrne Mar 23, 2022
9ff53da
fix nested fonts folder
will-byrne Apr 1, 2022
a4deb9a
Merge branch 'master' of github.com:elifesciences/pattern-library int…
will-byrne Apr 5, 2022
db2975f
run production js build for assets builder
will-byrne Apr 5, 2022
610a73f
clean up package.json and package.lock
will-byrne Apr 26, 2022
582df15
add watch target to Makefile
will-byrne May 10, 2022
262dda9
cleanup npm scripts
will-byrne May 10, 2022
ade5bcb
update readme for new makefile
will-byrne May 17, 2022
ec00e34
Improvements to README.md
nlisgo Jun 8, 2022
2c4346e
Improvements to Makefile with one essential fix for node_modules
nlisgo Jun 8, 2022
f3650c2
cs
nlisgo Jun 8, 2022
4d30551
switch to docker compose to more easily compartmentalise the watch ta…
will-byrne Jun 29, 2022
2a29690
Merge branch 'develop' into upgrade-node
smoqadam May 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015"]
"presets": ["@babel/preset-env"]
}
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ IMAGE_TAG=develop
ENVIRONMENT=production
DESCRIPTION=
TEST_HTML=
NODE_VERSION=6.14.3
NODE_VERSION=16.13.2
# add '-debug' for VNC support
SELENIUM_IMAGE_SUFFIX=
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/boron
lts/gallium
54 changes: 51 additions & 3 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": ["stylelint-config-standard-scss"],
"plugins": [
"stylelint-selector-bem-pattern"
],
"rules": {
"block-closing-brace-newline-after": ["always", {"ignoreAtRules": ["if", "else"]}],
"block-no-empty": true,
Expand All @@ -8,7 +12,6 @@
"color-hex-length": "short",
"color-no-invalid-hex": true,
"comment-empty-line-before": "always",
"block-no-single-line": true,
"declaration-block-semicolon-newline-after": "always",
"declaration-block-semicolon-space-before": "never",
"declaration-block-trailing-semicolon": "always",
Expand All @@ -18,7 +21,7 @@
"indentation": 2,
"max-empty-lines": 1,
"no-eol-whitespace": true,
"no-missing-eof-newline": true,
"no-missing-end-of-source-newline": true,
"number-leading-zero": "always",
"number-no-trailing-zeros": true,
"selector-combinator-space-after": "always",
Expand All @@ -27,6 +30,51 @@
"selector-list-comma-space-before": "never",
"string-quotes": "double",
"value-list-comma-space-after": "always-single-line",
"value-list-comma-space-before": "never"
"value-list-comma-space-before": "never",
"declaration-block-no-duplicate-properties": null,
"declaration-block-no-redundant-longhand-properties": null,
"no-descending-specificity": null,
"no-duplicate-selectors": null,
"number-max-precision": null,
"selector-class-pattern": null,
"scss/dollar-variable-pattern": null,
"at-rule-empty-line-before": null,
"rule-empty-line-before": null,
"declaration-empty-line-before": null,
"selector-pseudo-element-colon-notation": null,
"block-closing-brace-empty-line-before": null,
"scss/at-mixin-argumentless-call-parentheses": null,
"scss/double-slash-comment-empty-line-before": null,
"scss/at-import-no-partial-leading-underscore": null,
"property-no-vendor-prefix": null,
"selector-no-vendor-prefix": null,
"shorthand-property-no-redundant-values": null,
"alpha-value-notation": null,
"function-url-quotes": null,
"function-comma-space-after": null,
"scss/at-rule-conditional-no-parentheses": null,
"max-line-length": null,
"color-function-notation": null,
"scss/at-mixin-pattern": null,
"block-closing-brace-newline-before": null,
"scss/operator-no-unspaced": null,
"scss/no-global-function-names": null,
"selector-max-empty-lines": null,
"selector-descendant-combinator-no-non-space": null,
"comment-whitespace-inside": null,
"scss/double-slash-comment-whitespace-inside": null,
"selector-id-pattern": null,
"scss/at-import-partial-extension": null,
"scss/dollar-variable-empty-line-before": null,
"value-keyword-case": null,
"scss/comment-no-empty": null,
"scss/at-mixin-parentheses-space-before": null,
"scss/at-else-closing-brace-newline-after": null,
"scss/at-else-closing-brace-space-after": null,
"scss/at-if-closing-brace-space-after": null,
"scss/at-if-closing-brace-newline-after": null,
"plugin/selector-bem-pattern": {
"preset": "bem"
}
}
}
22 changes: 16 additions & 6 deletions Dockerfile.assets-builder
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@ COPY .babelrc \
.jscsrc \
.jshintrc \
.stylelintrc \
gulpfile.js \
package.json \
Makefile \
./

COPY --from=npm /node_modules/ node_modules/

ARG environment=production
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

ARG ENVIRONMENT=production

COPY assets/fonts/ assets/fonts/
RUN node_modules/.bin/gulp --environment ${environment} fonts
RUN make fonts

COPY assets/img/ assets/img/
RUN node_modules/.bin/gulp --environment ${environment} img
RUN make images

COPY assets/js/ assets/js/
RUN node_modules/.bin/gulp --environment ${environment} js
RUN make source/assets/js/main.js

COPY assets/sass/ assets/sass/
RUN node_modules/.bin/gulp --environment ${environment} generateCss
RUN make source/assets/css/all.css
6 changes: 2 additions & 4 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ COPY source/_patterns/00-atoms/errors/ source/_patterns/00-atoms/errors/
COPY test-selenium/ test-selenium/
COPY test/ test/

RUN mkdir -p test/build && \
chown --recursive node:node test/build

USER node
RUN apt-get update
RUN apt-get install -y chromium
2 changes: 1 addition & 1 deletion Dockerfile.npm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG node_version
FROM node:${node_version}

COPY npm-shrinkwrap.json \
COPY package-lock.json \
package.json \
./

Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.npm-watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:16.15-slim
RUN mkdir /opt/pattern-library
# this expects a volume to be mounted to /opt/pattern-library
WORKDIR /opt/pattern-library
COPY package-lock.json \
package.json \
./

RUN npm install
5 changes: 5 additions & 0 deletions Dockerfile.watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM php:7.4-cli
RUN mkdir /opt/pattern-library
# this expects a volume to be mounted to /opt/pattern-library
WORKDIR /opt/pattern-library

106 changes: 106 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

PROJECT := $(notdir $(CURDIR))
NODE_VERSION ?= gallium
PHP_VERSION ?= 7.3-fpm
COMPOSER_VERSION ?= 1.6.4
PORT ?= 8889

# Source files that when changed should trigger a rebuild.
FONTS = $(shell find assets/fonts -type f)
SASS = $(shell find assets/sass -type f)
JAVASCRIPT = $(shell find assets/js -type f)
SOURCES = $(wildcard assets/js/**/* assets/sass/**/* source/**/*)

TESTS = $(wildcard test/*.spec.js)
TESTS_OUTPUT = $(patsubst test/%,test/build/%,$(TESTS))
TESTS_HTML = $(patsubst test/%.spec.js,test/%.html,$(TESTS))

SASS_ARGS =

ifeq ($(ENVIRONMENT),production)
SASS_ARGS=--output-style compressed
endif

JS_ARGS=--debug ./assets/js/main.js | npx exorcist ./source/assets/js/main.js.map > ./source/assets/js/main.js && cp assets/js/elife-loader.js ./source/assets/js/elife-loader.js

ifeq ($(ENVIRONMENT),production)
JS_ARGS=./assets/js/main.js | npx uglifyjs > ./source/assets/js/main.js && cp assets/js/elife-loader.js ./source/assets/js/elife-loader.js
endif

# Targets that don't result in output of the same name.
.PHONY: start watch stop clean distclean test test_notify fonts images

# When no target is specified, the default target to run.
.DEFAULT_GOAL := start

# Cleans build output and local dependencies
distclean: clean
@rm -rf node_modules vendor

# Cleans build output
clean:
@rm -rf public source/assets test/build

# Install Node.js dependencies if either, the node_modules directory is not present or package.json has changed.
node_modules: package.json
@npm install
@touch $@

# Create directories
source/assets source/assets/js source/assets/css test/build:
@mkdir -p $@

# Copy the fonts
fonts: source/assets $(FONTS)
@mkdir -p $(CURDIR)/source/assets/fonts
@cp -r ./assets/fonts $(CURDIR)/source/assets

# Optimise image assets
images: node_modules
@mkdir -p source/assets/img/errors source/assets/img/icons source/assets/img/patterns/molecules source/assets/img/patterns/organisms
@npx imagemin-cli './assets/img/errors' -o ./source/assets/img/errors/ --plugin.mozjpeg.progressive=true
@npx imagemin-cli './assets/img/icons' -o ./source/assets/img/icons --plugin.mozjpeg.progressive=true
@npx imagemin-cli './assets/img/patterns/molecules' -o ./source/assets/img/patterns/molecules/ --plugin.mozjpeg.progressive=true
@npx imagemin-cli './assets/img/patterns/organisms' -o ./source/assets/img/patterns/organisms/ --plugin.mozjpeg.progressive=true

# Convert the sass to css
source/assets/css/all.css: node_modules source/assets/css $(SASS)
npx node-sass assets/sass/build.scss ./$@ --importer node_modules/node-sass-magic-importer/dist/cli.js --source-map true --source-map-root file://${PWD} --source-map-embed true --source-comments true ${SASS_ARGS}

# Compile the Javascript
source/assets/js/main.js: node_modules source/assets/js $(JAVASCRIPT)
@npx browserify ${JS_ARGS}

# Builds the patterns, and pattern-lab static site.
public: fonts images source/assets/css/all.css source/assets/js/main.js
@mkdir -p $(CURDIR)/public
@cp -r ./core/styleguide $(CURDIR)/public/
@docker run --rm -v $(CURDIR):/$(PROJECT):rw -w=/$(PROJECT) php:$(PHP_VERSION) php ./core/builder.php --generate

test_notify:
@echo "Building tests. This might take a while. Grab a coffee!"

# Builds the JavaScript for the tests
test/build/%.spec.js: test/build test/%.spec.js
@npx browserify -o ./$@ ./test/$*.spec.js

# Runs the tests
test/%.html: test/build/%.spec.js
@npx mocha-headless-chrome -f ./$@ -a no-sandbox

# Runs all tests
test: test_notify $(TESTS_OUTPUT) $(TESTS_HTML)

# Watch files for changes and rebuild when detected
watch:
docker-compose -f docker-compose.watch.yml up

# Builds and runs the application on localhost:8889.
start: public
@echo "$(PROJECT) listening on 'http://localhost:$(PORT)'"
@docker run --rm --name $(PROJECT) -p $(PORT):80 -e NGINX_ENTRYPOINT_QUIET_LOGS=1 -v $(CURDIR)/public:/usr/share/nginx/html/:ro nginx:alpine

# If running, stops the container.
stop:
@echo $(SOURCES)
@-docker stop $(PROJECT)
2 changes: 1 addition & 1 deletion assets/js/elife-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function (window) {
'use strict';

console.log('foo');
try {
var scriptPaths,
$body;
Expand Down
28 changes: 3 additions & 25 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
#!/usr/bin/env bash
# First time...
if [ ! -d ./public ]; then
echo -e "Setting up for the first time...";
npm install
mkdir ./public
cp -r ./core/styleguide ./public/
fi

PORT=${1:-8889}

echo "Building patterns..."
node_modules/.bin/gulp

(while true; do
node_modules/.bin/gulp watch && sleep 5
done) & pid=$!
PID_LIST+=" $pid";
PORT=8889

# Need to generate before watch to ensure images are in the right place.
php ./core/builder.php --generate

php ./core/builder.php --watch > /dev/null 2>&1 & pid=$!
PID_LIST+=" $pid";
php ./core/builder.php --watch > /dev/null 2>&1 &

php -S 0.0.0.0:${PORT} -t ./public > /dev/null 2>&1 & pid=$!
PID_LIST+=" $pid";

trap "kill ${PID_LIST}" SIGINT

echo "Running Pattern Library at http://localhost:${PORT}/";
wait ${PID_LIST}
echo
wait $pid
echo "Stopping pattern library, gulp and server.";
5 changes: 1 addition & 4 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ services:
- node_modules:/srv/pattern-library/node_modules
- source_assets:/srv/pattern-library/source/assets
- ./.container_source_assets:/srv/pattern-library/.container_source_assets
- test_build:/srv/pattern-library/test/build
ui-builder:
volumes:
- ./source:/source
Expand All @@ -23,7 +22,7 @@ services:
- public:/usr/share/nginx/html
tests:
image: elifesciences/pattern-library_assets-builder:${IMAGE_TAG}
command: node_modules/.bin/gulp --test-html=${TEST_HTML} tests:watch
command: make test
ports:
- "3000:3000"
- "3001:3001"
Expand All @@ -32,12 +31,10 @@ services:
- ./:/srv/pattern-library
- /srv/pattern-library/node_modules
- source_assets:/srv/pattern-library/source/assets
- test_build:/srv/pattern-library/test/build
depends_on:
- assets-builder

volumes:
node_modules:
source_assets:
test_build:
public:
Loading