Skip to content
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

Bye bye Foundation & Browserify, hello Webpack & PostCSS #77

Merged
merged 47 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
dc4ed39
removed sass; added webpack and postcss
thomasdegry Mar 13, 2017
dce394a
Add postcss-css to deps
thomasdegry Mar 13, 2017
c2d5535
removed watchify
thomasdegry Mar 13, 2017
8984424
Remove cookiecutter question on generation
thomasdegry Mar 14, 2017
7d487a6
Fixed some gulp issues
thomasdegry Mar 14, 2017
a18809e
removed default open because it drives me INSANE
thomasdegry Mar 14, 2017
9866025
Fix npm run lint to lint css instead of scss
thomasdegry Mar 14, 2017
db863af
Updated dependencies
thomasdegry Mar 14, 2017
237ecc6
Updated to es2017 and explicitely use it in webpack config
thomasdegry Mar 14, 2017
7d1e263
Fixed some missing deps
thomasdegry Mar 14, 2017
b6bc623
Remove rest plugin since it's built into es2017
thomasdegry Mar 14, 2017
e26c42c
Trying to add suitcss
thomasdegry Mar 15, 2017
06d5d25
Add suitcss dep
thomasdegry Mar 15, 2017
e159b5f
remove all references to use_foundation_sites
akrawchyk Mar 15, 2017
a3bdb4b
gulp-suitcss
akrawchyk Mar 20, 2017
f809f71
Merge pull request #78 from istrategylabs/ak-fix
akrawchyk Mar 20, 2017
f1b20c9
Continue suitcss setup and linting config
thomasdegry Mar 21, 2017
34f2b12
Added basic circle.yml file for linting
thomasdegry Mar 21, 2017
d44dc2e
Dev install on circle
thomasdegry Mar 21, 2017
314c9a7
fix path to css file
akrawchyk Apr 11, 2017
2eeb568
prefer standard to eslint, remove unused config, upgrade packages, ad…
akrawchyk Apr 11, 2017
a0ddfc3
lock version of postcss-import to 8.0.2
akrawchyk Apr 12, 2017
7ff0713
more strict version of node and npm
akrawchyk Apr 13, 2017
7c50263
Added more css boilerplate
thomasdegry Apr 18, 2017
2f05437
add error logging to critical output, remove redundant role attr
akrawchyk Apr 18, 2017
4210cff
code instead of span tags
thomasdegry Apr 19, 2017
3701a4a
Fixed some stylelint issues
thomasdegry Apr 19, 2017
2b89fd0
Readme updates
thomasdegry Apr 19, 2017
855652a
Added raw tags to grid.html
thomasdegry Apr 19, 2017
b10496d
Added convict to the nunjucks and js
thomasdegry Apr 20, 2017
47c8e9f
Updated readme with convict info
thomasdegry Apr 20, 2017
8e5e840
Little mistake in convict readme section
thomasdegry Apr 20, 2017
70d2375
Removed one more nconf reference
thomasdegry Apr 20, 2017
e4b4b15
Added some more css boiler plate and variables
thomasdegry Apr 20, 2017
3f1c539
Yarn in circle.yml file
thomasdegry Apr 21, 2017
7c8ace9
Made code 0.9rem instead of 9rem lol
thomasdegry Apr 21, 2017
4e57981
Added buildpack urls to readme for convenience
thomasdegry Apr 21, 2017
9e4368b
Fix circleci
thomasdegry Apr 21, 2017
a179db2
Nesting was broken
thomasdegry Apr 21, 2017
6c5d001
Updated cookiecutter readme
thomasdegry Apr 24, 2017
a0a06a9
Uglify by default and generate sourcemaps
thomasdegry Apr 25, 2017
a9c6912
Spelling error in readme fix
thomasdegry Apr 26, 2017
7185eb4
Hex codes
thomasdegry Apr 26, 2017
f167e81
Added new line to readme
thomasdegry Apr 26, 2017
309acd6
Another red -> hex red
thomasdegry Apr 26, 2017
cfd1321
Readme update re. convict and heroku
thomasdegry Apr 27, 2017
7178d4f
fix cookiecutter var
akrawchyk Apr 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Mo-static is a static project template with batteries included.
## Features

* [editorconfig](http://editorconfig.org/)
* [nconf](https://github.com/indexzero/nconf)
* [convict](https://github.com/mozilla/node-convict)
* [Gulp](http://gulpjs.com/)
* [Browserify](http://browserify.org/) (w/[babelify](https://github.com/babel/babelify), [envify](https://github.com/zertosh/loose-envify), and [uglifyify](https://github.com/hughsk/uglifyify))
* [ESLint](http://eslint.org/) (w/[Airbnb config](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb#eslint-config-airbnbbase))
* [SASS](https://github.com/dlmanning/gulp-sass) (w/[Autoprefixer](https://autoprefixer.github.io/))
* [Stylelint](https://github.com/stylelint/stylelint) (w/[stylelint-config-standard](https://github.com/stylelint/stylelint-config-standard) and [stylelint-selector-bem-pattern](https://github.com/davidtheclark/stylelint-selector-bem-pattern))
* [Webpack](https://webpack.js.org/) (w/[babelify](https://github.com/babel/babelify)
* [Standard](https://github.com/feross/standard)
* [SuitCSS](https://suitcss.github.io) (w/[Autoprefixer](https://autoprefixer.github.io/))
* [Stylelint](https://github.com/stylelint/stylelint) (w/[stylelint-config-suitcss](https://github.com/suitcss/stylelint-config-suitcss)
* [Nunjucks](https://mozilla.github.io/nunjucks/)
* [Browsersync](http://www.browsersync.io/)
* [UglifyJS](https://github.com/mishoo/UglifyJS2/)
Expand Down
3 changes: 1 addition & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"repo_name": "{{ cookiecutter.project_name|lower|replace(' ', '-') }}",
"author_name": "ISL",
"email": "dev@isl.co",
"description": "",
"use_foundation_sites": "y"
"description": ""
}
5 changes: 1 addition & 4 deletions {{cookiecutter.repo_name}}/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"presets": ["es2015"],
"plugins": ["syntax-trailing-function-commas"]{% if cookiecutter.use_foundation_sites == 'y' -%},
"ignore": "jquery"
{%- endif %}
"presets": ["es2015"]
}
15 changes: 0 additions & 15 deletions {{cookiecutter.repo_name}}/.eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion {{cookiecutter.repo_name}}/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6
6.10
21 changes: 0 additions & 21 deletions {{cookiecutter.repo_name}}/.stylelintrc

This file was deleted.

100 changes: 35 additions & 65 deletions {{cookiecutter.repo_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

## Requirements:

- Node 6.3.x
- Node 6.10.x
- nvm

## Installation

```
$ nvm install
$ npm install
$ yarn
```

## Quick Start
Expand All @@ -23,14 +23,13 @@ $ npm run dev
```

## Usage

First, install your dependencies:
First, install your dependencies, there is a `yarn.lock` file, make sure you have yarn installed globally:

```
npm install
yarn
```

To start a Browsersync server and watch files for development:
To start a hot reload dev server and watch files for development:

```
npm run dev
Expand All @@ -48,82 +47,53 @@ You can also optimize PNG and JPEG images using [tinify](https://www.npmjs.com/p
npm run tinify
```

## Configuration

[nconf](https://github.com/indexzero/nconf) is used to handle configuration which lives in `config.js`.
## SUIT CSS
mo-static relies on [SUIT CSS](https://suitcss.github.io/) to package it's css but it does more than just that. Suit comes with a bunch of CSS packages such as a grid and buttons. It also ships with a whole bunch of utilities for text positioning, visibility and positioning. All of these components and utils are included by default since we import suit completely in `app.css`. Some useful docs of utilities and components include:
- [Grid component](https://github.com/suitcss/components-grid/)
- [Button component](https://github.com/suitcss/components-button/)
- [Text utilities (alignment, truncation, line breaks) ](https://github.com/suitcss/utils-text)
- [Display utilities (block, inline, hidden)](https://github.com/suitcss/utils-display)
- [Position utilities (relative, absolute, full screen](https://github.com/suitcss/utils-position)

All configuration variables should be defined in the `nconf.defaults` and it should be indicated if they are required.
A list with all utilities can be found [here](https://github.com/suitcss/utils) and a list with all components can be found [here](https://github.com/suitcss/components)

The configuration is passed to [envyify](https://github.com/zertosh/loose-envify) for transforming with browserify. This
means you can use `process.env.FOO` in your browserified JavaScript files and the appropriate environment variable
will be substituted during the build process to be shipped in the browser.

__🔐 TIP:__ Don't leak secret keys, neither by commmitting them nor by passing them to browserify. If the var you are
using should be kept secret, you should not add it to `config.js`.


__⏱ TIP:__ If the config var is an amount of time, specify the units in the var name:
## Configuration
[convict](https://github.com/mozilla/node-convict) is used to handle configuration which lives in `config.js`.

```
nconf.defaults({
TIMEOUT_MS: 2000,
EXPIRATION_S: 3
})
The convict instance just holds a javascript object. In there you can define all variables you like. If they have an `env` key the default value will be overwritten if the value is present in the environment variables. If you want to be even more specific with values only being present in some environments you can uncomment these lines and create the appropriate files:
```javascript
// var env = config.get('env');
// config.loadFile('./config/' + env + '.json');
```

{% if cookiecutter.use_foundation_sites == 'y' -%}
## Foundation
`gulp-nunjucks` automatically passes all this data when it compiles your HTML. This means you can just output `{% raw %}{{ secretMessage }}{% endraw %}` within your HTML and the compiler will replace it with whatever value you have in convict.

[Foundation Sites](http://foundation.zurb.com/sites.html) 6.2.0 is included with a small set of components enabled by
default. There is a list of everything you can add at [Foundation's Kitchen Sink](http://foundation.zurb.com/sites/docs/kitchen-sink.html).
To add more, uncomment the appropriate includes from the `app.scss` file along
with the appropriate settings section for the component in the `_.settings.scss`
file. This is described in detail at [Foundation's Sass docs](http://foundation.zurb.com/sites/docs/sass.html#adjusting-css-output).
As for the JS you need to explicitly indicate which values you want passed to your code via webpack to prevent passing any sensitive data. You can do so by modifying the `webpack.config.js` file, we use the `DefinePlugin` to make our environment variables available in our code. This means you can use `process.env.SECRET_MESSAGE` in your Javascript files and the appropriate environment variable will be substituted during the build process to be shipped in the browser.

[Browserify-shim](https://github.com/thlorenz/browserify-shim) is used to bundle individual Foundation JavaScript plugins. When adding
new plugins, you will need to update the shim configuration in `package.json` with the [appropriate Foundation files](http://foundation.zurb.com/sites/docs/javascript.html#file-structure).
__⚠️ WARNING__: Due to how Heroku pipelines work, the environment variables are piped into your code during build time. This means that when you promote an app from staging to production within a pipeline that the environment variables from staging will also make it to prdouction, since Heroku doesn't build again on production.

Foundation's documentation can be found at [foundation.zurb.com](http://foundation.zurb.com/sites/docs/).
To get started with what's included by default, read these docs:

* [Global styles](http://foundation.zurb.com/sites/docs/global.html)
* [Flex Grid](http://foundation.zurb.com/sites/docs/flex-grid.html) and [Media Queries](http://foundation.zurb.com/sites/docs/media-queries.html)
* [Typography](http://foundation.zurb.com/sites/docs/typography-base.html) and [Helper Classes](http://foundation.zurb.com/sites/docs/typography-helpers.html)
* [Forms](http://foundation.zurb.com/sites/docs/forms.html) and [Buttons](http://foundation.zurb.com/sites/docs/button.html)
* [Button Group](http://foundation.zurb.com/sites/docs/button-group.html)
* [Visibility Classes](http://foundation.zurb.com/sites/docs/visibility.html)
* [Float Classes](http://foundation.zurb.com/sites/docs/float-classes.html)
* [Flexbox Classes](http://foundation.zurb.com/sites/docs/flexbox.html)
* [JavaScript](http://foundation.zurb.com/sites/docs/javascript.html)
{%- endif %}

## ESlint

[ESlint](http://eslint.org/) is used for static analysis of JavaScript files. By default,
the `.eslintrc` is configured to extend [Airbnb's base](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb#eslint-config-airbnbbase) configuration,
with a few small modifications:
__🔐 TIP:__ Don't leak secret keys, neither by commmitting them nor by passing them to your JS. If the var you are
using should be kept secret, you should not add it to `config.js`.

* 2 spaces for indentation.
* No semicolons.
* Only single quotes.
* Unix linebreaks.

If you use global variables that are already defined in the DOM, add them to the `globals` object
in the `.eslintrc` to [register them](http://eslint.org/docs/user-guide/configuring#specifying-globals) with the linter.
## Standard
[Standard](https://github.com/feross/standard) is used for static analysis of JavaScript files. Standard, compared to ESlint allows/needs no configuration, if you really need to suppress a warning you can take a look [here](https://github.com/feross/standard#how-do-i-hide-a-certain-warning).

## Stylelint

[Stylelint](https://github.com/stylelint/stylelint) is used for static analysis of SASS files. By default,
the `.stylelintrc` is configured to extend [stylelint-config-standard](https://github.com/stylelint/stylelint-config-standard)
and uses [stylelint-selector-bem-pattern](https://github.com/davidtheclark/stylelint-selector-bem-pattern),
with a few small modifications:
[Stylelint](https://github.com/stylelint/stylelint) is used for static analysis of css files. There is a suitcss config installed for Stylelint. All configuration lives in `stylelint.config.js` , it exports a object that can be passed to the suitcss preprocessor in `build.js` and be used when running `npm run lint`

* 4 spaces for indentation.
* Properties in alphabetical order
* Only single quotes.
* No vendor prefixes (autoprefixer is preferred).
* No vendor prefixes (autoprefixer is enabled).
* Max of 2 adjacent empty lines.
* Required empty line between nested selectors, except first nested.
* No [browser hacks](https://github.com/stylelint/stylelint/tree/master/src/rules/no-browser-hacks).
* No [unsupported browser features](http://stylelint.io/user-guide/rules/no-unsupported-browser-features/).

Generated by [mo static](https://github.com/istrategylabs/mo-static).

## Deploying to Heroku
In order to deploy your new `mo-static` app to Heroku you'll need these buildpacks, in this order:
- Nodejs: `heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs -a <my-app>`
- Heroku Static Buildpack `heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static.git -a <my-app>`

11 changes: 11 additions & 0 deletions {{cookiecutter.repo_name}}/circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
machine:
node:
version: 6
environment:
NODE_ENV: production
dependencies:
override:
- npm install --dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomasdegry can we use yarn here instead? https://circleci.com/docs/1.0/yarn/

Also, can you try integrating an example application with circle before we merge this?

test:
override:
- npm run lint
26 changes: 21 additions & 5 deletions {{cookiecutter.repo_name}}/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import nconf from 'nconf'
var convict = require('convict');

nconf.env().argv()

nconf.defaults({
var config = convict({
env: {
doc: 'The applicaton environment.',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV'
},
secretMessage: {
doc: 'Some test secret message.',
format: String,
default: 'WHAZZAAAAHHHHH'
}
})

export default nconf
// Load environment dependent configuration if desired
// var env = config.get('env');
// config.loadFile('./config/' + env + '.json');

// Perform validation
config.validate({allowed: 'strict'});

module.exports = config;
82 changes: 19 additions & 63 deletions {{cookiecutter.repo_name}}/gulp/build.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,39 @@
import gulp from 'gulp'
import gutil from 'gulp-util'
import del from 'del'
import autoprefixer from 'autoprefixer'
import postcss from 'gulp-postcss'
import sass from 'gulp-sass'
import sourcemaps from 'gulp-sourcemaps'
import suitcss from 'gulp-suitcss'
import nunjucks from 'gulp-nunjucks'
import source from 'vinyl-source-stream'
import buffer from 'vinyl-buffer'
import browserify from 'browserify'
import envify from 'loose-envify/custom'
import plumber from 'gulp-plumber'
import config from '../config'
import webpackStream from 'webpack-stream'
import webpack from 'webpack'
import styleLintConfig from '../stylelint.config'
import projectConfig from '../config'

export const EXTRAS_GLOB = 'src/**/*.{txt,json,xml,ico,jpeg,jpg,png,gif,svg,ttf,otf,eot,woff,woff2,mp3,mp4,ogv,ogg,webm}'

let bundler = browserify(['src/static/js/app.js'], { debug: true })
.transform('babelify')
.transform(envify(config.get()))
.transform('uglifyify')

function bundle() {
return bundler.bundle()
.on('error', err => {
gutil.log(gutil.colors.red(err.message))
this.emit('end')
})
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/static/js/'))
}


gulp.task('clean', () => del('public/'))

gulp.task('browserify', () => bundle())
gulp.task('remove-help', () => del('public/help'))

gulp.task('watchify', () => {
const watchify = require('watchify')
bundler = watchify(bundler)
bundler.on('update', () => {
gutil.log('-> bundling...')
bundle()
})
return bundle
})
gulp.task('webpack', () =>
webpackStream(require('../webpack.config.js'), webpack)
.pipe(gulp.dest('public/static/js/')))

gulp.task('sass', () =>
gulp.src('src/static/scss/**/*.scss')
.pipe(plumber())
gulp.task('css', () =>
gulp.src('src/static/css/app.css')
.pipe(sourcemaps.init())
.pipe(sass({% if cookiecutter.use_foundation_sites == 'y' -%}{
includePaths: ['node_modules/foundation-sites/scss'],
}{%- endif %}))
.pipe(postcss([autoprefixer({
// see https://github.com/ai/browserslist#queries
// and https://github.com/google/web-starter-kit/blob/128b2efdab595e0a4c8a563fcf1d1724ef98b8aa/gulpfile.babel.js#L73
browsers: [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
]
})]))
.pipe(sourcemaps.write())
.pipe(plumber.stop())
.pipe(gulp.dest('public/static/css/')))
.pipe(suitcss({
stylelint: styleLintConfig,
use: [ 'postcss-nested' ]
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/static/css/'))
)

gulp.task('nunjucks', () =>
gulp.src(['src/templates/**/*.html', '!**/_*'])
.pipe(plumber())
.pipe(nunjucks.compile(config.get(), {
.pipe(nunjucks.compile(projectConfig.getProperties(), {
throwOnUndefined: true,
}))
.pipe(plumber.stop())
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.repo_name}}/gulp/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ gulp.task('critical', () =>
height: 640,
}],
}))
.on('error', (err) => { console.log(err.message) })
.pipe(gulp.dest('public/')))

gulp.task('minify:html', () =>
Expand Down
Loading