-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
179 lines (156 loc) · 4.31 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env node
let npm = require('./package.json');
let program = require('commander');
let init = require('./chains/init');
let build = require('./chains/build');
// _____ ______ _______ _______ _____ _ _ _____ _____
// / ____| | ____| |__ __| |__ __| |_ _| | \ | | / ____| / ____|
// | (___ | |__ | | | | | | | \| | | | __ | (___
// \___ \ | __| | | | | | | | . ` | | | |_ | \___ \
// ____) | | |____ | | | | _| |_ | |\ | | |__| | ____) |
// |_____/ |______| |_| |_| |_____| |_| \_| \_____| |_____/
//
//
// The CLI options for this app. At this moment we just support Version.
//
program
.version(npm.version)
.option('-s, --source [type]', 'path to the source CF project folder')
.option('-d, --destination [type]', 'path to the destination CF project folder')
.option('-i, --init [type]', 'initiate the folder structure')
//
// React when the user needs help.
//
program.on('--help', function() {
//
// Just add an empty line at the end of the help to make the text more
// clear to the user.
//
console.log("");
});
//
// Pass the user input to the module.
//
program.parse(process.argv);
// __ __ _____ _ _
// | \/ | /\ |_ _| | \ | |
// | \ / | / \ | | | \| |
// | |\/| | / /\ \ | | | . ` |
// | | | | / ____ \ _| |_ | |\ |
// |_| |_| /_/ \_\ |_____| |_| \_|
//
//
// Set the work location of the CLI which depends if we are initializing
// a structure or we are building one.
//
let location = program.source || program.destination;
//
// The main container that will be passed around in each chain to collect
// all the data and keep it in one place.
//
let container = {
//
// A list of all the dirrectories that we have to scan to get
// all the data.
//
dir: {
description: process.cwd() + "/" + location + "/01_Description",
metadata: process.cwd() + "/" + location + "/02_Metadata",
parameters: process.cwd() + "/" + location + "/03_Parameters",
mappings: process.cwd() + "/" + location + "/04_Mappings",
conditions: process.cwd() + "/" + location + "/05_Conditions",
transform: process.cwd() + "/" + location + "/06_Transform",
resources: process.cwd() + "/" + location + "/07_Resources",
outputs: process.cwd() + "/" + location + "/08_Output",
},
//
// The path where to save the end result
//
save_to: process.cwd() + "/" + location + "/CloudFormation.json",
//
// Files that needs to be skiped when we read the content of the dirs
//
skip: [".DS_Store", "README.md"],
//
// This object will hold all the dirrect paths to the files, that
// later on needs to be read.
//
files: {},
//
// The content of all the files that we read
//
jsons: {
description:[],
metadata: [],
parameters: [],
mappings: [],
conditions: [],
transform: [],
resources: [],
outputs: []
},
//
// This object is the final structure of the CloudFormation file.
//
final_json: {
AWSTemplateFormatVersion: "2010-09-09",
Description:{},
Metadata: {},
Parameters: {},
Mappings: {},
Conditions: {},
Transform: {},
Resources: {},
Outputs: {}
}
};
//
// Start the chain.
//
cross_road(container)
.then(function(container) {
//
// 1. Notify that we finished working
//
console.log("Done!");
//
// -> Exit the app.
//
process.exit();
}).catch(function(error) {
//
// <>> Debug.
//
console.log(error);
//
// -> Exit the app.
//
process.exit(-1);
});
// _____ _____ ____ __ __ _____ _____ ______ _____
// | __ \ | __ \ / __ \ | \/ | |_ _| / ____| | ____| / ____|
// | |__) | | |__) | | | | | | \ / | | | | (___ | |__ | (___
// | ___/ | _ / | | | | | |\/| | | | \___ \ | __| \___ \
// | | | | \ \ | |__| | | | | | _| |_ ____) | | |____ ____) |
// |_| |_| \_\ \____/ |_| |_| |_____| |_____/ |______| |_____/
//
//
// Decide what do to based on the parameters set by the user.
//
function cross_road(container)
{
return new Promise(function(resolve, reject) {
//
// 1. Check if we want to create a folder structure.
//
if(program.init)
{
return init(container);
}
//
// 2. and if not init is specified we assume we want to build
// by default.
//
return build(container);
});
}