+122
-56
@@ -75,8 +75,23 @@ #!/usr/bin/env node | ||
| isFileMatch = (path, link, wex, p) -> | ||
| match = path.match link | ||
| match and match.index is 0 and wex is Path.join match[0], p | ||
| getParentFiles = (file) -> | ||
| return false unless file.requires | ||
| res = [] | ||
| if r = requiredFile[file.pathWithoutExt] | ||
| for path of r | ||
| res.push files[path] | ||
| path = file.path | ||
| type = file.type | ||
| ext = file.ext | ||
| wex = file.pathWithoutExt | ||
| for r, a of requiredFile | ||
| for p, o of a | ||
| f = files[p] | ||
| if f.type is type | ||
| if wex is o.rel | ||
| res.push f | ||
| else | ||
| if link = f.link | ||
| if isFileMatch path, link, wex, o.path | ||
| res.push f | ||
| getParentFilesInDirs file.dir, file.type, res | ||
@@ -95,9 +110,3 @@ res.length and res or false | ||
| # file functions | ||
| getFileRule = (path) -> | ||
| for from, rule of rules | ||
| if 0 is path.indexOf from | ||
| return rule | ||
| false | ||
| addFile = (path, rule) -> | ||
| addFile = (path, rule, skip) -> | ||
| split = path.split '/' | ||
@@ -117,2 +126,3 @@ dirPath = split.slice(0, -1).join '/' | ||
| files[path] = dir.files[path] = file = | ||
| base: dirPath.slice skip | ||
| path: path | ||
@@ -134,2 +144,3 @@ dir: dir | ||
| file.requires = handler.requires | ||
| file.link = rule.link | ||
| parse file | ||
@@ -140,6 +151,8 @@ return file | ||
| addFileFromStream = (path, stat) -> | ||
| if rule = getFileRule path | ||
| if file = addFile path, rule | ||
| file.stat = stat | ||
| return file | ||
| for from, rule of rules | ||
| match = path.match rule.patt | ||
| if match and match.index is 0 | ||
| if file = addFile path, rule, match[0].length + 1 | ||
| file.stat = stat | ||
| return file | ||
| false | ||
@@ -158,4 +171,4 @@ | ||
| dirPath = file.dir.path | ||
| for r in requires | ||
| if r = r.match /require(\S*)\s*(\S*)/ | ||
| for line in requires | ||
| if r = line.match /require(\S*)\s*(\S*)/ | ||
| switch r[1] | ||
@@ -176,6 +189,10 @@ when '_self' | ||
| when '' | ||
| p = Path.join dirPath, r[2] | ||
| requiredFile[p] = {} unless requiredFile[p] | ||
| requiredFile[p][path] = true | ||
| order.push type: 'file', path: p | ||
| r = r[2] | ||
| requiredFile[r] = {} unless requiredFile[r] | ||
| requiredFile[r][path] = | ||
| rel: rel = Path.join dirPath, r | ||
| path: p = Path.join(file.base, r) | ||
| order.push type: 'file', path: p, rel: rel, original: r | ||
| else if ~line.indexOf 'save' | ||
| file.save = true | ||
| order.push type: 'self' unless selfRequired | ||
@@ -229,19 +246,34 @@ file | ||
| when 'dir' | ||
| if dir = dirs[o.path] | ||
| res = getDirContent dir, type | ||
| return false if res is false | ||
| content += res | ||
| unless dir = dirs[o.path] | ||
| return false | ||
| res = getDirContent dir, type | ||
| return false if res is false | ||
| content += res | ||
| when 'tree' | ||
| if dir = dirs[o.path] | ||
| res = getTreeContent dir, type | ||
| return false if res is false | ||
| content += res | ||
| unless dir = dirs[o.path] | ||
| return false | ||
| res = getTreeContent dir, type | ||
| return false if res is false | ||
| content += res | ||
| when 'file' | ||
| p = o.path | ||
| rel = o.rel | ||
| finded = false | ||
| for _, f of files | ||
| if f.pathWithoutExt is p | ||
| if f.pathWithoutExt is rel | ||
| res = getContent f | ||
| return false if res is false | ||
| content += res + '\n' | ||
| finded = true | ||
| break | ||
| if finded is false | ||
| if link = file.link | ||
| p = o.path | ||
| for path, f of files | ||
| if isFileMatch path, link, f.pathWithoutExt, p | ||
| res = getContent f | ||
| return false if res is false | ||
| content += res + '\n' | ||
| finded = true | ||
| break | ||
| return false if finded is false | ||
| content | ||
@@ -279,7 +311,7 @@ else | ||
| saveParents parentFiles | ||
| saveRoot file if file.save | ||
| else | ||
| saveRoot file | ||
| change = (file) -> | ||
| delete file.self | ||
| clearDeps = (file) -> | ||
| if order = file.order | ||
@@ -294,3 +326,8 @@ path = file.path | ||
| when 'file' | ||
| removeRequire requiredFile, o.path, path | ||
| removeRequire requiredFile, o.original, path | ||
| change = (file) -> | ||
| delete file.self | ||
| file.save = false | ||
| clearDeps file | ||
| save parse file | ||
@@ -329,2 +366,3 @@ | ||
| saveParents parentFiles | ||
| saveRoot part if part.save | ||
| break | ||
@@ -350,14 +388,16 @@ for path of saving | ||
| if comment = not comment | ||
| if requires = content.slice(a, b).match /^=\s*require(_self|(_tree|_dir|)\s*[^\s]*)/gm | ||
| if requires = content.slice(a, b).match /^=\s*(save|require(_self|(_tree|_dir|)\s*[^\s]*))/gm | ||
| ret.push r for r in requires | ||
| a = b + 3 | ||
| if requires = content.match /^\s*#=\s*require(_self|(_tree|_dir|)\s*[^\s]*)/gm | ||
| if requires = content.match /^\s*#=\s*(save|require(_self|(_tree|_dir|)\s*[^\s]*))/gm | ||
| ret.push r for r in requires | ||
| star: (content, ret) -> | ||
| if requires = content.match /^\s*\*=\s*require(_self|(_tree|_dir|)\s*[^\s]*)/gm | ||
| if requires = content.match /^\s*\*=\s*(save|require(_self|(_tree|_dir|)\s*[^\s]*))/gm | ||
| ret.push r for r in requires | ||
| slash: (content, ret) -> | ||
| if requires = content.match /^\s*\/\/=\s*require(_self|(_tree|_dir|)\s*[^\s]*)/gm | ||
| if requires = content.match /^\s*\/\/=\s*(save|require(_self|(_tree|_dir|)\s*[^\s]*))/gm | ||
| ret.push r for r in requires | ||
| watchPathes = [] | ||
| watcher = | ||
@@ -378,2 +418,4 @@ flags: (handlers, flags) -> | ||
| do: (froms, baseTo, handlers, options) -> | ||
| options = {} unless options | ||
| ocopy = options.copy | ||
| unless baseTo[baseTo.length - 1] is '/' | ||
@@ -400,6 +442,37 @@ baseTo += '/' | ||
| fromLen = from.length + 1 | ||
| handlers = [handlers] unless Array.isArray handlers | ||
| for handler in handlers | ||
| handler.type or= handler.ext | ||
| handler.flags = handler.setFlags or handler.flags | ||
| if includes = handler.includes | ||
| includes = [includes] if typeof includes is 'string' | ||
| handler.requires = includes.map (i) -> requireRegulars[i] | ||
| if link = options.link | ||
| watchPathes.push link.slice 0, -1 + link.indexOf '*' | ||
| linkPatt = new RegExp link.replace /\*/g, '([^\/]+)' | ||
| rules[link] = rule = | ||
| patt: linkPatt | ||
| copy: ocopy | ||
| getDest: (par, name, ext) -> | ||
| p = par.slice par.match(linkPatt)[0].length | ||
| s = skipBefore | ||
| pos = 1 | ||
| while s-- | ||
| if pos = p.indexOf('/', pos) + 1 | ||
| p = p.slice pos | ||
| else | ||
| p = '' | ||
| break | ||
| p += '/' if p isnt '' | ||
| ext = '.' + ext if ext | ||
| prepend + p + name + ext | ||
| for handler in handlers | ||
| rule[handler.ext] = handler | ||
| watchPathes.push from | ||
| rules[from] = rule = | ||
| copy: options and options.copy | ||
| patt: new RegExp from | ||
| link: linkPatt | ||
| copy: ocopy | ||
| getDest: (par, name, ext) -> | ||
| p = par.slice(fromLen) | ||
| p = par.slice fromLen | ||
| s = skipBefore | ||
@@ -416,11 +489,4 @@ pos = 1 | ||
| prepend + p + name + ext | ||
| handlers = [handlers] unless Array.isArray handlers | ||
| for handler in handlers | ||
| rule[handler.ext] = h = | ||
| type: handler.type or handler.ext | ||
| compile: handler.compile | ||
| flags: handler.setFlags or handler.flags | ||
| if includes = handler.includes | ||
| includes = [includes] if typeof includes is 'string' | ||
| h.requires = includes.map (i) -> requireRegulars[i] | ||
| rule[handler.ext] = handler | ||
@@ -510,3 +576,3 @@ pipe: (handler) -> | ||
| when 'w', 'watch' | ||
| require('chokidar').watch( Object.keys rules ) | ||
| require('chokidar').watch( watchPathes ) | ||
| .on 'add', (p, stat) -> | ||
@@ -532,12 +598,12 @@ file = addFileFromStream p, stat | ||
| delete file.dir.files[p] | ||
| delete requiredFile[file.pathWithoutExt] | ||
| clearDeps file | ||
| if parentFiles | ||
| saveParents parentFiles | ||
| else | ||
| fs.unlinkSync dest = file.dest | ||
| console.log "#{dest} was deleted" | ||
| p = file.dir.path | ||
| if exist(p) and not ls(p).length | ||
| fs.unlinkSync p | ||
| console.log "#{p} was deleted" | ||
| return unless file.save | ||
| fs.unlinkSync dest = file.dest | ||
| console.log "#{dest} was deleted" | ||
| p = file.dir.path | ||
| if exist(p) and not ls(p).length | ||
| fs.unlinkSync p | ||
| console.log "#{p} was deleted" | ||
| .on 'ready', -> | ||
@@ -544,0 +610,0 @@ ready = true |
+1
-1
@@ -13,3 +13,3 @@ { | ||
| "author": "Roman Kushin", | ||
| "version": "1.0.21", | ||
| "version": "1.0.22", | ||
| "license": "MIT", | ||
@@ -16,0 +16,0 @@ "directories": { |
Sorry, the diff of this file is not supported yet
43497
12.73%