fis-command-release
Advanced tools
Comparing version 0.9.10 to 0.11.0
@@ -9,2 +9,5 @@ /* | ||
var hostname; | ||
var DEFAULT_DEPLOY_KEY = 'deploy.default'; | ||
var async = require('async'); | ||
var defaultHostname = (function(){ | ||
@@ -28,54 +31,2 @@ var net = require('os').networkInterfaces(); | ||
function upload(receiver, to, release, content, subpath, callback){ | ||
fis.util.upload( | ||
//url, request options, post data, file | ||
receiver, null, { to : to + release }, content, subpath, | ||
function(err, res){ | ||
if(err || res.trim() != '0'){ | ||
fis.log.error('upload file [' + subpath + '] to [' + to + | ||
'] by receiver [' + receiver + '] error [' + (err || res) + ']'); | ||
} else { | ||
var time = '[' + fis.log.now(true) + ']'; | ||
process.stdout.write( | ||
' - '.green.bold + | ||
time.grey + ' ' + | ||
subpath.replace(/^\//, '') + | ||
' >> '.yellow.bold + | ||
to + release + | ||
'\n' | ||
); | ||
callback(); | ||
} | ||
} | ||
); | ||
} | ||
function deliver(output, md5, release, content, file, callback){ | ||
if(!release){ | ||
fis.log.error('unable to get release path of file[' | ||
+ file.realpath | ||
+ ']: Maybe this file is neither in current project or releasable'); | ||
} | ||
if(fis.util.exists(output) && !fis.util.isDir(output)){ | ||
fis.log.error('unable to deliver file[' | ||
+ file.realpath + '] to dir[' | ||
+ output + ']: invalid output dir.'); | ||
} | ||
var target; | ||
if(md5 == 0 || !file.useHash){ | ||
target = fis.util(output, release); | ||
fis.util.write(target, content); | ||
} else if(md5 == 1){ | ||
target = fis.util(output, file.getHashRelease(release)); | ||
fis.util.write(target, content); | ||
} else { | ||
target = fis.util(output, release); | ||
fis.util.write(target, content); | ||
target = fis.util(output, file.getHashRelease(release)); | ||
fis.util.write(target, content); | ||
} | ||
callback(); | ||
} | ||
function replaceFrom(path, from, subOnly){ | ||
@@ -98,3 +49,3 @@ if(path.indexOf(from) === 0){ | ||
function deploy(dest, file, callback){ | ||
function prepareDeploy(dest, file, callback){ | ||
if(file.release){ | ||
@@ -134,13 +85,9 @@ var release = replaceFrom(file.release, dest.from, dest.subOnly); | ||
} | ||
file.setContent(content); | ||
} | ||
if(dest.receiver){ | ||
if(!file.useHash || dest.opt.md5 != 1){ | ||
upload(dest.receiver, dest.to, release, content, file.subpath, callback); | ||
} | ||
if(file.useHash && dest.opt.md5 > 0){ | ||
upload(dest.receiver, dest.to, file.getHashRelease(release), content, file.subpath, callback); | ||
} | ||
} else { | ||
deliver(dest.to, dest.opt.md5, release, content, file, callback); | ||
if(file.useHash && dest.opt.md5 > 0){ | ||
release = file.getHashRelease(release); | ||
} | ||
callback && callback(processors[dest._type], dest, release, file, settings[dest._name]); | ||
} else { | ||
@@ -159,16 +106,3 @@ fis.log.error('unreleasable file [' + file.realpath + ']'); | ||
var serverRoot = (function(){ | ||
var key = 'FIS_SERVER_DOCUMENT_ROOT'; | ||
if(process.env && process.env[key]){ | ||
var path = process.env[key]; | ||
if(fis.util.exists(path) && !fis.util.isDir(path)){ | ||
fis.log.error('invalid environment variable [' + key + '] of document root [' + path + ']'); | ||
} | ||
return path; | ||
} else { | ||
return fis.project.getTempPath('www'); | ||
} | ||
})(); | ||
var cwd = process.cwd(); | ||
function factory(dest, opt, root){ | ||
@@ -179,72 +113,156 @@ var ret = fis.util.clone(dest); | ||
ret.from = normilize(ret.from); | ||
if(ret.to[0] === '.'){ | ||
ret.to = fis.util(cwd + '/' + ret.to); | ||
} else if(/^output\b/.test(ret.to)){ | ||
ret.to = fis.util(root + '/' + ret.to); | ||
} else if(ret.to === 'preview'){ | ||
ret.to = serverRoot; | ||
} else { | ||
ret.to = fis.util(ret.to); | ||
} | ||
return ret; | ||
} | ||
var tasks = []; | ||
var running = 0; | ||
function doTask(){ | ||
if(tasks.length){ | ||
if(running < exports.MAX_TASK_SIZE){ | ||
var task = tasks.shift(); | ||
running++; | ||
deploy(task.dest, task.file, function(){ | ||
running--; | ||
setTimeout(doTask, 0); | ||
function doTask(tasks, done){ | ||
var asyncTasks = []; | ||
tasks.forEach(function(task){ | ||
asyncTasks.push(function(cb){ | ||
prepareDeploy(task.dest, task.file, function(processor, dest, release, file, settings){ | ||
processor({to: dest.to, release: release}, file, dest, cb); | ||
}); | ||
} else { | ||
setTimeout(doTask, 1000); | ||
}); | ||
}); | ||
async.parallelLimit(asyncTasks, exports.MAX_TASK_SIZE, done); | ||
} | ||
function doPackTasks(packTasks, done){ | ||
var asyncTasks = []; | ||
fis.util.map(packTasks, function(name, tasks){ | ||
var files = []; | ||
var taskSettings, taskProcessor; | ||
tasks.forEach(function(task){ | ||
prepareDeploy(task.dest, task.file, function(processor, dest, release, file, settings){ | ||
taskSettings = settings; | ||
taskProcessor = processor; | ||
files.push({ | ||
dest: { | ||
to: dest.to, | ||
release: release | ||
}, | ||
file: file | ||
}); | ||
}); | ||
}); | ||
if (taskProcessor){ | ||
asyncTasks.push(function(cb){ | ||
taskProcessor(files, taskSettings, cb); | ||
}); | ||
}else{ | ||
fis.log.warning('invalid pack deploy content: empty') | ||
} | ||
} else { | ||
running = 0; | ||
exports.done(); | ||
} | ||
}); | ||
async.parallelLimit(asyncTasks, exports.MAX_TASK_SIZE, done); | ||
} | ||
exports = module.exports = function(opt, collection){ | ||
var settings = fis.config.get('deploy', {}); | ||
var processors = {}; | ||
var settings = {}; | ||
exports = module.exports = function(opt, collection, total){ | ||
var root = fis.project.getProjectPath(); | ||
var dests = []; | ||
opt.dest.split(/,/g).forEach(function(d){ | ||
var dest = settings[d] || {}; | ||
/** | ||
* create task for files | ||
* @param {[type]} deploy config | ||
* @param {[type]} files | ||
* @param {[type]} tasks should wrap with deploy name or not | ||
* @return {[type]} | ||
*/ | ||
function createDeployTasks(depolyConfs, files, flaten){ | ||
var tasks = flaten ? [] : {}; | ||
fis.util.map(files, function(subpath, file){ | ||
fis.util.map(depolyConfs, function(name, depolyConf){ | ||
var target = flaten? tasks : (tasks[name] = tasks[name] || []); | ||
depolyConf.forEach(function(d){ | ||
if( | ||
file.release && | ||
file.release.indexOf(d.from) === 0 && //relate to replaceFrom | ||
fis.util.filter(file.release, d.include, d.exclude) | ||
){ | ||
target.push({dest : d, file : file }); | ||
} | ||
}); | ||
}); | ||
}); | ||
return tasks; | ||
} | ||
function bindConfInfo(conf, type, name, fullpack){ | ||
if(fis.util.is(conf, 'Array')){ | ||
conf.forEach(function(item){ | ||
item._type = DEFAULT_DEPLOY_KEY; | ||
item._name = name; | ||
item._fullpack = false; | ||
}); | ||
} | ||
conf._type = DEFAULT_DEPLOY_KEY; | ||
conf._name = name; | ||
conf._fullpack = false; | ||
} | ||
settings = fis.config.get('deploy', {}); | ||
//downward compatibility | ||
fis.util.map(settings, function(name, conf){ | ||
bindConfInfo(conf, DEFAULT_DEPLOY_KEY, name, false); | ||
}); | ||
//merge deploy config with settings.deploy | ||
fis.util.pipe('deploy', function(processor, pluginSettings, key){ | ||
processors[key] = processor; | ||
fis.util.map(pluginSettings, function(name, conf){ | ||
bindConfInfo(conf, key, name, !!processor.fullpack); | ||
}); | ||
fis.util.merge(settings, pluginSettings); | ||
}); | ||
var deployConfs = {}; | ||
var packDeployConfs = {}; | ||
//choose deploy config by deploy option | ||
opt.dest.split(/,/g).forEach(function(destName){ | ||
if (!destName){ | ||
return false; | ||
} | ||
var dest = settings[destName] || {}; | ||
if (!dest._type){ | ||
dest._type = DEFAULT_DEPLOY_KEY; | ||
} | ||
var target; | ||
if (dest._fullpack){ | ||
target = packDeployConfs[destName] = packDeployConfs[destName] || []; | ||
}else{ | ||
target = deployConfs[destName] = deployConfs[destName] || []; | ||
} | ||
if(fis.util.is(dest, 'Array')){ | ||
dest.forEach(function(item){ | ||
dests.push(factory(item, opt, root)); | ||
target.push(factory(item, opt, root)); | ||
}); | ||
} else { | ||
if(!dest.to){ | ||
}else { | ||
//only used when deploy type is default or none | ||
if(!dest.to && dest._type == DEFAULT_DEPLOY_KEY){ | ||
if( | ||
d === 'preview' || //release to preivew | ||
/^(?:\.|output\b)/.test(d) || //release to output | ||
fis.util.isAbsolute(d) //absolute path | ||
destName === 'preview' || //release to preivew | ||
/^(?:\.|output\b)/.test(destName) || //release to output | ||
fis.util.isAbsolute(destName) //absolute path | ||
){ | ||
dest.to = d; | ||
dest.to = destName; | ||
dest._type = DEFAULT_DEPLOY_KEY; | ||
} else { | ||
fis.log.error('invalid deploy destination options [' + d + ']'); | ||
fis.log.error('invalid deploy destination options [' + destName + ']'); | ||
} | ||
} | ||
dests.push(factory(dest, opt, root)); | ||
target.push(factory(dest, opt, root)); | ||
} | ||
}); | ||
fis.util.map(collection, function(subpath, file){ | ||
dests.forEach(function(d){ | ||
if( | ||
file.release && | ||
file.release.indexOf(d.from) === 0 && //relate to replaceFrom | ||
fis.util.filter(file.release, d.include, d.exclude) | ||
){ | ||
tasks.push({dest : d, file : file }); | ||
} | ||
var tasks = createDeployTasks(deployConfs, collection, true); | ||
var packTasks = createDeployTasks(packDeployConfs, total); | ||
doTask(tasks, function(){ | ||
doPackTasks(packTasks, function(){ | ||
exports.done(); | ||
}); | ||
}); | ||
doTask(); | ||
}; | ||
@@ -251,0 +269,0 @@ |
@@ -0,0 +0,0 @@ Copyright (C) 2013 baidu.com |
{ | ||
"name" : "fis-command-release", | ||
"description" : "fis release command.", | ||
"version" : "0.9.10", | ||
"author" : "FIS Team <fis@baidu.com>", | ||
"homepage" : "http://fis.baidu.com/", | ||
"keywords": [ "fis" ], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fis-dev/fis-command-release.git" | ||
}, | ||
"engines" : { | ||
"node" : ">= 0.8.0" | ||
}, | ||
"main" : "release.js", | ||
"scripts" : { | ||
"test" : "mocha test/ut --recursive" | ||
}, | ||
"dependencies" : { | ||
"chokidar" : "0.8.4", | ||
"livereload-server-spec" : "0.2.3" | ||
}, | ||
"devDependencies": {} | ||
} | ||
"name": "fis-command-release", | ||
"description": "fis release command.", | ||
"version": "0.11.0", | ||
"author": "FIS Team <fis@baidu.com>", | ||
"homepage": "http://fis.baidu.com/", | ||
"keywords": [ | ||
"fis" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fis-dev/fis-command-release.git" | ||
}, | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"main": "release.js", | ||
"scripts": { | ||
"test": "mocha test/ut --recursive" | ||
}, | ||
"dependencies": { | ||
"async": "0.9.0", | ||
"chokidar": "0.8.4", | ||
"livereload-server-spec": "0.2.3" | ||
}, | ||
"devDependencies": {} | ||
} |
@@ -0,0 +0,0 @@ # fis-command-release |
@@ -25,2 +25,10 @@ /* | ||
} | ||
//添加usePolling配置 | ||
var usePolling = null; | ||
if (typeof fis.config.get('project.watch.usePolling') !== 'undefined'){ | ||
usePolling = fis.config.get('project.watch.usePolling'); | ||
} | ||
require('chokidar') | ||
@@ -40,3 +48,3 @@ .watch(root, { | ||
}, | ||
usePolling: false, | ||
usePolling: usePolling, | ||
persistent: true | ||
@@ -82,2 +90,3 @@ }) | ||
var collection = {}; | ||
var total = {}; | ||
var deploy = require('./lib/deploy.js'); | ||
@@ -93,5 +102,6 @@ | ||
process.stdout.write('\n Ω '.green.bold); | ||
opt.beforeEach = function(){ | ||
opt.beforeEach = function(file){ | ||
flag = opt.verbose ? '' : '.'; | ||
cost = (new Date).getTime(); | ||
total[file.subpath] = file; | ||
}; | ||
@@ -130,12 +140,18 @@ opt.afterEach = function(file){ | ||
); | ||
for(var item in collection){ | ||
if(collection.hasOwnProperty(item)){ | ||
if(opt.unique){ | ||
time(fis.compile.clean); | ||
} | ||
deploy(opt, collection); | ||
deploy(opt, ret.pkg); | ||
collection = {}; | ||
return; | ||
var changed = false; | ||
fis.util.map(collection, function(key, file){ | ||
//get newest file from src | ||
collection[key] = ret.src[key] || file; | ||
changed = true; | ||
}); | ||
if (changed){ | ||
if(opt.unique){ | ||
time(fis.compile.clean); | ||
} | ||
fis.util.merge(collection, ret.pkg) | ||
fis.util.merge(total, ret.pkg) | ||
deploy(opt, collection, total); | ||
collection = {}; | ||
total = {}; | ||
return; | ||
} | ||
@@ -142,0 +158,0 @@ }); |
@@ -0,0 +0,0 @@ (function() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
58566
1510
1
3
+ Addedasync@0.9.0
+ Addedasync@0.9.0(transitive)