diff --git a/.bowerrc b/.bowerrc index eae9ba1..ac305ab 100644 --- a/.bowerrc +++ b/.bowerrc @@ -1,3 +1,6 @@ { - "directory": "dependencies" + "directory": "dependencies", + "scripts": { + "postinstall": "node bin/install/install-check.js" + } } diff --git a/.gitignore b/.gitignore index 5cc990c..3b09711 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ skeleton.* skeleton_template.css *.html dependencies/ +.idea/ diff --git a/README.md b/README.md index b3620d5..fbc7dc5 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ Changelog ### 2.5.4 * Adding `normalize.scss` as a dependency * Merged master in development for version bump +* Added scripts to check and automagically fix import paths ### 2.5.3 * Comment cleanup diff --git a/bin/install/install-check.js b/bin/install/install-check.js new file mode 100644 index 0000000..dc3901e --- /dev/null +++ b/bin/install/install-check.js @@ -0,0 +1,63 @@ +/** + * A simple script to determine where normalize.scss lives. We look for two cases: + * 1. my_bower/skeleton-sass/dependencies/normalize.scss + * 2. my_bower/normalize.scss + * Why is this needed? Sass provides no means for us to reluctantly import + * files meaning we can't use `!optional` + * There are ways to circumvent this by creating a new ruby module for Sass, + * but that doesn't port over to other compilers like libsass or phpsass. + * + * What this script does: + * This script validates the existence of normalize.scss either in skeleton sass + * or in a parent bower folder. This script will find a replace the instances where + * normalize.scss is imported in skeleton sass so you're ready to use skeleton + * out of the box. + * + * Note: normalize.scss is assumed to be in a parent bower directory. This script only + * fixes the import reference if `bower install` is run within skeleton sass. + */ + +const fs = require('fs'); +const path = require('path'); + +const MODULE_NAME = "skeleton-sass"; +const SEARCH_MODULE = "normalize.scss"; +const SKELETON_DEPS_DIRNAME = "dependencies"; + +(function () { + 'use strict'; + + let segments = __dirname.split(path.sep); + + let basePath = segments.slice(0, segments.indexOf(MODULE_NAME)).join(path.sep); + let bowerPath = basePath + path.join(path.sep, SEARCH_MODULE, path.sep); + let internalPath = basePath + path.join(path.sep, MODULE_NAME, SKELETON_DEPS_DIRNAME, SEARCH_MODULE, path.sep); + let normalizeImportFile = basePath + path.join(path.sep, MODULE_NAME, 'skeleton', 'themes', 'fresh', '_vars.scss'); + + fs.access(bowerPath, fs.F_OK, (bowerError) => { + if(bowerError) { + console.log(bowerPath + ' not found, checking ' + MODULE_NAME + ' dependencies'); + fs.access(internalPath, fs.R_OK, (internalDepsError) => { + if(internalDepsError) { + console.error('Missing core dependency for Skeleton Sass: ' + SEARCH_MODULE); + } else { + fs.readFile(normalizeImportFile, 'utf-8', (err, data) => { + if(err) { + throw err; + } + + let result = data.replace(/@import.+normalize\.scss.+;/, '@import' + + ' "../../../dependencies/normalize.scss/sass/normalize";'); + + fs.writeFile(normalizeImportFile, result, 'utf-8', (fwErr) => { + if(fwErr) { + throw fwErr; + } + }); + }); + } + }); + } + }); + +}()); diff --git a/bower.json b/bower.json index 8aec739..6089cb2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "skeleton-sass", - "version": "2.5.4", + "version": "2.5.4-dev2", "author": "Dennis Thompson", "homepage": "http://atomicpages.github.io/skeleton-sass/", "repository": { diff --git a/skeleton/themes/fresh/_vars.scss b/skeleton/themes/fresh/_vars.scss index 0ab1ee5..e4876f8 100644 --- a/skeleton/themes/fresh/_vars.scss +++ b/skeleton/themes/fresh/_vars.scss @@ -3,7 +3,7 @@ // stored in the marrow folder, but to also create project-level // variables. -@import "../../../dependencies/normalize.scss/sass/normalize"; +@import "../../../../normalize.scss/sass/normalize"; @import "marrow/mixins"; // @import "my_folder/_foo.scss"; // import dependencies from a custom folder // @import "bourbon"; // install bourbon in this directory and uncomment this line to enable bourbon, for example