Skip to content

Commit

Permalink
feat: ✨ change netlfy deploy process (use netlify-cli)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarnaiz committed Oct 18, 2019
1 parent 2d4cbac commit eb559c5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_js:
before_install:
- npm install -g bower
- npm install -g gulp-cli
- npm install -g netlify-cli
- yarn install
before_script:
- chmod a+x ./netlify_deploy.sh
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Starts a local development environment which:

## Deployment
```
$ yarn run deploy --type=production
$ yarn run deploy --mode=production
```

Builds the project with optimization for distribution.
Expand All @@ -51,7 +51,7 @@ The file `config.json` contains the definition of all the configuration needed b
* Saas files by calling `@@config`. (#{localConfig.} cant be use because saas define his own vars in that way)
* JSON i18n files by calling `@@config`.

You can override this vars passing the concrete key as parameter with the prefix `config.`. Example `yarn run deploy -- --env=localhost --config.token_manager=1337 --type=production` load all the vars defined in the localhost section and override the token_manager var with the value `1337`
You can override this vars passing the concrete key as parameter with the prefix `config.`. Example `yarn run deploy -- --env=localhost --config.token_manager=1337 --mode=production` load all the vars defined in the localhost section and override the token_manager var with the value `1337`

### Add a new view

Expand Down
50 changes: 25 additions & 25 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ gulp.task('vendor:js', function() {
'./node_modules/@bower_components/owl.carousel/dist/owl.carousel.min.js',
'./node_modules/@bower_components/aos/dist/aos.js'
])
.pipe(gutil.env.type !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(concat('base.js'))
.pipe(gutil.env.type !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest('./dist/scripts/vendor'));

var vodafoneTask =
gulp.src([
'./node_modules/@bower_components/jquery/dist/jquery.min.js',
'./node_modules/@bower_components/materialize/dist/js/materialize.min.js'
])
.pipe(gutil.env.type !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(concat('vodafone.js'))
.pipe(gutil.env.type !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest('./dist/scripts/vendor'));


Expand All @@ -159,19 +159,19 @@ gulp.task('vendor:css', function() {
'./node_modules/@bower_components/owl.carousel/dist/assets/owl.carousel.min.css',
'./node_modules/@bower_components/aos/dist/aos.css'
])
.pipe(gutil.env.type !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(concat('base.css'))
.pipe(gutil.env.type !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest('./dist/styles/vendor'));

var vodafoneTask =
gulp.src([
'./node_modules/@bower_components/upplication-icons/dist/wingu/wingu-icons.css',
'./node_modules/@bower_components/materialize/dist/css/materialize.min.css'
])
.pipe(gutil.env.type !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(concat('vodafone.css'))
.pipe(gutil.env.type !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest('./dist/styles/vendor'));

// add all bower_components
Expand Down Expand Up @@ -218,7 +218,7 @@ gulp.task('templates', function() {
return getLocale(file);
}))
.pipe(jade({
pretty: gutil.env.type !== 'production'
pretty: gutil.env.mode !== 'production'
}))
.pipe(through2.obj(function(data, enc, cb) {
data.path = path.dirname(data.path) + data.config.url + 'index.html';
Expand All @@ -232,7 +232,7 @@ gulp.task('templates', function() {
prefix: '@@config.'
}))
.pipe(gulp.dest('./dist/'))
.pipe(gutil.env.type !== 'production' ? connect.reload() : gutil.noop());
.pipe(gutil.env.mode !== 'production' ? connect.reload() : gutil.noop());
});

gulp.task('scripts', function() {
Expand All @@ -249,18 +249,18 @@ gulp.task('scripts', function() {
var folders = getFolders(stylesPath);
var tasks = folders.map(function(folder) {
return gulp.src(path.join(stylesPath, folder, '/**/*.js'))
.pipe(gutil.env.type !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(concat(folder + '.js'))
.pipe(gutil.env.type !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gulp.dest("./dist/scripts"))
.pipe(gutil.env.type !== 'production' ? connect.reload() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? connect.reload() : gutil.noop())
});

return merge(tasks);
});

gulp.task('post', ['rev:scripts', 'rev:styles', 'templates'], function() {
if (gutil.env.type === 'production') {
if (gutil.env.mode === 'production') {
return gulp.src([
'!./node_modules/@bower_components/**/*',
'./dist/**/*.html'
Expand All @@ -269,12 +269,12 @@ gulp.task('post', ['rev:scripts', 'rev:styles', 'templates'], function() {
.pipe(minifyInline())
.pipe(gulp.dest('./dist/'));
} else {
gutil.log("Skipped", gutil.colors.cyan("'post'"), "task when", gutil.colors.green("--type=production"), "not present");
gutil.log("Skipped", gutil.colors.cyan("'post'"), "task when", gutil.colors.green("--mode=production"), "not present");
}
});

gulp.task('rev:scripts', ['scripts'], function() {
if (gutil.env.type === 'production') {
if (gutil.env.mode === 'production') {
return gulp.src('./dist/scripts/**/*.js')
.pipe(uglify())
.pipe(rev())
Expand All @@ -283,12 +283,12 @@ gulp.task('rev:scripts', ['scripts'], function() {
.pipe(rev.manifest('rev-manifest-js.json'))
.pipe(gulp.dest("./dist"))
} else {
gutil.log("Skipped", gutil.colors.cyan("'rev:scripts'"), "task when", gutil.colors.green("--type=production"), "not present");
gutil.log("Skipped", gutil.colors.cyan("'rev:scripts'"), "task when", gutil.colors.green("--mode=production"), "not present");
}
});

gulp.task('rev:styles', ['styles'], function() {
if (gutil.env.type === 'production') {
if (gutil.env.mode === 'production') {
return gulp.src('./dist/styles/**/*.css')
.pipe(cleanCSS({processImport: false}))// not process import because a timeout error:
.pipe(rev())
Expand All @@ -297,23 +297,23 @@ gulp.task('rev:styles', ['styles'], function() {
.pipe(rev.manifest('rev-manifest-css.json'))
.pipe(gulp.dest("./dist"))
} else {
gutil.log("Skipped", gutil.colors.cyan("'rev:styles'"), "task when", gutil.colors.green("--type=production"), "not present");
gutil.log("Skipped", gutil.colors.cyan("'rev:styles'"), "task when", gutil.colors.green("--mode=production"), "not present");
}
});

gulp.task('styles', function() {
return gulp.src("./app/styles/less/**/[^_]*.less")
.pipe(gutil.env.type !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.init() : gutil.noop())
.pipe(less())
.pipe(gutil.env.type !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(gutil.env.mode !== 'production' ? sourcemaps.write() : gutil.noop())
.pipe(replace({
patterns: [{
json: envConfig
}],
prefix: '@@config.'
}))
.pipe(gulp.dest("./dist/styles"))
.pipe(gutil.env.type !== 'production' ? connect.reload() : gutil.noop());
.pipe(gutil.env.mode !== 'production' ? connect.reload() : gutil.noop());
});

gulp.task('connect', ['templates'], function() {
Expand All @@ -340,7 +340,7 @@ gulp.task('clean', function() {

gulp.task('copy:images', function() {
return gulp.src('./app/images/**', { base: 'app' })
.pipe(gutil.env.type === 'production' ? imagemin() : gutil.noop())
.pipe(gutil.env.mode === 'production' ? imagemin() : gutil.noop())
.pipe(gulp.dest('./dist/'));
});

Expand All @@ -350,13 +350,13 @@ gulp.task('copy', function() {
});

gulp.task('watch', function () {
if (gutil.env.type !== 'production') {
if (gutil.env.mode !== 'production') {
gulp.watch(['./app/**/*.jade', './app/locales/*.json'], ['templates']);
gulp.watch(['./app/styles/less/**/*.less'], ['styles']);
gulp.watch(['./app/**/*.js'], ['scripts']);
gulp.watch(['./app/images/**'], ['copy:images']);
} else {
gutil.log("Skipped", gutil.colors.cyan("'watch'"), "task when", gutil.colors.green("--type=production"));
gutil.log("Skipped", gutil.colors.cyan("'watch'"), "task when", gutil.colors.green("--mode=production"));
}

});
Expand Down
14 changes: 2 additions & 12 deletions netlify_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@
# halt script on error
set -ev

zip -r website.zip dist

if [ "$TRAVIS_BRANCH" = "master" ] ; then
curl -H "Content-Type: application/zip" \
-H "Authorization: Bearer $NETLIFY_ACCESS_TOKEN" \
--data-binary "@website.zip" \
https://api.netlify.com/api/v1/sites/914901f4-03d3-4a52-b3ce-1a499b5f90f5/deploys
echo "Build successful, publishing in production environment!"
netlify deploy -s 914901f4-03d3-4a52-b3ce-1a499b5f90f5 -a $NETLIFY_ACCESS_TOKEN -d ./dist --prod

elif [ "$TRAVIS_BRANCH" = "develop" ] ; then
curl -H "Content-Type: application/zip" \
-H "Authorization: Bearer $NETLIFY_ACCESS_TOKEN" \
--data-binary "@website.zip" \
https://api.netlify.com/api/v1/sites/47f96b73-9e2b-4d08-9935-767b12fdf79b/deploys
echo "Build successful, publishing in develop environment!"
netlify deploy -s 47f96b73-9e2b-4d08-9935-767b12fdf79b -a $NETLIFY_ACCESS_TOKEN -d ./dist --prod

else
echo "Build successful, but not publishing!"
Expand Down

0 comments on commit eb559c5

Please sign in to comment.