-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·97 lines (85 loc) · 3.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /usr/bin/env node
var program = require('commander');
var prompt = require('prompt');
var path = require('path');
var gitConfig = require('git-config');
var osenv = require('osenv');
var fs = require('fs');
var actions = require(__dirname + '/lib/actions');
var userHome = osenv.home();
var credentialsFile = userHome + '/.hocus/credentials.json';
program
.version('0.0.1')
.command('new [name]')
.description('create a new hocus app')
.action( actions.new );
program
.command('configure')
.description('configure your AWS access and settings')
.action( function(){
var credentials = {};
var schema = {
properties : {
'profile' : {
require : true,
default : 'dev',
description : 'Credential Profile Name:'.cyan
},
'awsAccessKey' : {
required : true,
pattern : /^[a-zA-Z0-9]{20}$/, // 20 alphanumeric characters
description: 'AWS Access Key ID:'.cyan,
message: 'That does not seem to be a valid AWS Access Key.'
},
'awsSecretAccessKey' : {
required : true,
pattern : /^[a-zA-Z0-9/+=]{40}$/, // 40 base64 characters
description: 'AWS Secret Access Key:'.cyan,
message: 'That does not seem to be a valid AWS Secret Access Key.'
},
'regionName' :{
default : 'us-east-1',
description: 'Default Region Name:'.cyan,
message : 'Must be one of us-east-1, us-west-2, or eu-west-1. Default is us-east-1.',
conform : function( value ){
var validRegions = [
'us-east-1',
'us-west-2',
'eu-west-1'
];
return (validRegions.indexOf(value) > -1);
}
}
}
}
if (fs.existsSync(credentialsFile)){
credentials = JSON.parse(fs.readFileSync(credentialsFile));
} else {
var gitconfig = gitConfig.sync();
var userNameDefault = '';
if ( typeof gitconfig.user !== 'undefined' ){
userNameDefault = gitconfig.user.name;
}
schema.properties[ 'userName' ] = {
default : userNameDefault,
description : 'Your Name:'.cyan,
required : true
}
}
prompt.message = '';
prompt.delimiter = '';
prompt.start();
prompt.get(schema, function(err, result){
actions.configure(result);
});
});
program.command('generate model', 'generate a model');
program.command('delete model', 'delete a model');
program.command('generate controller', 'generate a controller');
program
.command('test')
.action( actions.test );
program
.command('deploy [environment]')
.action( actions.deploy );
program.parse(process.argv);