Skip to content
Permalink
Browse files

fix(css imports): add support for css imports

  • Loading branch information
jyounce committed Sep 20, 2015
1 parent bd2b1c1 commit 032f470d9436888ca545b2df9a1d71a1d872e59c
@@ -31,6 +31,7 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config}/config-globs") config
config = require("#{config.req.config}/config-bower") config, options
config = require("#{config.req.config}/config-test") config, options
config = require("#{config.req.config}/config-internal") config

# format
# ======
@@ -0,0 +1,57 @@
module.exports = (config) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
pathHelp = require "#{config.req.helpers}/path"
test = require("#{config.req.helpers}/test")()

# init internal
# =============
internal =
rb:
client:
css:
imports: {} # populated via task
app:
client:
css:
imports: {} # populated via task

# methods
# =======
internal.deleteFileImports = (appOrRb, _path) ->
key = pathHelp.format _path
imports = @[appOrRb].client.css.imports
return unless imports[key]
delete imports[key]

internal.getImports = (negated=false) ->
rbImports = @getImportsAppOrRb 'rb', negated
appImports = @getImportsAppOrRb 'app', negated
imports = [].concat rbImports, appImports

internal.getImportsAppOrRb = (appOrRb, negated=false) ->
imports = @[appOrRb].client.css.imports
return [] unless Object.keys(imports).length
_imports = []
negated = if negated then '!' else ''
for own k1, v1 of imports
continue if not v1.length
for v2 in v1
_imports.push "#{negated}#{v2}"
_imports

# add internal to config
# ======================
config.internal = internal

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

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

# return
# ======
config
@@ -1,7 +1,10 @@
module.exports = (config, gulp) ->
q = require 'q'
lessImports = require 'less-imports'
log = require "#{config.req.helpers}/log"
q = require 'q'
path = require 'path'
log = require "#{config.req.helpers}/log"
pathHelp = require "#{config.req.helpers}/path"
cmtsRegex = /\/\/.*|\/\*\s*?.*?\s*?\*\//g
importRegX = /@import\s*?(?!\s*?\(css\)*?).*?['"]+?(.*?)['"]/g

class Less
# private methods
@@ -22,6 +25,21 @@ module.exports = (config, gulp) ->
isImport = (imports, _path) ->
imports.indexOf(_path) isnt -1

findImports = (file) ->
contents = file.contents
return [] unless contents
contents = contents.toString()
base = file.base
imports = []
contents = contents.replace cmtsRegex, '' # first strip the comments
while (matches = importRegX.exec contents) != null
match = matches[1]
continue if match.indexOf('//') isnt -1
_path = path.resolve base, match
_path = pathHelp.format _path
imports.push _path
imports

# constructor
# ===========
constructor: (@src) ->
@@ -30,17 +48,17 @@ module.exports = (config, gulp) ->

# public methods
# ==============
addImport: (_path) ->
paths = lessImports.findImports _path
addImport: (file) ->
paths = findImports file
return @ if not paths.length
@files[_path] = paths
@files[file.path] = paths
@

setImports: ->
defer = q.defer()
gulp.src @src, read:false
gulp.src @src
.on 'data', (file) =>
@addImport file.path
@addImport file
.on 'end', =>
defer.resolve @
defer.promise
@@ -0,0 +1,16 @@
module.exports = (config) ->
q = require 'q'
fse = require 'fs-extra'
promiseHelp = require "#{config.req.helpers}/promise"

buildFile: (build=true, msg='built') ->
return promiseHelp.get() unless build
msg = 'rebuilt' if msg isnt 'built'
defer = q.defer()
format = spaces: '\t'
configFile = config.templates.config.dest.path
fse.writeJson configFile, config, format, (e) ->
console.log "#{msg} config.json".yellow
defer.resolve()
defer.promise

@@ -5,93 +5,97 @@
module.exports = (gulp, config) ->
# browser
# =======
bs = require("#{config.req.tasks}/browser/browser-sync") gulp, config # browser-sync
require("#{config.req.tasks}/browser/open-browser") gulp, config # open-browser
bs = require("#{config.req.tasks}/browser/browser-sync") gulp, config # browser-sync
require("#{config.req.tasks}/browser/open-browser") gulp, config # open-browser

# build
# =====
require("#{config.req.tasks}/build/build-angular-modules") gulp, config # build-angular-modules
require("#{config.req.tasks}/build/build-bower-json") gulp, config # build-bower-json
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-prod-files") gulp, config # build-prod-files
require("#{config.req.tasks}/build/build-prod-files-blueprint") gulp, config # build-prod-files-blueprint
require("#{config.req.tasks}/build/build-spa") gulp, config # build-spa
require("#{config.req.tasks}/build/build-angular-modules") gulp, config # build-angular-modules
require("#{config.req.tasks}/build/build-bower-json") gulp, config # build-bower-json
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-prod-files") gulp, config # build-prod-files
require("#{config.req.tasks}/build/build-prod-files-blueprint") gulp, config # build-prod-files-blueprint
require("#{config.req.tasks}/build/build-spa") gulp, config # build-spa

# clean
# =====
require("#{config.req.tasks}/clean/clean-config") gulp, config # clean-config
require("#{config.req.tasks}/clean/clean-dist") gulp, config # clean-dist
require("#{config.req.tasks}/clean/clean-files") gulp, config # clean-files
require("#{config.req.tasks}/clean/cleanup-client") gulp, config # cleanup-client
require("#{config.req.tasks}/clean/clean-config") gulp, config # clean-config
require("#{config.req.tasks}/clean/clean-dist") gulp, config # clean-dist
require("#{config.req.tasks}/clean/clean-files") gulp, config # clean-files
require("#{config.req.tasks}/clean/cleanup-client") gulp, config # cleanup-client

# common
# ======
require("#{config.req.tasks}/common") gulp, config # common
require("#{config.req.tasks}/common") gulp, config # common

# compile
# =======
require("#{config.req.tasks}/compile/coffee") gulp, config # coffee
require("#{config.req.tasks}/compile/es6") gulp, config # es6
require("#{config.req.tasks}/compile/less") gulp, config # less
require("#{config.req.tasks}/compile/coffee") gulp, config # coffee
require("#{config.req.tasks}/compile/es6") gulp, config # es6
require("#{config.req.tasks}/compile/less") gulp, config # less

# config
# ======
require("#{config.req.tasks}/config/update-config") gulp, config # update-config
require("#{config.req.tasks}/config/update-config") gulp, config # update-config

# copy
# ====
require("#{config.req.tasks}/copy/copy-bower_components") gulp, config # copy-bower_components
require("#{config.req.tasks}/copy/copy-css") gulp, config # copy-css
require("#{config.req.tasks}/copy/copy-extra-files") gulp, config # copy-extra-files
require("#{config.req.tasks}/copy/copy-html") gulp, config # copy-html
require("#{config.req.tasks}/copy/copy-images") gulp, config # copy-images
require("#{config.req.tasks}/copy/copy-js") gulp, config # copy-js
require("#{config.req.tasks}/copy/copy-libs") gulp, config # copy-libs
require("#{config.req.tasks}/copy/copy-server-config") gulp, config # copy-server-config
require("#{config.req.tasks}/copy/copy-server-node_modules") gulp, config # copy-server-node_modules
require("#{config.req.tasks}/copy/copy-views") gulp, config # copy-views
require("#{config.req.tasks}/copy/copy-bower_components") gulp, config # copy-bower_components
require("#{config.req.tasks}/copy/copy-css") gulp, config # copy-css
require("#{config.req.tasks}/copy/copy-extra-files") gulp, config # copy-extra-files
require("#{config.req.tasks}/copy/copy-html") gulp, config # copy-html
require("#{config.req.tasks}/copy/copy-images") gulp, config # copy-images
require("#{config.req.tasks}/copy/copy-js") gulp, config # copy-js
require("#{config.req.tasks}/copy/copy-libs") gulp, config # copy-libs
require("#{config.req.tasks}/copy/copy-server-config") gulp, config # copy-server-config
require("#{config.req.tasks}/copy/copy-server-node_modules") gulp, config # copy-server-node_modules
require("#{config.req.tasks}/copy/copy-views") gulp, config # copy-views

# format
# ======
require("#{config.req.tasks}/format/absolute-css-urls") gulp, config # absolute-css-urls

# manage
# ======
require("#{config.req.tasks}/manage/bower") gulp, config # bower
require("#{config.req.tasks}/manage/bower") gulp, config # bower

# minify
# ======
require("#{config.req.tasks}/minify/cache-bust") gulp, config # cache-bust
require("#{config.req.tasks}/minify/concat-scripts-and-styles") gulp, config # concat-scripts-and-styles
require("#{config.req.tasks}/minify/css-file-split") gulp, config # css-file-split
require("#{config.req.tasks}/minify/minify-client") gulp, config # minify-client
require("#{config.req.tasks}/minify/minify-css") gulp, config # minify-css
require("#{config.req.tasks}/minify/minify-html") gulp, config # minify-html
require("#{config.req.tasks}/minify/minify-images") gulp, config # minify-images
require("#{config.req.tasks}/minify/minify-js") gulp, config # minify-js
require("#{config.req.tasks}/minify/minify-server") gulp, config # minify-server
require("#{config.req.tasks}/minify/minify-spa") gulp, config # minify-spa
require("#{config.req.tasks}/minify/relative-to-absolute-css-urls") gulp, config # relative-to-absolute-css-urls
require("#{config.req.tasks}/minify/template-cache") gulp, config # template-cache
require("#{config.req.tasks}/minify/cache-bust") gulp, config # cache-bust
require("#{config.req.tasks}/minify/concat-scripts-and-styles") gulp, config # concat-scripts-and-styles
require("#{config.req.tasks}/minify/css-file-split") gulp, config # css-file-split
require("#{config.req.tasks}/minify/inline-css-imports") gulp, config # inline-css-imports
require("#{config.req.tasks}/minify/minify-client") gulp, config # minify-client
require("#{config.req.tasks}/minify/minify-css") gulp, config # minify-css
require("#{config.req.tasks}/minify/minify-html") gulp, config # minify-html
require("#{config.req.tasks}/minify/minify-images") gulp, config # minify-images
require("#{config.req.tasks}/minify/minify-js") gulp, config # minify-js
require("#{config.req.tasks}/minify/minify-server") gulp, config # minify-server
require("#{config.req.tasks}/minify/minify-spa") gulp, config # minify-spa
require("#{config.req.tasks}/minify/template-cache") gulp, config # template-cache

# server
# ======
require("#{config.req.tasks}/server/find-open-port") gulp, config # find-open-port
require("#{config.req.tasks}/server/start-server") gulp, config # start-server
require("#{config.req.tasks}/server/spawn-server") gulp, config # spawn-server
require("#{config.req.tasks}/server/nodemon") gulp, config, bs # nodemon
require("#{config.req.tasks}/server/find-open-port") gulp, config # find-open-port
require("#{config.req.tasks}/server/start-server") gulp, config # start-server
require("#{config.req.tasks}/server/spawn-server") gulp, config # spawn-server
require("#{config.req.tasks}/server/nodemon") gulp, config, bs # nodemon

# test
# ====
require("#{config.req.tasks}/test/build-inject-angular-mocks") gulp, config # build-inject-angular-mocks
require("#{config.req.tasks}/test/build-test-files") gulp, config # build-test-files
require("#{config.req.tasks}/test/clean-rb-test-src") gulp, config # clean-rb-test-src
require("#{config.req.tasks}/test/clean-test-dist") gulp, config # clean-test-dist
require("#{config.req.tasks}/test/common-test") gulp, config # common-test
require("#{config.req.tasks}/test/copy-angular-mocks") gulp, config # copy-angular-mocks
require("#{config.req.tasks}/test/copy-tests") gulp, config # copy-tests
require("#{config.req.tasks}/test/run-tests") gulp, config # run-tests
require("#{config.req.tasks}/test/build-inject-angular-mocks") gulp, config # build-inject-angular-mocks
require("#{config.req.tasks}/test/build-test-files") gulp, config # build-test-files
require("#{config.req.tasks}/test/clean-rb-test-src") gulp, config # clean-rb-test-src
require("#{config.req.tasks}/test/clean-test-dist") gulp, config # clean-test-dist
require("#{config.req.tasks}/test/common-test") gulp, config # common-test
require("#{config.req.tasks}/test/copy-angular-mocks") gulp, config # copy-angular-mocks
require("#{config.req.tasks}/test/copy-tests") gulp, config # copy-tests
require("#{config.req.tasks}/test/run-tests") gulp, config # run-tests

# watch
# =====
require("#{config.req.tasks}/watch/watch") gulp, config, bs # watch
require("#{config.req.tasks}/watch/watch-build-spa") gulp, config # watch-build-spa
require("#{config.req.tasks}/watch/watch") gulp, config, bs # watch
require("#{config.req.tasks}/watch/watch-build-spa") gulp, config # watch-build-spa


@@ -28,7 +28,7 @@
"prepend-file": "1.3.0"
},
"dependencies": {
"body-parser": "1.13.3",
"body-parser": "1.14.0",
"bower": "1.5.2",
"browser-sync": "2.9.3",
"coffee-script": "1.10.0",
@@ -71,8 +71,10 @@
"karma-ie-launcher": "0.2.0",
"karma-phantomjs-launcher": "0.2.1",
"karma-safari-launcher": "0.1.1",
"less-imports": "1.1.0",
"lodash": "3.10.1",
"open": "0.0.5",
"postcss": "5.0.5",
"postcss-import": "7.0.0",
"q": "1.4.1",
"through2": "2.0.0"
},

0 comments on commit 032f470

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