Skip to content
Permalink
Browse files

feat(config): add angular option to change the module name and add ad…

…ditional modules
  • Loading branch information
jyounce committed Jun 5, 2015
1 parent fca562f commit aeaa8c1b841e8816b2628c39e783fc2b635891d0
@@ -46,22 +46,27 @@ gulp rapid-build:prod
##### Config Documentation - (better documentation coming soon)
```coffeescript
# CONFIG API (optional): config is an object
# dist.dir = (string) defaults to 'dist'
# dist.client.dir = (string) defaults to 'client'
# dist.client[images|libs|scripts|styles|views].dir = (string) defaults to property name
# dist.client.spa.file = (string) defaults to 'spa.html'
# dist.server.dir = (string) defaults to 'server'
# dist.server.file = (string) defaults to 'routes.js'
# src.dir = (string) defaults to 'src'
# src.client.dir = (string) defaults to 'client'
# src.client[images|libs|scripts|styles|views].dir = (string) defaults to property name
# src.server.dir = (string) defaults to 'server'
# ports.server = (int) defaults to 3000
# ports.reload = (int) defaults to 3001
# order[scripts|styles][first|last] = (array of strings) file paths
# angular.templateCache.dev.enable = (boolean) defaults to false
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false
# ======================================================================================
# dist.dir = (string) defaults to 'dist'
# dist.client.dir = (string) defaults to 'client'
# dist.client[images|libs|scripts|styles|views].dir = (string) defaults to property name
# dist.client.spa.file = (string) defaults to 'spa.html'
# dist.server.dir = (string) defaults to 'server'
# dist.server.file = (string) defaults to 'routes.js'
# src.dir = (string) defaults to 'src'
# src.client.dir = (string) defaults to 'client'
# src.client[images|libs|scripts|styles|views].dir = (string) defaults to property name
# src.server.dir = (string) defaults to 'server'
# ports.server = (int) defaults to 3000
# ports.reload = (int) defaults to 3001
# order[scripts|styles][first|last] = (array of strings) = file paths
# angular.modules = (array of strings) = additional angular modules to load, already loaded are ['ngAnimate', 'ngResource', 'ngRoute', 'ngSanitize']
# angular.version = (string) defaults to '1.x' = semver version required
# angular.moduleName = (string) defaults to 'app' = application module name, value for ng-app
# angular.templateCache.dev.enable = (boolean) defaults to false = use template cache when running default and dev task
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false = prefix template urls with a '/'
# spaFile.title = (string) defaults to package.json name or 'Application'
# spaFile.description = (string) defaults to package.json description
# =====================================================================================================================================================================================
```


@@ -6,36 +6,28 @@ module.exports = (rbDir, options) ->
config = {}
config.env = {} # declare here so it will show up first

# require
# =======
req =
rb: rbDir
config: "#{rbDir}/config"
files: "#{rbDir}/files"
helpers: "#{rbDir}/helpers"
init: "#{rbDir}/init"
tasks: "#{rbDir}/tasks"

config.req = req

# get config in order
# ===================
config = require("#{rbDir}/config/config-req") config, rbDir
options = require("#{config.req.config}/config-options") config, options
config = require("#{config.req.config}/config-env") config
config = require("#{config.req.config}/config-rb") config, rbDir
config = require("#{config.req.config}/config-app") config, options
config = require("#{config.req.config}/config-spa-file") config, options
config = require("#{config.req.config}/config-file-names") config
config = require("#{config.req.config}/config-angular") config, options
config = require("#{config.req.config}/config-dist-and-src") config, options
config = require("#{config.req.config}/config-templates") config
config = require("#{config.req.config}/config-temp") config
config = require("#{config.req.config}/config-node_modules") config
config = require("#{config.req.config}/config-angular") config, options
config = require("#{config.req.config}/config-order") config, options
config = require("#{config.req.config}/config-globs") config
config = require("#{config.req.config}/config-json") config
config = require("#{config.req.config}/config-bower") config, options

# format
# ======
req = config.req
delete config.req # so req will show up last
config.req = req

@@ -2,13 +2,18 @@ module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# default modules
# ===============
modules = ['ngAnimate', 'ngResource', 'ngRoute', 'ngSanitize']

# init angular
# ============
angular = {}

# modules
# =======
angular.modules = options.angular.modules or []
angular.modules = modules.concat angular.modules

# version
# =======
@@ -5,7 +5,7 @@ module.exports = (config, options) ->
# init app
# ========
app = {}
app.dir = process.cwd()
app.dir = config.req.app

# ports
# =====
@@ -13,11 +13,13 @@
# ports.reload = (int) defaults to 3001
# order[scripts|styles][first|last] = (array) expects file paths
# angular.modules = (array) additional angular modules
# angular.version = (string) defaults to '1.4.x'
# angular.version = (string) defaults to '1.x'
# angular.moduleName = (string) application module name
# angular.templateCache.dev.enable = (boolean) defaults to false
# angular.templateCache.useAbsolutePaths = (boolean) defaults to false
# ========================================================================================
# spaFile.title = (string) defaults to package.json name
# spaFile.description = (string) defaults to package.json description
# ==================================================================================================
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
isType = require "#{config.req.helpers}/isType"
@@ -69,11 +71,17 @@ module.exports = (config, options) ->
options.angular.templateCache.dev = {} if not isType.object options.angular.templateCache.dev
options.angular.templateCache.dev.enable = null if not isType.boolean options.angular.templateCache.dev.enable

formatSpaFileOptions = ->
options.spaFile = {} if not isType.object options.spaFile
options.spaFile.title = null if not isType.string options.spaFile.title
options.spaFile.description = null if not isType.string options.spaFile.description

formatOptions()
formatServerOptions()
formatPortOptions()
formatAngularOptions()
formatOrderOptions()
formatAngularOptions()
formatSpaFileOptions()

# logs
# ====
@@ -0,0 +1,25 @@
module.exports = (config, rbDir) ->
# init req
# ========
req =
rb: rbDir
app: process.cwd()
config: "#{rbDir}/config"
files: "#{rbDir}/files"
helpers: "#{rbDir}/helpers"
init: "#{rbDir}/init"
tasks: "#{rbDir}/tasks"

# add req to config
# =================
config.req = req

# logs
# ====
# console.log req, 'req ='

# return
# ======
config


@@ -0,0 +1,28 @@
module.exports = (config, options) ->
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()
pkg = require "#{config.req.app}/package.json"

# init spaFile
# ============
spaFile = {}
spaFile.title = options.spaFile.title or pkg.name or 'Application'
spaFile.description = options.spaFile.description or pkg.description or null

# add spaFile to config
# =====================
config.spaFile = spaFile

# logs
# ====
# log.json spaFile, 'spaFile ='

# tests
# =====
test.log 'true', config.spaFile, 'add spaFile to config'

# return
# ======
config


@@ -0,0 +1,35 @@
# todo: move all templates to here
# ================================
module.exports = (config) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# init templates
# ==============
templates = {}
templates.dir = path.join config.rb.dir, 'templates'
templates.angularModules =
src:
path: path.join templates.dir, 'angular-modules.tpl'
dest:
file: 'app.coffee'
dir: path.join config.src.rb.client.scripts.dir

# add templates to config
# =======================
config.templates = templates

# logs
# ====
# log.json templates, 'templates ='

# tests
# =====
test.log 'true', config.templates, 'add templates to config'

# return
# ======
config


@@ -10,6 +10,7 @@ module.exports = (gulp, config) ->

# build
# =====
require("#{config.req.tasks}/build/build-angular-modules") gulp, config # build-angular-modules
require("#{config.req.tasks}/build/build-config") gulp, config # build-config
require("#{config.req.tasks}/build/build-files") gulp, config # build-files
require("#{config.req.tasks}/build/build-files-prod") gulp, config # build-files-prod
No changes.

This file was deleted.

@@ -1,26 +1,26 @@
<!doctype html>
<html xmlns:ng="http://angularjs.org" xmlns:app="ignored" <% if (typeof appName === 'undefined') { %>ng-app="app"<% } else { %><% if (!!appName) { %>ng-app="<%= appName %>"<% } %><% } %>>
<html xmlns:ng="http://angularjs.org" xmlns:app="ignored" ng-app="<%= moduleName %>">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Rapid Build</title>
<meta name="description" content="AngularJS Reference Architecture" />
<title><%= title %></title>
<meta name="description" content="<%= description %>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<!-- ClickJacking Defense begin (https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet) -->
<style id="antiClickjack">body{display:none !important;}</style>
<script>(function(w){if(w.top===w.self){var a=w.document.getElementById('antiClickjack');a.parentNode.removeChild(a);}else{w.top.location=w.self.location;}}(window));</script>
<!-- ClickJacking Defense end -->

<% _.forEach(styles, function (style) { %><link rel="stylesheet" href="<%= style %>" />
<% _.forEach(styles, function(style) { %><link rel="stylesheet" href="<%= style %>" />
<% }); %>
<!-- When you load angular at the bottom, you need to create the "ng-cloak" rules yourself -->
<style>[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak{display:none;}ng\:form{display:block;}</style>
</head>
<body ng-cloak class="ng-cloak">
<div ng-view></div>

<% _.forEach(scripts, function (script) { %><script src="<%= script %>"></script>
<% _.forEach(scripts, function(script) { %><script src="<%= script %>"></script>
<% }); %>
</body>
</html>
@@ -0,0 +1,36 @@
module.exports = (gulp, config) ->
q = require 'q'
rename = require 'gulp-rename'
template = require 'gulp-template'

# task
# ====
runTask = (src, dest, file, data={}) ->
defer = q.defer()
gulp.src src
.pipe rename file
.pipe template data
.pipe gulp.dest dest
.on 'end', ->
# console.log 'app.coffee built'.yellow
defer.resolve()
defer.promise

# helpers
# =======
getData = ->
data =
modules: config.angular.modules
moduleName: config.angular.moduleName

# register task
# =============
gulp.task "#{config.rb.prefix.task}build-angular-modules", ->
data = getData()
runTask(
config.templates.angularModules.src.path
config.templates.angularModules.dest.dir
config.templates.angularModules.dest.file
data
)

@@ -16,15 +16,30 @@ module.exports = (gulp, config) ->
defer.resolve()
defer.promise

# register task
# =============
gulp.task "#{config.rb.prefix.task}build-spa", ->
# helpers
# =======
getFilesJson = ->
moduleHelp.cache.delete config.json.files.path
files = require(config.json.files.path).client
files = pathHelp.removeLocPartial files, config.dist.app.client.dir
files

getData = ->
files = getFilesJson()
data =
scripts: files.scripts
styles: files.styles
moduleName: config.angular.moduleName
title: config.spaFile.title
description: config.spaFile.description

# register task
# =============
gulp.task "#{config.rb.prefix.task}build-spa", ->
data = getData()
runTask(
config.src.rb.client.spa.path
config.dist.app.client.dir
files
data
)

@@ -9,6 +9,7 @@ module.exports = (gulp, config) ->
"#{config.rb.prefix.task}bower"
"#{config.rb.prefix.task}clean-dist"
"#{config.rb.prefix.task}build-config"
"#{config.rb.prefix.task}build-angular-modules"
[
"#{config.rb.prefix.task}copy-css"
"#{config.rb.prefix.task}copy-views"
@@ -42,7 +42,7 @@ module.exports = (gulp, config, watchFile={}) ->
defer = q.defer()
opts = {}
opts.root = '/' if config.angular.templateCache.useAbsolutePaths
opts.module = 'app'
opts.module = config.angular.moduleName
gulp.src src
.pipe addToDistPath()
.pipe gulpif isProd, minifyHtml()
@@ -0,0 +1,6 @@
# Do not check this file in.
# It gets generated from /templates/angular-modules.tpl
# =====================================================
angular.module '<%= moduleName %>', [<% _.forEach(modules, function(module) { %>
'<%= module %>'<% }); %>
]

0 comments on commit aeaa8c1

Please sign in to comment.
You can’t perform that action at this time.