Created
July 28, 2013 07:29
-
-
Save barbuza/6097811 to your computer and use it in GitHub Desktop.
bottomgirl is not middleman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import json | |
from argparse import ArgumentParser | |
parser = ArgumentParser() | |
parser.add_argument("--haml", dest="haml", action="store_true", default=False, | |
help="enable haml templates") | |
parser.add_argument("--jade", dest="jade", action="store_true", default=False, | |
help="enable jade templates") | |
parser.add_argument("--stylus", dest="stylus", action="store_true", default=False, | |
help="enable stylus styles") | |
parser.add_argument("--less", dest="less", action="store_true", default=False, | |
help="enable less styles") | |
parser.add_argument("--autoprefixer", dest="autoprefixer", action="store_true", default=False, | |
help="enable autoprefixer") | |
parser.add_argument("--coffee", dest="coffee", action="store_true", default=False, | |
help="enable coffeescript") | |
parser.add_argument("--images", dest="images", action="store_true", default=False, | |
help="enable images optimization") | |
parser.add_argument("path", help="path to be created") | |
options = parser.parse_args() | |
if os.path.exists(options.path): | |
print "%s already exists" % options.path | |
sys.exit(1) | |
os.makedirs(options.path) | |
deps = { | |
"grunt": "~0.4.1", | |
"grunt-contrib-watch": "~0.4.4", | |
"grunt-contrib-connect": "~0.3.0", | |
"grunt-parallel": "~0.2.0" | |
} | |
if options.coffee: | |
deps["grunt-contrib-coffee"] = "~0.7.0" | |
if options.stylus: | |
deps["grunt-contrib-stylus"] = "~0.5.0" | |
if options.jade: | |
deps["grunt-contrib-jade"] = "~0.7.0" | |
if options.less: | |
deps["grunt-contrib-less"] = "~0.6.4" | |
if options.haml: | |
deps["grunt-haml"] = "~0.5.0" | |
if options.images: | |
deps["grunt-contrib-imagemin"] = "~0.1.4" | |
if options.autoprefixer: | |
deps["grunt-autoprefixer"] = "~0.2.0" | |
package = """{ | |
"name": "bottom-girl", | |
"version": "0.0.1", | |
"devDependencies": %s | |
} | |
""" % json.dumps(deps, indent=2) | |
static_patterns = ["*.*"] | |
build_commands = ["static"] | |
watchers = [] | |
if options.images: | |
static_patterns.extend(["!*.jpg", "!*.jpeg", "!*.png"]) | |
build_commands.append("imagemin") | |
watchers.append('images: watch("jpg", "jpeg", "png").run("imagemin")') | |
if options.coffee: | |
static_patterns.append("!*.coffee") | |
build_commands.append("coffee") | |
watchers.append('coffee: watch("coffee").run("coffee")') | |
if options.haml: | |
static_patterns.append("!*.haml") | |
build_commands.append("haml") | |
watchers.append('haml: watch("haml").run("haml")') | |
if options.jade: | |
static_patterns.append("!*.jade") | |
build_commands.append("jade") | |
watchers.append('jade: watch("jade").run("jade")') | |
if options.stylus: | |
static_patterns.append("!*.styl") | |
build_commands.append("stylus") | |
if options.autoprefixer: | |
watchers.append('stylus: watch("styl").run("stylus", "autoprefixer")') | |
else: | |
watchers.append('stylus: watch("styl").run("stylus")') | |
if options.less: | |
static_patterns.append("!*.less") | |
build_commands.append("less") | |
if options.autoprefixer: | |
watchers.append('less: watch("less").run("less", "autoprefixer")') | |
else: | |
watchers.append('less: watch("less").run("less")') | |
if options.autoprefixer: | |
build_commands.append("autoprefixer") | |
gruntfile = """ | |
module.exports = (grunt) -> | |
"use strict" | |
source_path = "source" | |
build_path = "build" | |
compile = (source_exts...) -> | |
to: (target_exts...) -> | |
options = | |
files: [ | |
expand: yes | |
cwd: source_path | |
matchBase: yes | |
src: ["*.#{source_ext}" for source_ext in source_exts] | |
dest: build_path | |
] | |
options.files[0].ext = [".#{target_ext}" for target_ext in target_exts] if target_exts.length | |
options | |
watch = (source_exts...) -> | |
run: (tasks...) -> | |
files: [require("path").join(source_path, "**", "*.#{source_ext}") for source_ext in source_exts] | |
tasks: tasks | |
options: | |
livereload: yes | |
grunt.initConfig | |
parallel: | |
server: | |
options: | |
grunt: yes | |
stream: yes | |
tasks: ["watch", "connect:server"] | |
connect: | |
server: | |
options: | |
port: 5678 | |
base: build_path | |
keepalive: yes | |
watch: | |
%(watchers)s | |
imagemin: | |
options: | |
optimizationLevel: 0 | |
progressive: yes | |
compile: compile("jpg", "jpeg", "png").to() | |
coffee: | |
compile: compile("coffee").to("js") | |
stylus: | |
compile: compile("styl").to("css") | |
less: | |
compile: compile("less").to("css") | |
autoprefixer: | |
options: | |
browsers: ["last 2 versions"] | |
compile: | |
files: [ | |
expand: yes | |
matchBase: yes | |
cwd: build_path | |
src: "*.css" | |
dest: build_path | |
] | |
haml: | |
options: | |
language: "coffee" | |
compile: | |
files: compile("haml").to("html").files | |
options: | |
target: "html" | |
jade: | |
options: | |
pretty: yes | |
compile: compile("jade").to("html") | |
for name in require("fs").readdirSync "node_modules" | |
grunt.loadNpmTasks name if /^grunt-/.test name | |
grunt.registerTask "clean", "Remove build dir", -> | |
grunt.file.delete build_path if grunt.file.exists build_path | |
grunt.registerTask "static", "Copy static files", -> | |
patterns = %(static_patterns)s | |
for {src, dest} in grunt.file.expandMapping patterns, build_path, {cwd: source_path, matchBase: yes} | |
grunt.file.copy src, dest | |
grunt.registerTask "server", ["parallel:server"] | |
grunt.registerTask "build", %(build_commands)s | |
grunt.registerTask "default", ["clean", "build", "server"] | |
""" % { | |
"build_commands": json.dumps(build_commands), | |
"static_patterns": json.dumps(static_patterns), | |
"watchers": "\n ".join(watchers) | |
} | |
print "create %s" % os.path.join(options.path, "package.json") | |
with open(os.path.join(options.path, "package.json"), "w") as fp: | |
fp.write(package) | |
print "create %s" % os.path.join(options.path, "Gruntfile.coffee") | |
with open(os.path.join(options.path, "Gruntfile.coffee"), "w") as fp: | |
fp.write(gruntfile) | |
print "make dir %s" % os.path.join(options.path, "source") | |
os.makedirs(os.path.join(options.path, "source")) | |
print "create %s" % os.path.join(options.path, "source", "index.html") | |
with open(os.path.join(options.path, "source", "index.html"), "w") as fp: | |
fp.write("me ur bottom girl!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment