Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "tpm", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Static Package Manager", | ||
@@ -5,0 +5,0 @@ "author": "Longhao Luo <lhluo@tudou.com>", |
@@ -110,2 +110,42 @@ | ||
// 是否可发布的文件 | ||
function canDeploy(path) { | ||
if (!Util.indir(path, Path.resolve(config.root + '/dist'))) { | ||
return false; | ||
} | ||
return /\.(js|css|jpg|png|gif|ico|swf|htm|html)$/.test(path); | ||
} | ||
// 返回一个目录里所有要构建的文件 | ||
function grepPaths(rootDirPath) { | ||
var paths = []; | ||
function walk(dirPath) { | ||
var files = Fs.readdirSync(dirPath); | ||
for (var i = 0, len = files.length; i < len; i++) { | ||
var file = files[i]; | ||
if (file.charAt(0) === '.') { | ||
continue; | ||
} | ||
var path = Path.resolve(dirPath + '/' + file); | ||
var stat = Fs.statSync(path); | ||
if (stat.isDirectory()) { | ||
walk(path); | ||
} else if (canDeploy(path)) { | ||
paths.push(path); | ||
} | ||
} | ||
} | ||
walk(rootDirPath); | ||
return paths; | ||
} | ||
if (args.length < 2) { | ||
@@ -119,2 +159,4 @@ console.log(DEPLOY_USAGE); | ||
path = Path.resolve(path); | ||
var pathList = []; | ||
@@ -126,8 +168,11 @@ | ||
var stat = Fs.statSync(path); | ||
if (!Util.indir(path, config.root + '/dist') || stat.isDirectory(path)) { | ||
Util.error('Cannot deploy: ' + path); | ||
return; | ||
if (stat.isDirectory(path)) { | ||
pathList = grepPaths(path); | ||
} else { | ||
if (!canDeploy(path)) { | ||
Util.error('Cannot deploy: ' + path); | ||
return; | ||
} | ||
pathList.push(path); | ||
} | ||
path = Path.resolve(path); | ||
pathList.push(path); | ||
} | ||
@@ -134,0 +179,0 @@ |
1458703
38096