Skip to content

Instantly share code, notes, and snippets.

@aj0strow
Created November 2, 2014 21:53
Show Gist options
  • Save aj0strow/7deb24b8fbf6f19d2116 to your computer and use it in GitHub Desktop.
Save aj0strow/7deb24b8fbf6f19d2116 to your computer and use it in GitHub Desktop.
Web Generator
system 'touch README.md'
system 'mkdir scripts stylesheets templates'
# git
# http://git-scm.com/
# http://git-scm.com/docs/gitignore
file = <<___
node_modules
bower_components
.build
.divshot-cache
.sass-cache
___
IO.write('.gitignore', file)
# npm & bower
# https://www.npmjs.org/
# http://bower.io/
system 'npm install --global bower'
file = <<___
{
"name": "#{ ARGV[0] }",
"private": true
}
___
IO.write('package.json', file)
IO.write('bower.json', file)
# gulp
# http://gulpjs.com/
system 'npm install --save coffee-script'
%w(gulp del merge).each do |package|
system "npm install --save #{ package }"
end
%w(load-plugins concat autoprefixer sourcemaps uglify).each do |plugin|
system "npm install --save gulp-#{ plugin }"
end
file = <<___
require('coffee-script/register')
require('./gulpfile.coffee')
___
IO.write('gulpfile.js', file)
# coffee-script to avoid syntax errors keeping track of commas
file = <<___
gulp = require 'gulp'
merge = require 'merge'
del = require 'del'
plugins = require 'gulp-load-plugins'
merge gulp, plugins(lazy: false)
# setup
build_dir = '.build'
paths = {
templates: [
'templates/**/*.html'
]
scripts: [
'scripts/*'
]
stylesheets: [
'stylesheets/*'
]
}
commands = Object.keys(paths)
pipe = (paths, plugins) ->
plugins ||= []
plugins.unshift gulp.src(paths)
plugins.push gulp.dest(build_dir)
plugins.reduce (a, b) -> a.pipe(b)
# tasks
gulp.task 'default', [ 'clean', 'build', 'watch' ]
gulp.task 'clean', (cb) ->
del(build_dir, cb)
gulp.task 'build', commands
gulp.task 'watch', ->
gulp.watch 'Gulpfile.js', [ 'build' ]
for command in commands
gulp.watch paths[command], [ command ]
gulp.task 'templates', ->
pipe paths.templates
gulp.task 'scripts', ->
pipe paths.scripts, [
gulp.concat('main.js')
gulp.sourcemaps.init()
gulp.uglify()
gulp.sourcemaps.write()
]
gulp.task 'stylesheets', ->
pipe paths.stylesheets, [
gulp.concat('style.css')
gulp.autoprefixer(cascade: false)
]
___
IO.write('gulpfile.coffee', file)
# divshot
# https://divshot.com/
system 'npm install --global divshot-cli'
file = <<___
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="/style.css">
<script src="/__/env.js"></script>
<script src="/main.js"></script>
</head>
<body>
</body>
</html>
___
IO.write('templates/index.html', file)
root = `npm root --global`.strip
file = IO.read(File.join(root, 'divshot-cli/lib/templates/error.html'))
IO.write('templates/error.html', file)
file = <<___
{
"name": "#{ ARGV[0] }",
"root": ".build",
"clean_urls": false,
"error_page": "error.html",
"routes": {
"/**": "index.html"
}
}
___
IO.write('divshot.json', file)
file = <<___
{
"SERVER_URL": "http://localhost:3000"
}
___
IO.write('.env.json', file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment