Skip to content

Commit

Permalink
Merge pull request #5 from unau/upload-files-that-are-only-in-local
Browse files Browse the repository at this point in the history
Modify upload command so that can upload files only in local
  • Loading branch information
soundTricker committed Dec 23, 2015
2 parents 0838eba + 75dd865 commit dd94623
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/lib/command.coffee
Expand Up @@ -78,8 +78,10 @@ exports.run = ()->
)
.option(
'-F, --force'
,"If does not exist source in config.json but exist on server,
server's file will be deleted"
,"If does not exist source in gas-project.json but exist on server,
server's file will be deleted.
And if does not exist source on server but in gas-project.json,
upload the new file to server"
)
.action(require('./commands/upload-command').upload)

Expand Down
50 changes: 34 additions & 16 deletions src/lib/commands/upload-command.coffee
Expand Up @@ -44,33 +44,51 @@ exports.upload = (options)->
(cb)->
manager.getProject fileId, cb
(project, response, cb)->
readFiles = []
readFiles = {}
for file in project.getFiles()

if !config[program.env].files[file.name]
project.deleteFile(file.name) if options.force
continue

readFiles.push(
readFiles[file.name] =
name : file.name
setting : config[program.env].files[file.name]
)
exist : yes

if options.force
for name,file of config[program.env].files
if !readFiles[name]
readFiles[name] =
name : name
setting : file
exist : no

async.parallel(
readFiles.map((readFile)->
return (callback)->
fs.readFile(path.resolve(readFile.setting.path)
,encoding : options.encoding
,(err, source)->

return callback(err) if err
project.changeFile(readFile.name, {
type : readFile.setting.type
source : source
})
callback(null)
do (tasks = []) ->
for name,readFile of readFiles
tasks.push(
do (file = readFile) ->
(callback)->
fs.readFile(path.resolve(file.setting.path)
,encoding : options.encoding
,(err, source)->

return callback(err) if err
if file.exist
project.changeFile(name, {
type : file.setting.type
source : source
})
else
project.addFile(name, {
type : file.setting.type
source : source
})
callback(null)
)
)
)
tasks
,(err)->
throw err if err
cb(null, project)
Expand Down

0 comments on commit dd94623

Please sign in to comment.