@twilio/create-flex-plugin 5.0.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +132 -0
  3. package/bin/create-flex-plugin +10 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +14 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/cli.d.ts +26 -0
  8. package/dist/lib/cli.js +128 -0
  9. package/dist/lib/cli.js.map +1 -0
  10. package/dist/lib/commands.d.ts +22 -0
  11. package/dist/lib/commands.js +128 -0
  12. package/dist/lib/commands.js.map +1 -0
  13. package/dist/lib/create-flex-plugin.d.ts +28 -0
  14. package/dist/lib/create-flex-plugin.js +176 -0
  15. package/dist/lib/create-flex-plugin.js.map +1 -0
  16. package/dist/prints/finalMessage.d.ts +7 -0
  17. package/dist/prints/finalMessage.js +20 -0
  18. package/dist/prints/finalMessage.js.map +1 -0
  19. package/dist/utils/github.d.ts +77 -0
  20. package/dist/utils/github.js +222 -0
  21. package/dist/utils/github.js.map +1 -0
  22. package/dist/utils/validators.d.ts +19 -0
  23. package/dist/utils/validators.js +103 -0
  24. package/dist/utils/validators.js.map +1 -0
  25. package/package.json +61 -0
  26. package/templates/core/README.md +31 -0
  27. package/templates/core/_.gitignore +66 -0
  28. package/templates/core/jest.config.js +8 -0
  29. package/templates/core/public/appConfig.example.js +9 -0
  30. package/templates/core/public/appConfig.js +7 -0
  31. package/templates/core/webpack.config.js +8 -0
  32. package/templates/core/webpack.dev.js +8 -0
  33. package/templates/js/package.json +18 -0
  34. package/templates/js/src/DemoPlugin.js +43 -0
  35. package/templates/js/src/components/CustomTaskList/CustomTaskList.Container.js +15 -0
  36. package/templates/js/src/components/CustomTaskList/CustomTaskList.Styles.js +14 -0
  37. package/templates/js/src/components/CustomTaskList/CustomTaskList.jsx +29 -0
  38. package/templates/js/src/components/__tests__/CustomTaskListComponent.spec.jsx +15 -0
  39. package/templates/js/src/index.js +5 -0
  40. package/templates/js/src/states/CustomTaskListState.js +24 -0
  41. package/templates/js/src/states/index.js +11 -0
  42. package/templates/ts/package.json +19 -0
  43. package/templates/ts/src/DemoPlugin.tsx +43 -0
  44. package/templates/ts/src/components/CustomTaskList/CustomTaskList.Container.ts +24 -0
  45. package/templates/ts/src/components/CustomTaskList/CustomTaskList.Styles.ts +14 -0
  46. package/templates/ts/src/components/CustomTaskList/CustomTaskList.tsx +31 -0
  47. package/templates/ts/src/components/__tests__/CustomTaskListComponent.spec.tsx +15 -0
  48. package/templates/ts/src/index.ts +5 -0
  49. package/templates/ts/src/states/CustomTaskListState.ts +30 -0
  50. package/templates/ts/src/states/index.ts +26 -0
  51. package/templates/ts/tsconfig.json +36 -0
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.createFlexPlugin = exports._scaffold = exports._install = void 0;
43
+ var fs_1 = __importDefault(require("fs"));
44
+ var path_1 = require("path");
45
+ var flex_dev_utils_1 = require("@twilio/flex-dev-utils");
46
+ var fs_2 = require("@twilio/flex-dev-utils/dist/fs");
47
+ var tmp_1 = require("tmp");
48
+ var commands_1 = require("./commands");
49
+ var finalMessage_1 = __importDefault(require("../prints/finalMessage"));
50
+ var validators_1 = __importDefault(require("../utils/validators"));
51
+ var templatesRootDir = path_1.resolve(__dirname, '../../templates');
52
+ var templateCorePath = path_1.resolve(templatesRootDir, 'core');
53
+ var templateJsPath = path_1.resolve(templatesRootDir, 'js');
54
+ var templateTsPath = path_1.resolve(templatesRootDir, 'ts');
55
+ /**
56
+ * Runs the NPM Installation
57
+ * @param config {FlexPluginArguments} the configuration
58
+ * @private
59
+ */
60
+ var _install = function (config) { return __awaiter(void 0, void 0, void 0, function () {
61
+ return __generator(this, function (_a) {
62
+ return [2 /*return*/, flex_dev_utils_1.progress('Installing dependencies', function () { return __awaiter(void 0, void 0, void 0, function () {
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0: return [4 /*yield*/, commands_1.installDependencies(config)];
66
+ case 1:
67
+ _a.sent();
68
+ return [2 /*return*/, true];
69
+ }
70
+ });
71
+ }); })];
72
+ });
73
+ }); };
74
+ exports._install = _install;
75
+ /**
76
+ * Creates all the directories and copies the templates over
77
+ *
78
+ * @param config {FlexPluginArguments} the configuration
79
+ * @private
80
+ */
81
+ var _scaffold = function (config) { return __awaiter(void 0, void 0, void 0, function () {
82
+ var dirObject, promise, cleanUp;
83
+ return __generator(this, function (_a) {
84
+ promise = flex_dev_utils_1.progress('Creating project directory', function () { return __awaiter(void 0, void 0, void 0, function () {
85
+ var srcPath, ext;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ // This copies the core such as public/
90
+ return [4 /*yield*/, fs_2.copyTemplateDir(templateCorePath, config.targetDirectory, config)];
91
+ case 1:
92
+ // This copies the core such as public/
93
+ _a.sent();
94
+ srcPath = templateJsPath;
95
+ if (config.typescript) {
96
+ srcPath = templateTsPath;
97
+ }
98
+ if (!config.template) return [3 /*break*/, 3];
99
+ dirObject = tmp_1.dirSync();
100
+ return [4 /*yield*/, commands_1.downloadFromGitHub(config.template, dirObject.name)];
101
+ case 2:
102
+ _a.sent();
103
+ srcPath = dirObject.name;
104
+ _a.label = 3;
105
+ case 3:
106
+ // This copies the src/ directory
107
+ return [4 /*yield*/, fs_2.copyTemplateDir(srcPath, config.targetDirectory, config)];
108
+ case 4:
109
+ // This copies the src/ directory
110
+ _a.sent();
111
+ // Rename plugins
112
+ if (!dirObject) {
113
+ ext = config.typescript ? 'tsx' : 'js';
114
+ fs_1.default.renameSync(path_1.join(config.targetDirectory, "src/DemoPlugin." + ext), path_1.join(config.targetDirectory, "src/" + config.pluginClassName + "." + ext));
115
+ }
116
+ return [2 /*return*/, true];
117
+ }
118
+ });
119
+ }); });
120
+ cleanUp = function () {
121
+ if (dirObject) {
122
+ dirObject.removeCallback();
123
+ }
124
+ };
125
+ promise.then(cleanUp).catch(cleanUp);
126
+ return [2 /*return*/, promise];
127
+ });
128
+ }); };
129
+ exports._scaffold = _scaffold;
130
+ /**
131
+ * Creates a Flex Plugin from the {@link FlexPluginArguments}
132
+ * @param config {FlexPluginArguments} the configuration
133
+ */
134
+ var createFlexPlugin = function (config) { return __awaiter(void 0, void 0, void 0, function () {
135
+ var _a;
136
+ return __generator(this, function (_b) {
137
+ switch (_b.label) {
138
+ case 0: return [4 /*yield*/, validators_1.default(config)];
139
+ case 1:
140
+ config = _b.sent();
141
+ config = commands_1.setupConfiguration(config);
142
+ // Check folder does not exist
143
+ if (fs_1.default.existsSync(config.targetDirectory)) {
144
+ throw new flex_dev_utils_1.FlexPluginError(flex_dev_utils_1.singleLineString("Path " + flex_dev_utils_1.logger.coloredStrings.link(config.targetDirectory) + " already exists;", 'please remove it and try again.'));
145
+ }
146
+ return [4 /*yield*/, exports._scaffold(config)];
147
+ case 2:
148
+ // Setup the directories
149
+ if (!(_b.sent())) {
150
+ throw new flex_dev_utils_1.FlexPluginError('Failed to scaffold project');
151
+ }
152
+ // Add new plugin to .twilio-cli/flex/plugins.json
153
+ return [4 /*yield*/, fs_2.checkPluginConfigurationExists(config.name, config.targetDirectory)];
154
+ case 3:
155
+ // Add new plugin to .twilio-cli/flex/plugins.json
156
+ _b.sent();
157
+ _a = config.install;
158
+ if (!_a) return [3 /*break*/, 5];
159
+ return [4 /*yield*/, exports._install(config)];
160
+ case 4:
161
+ _a = !(_b.sent());
162
+ _b.label = 5;
163
+ case 5:
164
+ // Install NPM dependencies
165
+ if (_a) {
166
+ flex_dev_utils_1.logger.error('Failed to install dependencies. Please run `npm install` manually.');
167
+ config.install = false;
168
+ }
169
+ finalMessage_1.default(config);
170
+ return [2 /*return*/];
171
+ }
172
+ });
173
+ }); };
174
+ exports.createFlexPlugin = createFlexPlugin;
175
+ exports.default = exports.createFlexPlugin;
176
+ //# sourceMappingURL=create-flex-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-flex-plugin.js","sourceRoot":"","sources":["../../src/lib/create-flex-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAoB;AACpB,6BAAqC;AAErC,yDAA6F;AAC7F,qDAAiG;AACjG,2BAAuE;AAEvE,uCAAyF;AAEzF,wEAAkD;AAClD,mEAA2C;AAE3C,IAAM,gBAAgB,GAAG,cAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAC/D,IAAM,gBAAgB,GAAG,cAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAC3D,IAAM,cAAc,GAAG,cAAO,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AACvD,IAAM,cAAc,GAAG,cAAO,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAWvD;;;;GAIG;AACI,IAAM,QAAQ,GAAG,UAAO,MAA2B;;QACxD,sBAAO,yBAAQ,CAAC,yBAAyB,EAAE;;;gCACzC,qBAAM,8BAAmB,CAAC,MAAM,CAAC,EAAA;;4BAAjC,SAAiC,CAAC;4BAElC,sBAAO,IAAI,EAAC;;;iBACb,CAAC,EAAC;;KACJ,CAAC;AANW,QAAA,QAAQ,YAMnB;AAEF;;;;;GAKG;AACI,IAAM,SAAS,GAAG,UAAO,MAA2B;;;QAGnD,OAAO,GAAG,yBAAQ,CAAC,4BAA4B,EAAE;;;;;oBACrD,uCAAuC;oBACvC,qBAAM,oBAAe,CAAC,gBAAgB,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,EAAA;;wBADvE,uCAAuC;wBACvC,SAAuE,CAAC;wBA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BAChC,MAAM,GAAG,6BAAkB,CAAC,MAAM,CAAC,CAAC;gBAEpC,8BAA8B;gBAC9B,IAAI,YAAE,CAAC,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;oBACzC,MAAM,IAAI,gCAAe,CACvB,iCAAgB,CACd,UAAQ,uBAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,qBAAkB,EAC5E,iCAAiC,CAClC,CACF,CAAC;iBACH;gBAGK,qBAAM,iBAAS,CAAC,MAAM,CAAC,EAAA;;gBAD7B,wBAAwB;gBACxB,IAAI,CAAC,CAAC,SAAuB,CAAC,EAAE;oBAC9B,MAAM,IAAI,gCAAe,CAAC,4BAA4B,CAAC,CAAC;iBACzD;gBAED,kDAAkD;gBAClD,qBAAM,mCAA8B,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,eAAe,CAAC,EAAA;;gBADzE,kDAAkD;gBAClD,SAAyE,CAAC;gBAGtE,KAAA,MAAM,CAAC,OAAO,CAAA;yBAAd,wBAAc;gBAAM,qBAAM,gBAAQ,CAAC,MAAM,CAAC,EAAA;;gBAAxB,KAAA,CAAC,CAAC,SAAsB,CAAC,CAAA;;;gBAD/C,2BAA2B;gBAC3B,QAAiD;oBAC/C,uBAAM,CAAC,KAAK,CAAC,oEAAoE,CAAC,CAAC;oBACnF,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;iBACxB;gBAED,sBAAY,CAAC,MAAM,CAAC,CAAC;;;;KACtB,CAAC;AA7BW,QAAA,gBAAgB,oBA6B3B;AAEF,kBAAe,wBAAgB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { FlexPluginArguments } from '../lib/create-flex-plugin';
2
+ declare const _default: (config: FlexPluginArguments) => void;
3
+ /**
4
+ * Prints the final message after the successful creation of a new project
5
+ * @param config
6
+ */
7
+ export default _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var flex_dev_utils_1 = require("@twilio/flex-dev-utils");
4
+ var headline = flex_dev_utils_1.logger.coloredStrings.headline;
5
+ /**
6
+ * Prints the final message after the successful creation of a new project
7
+ * @param config
8
+ */
9
+ exports.default = (function (config) {
10
+ var installCommand = config.yarn ? 'yarn install' : 'npm install';
11
+ var setupMessage = flex_dev_utils_1.multilineString("" + headline('Setup:'), "$ cd " + config.name + "/", "$ " + installCommand);
12
+ var devMessage = flex_dev_utils_1.multilineString("" + headline('Development:'), "$ cd " + config.name + "/", "$ twilio flex:plugins:start");
13
+ var buildMessage = flex_dev_utils_1.multilineString("" + headline('Build Command:'), "$ cd " + config.name + "/", "$ twilio flex:plugins:build");
14
+ var deployMessage = flex_dev_utils_1.multilineString("" + headline('Deploy Command:'), "$ cd " + config.name + "/", "$ twilio flex:plugins:deploy");
15
+ var message = flex_dev_utils_1.multilineString("Your Twilio Flex Plugin project has been successfully created!", (config.install ? '' : "\n\n " + setupMessage) + "\n", devMessage + "\n", buildMessage + "\n", deployMessage + "\n", 'For more info check the README.md file or go to:', '➡ https://www.twilio.com/docs/flex');
16
+ var columns = (process.stdout.columns || 100) - 14;
17
+ message = flex_dev_utils_1.logger.wrap(message, columns, { hard: true });
18
+ flex_dev_utils_1.boxen.info(message, false);
19
+ });
20
+ //# sourceMappingURL=finalMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finalMessage.js","sourceRoot":"","sources":["../../src/prints/finalMessage.ts"],"names":[],"mappings":";;AAAA,yDAAwE;AAIhE,IAAA,QAAQ,GAAK,uBAAM,CAAC,cAAc,SAA1B,CAA2B;AAE3C;;;GAGG;AACH,mBAAe,UAAC,MAA2B;IACzC,IAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC;IACpE,IAAM,YAAY,GAAG,gCAAe,CAAC,KAAG,QAAQ,CAAC,QAAQ,CAAG,EAAE,UAAQ,MAAM,CAAC,IAAI,MAAG,EAAE,OAAK,cAAgB,CAAC,CAAC;IAE7G,IAAM,UAAU,GAAG,gCAAe,CAChC,KAAG,QAAQ,CAAC,cAAc,CAAG,EAC7B,UAAQ,MAAM,CAAC,IAAI,MAAG,EACtB,6BAA6B,CAC9B,CAAC;IAEF,IAAM,YAAY,GAAG,gCAAe,CAClC,KAAG,QAAQ,CAAC,gBAAgB,CAAG,EAC/B,UAAQ,MAAM,CAAC,IAAI,MAAG,EACtB,6BAA6B,CAC9B,CAAC;IAEF,IAAM,aAAa,GAAG,gCAAe,CACnC,KAAG,QAAQ,CAAC,iBAAiB,CAAG,EAChC,UAAQ,MAAM,CAAC,IAAI,MAAG,EACtB,8BAA8B,CAC/B,CAAC;IAEF,IAAI,OAAO,GAAG,gCAAe,CAC3B,gEAAgE,EAChE,CAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAQ,YAAc,QAAI,EAChD,UAAU,OAAI,EACd,YAAY,OAAI,EAChB,aAAa,OAAI,EACpB,kDAAkD,EAClD,oCAAoC,CACrC,CAAC;IAEF,IAAM,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;IACrD,OAAO,GAAG,uBAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAExD,sBAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC,EAAC"}
@@ -0,0 +1,77 @@
1
+ export interface GitHubInfo {
2
+ owner: string;
3
+ repo: string;
4
+ ref: string;
5
+ }
6
+ export interface GitHubBranches {
7
+ name: string;
8
+ commit: string;
9
+ protected: boolean;
10
+ }
11
+ export declare enum GitHubContentType {
12
+ File = "file",
13
+ Dir = "dir"
14
+ }
15
+ export interface GitHubContent {
16
+ name: string;
17
+ path: string;
18
+ sha: string;
19
+ size: number;
20
+ url: string;
21
+ html_url: string;
22
+ git_url: string;
23
+ download_url: string;
24
+ type: GitHubContentType;
25
+ _links: {
26
+ self: string;
27
+ git: string;
28
+ html: string;
29
+ };
30
+ }
31
+ export declare const ERROR_GITHUB_URL_PARSE = "Could not get owner and repo name from GitHub URL";
32
+ export declare const ERROR_BRANCH_MASTER_MAIN = "Could not find branch main or master on GitHub";
33
+ /**
34
+ * Generates a regex for matching the download url
35
+ * @param info {GitHubInfo} the GitHub information
36
+ * @param hasTemplateDir {boolean} whether the GitHub repo has a template directory
37
+ * @private
38
+ */
39
+ export declare const _getBaseRegex: (info: GitHubInfo, hasTemplateDir: boolean) => string;
40
+ /**
41
+ * Checks for back-ward compatible changes; returns true is the repo has a template/ directory
42
+ * @param info {GitHubInfo} the {@link GitHubInfo} information
43
+ * @private
44
+ */
45
+ export declare const _hasTemplateDir: (info: GitHubInfo) => Promise<boolean>;
46
+ /**
47
+ * Downloads the file
48
+ *
49
+ * @param url {string} the url of the file to download
50
+ * @param output {string} the output path
51
+ * @private
52
+ */
53
+ export declare const _downloadFile: (url: string, output: string) => Promise<void>;
54
+ /**
55
+ * Recursively downloads the directory
56
+ *
57
+ * @param url {string} the url to download
58
+ * @param dir {string} the path to the directory to save the content
59
+ * @param baseRegex {String} the base path regex
60
+ * @private
61
+ */
62
+ export declare const _downloadDir: (url: string, dir: string, baseRegex: string) => Promise<void>;
63
+ /**
64
+ * Parses the GitHub URL to extract owner and repo information
65
+ *
66
+ * @param url {string} the GitHub URL
67
+ * @return returns the {@link GitHubInfo}
68
+ */
69
+ export declare const parseGitHubUrl: (url: string) => Promise<GitHubInfo>;
70
+ /**
71
+ * Downloads the repo to the provided directory path
72
+ *
73
+ * @param info {GitHubInfo} the GitHub information
74
+ * @param dir {string} the directory to download the content to
75
+ * @return null
76
+ */
77
+ export declare const downloadRepo: (info: GitHubInfo, dir: string) => Promise<void>;
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.downloadRepo = exports.parseGitHubUrl = exports._downloadDir = exports._downloadFile = exports._hasTemplateDir = exports._getBaseRegex = exports.ERROR_BRANCH_MASTER_MAIN = exports.ERROR_GITHUB_URL_PARSE = exports.GitHubContentType = void 0;
43
+ /* eslint-disable camelcase */
44
+ var fs_1 = __importDefault(require("fs"));
45
+ var path_1 = __importDefault(require("path"));
46
+ var axios_1 = __importDefault(require("@twilio/flex-dev-utils/dist/axios"));
47
+ var fs_2 = require("@twilio/flex-dev-utils/dist/fs");
48
+ var GitHubContentType;
49
+ (function (GitHubContentType) {
50
+ GitHubContentType["File"] = "file";
51
+ GitHubContentType["Dir"] = "dir";
52
+ })(GitHubContentType = exports.GitHubContentType || (exports.GitHubContentType = {}));
53
+ exports.ERROR_GITHUB_URL_PARSE = 'Could not get owner and repo name from GitHub URL';
54
+ exports.ERROR_BRANCH_MASTER_MAIN = 'Could not find branch main or master on GitHub';
55
+ /**
56
+ * Generates a regex for matching the download url
57
+ * @param info {GitHubInfo} the GitHub information
58
+ * @param hasTemplateDir {boolean} whether the GitHub repo has a template directory
59
+ * @private
60
+ */
61
+ var _getBaseRegex = function (info, hasTemplateDir) {
62
+ var baseRegex = "/" + info.owner + "/" + info.repo + "/" + info.ref + "/";
63
+ if (hasTemplateDir) {
64
+ return baseRegex + "template/";
65
+ }
66
+ return baseRegex;
67
+ };
68
+ exports._getBaseRegex = _getBaseRegex;
69
+ /**
70
+ * Checks for back-ward compatible changes; returns true is the repo has a template/ directory
71
+ * @param info {GitHubInfo} the {@link GitHubInfo} information
72
+ * @private
73
+ */
74
+ var _hasTemplateDir = function (info) { return __awaiter(void 0, void 0, void 0, function () {
75
+ var url;
76
+ return __generator(this, function (_a) {
77
+ url = "https://api.github.com/repos/" + info.owner + "/" + info.repo + "/contents?ref=" + info.ref;
78
+ return [2 /*return*/, axios_1.default
79
+ .get(url)
80
+ .then(function (resp) { return resp.data; })
81
+ .then(function (contents) { return contents.some(function (content) { return content.name === 'template' && content.type === 'dir'; }); })];
82
+ });
83
+ }); };
84
+ exports._hasTemplateDir = _hasTemplateDir;
85
+ /**
86
+ * Downloads the file
87
+ *
88
+ * @param url {string} the url of the file to download
89
+ * @param output {string} the output path
90
+ * @private
91
+ */
92
+ var _downloadFile = function (url, output) { return __awaiter(void 0, void 0, void 0, function () {
93
+ var config, dir;
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0:
97
+ config = {
98
+ url: url,
99
+ responseType: 'arraybuffer',
100
+ method: 'GET',
101
+ };
102
+ dir = path_1.default.dirname(output);
103
+ return [4 /*yield*/, fs_2.mkdirpSync(dir)];
104
+ case 1:
105
+ _a.sent();
106
+ return [2 /*return*/, axios_1.default.request(config).then(function (result) { return fs_1.default.writeFileSync(output, result.data); })];
107
+ }
108
+ });
109
+ }); };
110
+ exports._downloadFile = _downloadFile;
111
+ /**
112
+ * Recursively downloads the directory
113
+ *
114
+ * @param url {string} the url to download
115
+ * @param dir {string} the path to the directory to save the content
116
+ * @param baseRegex {String} the base path regex
117
+ * @private
118
+ */
119
+ var _downloadDir = function (url, dir, baseRegex) { return __awaiter(void 0, void 0, void 0, function () {
120
+ return __generator(this, function (_a) {
121
+ return [2 /*return*/, axios_1.default
122
+ .get(url)
123
+ .then(function (resp) { return resp.data; })
124
+ .then(function (contents) { return __awaiter(void 0, void 0, void 0, function () {
125
+ var promises;
126
+ return __generator(this, function (_a) {
127
+ switch (_a.label) {
128
+ case 0:
129
+ promises = contents.map(function (content) { return __awaiter(void 0, void 0, void 0, function () {
130
+ var regex, relativePath, output;
131
+ return __generator(this, function (_a) {
132
+ if (content.type === GitHubContentType.Dir) {
133
+ return [2 /*return*/, exports._downloadDir(content.url, dir, baseRegex)];
134
+ }
135
+ if (content.type !== GitHubContentType.File) {
136
+ throw new Error("Unexpected content type " + content.type);
137
+ }
138
+ regex = new RegExp(baseRegex + "(.+)\\??");
139
+ relativePath = content.download_url.match(regex);
140
+ if (!relativePath || relativePath.length !== 2) {
141
+ throw new Error('Received invalid URL template');
142
+ }
143
+ output = path_1.default.resolve(dir, relativePath[1]);
144
+ return [2 /*return*/, exports._downloadFile(content.download_url, output)];
145
+ });
146
+ }); });
147
+ return [4 /*yield*/, Promise.all(promises)];
148
+ case 1:
149
+ _a.sent();
150
+ return [2 /*return*/];
151
+ }
152
+ });
153
+ }); })];
154
+ });
155
+ }); };
156
+ exports._downloadDir = _downloadDir;
157
+ /**
158
+ * Parses the GitHub URL to extract owner and repo information
159
+ *
160
+ * @param url {string} the GitHub URL
161
+ * @return returns the {@link GitHubInfo}
162
+ */
163
+ var parseGitHubUrl = function (url) { return __awaiter(void 0, void 0, void 0, function () {
164
+ var matches, info, branches, hasMaster, hasMain;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0:
168
+ matches = url.match(/github\.com\/([0-9a-zA-Z-_]+)\/([0-9a-zA-Z-_]+)(\/tree\/([0-9a-zA-Z._-]+))?/);
169
+ if (!matches || matches.length < 3) {
170
+ throw new Error(exports.ERROR_GITHUB_URL_PARSE);
171
+ }
172
+ info = {
173
+ owner: matches[1],
174
+ repo: matches[2],
175
+ ref: matches[4] || 'master',
176
+ };
177
+ if (!(info.ref === 'master' || info.ref === 'main')) return [3 /*break*/, 2];
178
+ return [4 /*yield*/, axios_1.default
179
+ .get("https://api.github.com/repos/" + info.owner + "/" + info.repo + "/branches")
180
+ .then(function (resp) { return resp.data; })];
181
+ case 1:
182
+ branches = _a.sent();
183
+ hasMaster = branches.find(function (branch) { return branch.name === 'master'; });
184
+ hasMain = branches.find(function (branch) { return branch.name === 'main'; });
185
+ if (hasMain) {
186
+ info.ref = 'main';
187
+ }
188
+ else if (hasMaster) {
189
+ info.ref = 'master';
190
+ }
191
+ else {
192
+ throw new Error(exports.ERROR_BRANCH_MASTER_MAIN);
193
+ }
194
+ _a.label = 2;
195
+ case 2: return [2 /*return*/, info];
196
+ }
197
+ });
198
+ }); };
199
+ exports.parseGitHubUrl = parseGitHubUrl;
200
+ /**
201
+ * Downloads the repo to the provided directory path
202
+ *
203
+ * @param info {GitHubInfo} the GitHub information
204
+ * @param dir {string} the directory to download the content to
205
+ * @return null
206
+ */
207
+ var downloadRepo = function (info, dir) { return __awaiter(void 0, void 0, void 0, function () {
208
+ var hasTemplateDir, url;
209
+ return __generator(this, function (_a) {
210
+ switch (_a.label) {
211
+ case 0: return [4 /*yield*/, exports._hasTemplateDir(info)];
212
+ case 1:
213
+ hasTemplateDir = _a.sent();
214
+ url = hasTemplateDir
215
+ ? "https://api.github.com/repos/" + info.owner + "/" + info.repo + "/contents/template?ref=" + info.ref
216
+ : "https://api.github.com/repos/" + info.owner + "/" + info.repo + "/contents?ref=" + info.ref;
217
+ return [2 /*return*/, exports._downloadDir(url, dir, exports._getBaseRegex(info, hasTemplateDir))];
218
+ }
219
+ });
220
+ }); };
221
+ exports.downloadRepo = downloadRepo;
222
+ //# sourceMappingURL=github.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/utils/github.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,0CAAoB;AACpB,8CAAwB;AAExB,4EAA8E;AAC9E,qDAA4D;AAc5D,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,kCAAa,CAAA;IACb,gCAAW,CAAA;AACb,CAAC,EAHW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAG5B;AAmBY,QAAA,sBAAsB,GAAG,mDAAmD,CAAC;AAC7E,QAAA,wBAAwB,GAAG,gDAAgD,CAAC;AAEzF;;;;;GAKG;AAC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AAM,IAAI,KAAK,CAAC,gCAAwB,CAAC,CAAC;iBAC3C;;oBAGH,sBAAO,IAAI,EAAC;;;KACb,CAAC;AAhCW,QAAA,cAAc,kBAgCzB;AAEF;;;;;;GAMG;AACI,IAAM,YAAY,GAAG,UAAO,IAAgB,EAAE,GAAW;;;;oBACvC,qBAAM,uBAAe,CAAC,IAAI,CAAC,EAAA;;gBAA5C,cAAc,GAAG,SAA2B;gBAE5C,GAAG,GAAG,cAAc;oBACxB,CAAC,CAAC,kCAAgC,IAAI,CAAC,KAAK,SAAI,IAAI,CAAC,IAAI,+BAA0B,IAAI,CAAC,GAAK;oBAC7F,CAAC,CAAC,kCAAgC,IAAI,CAAC,KAAK,SAAI,IAAI,CAAC,IAAI,sBAAiB,IAAI,CAAC,GAAK,CAAC;gBAEvF,sBAAO,oBAAY,CAAC,GAAG,EAAE,GAAG,EAAE,qBAAa,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,EAAC;;;KACpE,CAAC;AARW,QAAA,YAAY,gBAQvB"}
@@ -0,0 +1,19 @@
1
+ import { FlexPluginArguments } from '../lib/create-flex-plugin';
2
+ /**
3
+ * Prompts the user to enter AccountSid
4
+ * @private
5
+ */
6
+ export declare const _promptForAccountSid: () => Promise<string>;
7
+ /**
8
+ * Prompts the user to enter template URL
9
+ * @private
10
+ */
11
+ export declare const _promptForTemplateUrl: () => Promise<string>;
12
+ /**
13
+ * Further validates the configuration
14
+ *
15
+ * @param config {FlexPluginArguments} the configuration
16
+ * @return {Promise<FlexPluginArguments>}
17
+ */
18
+ declare const validate: (config: FlexPluginArguments) => Promise<FlexPluginArguments>;
19
+ export default validate;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports._promptForTemplateUrl = exports._promptForAccountSid = void 0;
40
+ var flex_dev_utils_1 = require("@twilio/flex-dev-utils");
41
+ var sids_1 = require("@twilio/flex-dev-utils/dist/sids");
42
+ var validators_1 = require("@twilio/flex-dev-utils/dist/validators");
43
+ /**
44
+ * Prompts the user to enter AccountSid
45
+ * @private
46
+ */
47
+ var _promptForAccountSid = function () { return __awaiter(void 0, void 0, void 0, function () {
48
+ return __generator(this, function (_a) {
49
+ return [2 /*return*/, flex_dev_utils_1.prompt({
50
+ type: 'input',
51
+ name: 'accountSid',
52
+ message: 'Twilio Flex Account SID',
53
+ validate: validators_1.validateAccountSid,
54
+ })];
55
+ });
56
+ }); };
57
+ exports._promptForAccountSid = _promptForAccountSid;
58
+ /**
59
+ * Prompts the user to enter template URL
60
+ * @private
61
+ */
62
+ var _promptForTemplateUrl = function () { return __awaiter(void 0, void 0, void 0, function () {
63
+ return __generator(this, function (_a) {
64
+ return [2 /*return*/, flex_dev_utils_1.prompt({
65
+ type: 'input',
66
+ name: 'template',
67
+ message: 'Template URL',
68
+ validate: validators_1.validateGitHubUrl,
69
+ })];
70
+ });
71
+ }); };
72
+ exports._promptForTemplateUrl = _promptForTemplateUrl;
73
+ /**
74
+ * Further validates the configuration
75
+ *
76
+ * @param config {FlexPluginArguments} the configuration
77
+ * @return {Promise<FlexPluginArguments>}
78
+ */
79
+ var validate = function (config) { return __awaiter(void 0, void 0, void 0, function () {
80
+ var _a, _b;
81
+ return __generator(this, function (_c) {
82
+ switch (_c.label) {
83
+ case 0:
84
+ config.name = config.name || '';
85
+ if (!(config.accountSid && !sids_1.isSidOfType(config.accountSid, sids_1.SidPrefix.AccountSid))) return [3 /*break*/, 2];
86
+ _a = config;
87
+ return [4 /*yield*/, exports._promptForAccountSid()];
88
+ case 1:
89
+ _a.accountSid = _c.sent();
90
+ _c.label = 2;
91
+ case 2:
92
+ if (!(config.template && !validators_1.isValidUrl(config.template))) return [3 /*break*/, 4];
93
+ _b = config;
94
+ return [4 /*yield*/, exports._promptForTemplateUrl()];
95
+ case 3:
96
+ _b.template = _c.sent();
97
+ _c.label = 4;
98
+ case 4: return [2 /*return*/, config];
99
+ }
100
+ });
101
+ }); };
102
+ exports.default = validate;
103
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAgD;AAChD,yDAA0E;AAC1E,qEAA2G;AAI3G;;;GAGG;AACI,IAAM,oBAAoB,GAAG;;QAClC,sBAAO,uBAAM,CAAC;gBACZ,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,yBAAyB;gBAClC,QAAQ,EAAE,+BAAkB;aAC7B,CAAC,EAAC;;KACJ,CAAC;AAPW,QAAA,oBAAoB,wBAO/B;AAEF;;;GAGG;AACI,IAAM,qBAAqB,GAAG;;QACnC,sBAAO,uBAAM,CAAC;gBACZ,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,cAAc;gBACvB,QAAQ,EAAE,8BAAiB;aAC5B,CAAC,EAAC;;KACJ,CAAC;AAPW,QAAA,qBAAqB,yBAOhC;AAEF;;;;;GAKG;AACH,IAAM,QAAQ,GAAG,UAAO,MAA2B;;;;;gBACjD,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;qBAE5B,CAAA,MAAM,CAAC,UAAU,IAAI,CAAC,kBAAW,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAS,CAAC,UAAU,CAAC,CAAA,EAA1E,wBAA0E;gBAC5E,KAAA,MAAM,CAAA;gBAAc,qBAAM,4BAAoB,EAAE,EAAA;;gBAAhD,GAAO,UAAU,GAAG,SAA4B,CAAC;;;qBAG/C,CAAA,MAAM,CAAC,QAAQ,IAAI,CAAC,uBAAU,CAAC,MAAM,CAAC,QAAQ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