Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
🔨 replace deploy Gulp task by a stronger shell script #21
Browse files Browse the repository at this point in the history
  • Loading branch information
Yago committed May 2, 2019
1 parent e0f09fc commit 2541b2d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 165 deletions.
44 changes: 44 additions & 0 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

jq --version || { echo "⚠️ You must have jq installed on your machine (brew install jq)" ; exit 1; }

cd $2

DEST=`jq -er ".ghpages" "$2/toolbox.json"`
DIRECTORY="$2/${DEST%?}"
BRANCH="gh-pages"
CURRENT_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')

# Check if the environment is ready for publishing ===========================
if [[ $(git status -s) ]]
then
echo "⚠️ The working directory is dirty. Please commit any pending changes."
exit 1;
fi

# Proceed =====================================================================
# yarn build --dev
echo "backup dist content"
echo $DIRECTORY
mkdir "$DIRECTORY-tmp"
cp -r $DIRECTORY/* "$DIRECTORY-tmp/"

echo "Deleting dist"
rm -rf $DIRECTORY
mkdir $DIRECTORY
git worktree prune
rm -rf .git/worktrees/$DIRECTORY/

echo "Checking out $BRANCH branch into dist"
git worktree add -B $BRANCH $DIRECTORY

echo "Removing existing files"
rm -rf $DIRECTORY/*

echo "Generating dist using the backup"
cp -r "$DIRECTORY-tmp"/* $DIRECTORY/
rm -rf "$DIRECTORY-tmp"

echo "Updating $BRANCH branch"
cd $DIRECTORY && git add --all && git commit -m "Publishing to $BRANCH (publish.sh)"
git push --force origin $BRANCH --tags
3 changes: 0 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const vendors = require('./tasks/vendors');
const single = require('./tasks/single');
const serve = require('./tasks/serve');
const prepare = require('./tasks/prepare');
const deploy = require('./tasks/deploy');
const icons = require('./tasks/icons');

const config = require('./tasks/config');
Expand Down Expand Up @@ -92,7 +91,6 @@ const build = gulp.series(

gulp.task('serve', gulp.series(build, serve));
gulp.task('prepare', prepare);
gulp.task('deploy', deploy);
gulp.task('build', build);
gulp.task('clean', clean);
gulp.task('copy-assets', copyAssets);
Expand All @@ -101,5 +99,4 @@ gulp.task('scripts', scripts);
gulp.task('vendors', vendors);
gulp.task('icons', icons);
gulp.task('single', gulp.series(single));
gulp.task('deploy', deploy);
gulp.task('default', build);
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ const args = process.argv[3] ? '--' + process.argv[3] : process.argv[3];

let env = script === 'build' ? '--production' : '--dev';

const result = spawn(
'./node_modules/.bin/gulp',
[script, '--project', process.cwd(), env, args],
{ stdio: 'inherit', cwd: './node_modules/toolbox-utils' },
);
const binaries = ['deploy'];

if (binaries.includes(script)) {
spawn(
'sh',
[`./bin/${script}.sh`, '--project', process.cwd(), env, args],
{ stdio: 'inherit', cwd: './node_modules/toolbox-utils' },
);
} else {
spawn(
'./node_modules/.bin/gulp',
[script, '--project', process.cwd(), env, args],
{ stdio: 'inherit', cwd: './node_modules/toolbox-utils' },
);
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"gulp-concat": "^2.6.1",
"gulp-consolidate": "^0.2.0",
"gulp-eslint": "^5.0.0",
"gulp-gh-pages": "^0.5.4",
"gulp-load-plugins": "^1.5.0",
"gulp-notify": "^3.2.0",
"gulp-plumber": "^1.2.1",
Expand Down
17 changes: 0 additions & 17 deletions tasks/deploy.js

This file was deleted.

Loading

0 comments on commit 2541b2d

Please sign in to comment.