forceios 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,199 @@
1
+ /*
2
+ * Copyright (c) 2019-present, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * Redistribution and use of this software in source and binary forms, with or
5
+ * without modification, are permitted provided that the following conditions
6
+ * are met:
7
+ * - Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * - Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * - Neither the name of salesforce.com, inc. nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software without
14
+ * specific prior written permission of salesforce.com, inc.
15
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
+ * POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+ const COLOR = require('./outputColors');
28
+
29
+ const SDK = require('./constants');
30
+ const configHelper = require('./configHelper');
31
+ const createHelper = require('./createHelper');
32
+ const templateHelper = require('./templateHelper');
33
+ const jsonChecker = require('./jsonChecker');
34
+ const logInfo = require('./utils').logInfo;
35
+ const logError = require('./utils').logError;
36
+ const os = require('os');
37
+
38
+ const { SfdxError } = require('@salesforce/core');
39
+ const { Command, flags } = require('@oclif/command');
40
+
41
+ const namespace = 'mobilesdk';
42
+
43
+ class OclifAdapter extends Command {
44
+
45
+ static formatDescription(description, help) {
46
+ return `${description}${os.EOL}${os.EOL}${help}`;
47
+ }
48
+
49
+ static listTemplates(cli) {
50
+ const applicableTemplates = templateHelper.getTemplates(cli);
51
+
52
+ logInfo('\nAvailable templates:\n', COLOR.cyan);
53
+ for (let i=0; i<applicableTemplates.length; i++) {
54
+ const template = applicableTemplates[i];
55
+ logInfo((i+1) + ') ' + template.description, COLOR.cyan);
56
+ logInfo('sfdx ' + [namespace, cli.topic, SDK.commands.createwithtemplate.name].join(':') + ' --' +
57
+ SDK.args.templateRepoUri.name + '=' + template.path, COLOR.magenta);
58
+ }
59
+ logInfo('');
60
+ }
61
+
62
+ static runCommand(cli, commandName, vals) {
63
+ switch(commandName) {
64
+ case SDK.commands.create.name:
65
+ case SDK.commands.createwithtemplate.name:
66
+ createHelper.createApp(cli, vals);
67
+ break;
68
+ case SDK.commands.version.name:
69
+ configHelper.printVersion(cli);
70
+ break;
71
+ case SDK.commands.listtemplates.name:
72
+ OclifAdapter.listTemplates(cli);
73
+ process.exit(0);
74
+ break;
75
+ case SDK.commands.checkconfig.name:
76
+ jsonChecker.validateJson(vals.configpath, vals.configtype);
77
+ break;
78
+ }
79
+ }
80
+
81
+ // Validation
82
+ static validateCommand(cli, commandName, vals) {
83
+ let success = true;
84
+ const args = configHelper.getArgsExpanded(cli, commandName);
85
+ for (const arg of args) {
86
+ const val = vals[arg.name];
87
+
88
+ if (typeof arg.validate === 'function' && !arg.validate(val, cli)) {
89
+ success = false;
90
+ logError(arg.error(val, cli));
91
+ }
92
+ }
93
+ return success;
94
+ }
95
+
96
+ /**
97
+ * Convert legacy-style flag declarations to SfdxCommand's updated format.
98
+ *
99
+ * @param {Array} flags The legacy flags to convert.
100
+ */
101
+ static toFlags(flagContent) {
102
+ const flagsConfig = {};
103
+ if (flagContent) {
104
+ flagContent.forEach(flag => {
105
+ const { name, char, hidden, required, longDescription, type, values, array } = flag;
106
+ const description = flag.description || '';
107
+ const config = {
108
+ description,
109
+ longDescription,
110
+ hidden,
111
+ required,
112
+ default: flag.default
113
+ };
114
+ if (char) {
115
+ // oclif types char as a single alpha char, but Flag specifies it as `string`,
116
+ // so we use `any` here to get tsc to accept the assignment
117
+ config.char = char;
118
+ }
119
+ if (values) {
120
+ config.options = values;
121
+ }
122
+ delete flagContent.hasValue;
123
+ if (type === 'boolean') {
124
+ flagsConfig[name] = flags.boolean(config);
125
+ }
126
+ else if (array) {
127
+ flagsConfig[name] = flags.array(config);
128
+ }
129
+ else if (type === 'string') {
130
+ flagsConfig[name] = flags.string(config);
131
+ }
132
+ else {
133
+ // TODO
134
+ throw new Error('oh noes! ' + JSON.stringify(flag));
135
+ }
136
+ });
137
+ }
138
+ return flagsConfig;
139
+ }
140
+
141
+ execute(cli, klass) {
142
+ const { flags } = this.parse(klass);
143
+ if (OclifAdapter.validateCommand(cli, klass.command.name, flags)) {
144
+ return OclifAdapter.runCommand(cli, klass.command.name, flags);
145
+ }
146
+ }
147
+
148
+ resolveHerokuContext() {
149
+ this.stringifyFlags();
150
+ return {
151
+ flags: this.flags
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Call to stringify parsed flags for backward compatibility.
157
+ */
158
+ stringifyFlags() {
159
+ Object.keys(this.flags).forEach(name => {
160
+ const flag = this.flags[name];
161
+ if (flag == null) {
162
+ return;
163
+ }
164
+ const typeOfFlag = typeof this.flags[name];
165
+ switch (typeOfFlag) {
166
+ case 'string':
167
+ case 'number':
168
+ this.flags[name] = flag + '';
169
+ break;
170
+ case 'boolean':
171
+ break;
172
+ case 'object':
173
+ if (Array.isArray(flag)) {
174
+ this.flags[name] = flag.join(',');
175
+ break;
176
+ } else if (flag instanceof Date) {
177
+ this.flags[name] = flag.toISOString();
178
+ break;
179
+ } else if (flag instanceof Duration) {
180
+ this.flags[name] = flag.quantity + '';
181
+ break;
182
+ } else {
183
+ throw new SfdxError(`Unexpected value type for flag ${name}`, 'UnexpectedFlagValueType');
184
+ }
185
+ default:
186
+ throw new SfdxError(`Unexpected value type for flag ${name}`, 'UnexpectedFlagValueType');
187
+ }
188
+ });
189
+ }
190
+ }
191
+
192
+ OclifAdapter.getCommand = function(cli, commandName) {
193
+ if (!this._command) {
194
+ this._command = configHelper.getCommandExpanded(cli, commandName);
195
+ }
196
+ return this._command;
197
+ };
198
+
199
+ module.exports = OclifAdapter;
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ 'red': '\x1b[31;1m',
3
+ 'green': '\x1b[32;1m',
4
+ 'yellow': '\x1b[33;1m',
5
+ 'blue': '\x1b[34;1m',
6
+ 'magenta': '\x1b[35;1m',
7
+ 'cyan': '\x1b[36;1m',
8
+ 'reset': '\x1b[0m'
9
+ };
@@ -0,0 +1,38 @@
1
+ {
2
+ "title" : "Store configuration schema",
3
+ "description" : "Use this schema to validate userstore.json or globalstore.json",
4
+ "definitions": {
5
+ "index": {
6
+ "type": "object",
7
+ "properties": {
8
+ "path": {
9
+ "type": "string"
10
+ },
11
+ "type": {
12
+ "type": "string",
13
+ "enum": ["string", "integer", "floating", "json1", "full_text"]
14
+ }
15
+ },
16
+ "required": ["path", "type"]
17
+ },
18
+ "soup": {
19
+ "type": "object",
20
+ "properties": {
21
+ "soupName": { "type": "string"},
22
+ "indexes": {
23
+ "type": "array",
24
+ "items": { "$ref": "#/definitions/index" }
25
+ }
26
+ },
27
+ "required": ["soupName", "indexes"]
28
+ }
29
+ },
30
+ "type": "object",
31
+ "properties": {
32
+ "soups": {
33
+ "type": "array",
34
+ "items": { "$ref": "#/definitions/soup" }
35
+ }
36
+ },
37
+ "required": ["soups"]
38
+ }
@@ -0,0 +1,295 @@
1
+ {
2
+ "title" : "Syncs configuration schema",
3
+ "description" : "Use this schema to validate usersyncs.json or globalsyncs.json",
4
+ "definitions": {
5
+ "mergeMode": {
6
+ "type": "string",
7
+ "enum": ["LEAVE_IF_CHANGED", "OVERWRITE"]
8
+ },
9
+ "fieldlist": {
10
+ "type": "array",
11
+ "items": { "type": "string"}
12
+ },
13
+ "query": {
14
+ "type": "string"
15
+ },
16
+ "sobjectType": {
17
+ "type": "string"
18
+ },
19
+ "sobjectTypePlural": {
20
+ "type": "string"
21
+ },
22
+ "formFactor": {
23
+ "type": "string",
24
+ "enum": ["Large", "Medium", "Small"]
25
+ },
26
+ "layoutType": {
27
+ "type": "string",
28
+ "enum": ["Compact", "Full"]
29
+ },
30
+ "mode": {
31
+ "type": "string",
32
+ "enum": ["Create", "Edit", "View"]
33
+ },
34
+ "recordTypeId": {
35
+ "type": "string"
36
+ },
37
+ "syncName": {
38
+ "type": "string"
39
+ },
40
+ "soupName": {
41
+ "type": "string"
42
+ },
43
+ "fieldName": {
44
+ "type": "string"
45
+ },
46
+ "impl": {
47
+ "type": "string"
48
+ },
49
+ "soqlFilter": {
50
+ "type": "string"
51
+ },
52
+ "maxBatchSize": {
53
+ "type": "integer"
54
+ },
55
+ "relationshipType": {
56
+ "type": "string",
57
+ "enum": ["MASTER_DETAIL", "LOOKUP"]
58
+ },
59
+ "parentInfo": {
60
+ "type": "object",
61
+ "properties": {
62
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
63
+ "externalIdFieldName": { "$ref": "#/definitions/fieldName" },
64
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" },
65
+ "sobjectType": { "$ref": "#/definitions/sobjectType" },
66
+ "soupName": { "$ref": "#/definitions/soupName" }
67
+ },
68
+ "required": ["sobjectType", "soupName"]
69
+ },
70
+ "childrenInfo": {
71
+ "type": "object",
72
+ "properties": {
73
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
74
+ "externalIdFieldName": { "$ref": "#/definitions/fieldName" },
75
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" },
76
+ "sobjectType": { "$ref": "#/definitions/sobjectType" },
77
+ "soupName": { "$ref": "#/definitions/soupName" },
78
+ "sobjectTypePlural": { "$ref": "#/definitions/sobjectTypePlural" },
79
+ "parentIdFieldName": { "$ref": "#/definitions/fieldName" }
80
+ },
81
+ "required": ["sobjectType", "soupName", "sobjectTypePlural", "parentIdFieldName"]
82
+ },
83
+ "syncDownOptions": {
84
+ "type": "object",
85
+ "properties": {
86
+ "mergeMode": { "$ref": "#/definitions/mergeMode" }
87
+ },
88
+ "required": ["mergeMode"]
89
+ },
90
+ "syncUpOptions": {
91
+ "type": "object",
92
+ "properties": {
93
+ "mergeMode": { "$ref": "#/definitions/mergeMode" },
94
+ "fieldlist": { "$ref": "#/definitions/fieldlist" }
95
+ },
96
+ "required": ["mergeMode", "fieldlist"]
97
+ },
98
+ "soqlSyncDownTarget": {
99
+ "type": "object",
100
+ "properties": {
101
+ "type": { "const": "soql" },
102
+ "query": { "$ref": "#/definitions/query" },
103
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
104
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" },
105
+ "maxBatchSize": { "$ref": "#/definitions/maxBatchSize" }
106
+ },
107
+ "required": ["type", "query"]
108
+ },
109
+ "soslSyncDownTarget": {
110
+ "type": "object",
111
+ "properties": {
112
+ "type": { "const": "sosl" },
113
+ "query": { "$ref": "#/definitions/query" },
114
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
115
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" }
116
+ },
117
+ "required": ["type", "query"]
118
+ },
119
+ "mruSyncDownTarget": {
120
+ "type": "object",
121
+ "properties": {
122
+ "type": { "const": "mru" },
123
+ "sobjectType": { "$ref": "#/definitions/sobjectType" },
124
+ "fieldlist": { "$ref": "#/definitions/fieldlist" },
125
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
126
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" }
127
+ },
128
+ "required": ["type", "sobjectType", "fieldlist"]
129
+ },
130
+ "refreshSyncDownTarget": {
131
+ "type": "object",
132
+ "properties": {
133
+ "type": { "const": "refresh" },
134
+ "sobjectType": { "$ref": "#/definitions/sobjectType" },
135
+ "fieldlist": { "$ref": "#/definitions/fieldlist" },
136
+ "soupName": { "$ref": "#/definitions/soupName" },
137
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
138
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" }
139
+ },
140
+ "required": ["type", "sobjectType", "fieldlist", "soupName"]
141
+ },
142
+ "layoutSyncDownTarget": {
143
+ "type": "object",
144
+ "properties": {
145
+ "type": { "const": "layout" },
146
+ "sobjectType": { "$ref": "#/definitions/sobjectType" },
147
+ "formFactor": { "$ref": "#/definitions/formFactor" },
148
+ "layoutType": { "$ref": "#/definitions/layoutType" },
149
+ "mode": { "$ref": "#/definitions/mode" },
150
+ "recordTypeId": { "$ref": "#/definitions/recordTypeId" },
151
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
152
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" }
153
+ },
154
+ "required": ["type", "sobjectType", "layoutType"]
155
+ },
156
+ "metadataSyncDownTarget": {
157
+ "type": "object",
158
+ "properties": {
159
+ "type": { "const": "metadata" },
160
+ "sobjectType": { "$ref": "#/definitions/sobjectType" },
161
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
162
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" }
163
+ },
164
+ "required": ["type", "sobjectType"]
165
+ },
166
+ "parentChildrenSyncDownTarget": {
167
+ "type": "object",
168
+ "properties": {
169
+ "type": { "const": "parent_children" },
170
+ "parent": { "$ref": "#/definitions/parentInfo" },
171
+ "parentFieldlist": { "$ref": "#/definitions/fieldlist" },
172
+ "children": { "$ref": "#/definitions/childrenInfo" },
173
+ "childrenFieldlist": { "$ref": "#/definitions/fieldlist" },
174
+ "relationshipType": { "$ref": "#/definitions/relationshipType" },
175
+ "parentSoqlFilter": { "$ref": "#/definitions/soqlFilter" }
176
+ },
177
+ "required": ["type", "parent", "parentFieldlist", "children", "childrenFieldlist", "relationshipType"]
178
+ },
179
+ "customSyncDownTarget": {
180
+ "type": "object",
181
+ "properties": {
182
+ "type": { "const": "custom" },
183
+ "iOSImpl" : { "$ref": "#/definitions/impl" },
184
+ "androidImpl" : { "$ref": "#/definitions/impl" },
185
+ "idFieldName": { "$ref": "#/definitions/fieldName" },
186
+ "modificationDateFieldName": { "$ref": "#/definitions/fieldName" }
187
+ },
188
+ "required": ["type", "iOSImpl", "androidImpl"]
189
+ },
190
+ "syncDownTarget": {
191
+ "anyOf": [
192
+ { "$ref": "#/definitions/soqlSyncDownTarget" },
193
+ { "$ref": "#/definitions/soslSyncDownTarget" },
194
+ { "$ref": "#/definitions/mruSyncDownTarget" },
195
+ { "$ref": "#/definitions/refreshSyncDownTarget" },
196
+ { "$ref": "#/definitions/layoutSyncDownTarget" },
197
+ { "$ref": "#/definitions/metadataSyncDownTarget" },
198
+ { "$ref": "#/definitions/parentChildrenSyncDownTarget" },
199
+ { "$ref": "#/definitions/customSyncDownTarget" }
200
+ ]
201
+ },
202
+ "noBatchSyncUpTarget": {
203
+ "type": "object",
204
+ "properties": {
205
+ "iOSImpl" : { "const": "SFSyncUpTarget" },
206
+ "androidImpl": { "const": "com.salesforce.androidsdk.mobilesync.target.SyncUpTarget" },
207
+ "createFieldlist": { "$ref": "#/definitions/fieldlist" },
208
+ "updateFieldlist": { "$ref": "#/definitions/fieldlist" },
209
+ "externalIdFieldName": { "$ref": "#/definitions/fieldName" }
210
+ },
211
+ "required": ["iOSImpl", "androidImpl"]
212
+ },
213
+ "batchSyncUpTarget": {
214
+ "type": "object",
215
+ "properties": {
216
+ "createFieldlist": { "$ref": "#/definitions/fieldlist" },
217
+ "updateFieldlist": { "$ref": "#/definitions/fieldlist" },
218
+ "externalIdFieldName": { "$ref": "#/definitions/fieldName" }
219
+ }
220
+ },
221
+ "parentChildrenSyncUpTarget": {
222
+ "type": "object",
223
+ "properties": {
224
+ "iOSImpl" : { "const": "SFParentChildrenSyncUpTarget" },
225
+ "androidImpl": { "const": "com.salesforce.androidsdk.mobilesync.target.ParentChildrenSyncUpTarget" },
226
+ "parent": { "$ref": "#/definitions/parentInfo" },
227
+ "createFieldlist": { "$ref": "#/definitions/fieldlist" },
228
+ "updateFieldlist": { "$ref": "#/definitions/fieldlist" },
229
+ "children": { "$ref": "#/definitions/childrenInfo" },
230
+ "childrenCreateFieldlist": { "$ref": "#/definitions/fieldlist" },
231
+ "childrenUpdateFieldlist": { "$ref": "#/definitions/fieldlist" },
232
+ "relationshipType": { "$ref": "#/definitions/relationshipType" }
233
+ },
234
+ "required": ["iOSImpl", "androidImpl",
235
+ "parent", "createFieldlist", "updateFieldlist",
236
+ "children", "childrenCreateFieldlist", "childrenUpdateFieldlist",
237
+ "relationshipType"]
238
+ },
239
+ "customSyncUpTarget": {
240
+ "type": "object",
241
+ "properties": {
242
+ "iOSImpl" : { "$ref": "#/definitions/impl" },
243
+ "androidImpl" : { "$ref": "#/definitions/impl" },
244
+ "createFieldlist": { "$ref": "#/definitions/fieldlist" },
245
+ "updateFieldlist": { "$ref": "#/definitions/fieldlist" }
246
+ },
247
+ "required": ["iOSImpl", "androidImpl"]
248
+ },
249
+ "syncUpTarget": {
250
+ "anyOf": [
251
+ { "$ref": "#/definitions/parentChildrenSyncUpTarget" },
252
+ { "$ref": "#/definitions/noBatchSyncUpTarget" },
253
+ { "$ref": "#/definitions/customSyncUpTarget" },
254
+ { "$ref": "#/definitions/batchSyncUpTarget" }
255
+ ]
256
+ },
257
+ "syncDown": {
258
+ "type": "object",
259
+ "properties": {
260
+ "syncName": { "$ref": "#/definitions/syncName" },
261
+ "soupName": { "$ref": "#/definitions/soupName" },
262
+ "syncType": { "const": "syncDown" },
263
+ "target": { "$ref": "#/definitions/syncDownTarget" },
264
+ "options": { "$ref": "#/definitions/syncDownOptions"}
265
+ },
266
+ "required": ["syncName", "soupName", "syncType", "target", "options"]
267
+ },
268
+ "syncUp": {
269
+ "type": "object",
270
+ "properties": {
271
+ "syncName": { "$ref": "#/definitions/syncName" },
272
+ "soupName": { "$ref": "#/definitions/soupName" },
273
+ "syncType": { "const": "syncUp" },
274
+ "target": { "$ref": "#/definitions/syncUpTarget" },
275
+ "options": { "$ref": "#/definitions/syncUpOptions"}
276
+ },
277
+ "required": ["syncName", "soupName", "syncType", "target", "options"]
278
+ },
279
+ "sync": {
280
+ "oneOf": [
281
+ { "$ref": "#/definitions/syncDown" },
282
+ { "$ref": "#/definitions/syncUp" }
283
+ ]
284
+ }
285
+ },
286
+
287
+ "type": "object",
288
+ "properties": {
289
+ "syncs": {
290
+ "type": "array",
291
+ "items": { "$ref": "#/definitions/sync" }
292
+ }
293
+ },
294
+ "required": ["syncs"]
295
+ }
@@ -0,0 +1,104 @@
1
+ /*
2
+ * Copyright (c) 2018-present, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * Redistribution and use of this software in source and binary forms, with or
5
+ * without modification, are permitted provided that the following conditions
6
+ * are met:
7
+ * - Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ * - Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ * - Neither the name of salesforce.com, inc. nor the names of its contributors
13
+ * may be used to endorse or promote products derived from this software without
14
+ * specific prior written permission of salesforce.com, inc.
15
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
+ * POSSIBILITY OF SUCH DAMAGE.
26
+ */
27
+
28
+ // Dependencies
29
+ var path = require('path'),
30
+ SDK = require('./constants'),
31
+ utils = require('./utils');
32
+
33
+ //
34
+ // Helper to prepare template
35
+ //
36
+ function prepareTemplate(config, templateDir) {
37
+ var template = require(path.join(templateDir, 'template.js'));
38
+ return utils.runFunctionThrowError(
39
+ function() {
40
+ return template.prepare(config, utils.replaceInFiles, utils.moveFile, utils.removeFile);
41
+ },
42
+ templateDir);
43
+ }
44
+
45
+ //
46
+ // Get templates for the given cli
47
+ //
48
+ function getTemplates(cli) {
49
+ try {
50
+
51
+ // Creating tmp dir for template clone
52
+ var tmpDir = utils.mkTmpDir();
53
+
54
+ // Cloning template repo
55
+ var repoDir = utils.cloneRepo(tmpDir, SDK.templatesRepoUri);
56
+
57
+ // Getting list of templates
58
+ var templates = require(path.join(repoDir, 'templates.json'));
59
+
60
+ // Keeping only applicable templates, adding full template url
61
+ var applicableTemplates = templates
62
+ .filter(template => cli.appTypes.includes(template.appType) && cli.platforms.filter(platform => template.platforms.includes(platform)).length > 0);
63
+
64
+ // Cleanup
65
+ utils.removeFile(tmpDir);
66
+
67
+ return applicableTemplates;
68
+ }
69
+ catch (error) {
70
+ utils.logError(cli.name + ' failed\n', error);
71
+ process.exit(1);
72
+ }
73
+ }
74
+
75
+ //
76
+ // Get appType for the given template given by its uri
77
+ //
78
+ function getAppTypeFromTemplate(templateRepoUriWithPossiblePath) {
79
+ var templateUriParsed = utils.separateRepoUrlPathBranch(templateRepoUriWithPossiblePath);
80
+ var templateRepoUri = templateUriParsed.repo + '#' + templateUriParsed.branch;
81
+ var templatePath = templateUriParsed.path;
82
+
83
+ // Creating tmp dir for template clone
84
+ var tmpDir = utils.mkTmpDir();
85
+
86
+ // Cloning template repo
87
+ var repoDir = utils.cloneRepo(tmpDir, templateRepoUri);
88
+
89
+ // Getting template
90
+ var appType = require(path.join(repoDir, templatePath, 'template.js')).appType;
91
+
92
+ // Cleanup
93
+ utils.removeFile(tmpDir);
94
+
95
+ // Done
96
+ return appType;
97
+ }
98
+
99
+
100
+ module.exports = {
101
+ prepareTemplate,
102
+ getTemplates,
103
+ getAppTypeFromTemplate
104
+ };