2015-04-20 12:56:10 +00:00
|
|
|
mkdirp = require('mkdirp')
|
2014-12-22 16:20:08 +00:00
|
|
|
async = require('async')
|
|
|
|
fs = require('fs')
|
|
|
|
path = require('path')
|
2014-12-22 16:00:01 +00:00
|
|
|
_ = require('lodash')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2015-01-21 13:50:19 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
2015-03-12 15:24:36 +00:00
|
|
|
vcs = require('resin-vcs')
|
2014-12-22 16:00:01 +00:00
|
|
|
examplesData = require('../data/examples.json')
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.list =
|
|
|
|
signature: 'examples'
|
|
|
|
description: 'list all example applications'
|
|
|
|
help: '''
|
|
|
|
Use this command to list available example applications from resin.io
|
|
|
|
|
|
|
|
Example:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin examples
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: ->
|
2015-01-15 17:10:14 +00:00
|
|
|
examplesData = _.map examplesData, (example, index) ->
|
|
|
|
example.id = index + 1
|
|
|
|
return example
|
|
|
|
|
|
|
|
examplesData = _.map examplesData, (example) ->
|
|
|
|
example.author ?= 'Unknown'
|
|
|
|
return example
|
|
|
|
|
2015-01-21 13:50:19 +00:00
|
|
|
console.log visuals.widgets.table.horizontal examplesData, [
|
2015-01-22 17:06:02 +00:00
|
|
|
'id'
|
2015-05-21 15:58:15 +00:00
|
|
|
'name'
|
2015-01-22 17:06:02 +00:00
|
|
|
'display_name'
|
|
|
|
'repository'
|
|
|
|
'author'
|
2015-01-15 17:10:14 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
exports.info =
|
2015-05-21 15:58:15 +00:00
|
|
|
signature: 'example <name>'
|
2015-01-15 17:10:14 +00:00
|
|
|
description: 'list a single example application'
|
|
|
|
help: '''
|
|
|
|
Use this command to show information of a single example application
|
|
|
|
|
|
|
|
Example:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-05-21 15:58:15 +00:00
|
|
|
$ resin example cimon
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-05-21 15:58:15 +00:00
|
|
|
example = _.findWhere(examplesData, name: params.name)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
if not example?
|
2015-05-21 15:58:15 +00:00
|
|
|
return done(new Error("Unknown example: #{params.name}"))
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2014-12-22 16:00:01 +00:00
|
|
|
example.author ?= 'Unknown'
|
|
|
|
|
2015-01-21 13:50:19 +00:00
|
|
|
console.log visuals.widgets.table.vertical example, [
|
2015-05-21 15:58:15 +00:00
|
|
|
'name'
|
2015-01-22 17:06:02 +00:00
|
|
|
'display_name'
|
|
|
|
'description'
|
|
|
|
'author'
|
|
|
|
'repository'
|
2015-01-15 17:10:14 +00:00
|
|
|
]
|
2014-12-22 16:00:01 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
return done()
|
2015-01-06 17:07:35 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
exports.clone =
|
2015-05-21 15:58:15 +00:00
|
|
|
signature: 'example clone <name>'
|
2015-01-15 17:10:14 +00:00
|
|
|
description: 'clone an example application'
|
|
|
|
help: '''
|
|
|
|
Use this command to clone an example application to the current directory
|
2014-12-22 16:20:08 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
This command outputs information about the cloning process.
|
|
|
|
Use `--quiet` to remove that output.
|
2015-01-15 13:47:17 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Example:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-05-21 15:58:15 +00:00
|
|
|
$ resin example clone cimon
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-05-21 15:58:15 +00:00
|
|
|
example = _.findWhere(examplesData, name: params.name)
|
2014-12-22 16:20:08 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
if not example?
|
2015-05-21 15:58:15 +00:00
|
|
|
return done(new Error("Unknown example: #{params.name}"))
|
2014-12-22 16:20:08 +00:00
|
|
|
|
2015-03-12 15:24:36 +00:00
|
|
|
currentDirectory = process.cwd()
|
2015-04-20 12:56:10 +00:00
|
|
|
destination = path.join(currentDirectory, example.name)
|
|
|
|
|
|
|
|
mkdirp destination, (error) ->
|
|
|
|
return done(error) if error?
|
|
|
|
console.info("Cloning #{example.display_name} to #{destination}")
|
|
|
|
vcs.clone(example.repository, destination, done)
|
|
|
|
return done()
|