Commit 5b32139d authored by Björn Bartels's avatar Björn Bartels

Merge branch 'npm-setup' into 'master'

Npm setup

See merge request !2
parents b92544c7 30f5ba07
Pipeline #146 passed with stages
in 7 minutes and 36 seconds
{
"env": {
"browser": true,
"builtin": true,
"es6": true,
"jasmine": true,
"jquery": true,
"mocha": true,
"node": true
},
"globals": {
"Foundation": true
},
"parserOptions": {
"ecmaFeatures": {
"impliedStrict": true,
"jsx": false
},
"ecmaVersion": 6,
"sourceType": "module"
},
"rules": {
"block-scoped-var": 2,
"camelcase": 2,
"comma-style": [2, "last"],
"curly": [0, "all"],
"dot-notation": [
2,
{
"allowKeywords": true
}
],
"eqeqeq": [2, "allow-null"],
"guard-for-in": 2,
"new-cap": 2,
"no-bitwise": 2,
"no-caller": 2,
"no-cond-assign": [2, "except-parens"],
"no-debugger": 2,
"no-empty": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-parens": 1,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-loop-func": 2,
"no-multi-str": 2,
"no-new": 2,
"no-plusplus": 0,
"no-proto": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 1,
"no-undef": 2,
"no-unused-vars": 1,
"no-with": 2,
"quotes": 0,
"radix" : 2,
"semi": [0, "never"],
"strict": [1, "global"],
"valid-typeof": 2,
"wrap-iife": [2, "inside"]
}
}
......@@ -4,6 +4,7 @@
.setting*
.nyc*
package-lock.json
node_modules
vendor
dist
......@@ -4,6 +4,17 @@ stages:
- test
- deploy
# Cache modules in between jobs
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
# cache JS dependencies
- node_modules/
# cache PHP dependencies
- vendor/
# cache package/project stuff, non-artifacts
- dist/
variables:
BUILD_TARGET: httpdocs
BUILD_LABEL_TMPFILE: build.txt
......@@ -11,22 +22,31 @@ variables:
before_script:
- if [ -f ${BUILD_LABEL_TMPFILE} ]; then export BUILD_LABEL=`cat ${BUILD_LABEL_TMPFILE}`; fi
init:
stage: setup
tags:
#- kunden-web
- kunden-web
#- node
- php
#- php
before_script:
- export BUILD_LABEL=$(TZ=Europe/Berlin date +%Y%m%d-%H%M)
script:
# save timestamp to file
- echo $BUILD_LABEL > ${BUILD_LABEL_TMPFILE}
- echo -e "\n\n\n\e[96mCreated new build label \e[107;30;1m $BUILD_LABEL \e[0m\n\n\n"
- echo -e "\n\n\e[96mCreated new build label \e[107;30;1m $BUILD_LABEL \e[0m\n\n"
# other init commands
- whoami
- pwd
- node -v
- npm -v
- php -v
# check if a build environment exists and copy it or install a new one if it doesn't
- if [ -d /build-env_DOES_NOT_EXIT_USE_INSTALL_FOR_NOW/node_modules ] && [ -f /build-env/package-lock.json ];
then echo -e "\e[96mFOUND EXISTING BUILD ENVIRONMENT" && mv /build-env/* ./;
else echo -e "\e[93mNO EXISTING BUILD ENVIRONMENT - RUNNING INSTALL" && npm install;
fi
# list used packages and info
- npm ls || true
artifacts:
paths:
- ${BUILD_LABEL_TMPFILE}
......@@ -34,29 +54,26 @@ init:
app-build:
stage: build
tags:
#- kunden-web
- kunden-web
#- node
- php
#- php
dependencies:
- init
variables:
BUILD_INFO_FILE: httpdocs/build.txt
script:
# check if a build environment exists and copy it or install a new one if it doesn't
- if [ -d /build-env_DOES_NOT_EXIT_USE_INSTALL_FOR_NOW/node_modules ] && [ -f /build-env/package-lock.json ];
then echo -e "\e[96mFOUND EXISTING BUILD ENVIRONMENT" && mv /build-env/* ./;
else echo -e "\e[93mNO EXISTING BUILD ENVIRONMENT - RUNNING INSTALL" && npm install;
fi
# list used packages
- npm ls || true
#
# run no build
#- echo "Warning - no build specified" && exit 0
#
# run node build
- npm -v
- php -v
- npm run build
# create build info file
- echo -e "LABEL=`cat ${BUILD_LABEL_TMPFILE}`" > ${BUILD_INFO_FILE}
- echo -e "TAG=${CI_COMMIT_TAG}" >> ${BUILD_INFO_FILE}
- echo -e "COMMIT=${CI_COMMIT_SHA}" >> ${BUILD_INFO_FILE}
- echo -e "PIPELINE=${CI_PIPELINE_ID}" >> ${BUILD_INFO_FILE}
- echo -e "USER=${GITLAB_USER_NAME} (${GITLAB_USER_LOGIN}) <${GITLAB_USER_EMAIL}>" >> ${BUILD_INFO_FILE}
# print debug-info
- cat ${BUILD_INFO_FILE}
- ls -la ${BUILD_TARGET}
......@@ -65,54 +82,104 @@ app-build:
- ${BUILD_TARGET}
app-tests:
app-test-sass:
stage: test
tags:
#- kunden-web
#- node
- php
- kunden-web
dependencies:
- app-build
variables:
BUILD_TEST_COVERAGE_FILE: httpdocs/coverage.xml
script:
# check if a build environment exists and copy it or install a new one if it doesn't
- php -v
- node -v
#
# run no tests
#- echo "Warning - no SASS tests specified" && exit 0
#
# run SASS tests
- npm run test:sass
artifacts:
paths:
- ${BUILD_TARGET}
app-test-javascript:
stage: test
tags:
- kunden-web
dependencies:
- app-build
script:
#
# run no tests
#- echo "Warning - no JavaScript tests specified" && exit 0
#
# run SASS tests
- npm run test:javascript
artifacts:
paths:
- ${BUILD_TARGET}
rsync:
stage: deploy
app-test-browser:
stage: test
tags:
- web-rsync-runner
- kunden-web
dependencies:
- app-build
- app-tests
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- ssh-add <(echo "$SSH_STAGING_PRIVATE_KEY")
- apt-get install rsync
script:
- ssh -p22 user@staging.example.com "mkdir -p /_tmp"
- rsync -rav -e ssh --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded /${BUILD_TARGET}/ user@staging.example.com:/_tmp
- ssh -p22 user@staging.example.com "mv /${BUILD_TARGET} /${BUILD_TARGET}_save && mv /_tmp /${BUILD_TARGET}"
- ssh -p22 user@staging.example.com "rm -rf /${BUILD_TARGET}_save"
only:
refs:
- master
when: manual
#
# run no tests
#- echo "Warning - no browser tests specified" && exit 0
#
# run browser/headless tests
- npm run test:browser
artifacts:
paths:
- ${BUILD_TARGET}
src-lint-sass:
stage: test
tags:
- kunden-web
dependencies:
- app-build
script:
#
# run no linting
#- echo "Warning - no SASS linting specified" && exit 0
#
# run SASS linting
- npm run lint:sass
artifacts:
paths:
- ${BUILD_TARGET}
src-lint-javascript:
stage: test
tags:
- kunden-web
dependencies:
- app-build
script:
#
# run no linting
#- echo "Warning - no JavaScript linting specified" && exit 0
#
# run SASS linting
- npm run lint:javascript
artifacts:
paths:
- ${BUILD_TARGET}
# ftp to dev host
ftp-dev:
stage: deploy
tags:
- kunden-web
dependencies:
- app-build
- app-tests
before_script:
#- no action for now...
script:
# deploy files
- npm run deploy
# ftp to host
- 'which lftp || ( apt-get update -qq && apt-get install -y -qq lftp )'
- lftp -c "set ftp:ssl-allow no; open -u $FTP_USERNAME,$FTP_PASSWORD $FTP_HOST; mirror -Rev ${BUILD_TARGET}/ ./$FTP_PATH/${BUILD_TARGET} --parallel=10 --exclude-glob .git* --exclude .git/"
except:
......@@ -121,20 +188,30 @@ ftp-dev:
- tags
- release
when: manual
artifacts:
paths:
- ${BUILD_TARGET}
# ftp to production/live host
ftp-prod:
stage: deploy
tags:
- kunden-web
dependencies:
- app-build
- app-tests
before_script:
#- no action for now...
script:
# deploy files
- npm run deploy
# ftp to host
- 'which lftp || ( apt-get update -qq && apt-get install -y -qq lftp )'
- lftp -c "set ftp:ssl-allow no; open -u $FTP_USERNAME_PROD,$FTP_PASSWORD_PROD $FTP_HOST_PROD; mirror -Rev ${BUILD_TARGET}/ ./$FTP_PATH_PROD/${BUILD_TARGET} --parallel=10 --exclude-glob .git* --exclude .git/"
only:
refs:
- master
- tags
- release
when: manual
artifacts:
paths:
- ${BUILD_TARGET}
options:
formatter: stylish
files:
include: '**/*.s+(a|c)ss'
ignore: ''
rules:
# Extends
extends-before-mixins: 1
extends-before-declarations: 1
placeholder-in-extend: 1
# Mixins
mixins-before-declarations: 1
# Line Spacing
one-declaration-per-line: 1
empty-line-between-blocks: 1
single-line-per-selector: 1
# Disallows
no-attribute-selectors: 0
no-color-hex: 0
no-color-keywords: 1
no-color-literals: 1
no-combinators: 0
no-css-comments: 1
no-debug: 1
no-disallowed-properties: 0
no-duplicate-properties: 1
no-empty-rulesets: 1
no-extends: 0
no-ids: 1
no-important: 1
no-invalid-hex: 1
no-mergeable-selectors: 1
no-misspelled-properties: 1
no-qualifying-elements: 1
no-trailing-whitespace: 1
no-trailing-zero: 1
no-transition-all: 1
no-universal-selectors: 0
no-url-domains: 1
no-url-protocols: 1
no-vendor-prefixes: 1
no-warn: 1
property-units: 0
# Nesting
declarations-before-nesting: 1
force-attribute-nesting: 1
force-element-nesting: 1
force-pseudo-nesting: 1
# Name Formats
class-name-format: 1
function-name-format: 1
id-name-format: 0
mixin-name-format: 1
placeholder-name-format: 1
variable-name-format: 1
# Style Guide
attribute-quotes: 1
bem-depth: 0
border-zero: 1
brace-style: 1
clean-import-paths: 1
empty-args: 1
hex-length: 1
hex-notation: 1
indentation: 1
leading-zero: 1
max-line-length: 0
max-file-line-count: 0
nesting-depth: 1
property-sort-order: 1
pseudo-element: 1
quotes: 1
shorthand-values: 1
url-quotes: 1
variable-for-property: 1
zero-unit: 1
# Inner Spacing
space-after-comma: 1
space-before-colon: 1
space-after-colon: 1
space-before-brace: 1
space-before-bang: 1
space-after-bang: 1
space-between-parens: 1
space-around-operator: 1
# Final Items
trailing-semicolon: 1
final-newline: 1
{
"name": "p-ad/web-base",
"name": "web-base",
"version": "0.0.1",
"license": "MIT",
"require": {}
}
# Your project's server will run on localhost:xxxx at this port
PORT: 8000
# Autoprefixer will make sure your CSS works with these browsers
COMPATIBILITY:
- "last 2 versions"
- "ie >= 9"
- "ios >= 7"
# UnCSS will use these settings
UNCSS_OPTIONS:
html:
# Search for used CSS classes in generated HTML files
- "dist/**/*.html"
ignore:
- !!js/regexp .foundation-mq
- !!js/regexp ^\.is-.*
# Gulp will reference these paths when it copies files
PATHS:
# Path to dist folder
dist: "dist"
# Paths to static assets that aren't images, CSS, or JavaScript
assets:
- "src/assets/**/*"
- "!src/assets/{img,js,scss}/**/*"
# Paths to Sass libraries, which can then be loaded with @import
sass:
- "node_modules/foundation-sites/scss"
- "node_modules/motion-ui/src"
# Paths to JavaScript entry points for webpack to bundle modules
entries:
- "src/assets/js/*.js"
deploy:
pages:
source: "dist/**/*.html"
target: "httpdocs/"
css:
source: "dist/assets/css/**/*"
target: "httpdocs/assets/css/"
js:
source: "dist/assets/js/**/*"
target: "httpdocs/assets/js/"
img:
source: "dist/assets/img/**/*"
target: "httpdocs/assets/img/"
'use strict';
import plugins from 'gulp-load-plugins';
import yargs from 'yargs';
import browser from 'browser-sync';
import gulp from 'gulp';
import panini from 'panini';
import rimraf from 'rimraf';
import sherpa from 'style-sherpa';
import yaml from 'js-yaml';
import fs from 'fs';
import webpackStream from 'webpack-stream';
import webpack2 from 'webpack';
import named from 'vinyl-named';
import uncss from 'uncss';
import autoprefixer from 'autoprefixer';
// Load all Gulp plugins into one variable
const $ = plugins();
// Check for --production flag
const PRODUCTION = !!(yargs.argv.production);
// Load settings from settings.yml
const { COMPATIBILITY, PORT, UNCSS_OPTIONS, PATHS } = loadConfig();
function loadConfig() {
let ymlFile = fs.readFileSync('config.yml', 'utf8');
return yaml.load(ymlFile);
}
// Delete the "dist" folder
// This happens every time a build starts
function clean(done) {
rimraf(PATHS.dist, done);
}
// Copy files out of the assets folder
// This task skips over the "img", "js", and "scss" folders, which are parsed separately
function copy() {
return gulp.src(PATHS.assets)
.pipe(gulp.dest(PATHS.dist + '/assets'));
}
// Copy page templates into finished HTML files
function pages() {
return gulp.src('src/pages/**/*.{html,hbs,handlebars}')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
data: 'src/data/',
helpers: 'src/helpers/'
}))
.pipe(gulp.dest(PATHS.dist));
}
// Load updated HTML templates and partials into Panini
function resetPages(done) {
panini.refresh();
done();
}
// Generate a style guide from the Markdown content and HTML template in styleguide/
function styleGuide(done) {
sherpa('src/styleguide/index.md', {
output: PATHS.dist + '/styleguide.html',
template: 'src/styleguide/template.html'
}, done);
}
// Compile Sass into CSS
// In production, the CSS is compressed
function sass() {
const postCssPlugins = [
// Autoprefixer
autoprefixer({ browsers: COMPATIBILITY }),
// UnCSS - Uncomment to remove unused styles in production
// PRODUCTION && uncss.postcssPlugin(UNCSS_OPTIONS),
].filter(Boolean);
return gulp.src('src/assets/scss/*.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
includePaths: PATHS.sass
})
.on('error', $.sass.logError))
.pipe($.postcss(postCssPlugins))
.pipe($.if(PRODUCTION, $.cleanCss({ compatibility: 'ie9' })))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest(PATHS.dist + '/assets/css'))
.pipe(browser.reload({ stream: true }));
}
let webpackConfig = {
mode: (PRODUCTION ? 'production' : 'development'),
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [ "@babel/preset-env" ],
compact: false
}
}
}
]
},
devtool: !PRODUCTION && 'source-map'
}
// Combine JavaScript into one file
// In production, the file is minified
function javascript() {
return gulp.src(PATHS.entries)
.pipe(named())
.pipe($.sourcemaps.init())
.pipe(webpackStream(webpackConfig, webpack2))
.pipe($.if(PRODUCTION, $.uglify()
.on('error', e => { console.log(e); })
))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest(PATHS.dist + '/assets/js'));
}
// Copy images to the "dist" folder
// In production, the images are compressed
function images() {
return gulp.src('src/assets/img/**/*')
.pipe($.if(PRODUCTION, $.imagemin([
$.imagemin.jpegtran({ progressive: true }),
])))
.pipe(gulp.dest(PATHS.dist + '/assets/img'));
}
// Start a server with BrowserSync to preview the site in
function server(done) {
browser.init({
server: PATHS.dist, port: PORT
}, done);
}
// Reload the browser with BrowserSync
function reload(done) {
browser.reload();
done();
}
// Watch for changes to static assets, pages, Sass, and JavaScript
function watch() {
gulp.watch(PATHS.assets, copy);
gulp.watch('src/pages/**/*.html').on('all', gulp.series(pages, browser.reload));
gulp.watch('src/{layouts,partials}/**/*.html').on('all', gulp.series(resetPages, pages, browser.reload));
gulp.watch('src/data/**/*.{js,json,yml}').on('all', gulp.series(resetPages, pages, browser.reload));
gulp.watch('src/helpers/**/*.js').on('all', gulp.series(resetPages, pages, browser.reload));
gulp.watch('src/assets/scss/**/*.scss').on('all', sass);
gulp.watch('src/assets/js/**/*.js').on('all', gulp.series(javascript, browser.reload));
gulp.watch('src/assets/img/**/*').on('all', gulp.series(images, browser.reload));
gulp.watch('src/styleguide/**').on('all', gulp.series(styleGuide, browser.reload));
}
// Deploy/copy HTML files
gulp.task('deploy:pages', () => {
return ( gulp.src( PATHS.deploy.pages.source ).pipe( gulp.dest(PATHS.deploy.pages.target) ) )
});
// Deploy/copy CSS files
gulp.task('deploy:stylesheets', () => {
return ( gulp.src( PATHS.deploy.css.source ).pipe( gulp.dest(PATHS.deploy.css.target) ) )
});
// Deploy/copy JS files
gulp.task('deploy:javascript', () => {
return ( gulp.src( PATHS.deploy.js.source ).pipe( gulp.dest(PATHS.deploy.js.target) ) )
});
// Deploy/copy images
gulp.task('deploy:images', () => {
return ( gulp.src( PATHS.deploy.img.source ).pipe( gulp.dest(PATHS.deploy.img.target) ) )
});
// Deploy/copy files
gulp.task('deploy', gulp.parallel('deploy:pages', 'deploy:stylesheets', 'deploy:javascript', 'deploy:images'));
// Build the "dist" folder by running all of the below tasks
// Sass must be run later so UnCSS can search for used classes in the others assets.
gulp.task('build', gulp.series(clean, gulp.parallel(pages, javascript, images, copy), sass, styleGuide /*, 'deploy'*/ ));
// Build the site, run the server, and watch for file changes
gulp.task('default', gulp.series('build', server, watch));
{
"name": "web-base",
"version": "1.0.0",
"version": "0.0.1",
"description": "",
"main": "index.js",
"author": "coding@bjoernbartels.earth",
"license": "MIT",
"repository": {
"type": "git",
"url": "git@gitlab.bjoernbartels.earth/devops/web-base.git"
},
"bugs": {
"url": "https://gitlab.bjoernbartels.earth/devops/web-base/issues",
"email": "coding@bjoernbartels.earth"
},
"private": false,
"main": "gulpfile.babel.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "gulp",
"build": "gulp build --production",
"build:dev": "gulp build",
"lint": "npm run lint:sass && npm run lint:javascript",
"lint:sass": "sass-lint './src/assets/scss/**/*.scss'",
"lint:javascript": "./node_modules/.bin/eslint ./src/assets/js/**/*.js",
"test": "npm run test:sass && npm run test:javascript && npm run test:browser",
"test:sass": "mocha ./test/sass/*.js",
"test:javascript": "nyc mocha --require '@babel/register' ./test/js/*.js;",
"test:browser": "mocha-headless-chrome -a no-sandbox -f ./test/headless/*.html -c ./dist/coverage.json",
"deploy": "gulp deploy",
"reinstall": "rm -rf node_modules package-lock.json; npm install;"
},
"dependencies": {
"aos": "^2.2.0",
"foundation-sites": "^6.5",
"jquery": "^3",
"jquery-ui": "^1",
"motion-ui": "^2.0.3",
"what-input": "^5.1.2"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"autoprefixer": "^9.1.5",
"babel-loader": "^8.0.4",
"browser-sync": "^2.10.0",
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0",
"gulp-clean-css": "^3.3.1",
"gulp-eslint": "^3.0.1",
"gulp-sass-lint": "^1.3.2",
"gulp-cli": "^2.0.1",
"gulp-concat": "^2.5.2",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-extname": "^0.2.0",
"gulp-if": "^2.0.0",
"gulp-imagemin": "^4.1.0",
"gulp-load-plugins": "^1.1.0",
"gulp-postcss": "^8.0.0",
"gulp-sass": "^4.0.1",