Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

validators

  • Loading branch information...
commit ce5ba051468ac2dd8d6fb4fef3c32bd59821c6ba 1 parent 87a4a1b
authored

Showing 2 changed files with 30 additions and 66 deletions. Show diff stats Hide diff stats

  1. 94  config.coffee
  2. 2  package.json
94  config.coffee
... ...
@@ -1,10 +1,7 @@
1 1
 "use strict"
2 2
 
3  
-path = require 'path'
4 3
 fs = require 'fs'
5 4
 
6  
-windowsDrive = /^[A-Za-z]:\\/
7  
-
8 5
 exports.defaults = ->
9 6
   importSource:
10 7
     copy:[]
@@ -19,75 +16,42 @@ exports.placeholder = ->
19 16
 
20 17
   """
21 18
 
22  
-exports.validate = (config) ->
  19
+exports.validate = (config, validators) ->
23 20
   errors = []
24 21
 
25  
-  if config.importSource?
26  
-    importSource = config.importSource
27  
-    if typeof importSource is "object" and not Array.isArray(importSource)
28  
-      if importSource.copy?
29  
-        copies = importSource.copy
30  
-        if Array.isArray(copies)
31  
-          for c in copies
32  
-            if typeof c is "object" and not Array.isArray(c)
33  
-
34  
-              if c.from?
35  
-                if typeof c.from is "string"
36  
-                  fromPath = __determinePath c.from, config.root
37  
-                  if fs.existsSync fromPath
38  
-                    stat = fs.statSync fromPath
39  
-                    c.from = fromPath
40  
-                    c.isDirectory = stat.isDirectory()
41  
-                  else
42  
-                    errors.push "importSource.copy.from [[ #{c.from} ]] must exist."
  22
+  if validators.ifExistsIsObject(errors, "importSource config", config.importSource)
  23
+    if config.importSource.copy?
  24
+      if validators.isArray(errors, "importSource.copy", config.importSource.copy)
  25
+        for c in config.importSource.copy
  26
+          if typeof c is "object" and not Array.isArray(c)
  27
+
  28
+            if c.from?
  29
+              if typeof c.from is "string"
  30
+                fromPath = validators.determinePath c.from, config.root
  31
+                if fs.existsSync fromPath
  32
+                  stat = fs.statSync fromPath
  33
+                  c.from = fromPath
  34
+                  c.isDirectory = stat.isDirectory()
43 35
                 else
44  
-                  errors.push "importSource.copy.from must be a string."
  36
+                  errors.push "importSource.copy.from [[ #{c.from} ]] must exist."
45 37
               else
46  
-                errors.push "importSource.copy entries must have a from property."
  38
+                errors.push "importSource.copy.from must be a string."
  39
+            else
  40
+              errors.push "importSource.copy entries must have a from property."
47 41
 
48  
-              if c.to?
49  
-                if typeof c.to is "string"
50  
-                  c.to = __determinePath c.to, config.root
51  
-                else
52  
-                  errors.push "importSource.copy.to must be a string."
  42
+            if c.to?
  43
+              if typeof c.to is "string"
  44
+                c.to = validators.determinePath c.to, config.root
53 45
               else
54  
-                errors.push "importSource.copy entries must have a to property."
55  
-
56  
-              if c.from?
57  
-                if c.exclude?
58  
-                  if Array.isArray(c.exclude)
59  
-                    regexes = []
60  
-                    newExclude = []
61  
-                    for exclude in c.exclude
62  
-                      if typeof exclude is "string"
63  
-                        newExclude.push __determinePath exclude, c.from
64  
-                      else if exclude instanceof RegExp
65  
-                        regexes.push exclude.source
66  
-                      else
67  
-                        errors.push "importSource.copy.exclude must be an array of strings and/or regexes."
68  
-                        break
69  
-
70  
-                    if regexes.length > 0
71  
-                      c.excludeRegex = new RegExp regexes.join("|"), "i"
72  
-
73  
-                    c.exclude = newExclude
74  
-                  else
75  
-                    errors.push "importSource.copy.exclude must be an array."
76  
-                else
77  
-                  c.excludeRegex = new RegExp /(^[.#]|(?:__|~)$)/
78  
-
  46
+                errors.push "importSource.copy.to must be a string."
79 47
             else
80  
-              errors.push "importSource.copy must be an array of objects"
81  
-              break
82  
-        else
83  
-          errors.push "importSource.copy must be an array"
84  
-    else
85  
-      errors.push "importSource config must be an object."
  48
+              errors.push "importSource.copy entries must have a to property."
86 49
 
87  
-  errors
  50
+            if c.from?
  51
+              validators.ifExistsFileExcludeWithRegexAndString(errors, "importSource.copy.exclude", c, c.from)
88 52
 
  53
+          else
  54
+            errors.push "importSource.copy must be an array of objects"
  55
+            break
89 56
 
90  
-__determinePath = (thePath, relativeTo) ->
91  
-  return thePath if windowsDrive.test thePath
92  
-  return thePath if thePath.indexOf("/") is 0
93  
-  path.join relativeTo, thePath
  57
+  errors
2  package.json
... ...
@@ -1,7 +1,7 @@
1 1
 {
2 2
   "name": "mimosa-import-source",
3 3
   "preferGlobal": "false",
4  
-  "version": "0.1.2",
  4
+  "version": "0.2.0",
5 5
   "homepage": "https://github.com/dbashford/mimosa-import-source",
6 6
   "author": "David Bashford",
7 7
   "description": "Mimosa module for copying files into the project before building starts",

0 notes on commit ce5ba05

Please sign in to comment.
Something went wrong with that request. Please try again.