2016-03-28 13:21:25 +00:00
|
|
|
###
|
|
|
|
Copyright 2016 Resin.io
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
###
|
|
|
|
|
2016-07-21 16:31:47 +00:00
|
|
|
# Loads '.resin-sync.yml' configuration from 'source' directory.
|
|
|
|
# Returns the configuration object on success
|
|
|
|
#
|
|
|
|
# TODO: Use 'config.load()' method from `resin sync` when resin sync gets
|
|
|
|
# integrated into resin CLI
|
|
|
|
loadConfig = (source) ->
|
|
|
|
fs = require('fs')
|
|
|
|
path = require('path')
|
|
|
|
_ = require('lodash')
|
|
|
|
jsYaml = require('js-yaml')
|
|
|
|
|
|
|
|
configPath = path.join(source, '.resin-sync.yml')
|
|
|
|
try
|
|
|
|
config = fs.readFileSync(configPath, encoding: 'utf8')
|
|
|
|
result = jsYaml.safeLoad(config)
|
|
|
|
catch error
|
|
|
|
# return empty object if '.resin-sync.yml' is missing
|
|
|
|
if error.code is 'ENOENT'
|
|
|
|
return {}
|
|
|
|
throw error
|
|
|
|
|
|
|
|
if not _.isPlainObject(result)
|
|
|
|
throw new Error("Invalid configuration file: #{configPath}")
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2016-03-28 13:21:25 +00:00
|
|
|
module.exports =
|
2016-07-19 16:10:26 +00:00
|
|
|
signature: 'sync [uuid]'
|
2016-07-18 16:07:07 +00:00
|
|
|
description: '(beta) sync your changes to a device'
|
2016-03-28 13:21:25 +00:00
|
|
|
help: '''
|
2016-05-19 14:10:45 +00:00
|
|
|
WARNING: If you're running Windows, this command only supports `cmd.exe`.
|
|
|
|
|
2016-03-28 13:21:25 +00:00
|
|
|
Use this command to sync your local changes to a certain device on the fly.
|
|
|
|
|
2016-07-18 16:07:07 +00:00
|
|
|
After every 'resin sync' the updated settings will be saved in
|
|
|
|
'<source>/.resin-sync.yml' and will be used in later invocations. You can
|
|
|
|
also change any option by editing '.resin-sync.yml' directly.
|
2016-03-28 13:21:25 +00:00
|
|
|
|
2016-07-18 16:07:07 +00:00
|
|
|
Here is an example '.resin-sync.yml' :
|
|
|
|
|
|
|
|
$ cat $PWD/.resin-sync.yml
|
|
|
|
uuid: 7cf02a6
|
|
|
|
destination: '/usr/src/app'
|
2016-03-28 13:21:25 +00:00
|
|
|
before: 'echo Hello'
|
|
|
|
ignore:
|
|
|
|
- .git
|
|
|
|
- node_modules/
|
|
|
|
|
2016-07-20 13:53:41 +00:00
|
|
|
Command line options have precedence over the ones saved in '.resin-sync.yml'.
|
2016-03-28 13:21:25 +00:00
|
|
|
|
2016-07-20 13:53:41 +00:00
|
|
|
If '.gitignore' is found in the source directory then all explicitly listed files will be
|
|
|
|
excluded from the syncing process. You can choose to change this default behavior with the
|
|
|
|
'--skip-gitignore' option.
|
2016-07-18 16:07:07 +00:00
|
|
|
|
2016-03-28 13:21:25 +00:00
|
|
|
Examples:
|
|
|
|
|
2016-07-18 16:07:07 +00:00
|
|
|
$ resin sync 7cf02a6 --source '.' --destination '/usr/src/app'
|
|
|
|
$ resin sync 7cf02a6 -s '/home/user/myResinProject' -d '/usr/src/app' --before 'echo Hello'
|
|
|
|
$ resin sync --ignore 'lib/'
|
|
|
|
$ resin sync --verbose false
|
|
|
|
$ resin sync
|
2016-03-28 13:21:25 +00:00
|
|
|
'''
|
|
|
|
permission: 'user'
|
|
|
|
primary: true
|
|
|
|
options: [
|
|
|
|
signature: 'source'
|
|
|
|
parameter: 'path'
|
2016-07-18 16:07:07 +00:00
|
|
|
description: 'local directory path to synchronize to device'
|
2016-03-28 13:21:25 +00:00
|
|
|
alias: 's'
|
2016-07-18 16:07:07 +00:00
|
|
|
,
|
|
|
|
signature: 'destination'
|
|
|
|
parameter: 'path'
|
|
|
|
description: 'destination path on device'
|
|
|
|
alias: 'd'
|
2016-03-28 13:21:25 +00:00
|
|
|
,
|
|
|
|
signature: 'ignore'
|
|
|
|
parameter: 'paths'
|
|
|
|
description: 'comma delimited paths to ignore when syncing'
|
|
|
|
alias: 'i'
|
2016-07-20 13:53:41 +00:00
|
|
|
,
|
|
|
|
signature: 'skip-gitignore'
|
|
|
|
boolean: true
|
|
|
|
description: 'do not parse excluded/included files from .gitignore'
|
2016-03-28 13:21:25 +00:00
|
|
|
,
|
|
|
|
signature: 'before'
|
|
|
|
parameter: 'command'
|
|
|
|
description: 'execute a command before syncing'
|
|
|
|
alias: 'b'
|
|
|
|
,
|
|
|
|
signature: 'port'
|
|
|
|
parameter: 'port'
|
|
|
|
description: 'ssh port'
|
|
|
|
alias: 't'
|
2016-07-20 13:53:41 +00:00
|
|
|
,
|
|
|
|
signature: 'progress'
|
|
|
|
boolean: true
|
|
|
|
description: 'show progress'
|
|
|
|
alias: 'p'
|
2016-06-22 14:59:14 +00:00
|
|
|
,
|
|
|
|
signature: 'verbose'
|
|
|
|
boolean: true
|
|
|
|
description: 'increase verbosity'
|
|
|
|
alias: 'v'
|
|
|
|
,
|
2016-03-28 13:21:25 +00:00
|
|
|
]
|
|
|
|
action: (params, options, done) ->
|
2016-07-18 16:07:07 +00:00
|
|
|
fs = require('fs')
|
|
|
|
path = require('path')
|
2016-04-25 12:32:58 +00:00
|
|
|
resin = require('resin-sdk')
|
2016-07-19 16:10:26 +00:00
|
|
|
Promise = require('bluebird')
|
2016-03-28 13:21:25 +00:00
|
|
|
resinSync = require('resin-sync')
|
2016-04-25 12:32:58 +00:00
|
|
|
patterns = require('../utils/patterns')
|
2016-07-19 16:10:26 +00:00
|
|
|
|
|
|
|
Promise.try ->
|
|
|
|
try
|
|
|
|
fs.accessSync(path.join(process.cwd(), '.resin-sync.yml'))
|
|
|
|
catch
|
|
|
|
if not options.source?
|
|
|
|
throw new Error('No --source option passed and no \'.resin-sync.yml\' file found in current directory.')
|
|
|
|
|
|
|
|
options.source ?= process.cwd()
|
2016-03-28 13:21:25 +00:00
|
|
|
|
2016-07-19 16:10:26 +00:00
|
|
|
# TODO: Add comma separated options to Capitano
|
|
|
|
if options.ignore?
|
|
|
|
options.ignore = options.ignore.split(',')
|
2016-03-28 13:21:25 +00:00
|
|
|
|
2016-07-19 16:10:26 +00:00
|
|
|
Promise.resolve(params.uuid ? loadConfig(options.source).uuid)
|
|
|
|
.then (uuid) ->
|
|
|
|
if not uuid?
|
|
|
|
return patterns.inferOrSelectDevice()
|
2016-04-25 12:32:58 +00:00
|
|
|
|
2016-07-19 16:10:26 +00:00
|
|
|
resin.models.device.has(uuid)
|
|
|
|
.then (hasDevice) ->
|
|
|
|
if not hasDevice
|
|
|
|
throw new Error("Device not found: #{uuid}")
|
|
|
|
return uuid
|
|
|
|
.then (uuid) ->
|
|
|
|
resinSync.sync(uuid, options)
|
2016-04-25 12:32:58 +00:00
|
|
|
.nodeify(done)
|