Comparing version 1.0.0 to 1.0.1
11
main.js
@@ -12,3 +12,3 @@ | ||
deploy : true, | ||
diff : true, | ||
list : true, | ||
cleanup : true, | ||
@@ -18,3 +18,3 @@ }; | ||
Optimist.usage([ | ||
'Usage: tpm [command] --config=[/path/to/config-file]\n\n', | ||
'Usage: tpm [COMMAND] --config=[CONFIG_FILE]\n\n', | ||
'Examples:\n', | ||
@@ -24,3 +24,3 @@ 'tpm src/js/g.js\n', | ||
'tpm min build/js/g.js\n', | ||
'tpm diff 100\n', | ||
'tpm list 100\n', | ||
'tpm deploy src/js/page/play wwwtest\n', | ||
@@ -56,7 +56,6 @@ 'tpm cleanup\n', | ||
var dirPath = (cmd != 'diff' && args.length > 0) ? args[0] : '.'; | ||
var dirPath = args.length > 0 ? args[0] : '.'; | ||
if (!Fs.existsSync(dirPath)) { | ||
Util.error('File not found: ' + dirPath); | ||
process.exit(); | ||
dirPath = '.'; | ||
} | ||
@@ -63,0 +62,0 @@ |
{ | ||
"name": "tpm", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Static Package Manager", | ||
@@ -5,0 +5,0 @@ "author": "Longhao Luo <lhluo@tudou.com>", |
@@ -127,24 +127,4 @@ | ||
function buildProject(path) { | ||
var content = Fs.readFileSync(path, 'utf-8'); | ||
var pathList = Util.readProjectFile(config, path, 'src'); | ||
var paths = content.replace(/^\s+|\s+$/g, '').split(/\r\n|\n/); | ||
var pathList = []; | ||
for (var i = 0, len = paths.length; i < len; i++) { | ||
var path = paths[i].replace(/^\s+|\s+$/g, ''); | ||
if (path == '' || path.charAt(0) == '#') { | ||
continue; | ||
} | ||
path = path.replace(/^(src|build|dist)\//, ''); | ||
path = path.replace(/\.css$/, '.less'); | ||
path = Path.resolve(config.root + '/src/' + path); | ||
if (Fs.existsSync(path)) { | ||
pathList.push(path); | ||
} | ||
} | ||
buildFiles(pathList); | ||
@@ -218,3 +198,7 @@ } | ||
pathList = grepPaths(path); | ||
} else if (canBuild(path)) { | ||
} else { | ||
if (!canBuild(path)) { | ||
Util.error('Cannot build: ' + path); | ||
return; | ||
} | ||
pathList.push(path); | ||
@@ -221,0 +205,0 @@ } |
@@ -80,3 +80,7 @@ | ||
pathList = grepPaths(path); | ||
} else if (canBuild(path)) { | ||
} else { | ||
if (!canBuild(path)) { | ||
Util.error('Cannot compress: ' + path); | ||
return; | ||
} | ||
pathList.push(path); | ||
@@ -83,0 +87,0 @@ } |
115
util.js
@@ -31,2 +31,7 @@ | ||
function trim(str) { | ||
// Forgive various special whitespaces, e.g. (\xa0). | ||
return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, ''); | ||
} | ||
function undef(val, defaultVal) { | ||
@@ -49,19 +54,6 @@ return typeof val === 'undefined' ? defaultVal : val; | ||
function indir(path, dirPath) { | ||
while (true) { | ||
if (!Fs.existsSync(path)) { | ||
return false; | ||
} | ||
path = Path.resolve(path); | ||
dirPath = Path.resolve(dirPath); | ||
if (path == dirPath) { | ||
return true; | ||
} | ||
var parentPath = Path.dirname(path); | ||
if (parentPath == path) { | ||
return false; | ||
} | ||
path = parentPath; | ||
} | ||
return path.indexOf(dirPath) == 0; | ||
} | ||
@@ -182,2 +174,38 @@ | ||
// @param type: "src", "build", "dist" | ||
function readProjectFile(config, path, type) { | ||
var content = Fs.readFileSync(path, 'utf-8'); | ||
var paths = trim(content).split(/\r\n|\n/); | ||
var pathList = []; | ||
for (var i = 0, len = paths.length; i < len; i++) { | ||
var path = trim(paths[i]); | ||
if (path == '' || path.charAt(0) == '#') { | ||
continue; | ||
} | ||
path = path.replace(/^(src|build|dist)\//, ''); | ||
if (type == 'src') { | ||
path = path.replace(/\.css$/, '.less'); | ||
} else { | ||
path = path.replace(/\.less$/, '.css'); | ||
} | ||
path = Path.resolve(config.root + '/' + type + '/' + path); | ||
if (!Fs.existsSync(path)) { | ||
error('File not found: ' + path); | ||
continue; | ||
} | ||
pathList.push(path); | ||
} | ||
return pathList; | ||
} | ||
// Escape mailto string | ||
@@ -223,57 +251,6 @@ // Reference: http://support.microsoft.com/kb/287573 | ||
// Open new mail window and insert deploy info | ||
function deployByEmail(config, projectName, paths, callback) { | ||
var pathCount = paths.length; | ||
var contentList = []; | ||
if (projectName !== '') { | ||
contentList.push(config.jira_host + '/browse/' + projectName); | ||
contentList.push(''); | ||
} | ||
contentList.push('文件列表:'); | ||
var newPaths = []; | ||
for (var i = 0, len = paths.length; i < len; i++) { | ||
var path = paths[i]; | ||
var cmd = 'svn info "' + path.replace(/\\/g, '\\\\') + '"'; | ||
var cp = ChildProcess.exec(cmd); | ||
cp.stdout.on('data', function(stdout) { | ||
var data = Iconv.fromEncoding(stdout, 'gbk'); | ||
var match; | ||
var line = ''; | ||
if ((match = /^URL:\s*(.+)$/im.exec(data))) { | ||
line += match[1]; | ||
} | ||
if ((match = /(?:Revision|版本):\s*(\d+)/i.exec(data))) { | ||
line += ' ' + match[1]; | ||
} | ||
contentList.push(line); | ||
}); | ||
cp.stderr.on('data', function(stderr){ | ||
error('[SVN] ' + stderr); | ||
}); | ||
cp.on('exit', function() { | ||
pathCount--; | ||
if (pathCount === 0) { | ||
var subject = '版本发布' + (projectName !== '' ? (' - ' + projectName) : ''); | ||
var content = contentList.join('\r\n') + '\r\n'; | ||
console.log(content); | ||
newMail(config.deploy_mail, subject, content, callback); | ||
} | ||
}); | ||
} | ||
} | ||
exports.linefeed = linefeed; | ||
exports.banner = banner; | ||
exports.each = each; | ||
exports.trim = trim; | ||
exports.undef = undef; | ||
@@ -292,3 +269,3 @@ exports.info = info; | ||
exports.setSvnKeywords = setSvnKeywords; | ||
exports.readProjectFile = readProjectFile; | ||
exports.newMail = newMail; | ||
exports.deployByEmail = deployByEmail; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1456641
69
38020
43
22