-
Notifications
You must be signed in to change notification settings - Fork 7
/
init.js
80 lines (62 loc) · 2.4 KB
/
init.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
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands,
{
createEnvFile,
createPackageJSON,
renameFile,
updateSchemaFile,
} = require("../../lib/serverless/create-files"),
{
installDependencies,
} = require("../../lib/serverless/install-dependencies"),
ora = require("ora"),
path = require("path"),
{ camelCase, kebabCase, snakeCase } = require("lodash"),
{ cloneTemplate } = require("../../lib/serverless/clone-template");
const { options, describe } = require("../../lib/options/init"),
{ convertYargsOptionsToOclifFlags, normalizeFlags } = require("../../utils");
class InitAssistant extends TwilioClientCommand {
async run() {
await super.run();
let spinner = await ora();
try {
let { flags } = await this.parse(InitAssistant),
clonedAssistant = "";
flags = normalizeFlags(flags);
// let url = 'https://raw.githubusercontent.com/Mohammad-Khalid/twilio-templates/master/templates.json';
// clonedAssistant = await AutopilotCore.cloneTemplate(url, false, 'Templates', kebabCase(flags.botName) || false);
clonedAssistant = await cloneTemplate(flags, this.inquirer);
const funcPath = path.join(clonedAssistant, "function");
spinner.start("Setting Up .env file");
let fullPath = `${path.resolve()}/${funcPath}`;
await createEnvFile(fullPath, {
accountSid: flags.accountSid || this.twilioClient.username,
authToken: flags.authToken || this.twilioClient.password,
});
spinner.succeed();
spinner.start("Setting Up package.json file");
await createPackageJSON(
fullPath,
camelCase(clonedAssistant).toLowerCase()
);
spinner.succeed();
if (flags.botName) {
const schemaPath = path.join(clonedAssistant, "model");
await updateSchemaFile(
`${path.resolve()}/${schemaPath}`,
kebabCase(flags.botName)
);
}
spinner.start(`Installing dependencies`);
await installDependencies(fullPath);
spinner.succeed();
} catch (err) {
spinner.fail();
console.error(`ERROR: ${err}`);
}
}
}
InitAssistant.description = describe;
InitAssistant.flags = Object.assign(convertYargsOptionsToOclifFlags(options), {
profile: TwilioClientCommand.flags.profile,
});
module.exports = InitAssistant;