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

Added weinre support

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