fix syntax
This commit is contained in:
41
resources.cm
41
resources.cm
@@ -41,20 +41,22 @@ function isRecognizedExtension(ext) {
|
||||
return false
|
||||
}
|
||||
|
||||
function find_in_path(filename, exts = []) {
|
||||
function find_in_path(filename, exts) {
|
||||
var _exts = exts || []
|
||||
if (!is_text(filename)) return null
|
||||
|
||||
var candidate = null
|
||||
if (search(filename, '.') != null) {
|
||||
var candidate = filename // possibly need "/" ?
|
||||
candidate = filename // possibly need "/" ?
|
||||
if (io.exists(candidate) && !io.is_directory(candidate)) return candidate
|
||||
return null
|
||||
}
|
||||
|
||||
// Only check extensions if exts is provided and not empty
|
||||
if (length(exts) > 0) {
|
||||
var cand = null
|
||||
arrfor(exts, function(ext) {
|
||||
var candidate = filename + '.' + ext
|
||||
var cand = null
|
||||
if (length(_exts) > 0) {
|
||||
arrfor(_exts, function(ext) {
|
||||
candidate = filename + '.' + ext
|
||||
if (io.exists(candidate) && !io.is_directory(candidate)){
|
||||
cand = candidate
|
||||
return true
|
||||
@@ -63,7 +65,7 @@ function find_in_path(filename, exts = []) {
|
||||
if (cand != null) return cand
|
||||
} else {
|
||||
// Fallback to extensionless file only if no extensions are specified
|
||||
var candidate = filename
|
||||
candidate = filename
|
||||
if (io.exists(candidate) && !io.is_directory(candidate)) return candidate
|
||||
}
|
||||
return null
|
||||
@@ -95,12 +97,13 @@ Resources.find_font = hashify(function(file) {
|
||||
function read_ignore(dir) {
|
||||
var path = dir + '/.prosperonignore'
|
||||
var patterns = []
|
||||
var lines = null
|
||||
if (io.exists(path)) {
|
||||
var lines = array(io.slurp(path), '\n')
|
||||
lines = array(io.slurp(path), '\n')
|
||||
arrfor(lines, function(line) {
|
||||
line = trim(line)
|
||||
if (!line || starts_with(line, '#')) return
|
||||
push(patterns, line)
|
||||
var trimmed = trim(line)
|
||||
if (!trimmed || starts_with(trimmed, '#')) return
|
||||
push(patterns, trimmed)
|
||||
})
|
||||
}
|
||||
return patterns
|
||||
@@ -108,20 +111,24 @@ function read_ignore(dir) {
|
||||
|
||||
// Return a list of recognized files in the directory (and subdirectories),
|
||||
// skipping those matched by .prosperonignore. Directory paths are skipped.
|
||||
Resources.getAllFiles = function(dir = "") {
|
||||
var patterns = read_ignore(dir)
|
||||
var all = io.globfs(patterns, dir)
|
||||
Resources.getAllFiles = function(dir) {
|
||||
var _dir = dir || ""
|
||||
var patterns = read_ignore(_dir)
|
||||
var all = io.globfs(patterns, _dir)
|
||||
var results = []
|
||||
arrfor(all, function(f) {
|
||||
var fullPath = dir + '/' + f
|
||||
try {
|
||||
var fullPath = _dir + '/' + f
|
||||
var _stat = function() {
|
||||
var st = io.stat(fullPath)
|
||||
// skip directories (filesize=0) or unrecognized extension
|
||||
if (!st.filesize) return
|
||||
var ext = getExtension(f)
|
||||
if (!isRecognizedExtension(ext)) return
|
||||
push(results, fullPath)
|
||||
} catch(e) {}
|
||||
} disruption {
|
||||
// skip files that can't be stat'd
|
||||
}
|
||||
_stat()
|
||||
})
|
||||
return results
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user