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