neft
Version:
Universal Platform
44 lines (31 loc) • 905 B
text/coffeescript
'use strict'
pathUtils = require 'path'
module.exports = (File) -> (file) ->
links = []
{children} = file.node
i = -1
n = children.length
while ++i < n
node = children[i]
if node.name isnt 'import'
continue
href = node.props.href or node.props.src
unless href then continue
node.name = 'blank'
namespace = node.props.as
path = getFilePath File, file, href
links.push
path: path
namespace: namespace
links
getFilePath = module.exports.getFilePath = (File, file, path) ->
if pathUtils.isAbsolute(path)
return path
if /\.{1,2}[\/\\]/.test(path)
dirname = pathUtils.dirname file.path
return pathUtils.join(dirname, path)
pathUtils.join File.FILES_PATH, path