-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SHOR-109: Manage bootstrap-sass via npm, upgrade to v3.4 #337
Conversation
gulpfile.js
Outdated
const PluginError = require('plugin-error'); | ||
|
||
// copy assets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide a bit more extended explanation which files are copied, where and why.
gulpfile.js
Outdated
const PluginError = require('plugin-error'); | ||
|
||
// copy assets | ||
{ | ||
const ASSETS_PATH = path.join(__dirname, '/node_modules/bootstrap-sass/assets/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ASSETS_PATH = path.join(__dirname, 'node_modules/bootstrap-sass/assets');
No trailing slashes are needed when using path join.
console.log(path.join('/Users', '/igorpavlov', 'www/', '/site/', 'index.html'))
will output /Users/igorpavlov/www/site/index.html
.
gulpfile.js
Outdated
const ASSETS_PATH = path.join(__dirname, '/node_modules/bootstrap-sass/assets/'); | ||
|
||
gulp.task('copy:fonts', () => { | ||
const source = path.join(ASSETS_PATH, 'fonts/bootstrap/*'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have 2 blocks with the similar code, please consider creating a function:
gulp.task('copy:js', () => {
return copyFiles('javascripts/bootstrap/*', 'base/js')
});
function copyFiles (source, destination) {
const sourceAbsolute = path.join(ASSETS_PATH, source);
return gulp.src(sourceAbsolute).pipe(gulp.dest(destination));
}
gulpfile.js
Outdated
*/ | ||
function copyFiles (source, dest) { | ||
return gulp.src( | ||
path.join(__dirname, '/node_modules/bootstrap-sass/assets', source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the trailing '/'
path.join(__dirname, 'node_modules/bootstrap-sass/assets', source)
gulpfile.js
Outdated
/** | ||
* Copies the source files in the destination folder | ||
* | ||
* @param {String} source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please align the params with return:
* @param {String} source
* @param {String} dest
* @return {Object}
3ed563e
to
9687c8c
Compare
The main goal of this PR is to make Shoreditch upgrade from Bootstrap v3.3.5 to v3.4, which contains two important XSS fixes: twbs/bootstrap@29f9237, twbs/bootstrap@13bf8ae
Given that the dependency on Bootstrap (more specifically, on bootstrap-sass) was not being managed gracefully (the package's source code had been simply copy-pasted in the
base/
folder), the PR also improves things on that front by properly declaringbootstrap-sass
as a devDependency in thepackage.json
fileNote: switch to bootstrap-sass as npm package
When switching to using
bootstrap-sass
as an npm package, the version used first wasv3.3.5
(the same version that was manually copy-pasted in thebase/
folder), before upgrading tov3.4
This was to make sure that no changes would result in the minified css files when running
gulp sass
after the switch, and before the upgradeNote: changes introduced by the new releases
The changes introduced by
v3.3.6
,v3.3.7
andv3.4
had been checked both manually on the styleguide and by running BackstopJS on the styleguide extension, on core screens, on CiviHR, and on MosaicoNo unexpected changes were detected
Note: v3.4 release
At the time of this writing, the v3.4 release is currently on hold, aiming for a ~December 10th release date
Given that,
bootstrap-sass
doesn't have a new release either, so the alternative is to simply point the dependency to thenext
branch until v3.4 will be properly releasedTechnical details
Removal of bootswatch themes
One feature we were considering during the early stage of development was to give the option to a user/dev to switch between the default Bootstrap style and one of the many Bootswatch themes
That was the reason for having a
base/scss/themes/
folder, where the user could add the Bootswatch theme he wanted, and this line inbase/scss/bootstrap.scss
, where the user could switch the currently enabled themeIn the end this didn't really go anywhere, but still we were left with this awkward set up that no one was using
This PR clean up and simplifies things, by removing the whole
base/scss/themes
folder, and placing inbase/scss/bootstrap.scss
the default Bootstrap's@import
s list (which was before inbase/scss/themes/_default.scss
)Move custom partials outside of
base/vendor/
In the
base/scss/bootstrap.scss
file one should find only the aforementioned default@import
s list (see here for example), but instead we had a handful of custom@import
s that shouldn't have been placed in what is in effect a vendor fileThe custom partials had now been moved, the end result being that
base/scss/
now contains only the originalbootstrap-sass
source code and nothing elseBefore
After
Following are details about each of the partials that have been moved:
overrides/variables
This file was removed and its content placed in scss/bootstrap/overrides/_variables.scss, where all the other override/custom variables reside
Couple of notes:
$icon-font-path
variable was not moved and thus simply ignored, as the"../fonts/"
value was never applied given thatscss/bootstrap/overrides/_variables.scss
was already defining a value for it, which was the one eventually used$crm-wizard-*
variables had been marked with!default
, so that their value can be overridden if neededmixins/initial-value
This mixin had been placed in the
scss/bootstrap/mixins
along with all the other mixinsoverrides/reset/*
partialsThese partials had been placed in the newly created
scss/bootstrap/reset
folder, and@import
ed right before the default Bootstrap styles (just as it was happening before)Each reset partial internally
@import
s the original Bootstrap variables and mixins in order to be properly processedFix vars declaration
The
$text-muted
variable was being overridden incorrectly: instead of assigning a new value inoverrides/_variables.scss
, the new value was being assigned directly on the original_variables.scss
partial (see here)The
$icon-font-path
variable was instead being declared, first herethen here
Given the usage of
!default
, the second declaration was always ignored, so there was no point keeping it around (the fist declaration was the correct one anyway)Add gulp
copy
tasksGiven that the
bootstrap-sass
package is placed in thenode_modules/
folder when installed, a group ofcopy:xyz
gulp tasks had been created in order to copy fonts, scripts, and scss partials in thebase/
folderthe
copy
task is then being called automatically on thepostinstall
hookNote
A better set up would be to have only the fonts and scripts copied over, while keeping the sass partials in node_modules, which would then be
@import
ed automatically when runninggulp sass
This would eliminate the need for having a
base/scss
folder at all.Despite that, and in order to keep the scope of this PR limited and to avoid changes in downstream projects (there are a handful that are
@import
ing partials inbase/scss/vendor
directly), this set up was scrapped for a more "conservative" approach (= keep the folder structure as-is)Fixed permissions on
base/
filesThe vast majority of the
base/
files had the permissions set to755
. This was fixed automatically when copying over the files from thebootstrap-sass
package, and now the permission are set to a more restrictive644
Ignore linting on
base/
filesBoth
stylelint
andsemistandard
are now configured to ignore any files inbase/
(given that it needs to be considered a vendor folder)