Commit 1f780f3e authored by Vadym Gidulian's avatar Vadym Gidulian

Added weinre support

parent 97afe6cc
stages:
- build
- deploy
- production
- build:production
- deploy:production
build:
.cache-and-save-artifacts: &cache-and-save-artifacts
cache:
paths:
- node_modules/
artifacts:
paths:
- dist/
build:testing:
stage: build
script:
- node -v
- npm -v
- npm run build-testing
tags:
- npm
<<: *cache-and-save-artifacts
only:
- branches
except:
- master
build:staging:
stage: build
script:
- node -v
- npm -v
- npm run build-staging
tags:
- npm
<<: *cache-and-save-artifacts
only:
- master
build:production:
stage: build:production
script:
- node -v
- npm -v
- npm run build
when: manual
tags:
- npm
cache:
paths:
- node_modules/
artifacts:
paths:
- dist/
<<: *cache-and-save-artifacts
only:
- master
deploy:review:
stage: deploy
......@@ -25,7 +58,7 @@ deploy:review:
script:
- rsync -rv --delete dist/ /test/$CI_PROJECT_NAME--$CI_COMMIT_REF_SLUG/
dependencies:
- build
- build:testing
tags:
- gviagroup-deploy
environment:
......@@ -45,7 +78,7 @@ deploy:testing:
script:
- rsync -rv --delete dist/ /test/$CI_PROJECT_NAME/
dependencies:
- build
- build:testing
tags:
- gviagroup-deploy
environment:
......@@ -53,6 +86,7 @@ deploy:testing:
url: http://$CI_PROJECT_NAME.test.$DOMAIN
on_stop: undeploy:testing
only:
- branches
- dev
deploy:staging:
......@@ -62,7 +96,7 @@ deploy:staging:
script:
- rsync -rv --delete dist/ /demo/$CI_PROJECT_NAME/
dependencies:
- build
- build:staging
tags:
- gviagroup-deploy
environment:
......@@ -73,15 +107,14 @@ deploy:staging:
- master
deploy:production:
stage: production
stage: deploy:production
variables:
GIT_STRATEGY: none
script:
- deploy html dist/
- deploy --chown
when: manual
dependencies:
- build
- build:production
tags:
- gviagroup-hosting
environment:
......@@ -121,6 +154,7 @@ undeploy:testing:
name: testing
action: stop
only:
- branches
- dev
undeploy:staging:
......
......@@ -3,16 +3,29 @@ var source = require('vinyl-source-stream');
var gulp = require('gulp');
var nano = require('gulp-cssnano');
var noop = require('gulp-empty');
var htmlMin = require('gulp-htmlmin');
var inject = require('gulp-inject-string');
var less = require('gulp-less');
var pug = require('gulp-pug');
var rename = require('gulp-rename');
var streamify = require('gulp-streamify');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var failSafe = false;
var production = true;
function isLocal() {
return !gutil.env.env;
}
function isTesting() {
return gutil.env.env === 'testing';
}
function isStaging() {
return gutil.env.env === 'staging';
}
function isProduction() {
return gutil.env.env === 'production';
}
function shallow(done) {
return function (error) {
......@@ -83,6 +96,15 @@ gulp.task('images', ['img-copy']);
gulp.task('html-min', function () {
return gulp.src(paths.html)
.pipe(isLocal() || isTesting()
? inject.replace('<!--\\s*?weinre\\s*?-->', '<script async src="http://weinre.dev.gvia.group/target/target-script-min.js"></script>')
: gutil.noop())
.pipe(isStaging()
? inject.replace('<!--\\s*?weinre\\s*?-->', '<script async src="http://weinre.dev.gvia.group/target/target-script-min.js#staging"></script>')
: gutil.noop())
.pipe(isProduction()
? inject.replace('<!--\\s*?weinre\\s*?-->', '')
: gutil.noop())
.pipe(htmlMin({
collapseWhitespace: true,
conservativeCollapse: true
......@@ -91,6 +113,15 @@ gulp.task('html-min', function () {
});
gulp.task('pug-compile', function () {
return gulp.src(paths.pug)
.pipe(isLocal() || isTesting()
? inject.replace('//-?\\s*?weinre', 'script(async src="http://weinre.dev.gvia.group/target/target-script-min.js")')
: gutil.noop())
.pipe(isStaging()
? inject.replace('//-?\\s*?weinre', 'script(async src="http://weinre.dev.gvia.group/target/target-script-min.js#staging")')
: gutil.noop())
.pipe(isProduction()
? inject.replace('//-?\\s*?weinre', '')
: gutil.noop())
.pipe(pug())
.pipe(gulp.dest(paths.pugOut));
});
......@@ -100,11 +131,11 @@ gulp.task('markup', ['html-min', 'pug-compile']);
gulp.task('js-browserify', function (done) {
return browserify(paths.js, {
debug: !production
debug: isLocal()
})
.bundle()
.pipe(source('script.all.min.js'))
.pipe(production ? streamify(uglify().on(failSafe ? 'error' : 'none', shallow(done))) : noop())
.pipe(!isLocal() ? streamify(uglify().on(failSafe ? 'error' : 'none', shallow(done))) : gutil.noop())
.pipe(gulp.dest(paths.jsOut));
});
gulp.task('scripts', ['js-browserify']);
......@@ -114,7 +145,7 @@ gulp.task('scripts', ['js-browserify']);
gulp.task('less-compile', function (done) {
return gulp.src(paths.less)
.pipe(less().on(failSafe ? 'error' : 'none', shallow(done)))
.pipe(production ? nano().on(failSafe ? 'error' : 'none', shallow(done)) : noop())
.pipe(!isLocal() ? nano().on(failSafe ? 'error' : 'none', shallow(done)) : gutil.noop())
.pipe(rename('style.all.min.css'))
.pipe(gulp.dest(paths.lessOut));
});
......@@ -122,15 +153,11 @@ gulp.task('styles', ['less-compile']);
// Stages
gulp.task('pretest', function () {
production = false;
});
gulp.task('test', ['pretest', 'files', 'images', 'markup', 'scripts', 'styles']);
gulp.task('watch', ['pretest'], function () {
gulp.task('watch', function () {
failSafe = true;
gulp.watch(paths.files, ['files']);
gulp.watch([paths.htmlFiles, paths.pugFiles], ['markup']);
gulp.watch(paths.imgFiles, ['images']);
gulp.watch(paths.imgFiles, ['images']);
gulp.watch([paths.htmlFiles, paths.pugFiles], ['markup']);
gulp.watch(paths.jsFiles, ['scripts']);
gulp.watch([paths.cssFiles, paths.lessFiles], ['styles']);
});
......
......@@ -4,9 +4,11 @@
"scripts": {
"prestart": "npm install",
"start": "gulp test && concurrently \"gulp watch\" \"lite-server\"",
"start": "gulp && concurrently \"gulp watch\" \"lite-server\"",
"build": "npm install && gulp"
"build-testing": "npm install && gulp --env testing",
"build-staging": "npm install && gulp --env staging",
"build": "npm install && gulp --env production"
},
"devDependencies": {
......@@ -17,12 +19,13 @@
"vinyl-source-stream": "^1.1.0",
"gulp": "^3.9.1",
"gulp-cssnano": "^2.1.2",
"gulp-empty": "^0.1.1",
"gulp-htmlmin": "^3.0.0",
"gulp-inject-string": "^1.1.0",
"gulp-less": "^3.3.0",
"gulp-pug": "^3.3.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^2.1.0",
"gulp-util": "^3.0.8",
"jquery": "^3.1.1"
}
......
......@@ -8,6 +8,7 @@
<link rel="stylesheet" href="css/style.all.min.css">
</head>
<body>
<!-- weinre -->
<!-- Code goes here -->
......
......@@ -4,4 +4,6 @@ doctype html
html(lang="en")
+head('Project')
body
// weinre
// Code goes here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment