-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build option): add build option dist.paths.absolute (defaults to…
… true) set to false to create relative urls, see build options doc for more info
- Loading branch information
Showing
18 changed files
with
182 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,80 @@ | |||
module.exports = (config, gulp, taskOpts={}) -> | |||
q = require 'q' | |||
path = require 'path' | |||
log = require "#{config.req.helpers}/log" | |||
pathHelp = require "#{config.req.helpers}/path" | |||
promiseHelp = require "#{config.req.helpers}/promise" | |||
urlRegX = /url\s*\(\s*['"]?(.*?)['"]?\s*\)(?![^\*]*?\*\/)/g | |||
importNoUrlRegX = /@import\s*?['"]+?(.*?)['"]+?(?![^\*]*?\*\/)/g | |||
forWatchFile = !!taskOpts.watchFilePath | |||
|
|||
# constants | |||
# ========= | |||
CLIENT_DIST_ROOT = path.join config.app.dir, config.dist.app.client.dir | |||
|
|||
# helpers | |||
# ======= | |||
getRelativePath = (cssPath, absPath) -> | |||
relPath = path.relative cssPath, absPath | |||
# for windows | |||
relPath = path.normalize relPath | |||
relPath = pathHelp.swapBackslashes relPath | |||
|
|||
findAndReplace = (css, cssPath, regX) -> | |||
css.replace regX, (match, urlPath) -> | |||
isAbsolute = urlPath[0] is '/' | |||
return match unless isAbsolute | |||
absPath = path.join CLIENT_DIST_ROOT, urlPath | |||
relPath = getRelativePath cssPath, absPath | |||
relUrl = match.replace urlPath, relPath | |||
# log.task relUrl, 'minor' | |||
return relUrl | |||
|
|||
# tasks | |||
# ===== | |||
runTask = (appOrRb, type, opts={}) -> | |||
defer = q.defer() | |||
src = opts.single if opts.single | |||
base = if opts.single then config.dist.app.client.styles.dir else null | |||
src = config.glob.dist[appOrRb].client[type][opts.glob] if opts.glob | |||
dest = config.dist[appOrRb].client[type].dir | |||
gulp.src src, { base } | |||
.on 'data', (file) -> | |||
css = file.contents | |||
return unless css | |||
css = css.toString() | |||
cssPath = path.dirname file.path # css file directory path | |||
css = findAndReplace css, cssPath, urlRegX # match = url('/images/x.png') | |||
css = findAndReplace css, cssPath, importNoUrlRegX # match = @import '/imports/x.css' | |||
file.contents = new Buffer css | |||
.pipe gulp.dest dest | |||
.on 'end', -> | |||
defer.resolve() | |||
defer.promise | |||
|
|||
# API | |||
# === | |||
api = | |||
runSingle: -> # for watch | |||
runTask 'app', 'styles', single: taskOpts.watchFilePath | |||
|
|||
runMulti: (env) -> # async | |||
defer = q.defer() | |||
q.all([ | |||
runTask 'rb', 'bower', glob: 'css' | |||
runTask 'rb', 'libs', glob: 'css' | |||
runTask 'rb', 'styles', glob: 'all' | |||
runTask 'app', 'bower', glob: 'css' | |||
runTask 'app', 'libs', glob: 'css' | |||
runTask 'app', 'styles', glob: 'all' | |||
]).done -> | |||
log.task 'changed all css urls to relative' | |||
defer.resolve() | |||
defer.promise | |||
|
|||
# return | |||
# ====== | |||
return api.runSingle() if forWatchFile | |||
api.runMulti taskOpts.env | |||
|
|||
|
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
module.exports = (config, gulp, taskOpts={}) -> | |||
q = require 'q' | |||
log = require "#{config.req.helpers}/log" | |||
promiseHelp = require "#{config.req.helpers}/promise" | |||
taskHelp = require("#{config.req.helpers}/tasks") config, gulp | |||
|
|||
# API | |||
# === | |||
api = | |||
runTask: -> # synchronously | |||
return promiseHelp.get() unless config.build.client | |||
calledFromMinTask = taskOpts.calledFrom is 'minify-task' | |||
skipInCommonTask = config.env.is.prod and not calledFromMinTask | |||
defer = q.defer() | |||
tasks = [ | |||
-> # only run in common-client task | |||
return promiseHelp.get() if calledFromMinTask | |||
taskHelp.startTask '/format/absolute-css-urls', taskOpts | |||
|
|||
-> # skip in common-client task if prod build | |||
return promiseHelp.get() if config.dist.client.paths.absolute | |||
return promiseHelp.get() if skipInCommonTask | |||
taskHelp.startTask '/format/relative-css-urls', taskOpts | |||
] | |||
tasks.reduce(q.when, q()).done -> | |||
# log.task 'updated css urls', 'minor' | |||
defer.resolve() | |||
defer.promise | |||
|
|||
# return | |||
# ====== | |||
api.runTask() | |||
|
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
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