-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcommands.ts
More file actions
71 lines (60 loc) · 2.49 KB
/
commands.ts
File metadata and controls
71 lines (60 loc) · 2.49 KB
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
import { findUp, resolveCwd } from '@twilio/flex-dev-utils/dist/fs';
import { spawn } from '@twilio/flex-dev-utils/dist/spawn';
import { camelCase, upperFirst } from '@twilio/flex-dev-utils/dist/lodash';
import { packages } from '@twilio/flex-dev-utils';
import * as github from '../utils/github';
import { FlexPluginArguments } from './create-flex-plugin';
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require, @typescript-eslint/no-require-imports
const pkg = require(findUp(__filename, 'package.json'));
/**
* Install dependencies
*
* @param config {FlexPluginArguments} the plugin argument
* @return {string} the stdout of the execution
*/
export const installDependencies = async (config: FlexPluginArguments): Promise<string> => {
const shellCmd = config.yarn ? 'yarn' : 'npm';
const args = ['install'];
const options = {
cwd: config.targetDirectory,
shell: process.env.SHELL,
};
const { stdout, exitCode, stderr } = await spawn(shellCmd, args, options);
if (exitCode === 1) {
throw new Error(stderr);
}
return stdout;
};
/**
* Appends className to the configuration
*
* @param config {FlexPluginArguments} the plugin configuration
* @return {FlexPluginArguments} the updated configuration
*/
export const setupConfiguration = async (config: FlexPluginArguments): Promise<FlexPluginArguments> => {
const name = config.name || '';
config.pluginClassName = `${upperFirst(camelCase(name)).replace('Plugin', '')}Plugin`;
config.pluginNamespace = name.toLowerCase().replace('plugin-', '');
config.runtimeUrl = config.runtimeUrl || 'http://flex.local.com:3000';
config.targetDirectory = resolveCwd(name);
config.flexSdkVersion = await packages.getLatestFlexUIVersion(2);
config.pluginScriptsVersion = pkg.devDependencies['@twilio/flex-plugin-scripts'];
config.flexPluginVersion = pkg.devDependencies['@twilio/flex-plugin'];
config.flexui2 = config.flexui2 || true;
config.flexui1 = config.flexui1 || false;
// Upgrade to latest Flex UI Version for 1.0 if selected
if (config.flexui1) {
config.flexSdkVersion = pkg.devDependencies['@twilio/flex-ui'];
}
return config;
};
/**
* Downloads content from GitHub
*
* @param url {string} the GitHub url
* @param dir {string} the temp directory to save the downloaded file to
*/
export const downloadFromGitHub = async (url: string, dir: string): Promise<void> => {
const info = await github.parseGitHubUrl(url);
return github.downloadRepo(info, dir);
};