An all-compassing department-maintained starting point for front end projects to help developers get up and running quickly.
Once you have installed the above dependencies:
- Clone this repository into your development folder
- Copy all files except for the .git directory into a new project folder
cd
into the root of the new project folder and runnpm install && bundle install
from the command line
From the root of the project, two commands can be issued from terminal:
gulp
: Builds project with sourcemaps from theapp
folder into thebuild
folder, spawns a Node server, opens a new browser with the website at http://localhost:3000, and listens for subsequent changes. When you edit and save a new file, Gulp will recompile accordingly and refresh your browser window with the latest changes.gulp build
: Builds project from theapp
folder into thebuild
and uglifies JS. This should generally be run before committing/pushing your code to the repo.
app/
: All work should be done in theapp
folder. This is where all of your website's code lives.build/
: When Gulp runs, it takes all of the files fromapp
and compiles them intobuild
. If you work out of thebuild
folder, your work will be overwritten.gulp/
: This contains all of the Gulp tasks that the project relies on. There is also a config.js file that most of the tasks reference to make file paths more manageable.node_modules/
: The folder where node_modules are installed when you runnpm install
..jshintrc
: The configuration file that dictates syntactical rules for JS linting. These should be followed closely.Gemfile
: The package file that contains the project's gem dependencies. These are installed when you runbundle install
.gulpfile
: This references all of the tasks ingulp/tasks/
. The tasks are broken apart for organizational purposes and referenced from this root file when you rungulp
.package.json
: The package file that contains the project's gem dependencies. These are installed when you runnpm install
.
To encourage organization, scalability, and code-reuse, we generally take an Atomic Design approach when structuring our HTML and SASS. Our SASS partials and HTML includes are broken apart in folders denoted by Atomic-style building blocks (atoms/pieces, molecules/components, organisms/regions, etc.).
Your HTML lives in the app
folder, and can contain references to reusable includes (which live in app/includes/
). For example:
//= include includes/1_core/head.html
This allows you to write a piece of code once and reuse it in multiple places. When Gulp runs, it takes these includes and compiles the full HTML into the build
folder.
Note: The paths in which these includes are referenced are relative to the HTML file you are authoring. If you include an include from another includer include, that path will need to be prefixed with ../
accordingly.
Your styles live in the app/styles/sass
folder. This folder is organized atomically:
0_utility/
: This contains font declarations, helper declarations, mixin declarations, variable declarations, and Normalize1_core/
: All bare (classless) HTML is styled in thehtml-elements
folder. Icons are specified in the_icons.scss
partial and the site's grid system is specified in the_layout.scss
partial.2_pieces/
: This is where your "Atoms" live.3_components/
: This is where your "Molecules" live.4_regions/
: This is where your "Organisms" live.5_pages/
: This is where your "Layouts" live.screen.scss
: This contains globbing patterns that@include
the partials in the above folders.
Init comes with a generic font set of icons that includes common things like arrows and social chiclets. To add more, upload the selection.js
in app/fonts/icomoon
. From here, you can add and remove icons, then re-export. When you re-export, make sure you save the updated selection.json
.
Init comes with a JS module loading system. This is how the JS folder is structured:
libs/
: This is where your vendor libraries/plugins live. Alternatively, you can use Bower if you really prefer.modules/
: This is where your JS modules live.modules/index.js
: This is the "module registry". It is essentially an object that contains a key/value for each module in the project.app.js
: This is your application bootstrap. All JS kicks off from here.
Create a new folder in app/scripts/modules/
. Name the module in camelCase (for example, app/scripts/modules/sampleModule/
), then create a new JS file in that folder with the same name + .main.js (for example, app/scripts/modules/sampleModule/sampleModule.main.js
). This naming convention must be followed for the folder and the main file. All modules should be written in the CommonJS fashion:
'use strict';
var $ = require('jquery'); //import jQuery
var somethingElse = require('./something-else.js'); //import something else
//Module constructor
function SampleModule($el) {
//Your code goes here.
}
//Export the constructor for instantiation
module.exports = SampleModule;
Now add that modules to the module registry's module.exports object (in app/scripts/modules/index.js
):
module.exports = {
sampleModule: require('./sampleModule/sampleModule.main')
};
Then reference the new module from somewhere in the HTML with the data-module
attribute:
<section class="outer-wrapper" data-module="sampleModule">
<div class="inner-wrapper">
<h1>Homepage Template</h1>
</div>
</section>
That's it! Now, when the page loads, app/scripts/app.js
runs the code below. This code loops through all of the data-module
attributes on the page and instantiates a new
version of that module via the reference in the module registry:
$('[data-module]').each(function(i, v) {
var name = $(v).data('module');
var module = new moduleRegistry[name]($(v));
});
Note: The module loader passes a jQuery object of the element that contains data-module
. This allows for easy scoping if you need to load more than one instance of the module on a page.
Some plugins can not be added via NPM. To add a non-NPM file to your project, manually save it to the libs folder (or alternatively, you can use Bower). Then, in package.json
, include a path to the new file in the "browser"
section. If it is a jQuery plugin, you might also need to add it to the "browserify-shim"
section. This tells Browserify that it depends on jQuery to run.
Now, include it in your module as you would a regular npm module:
var newPlugin = require('newPlugin');
Init leverages JS and SASS sourcemapping for easy debugging. The sourcemaps are already automatically built — all you need to do is set them up in your browser.
- Run
gulp
to get your server running. - In Chrome Inspector, go into settings and make sure sourcemaps are enabled for both JS and CSS.
- Open the "Sources" tab in the inspector, and in the side pane on the left, right-click and select "Add Folder to Workspace". Select the root folder of the project, from your file system.
- At the top of the browser, Chrome will prompt you for access. Click the "Allow" button.
- In the left side pane of the Sources tab, you should now see your project folder. Expand it and and drill down to any one of your SASS partials. Click it once. In the middle pane, an alert should come up asking if you want to map the workspace resource. Click the "more" link to expand the dialog, then click "Establish the mapping now...".
- A list of files should come up. Select the one that matches the file you just clicked on (generally the first one).
- Inspector will want to restart.
- That's it! Your local files should be tied to the sourcemaps the site loads. Now, when you inspect an element, look at the CSS pane and it should have a link to the exact partial for each rule declaration.
Make sure you've installed ALL dependencies specified above. Also, make sure you have up-to-date versions of Ruby and Node.
When you edit a Gulp task, a config file, or add any new file to the app
folder, you must stop and restart Gulp.