@twilio/flex-dev-utils 5.0.1-beta.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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -0
  3. package/dist/axios.d.ts +6 -0
  4. package/dist/axios.js +18 -0
  5. package/dist/axios.js.map +1 -0
  6. package/dist/credentials.d.ts +40 -0
  7. package/dist/credentials.js +241 -0
  8. package/dist/credentials.js.map +1 -0
  9. package/dist/env.d.ts +1 -0
  10. package/dist/env.js +13 -0
  11. package/dist/env.js.map +1 -0
  12. package/dist/errors/index.d.ts +6 -0
  13. package/dist/errors/index.js +19 -0
  14. package/dist/errors/index.js.map +1 -0
  15. package/dist/errors/lib/FlexPluginError.d.ts +7 -0
  16. package/dist/errors/lib/FlexPluginError.js +54 -0
  17. package/dist/errors/lib/FlexPluginError.js.map +1 -0
  18. package/dist/errors/lib/UserActionError.d.ts +5 -0
  19. package/dist/errors/lib/UserActionError.js +35 -0
  20. package/dist/errors/lib/UserActionError.js.map +1 -0
  21. package/dist/errors/lib/ValidationError.d.ts +3 -0
  22. package/dist/errors/lib/ValidationError.js +30 -0
  23. package/dist/errors/lib/ValidationError.js.map +1 -0
  24. package/dist/exit.d.ts +8 -0
  25. package/dist/exit.js +18 -0
  26. package/dist/exit.js.map +1 -0
  27. package/dist/fs.d.ts +318 -0
  28. package/dist/fs.js +797 -0
  29. package/dist/fs.js.map +1 -0
  30. package/dist/http/index.d.ts +1 -0
  31. package/dist/http/index.js +10 -0
  32. package/dist/http/index.js.map +1 -0
  33. package/dist/http/lib/http.d.ts +114 -0
  34. package/dist/http/lib/http.js +337 -0
  35. package/dist/http/lib/http.js.map +1 -0
  36. package/dist/index.d.ts +25 -0
  37. package/dist/index.js +93 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/keychain.d.ts +25 -0
  40. package/dist/keychain.js +84 -0
  41. package/dist/keychain.js.map +1 -0
  42. package/dist/lodash.d.ts +13 -0
  43. package/dist/lodash.js +30 -0
  44. package/dist/lodash.js.map +1 -0
  45. package/dist/logger/index.d.ts +13 -0
  46. package/dist/logger/index.js +52 -0
  47. package/dist/logger/index.js.map +1 -0
  48. package/dist/logger/lib/boxen.d.ts +38 -0
  49. package/dist/logger/lib/boxen.js +85 -0
  50. package/dist/logger/lib/boxen.js.map +1 -0
  51. package/dist/logger/lib/columnify.d.ts +2 -0
  52. package/dist/logger/lib/columnify.js +8 -0
  53. package/dist/logger/lib/columnify.js.map +1 -0
  54. package/dist/logger/lib/logger.d.ts +157 -0
  55. package/dist/logger/lib/logger.js +354 -0
  56. package/dist/logger/lib/logger.js.map +1 -0
  57. package/dist/logger/lib/strings.d.ts +16 -0
  58. package/dist/logger/lib/strings.js +33 -0
  59. package/dist/logger/lib/strings.js.map +1 -0
  60. package/dist/logger/lib/table.d.ts +25 -0
  61. package/dist/logger/lib/table.js +75 -0
  62. package/dist/logger/lib/table.js.map +1 -0
  63. package/dist/open.d.ts +2 -0
  64. package/dist/open.js +9 -0
  65. package/dist/open.js.map +1 -0
  66. package/dist/prints.d.ts +11 -0
  67. package/dist/prints.js +47 -0
  68. package/dist/prints.js.map +1 -0
  69. package/dist/progress/index.d.ts +1 -0
  70. package/dist/progress/index.js +9 -0
  71. package/dist/progress/index.js.map +1 -0
  72. package/dist/progress/lib/progress.d.ts +21 -0
  73. package/dist/progress/lib/progress.js +118 -0
  74. package/dist/progress/lib/progress.js.map +1 -0
  75. package/dist/questions/index.d.ts +1 -0
  76. package/dist/questions/index.js +12 -0
  77. package/dist/questions/index.js.map +1 -0
  78. package/dist/questions/lib/inquirer.d.ts +39 -0
  79. package/dist/questions/lib/inquirer.js +136 -0
  80. package/dist/questions/lib/inquirer.js.map +1 -0
  81. package/dist/random.d.ts +15 -0
  82. package/dist/random.js +28 -0
  83. package/dist/random.js.map +1 -0
  84. package/dist/runner.d.ts +8 -0
  85. package/dist/runner.js +98 -0
  86. package/dist/runner.js.map +1 -0
  87. package/dist/semver.d.ts +9 -0
  88. package/dist/semver.js +36 -0
  89. package/dist/semver.js.map +1 -0
  90. package/dist/sids.d.ts +48 -0
  91. package/dist/sids.js +50 -0
  92. package/dist/sids.js.map +1 -0
  93. package/dist/spawn/index.d.ts +4 -0
  94. package/dist/spawn/index.js +15 -0
  95. package/dist/spawn/index.js.map +1 -0
  96. package/dist/spawn/lib/node.d.ts +9 -0
  97. package/dist/spawn/lib/node.js +74 -0
  98. package/dist/spawn/lib/node.js.map +1 -0
  99. package/dist/spawn/lib/npm.d.ts +9 -0
  100. package/dist/spawn/lib/npm.js +74 -0
  101. package/dist/spawn/lib/npm.js.map +1 -0
  102. package/dist/spawn/lib/spawn.d.ts +22 -0
  103. package/dist/spawn/lib/spawn.js +111 -0
  104. package/dist/spawn/lib/spawn.js.map +1 -0
  105. package/dist/spawn/lib/yarn.d.ts +9 -0
  106. package/dist/spawn/lib/yarn.js +74 -0
  107. package/dist/spawn/lib/yarn.js.map +1 -0
  108. package/dist/updateNotifier.d.ts +6 -0
  109. package/dist/updateNotifier.js +20 -0
  110. package/dist/updateNotifier.js.map +1 -0
  111. package/dist/urls.d.ts +28 -0
  112. package/dist/urls.js +147 -0
  113. package/dist/urls.js.map +1 -0
  114. package/dist/validators.d.ts +42 -0
  115. package/dist/validators.js +78 -0
  116. package/dist/validators.js.map +1 -0
  117. package/package.json +86 -0
package/dist/fs.js ADDED
@@ -0,0 +1,797 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __generator = (this && this.__generator) || function (thisArg, body) {
31
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
+ function verb(n) { return function (v) { return step([n, v]); }; }
34
+ function step(op) {
35
+ if (f) throw new TypeError("Generator is already executing.");
36
+ while (_) try {
37
+ 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;
38
+ if (y = 0, t) op = [op[0] & 2, t.value];
39
+ switch (op[0]) {
40
+ case 0: case 1: t = op; break;
41
+ case 4: _.label++; return { value: op[1], done: false };
42
+ case 5: _.label++; y = op[1]; op = [0]; continue;
43
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
+ default:
45
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
+ if (t[2]) _.ops.pop();
50
+ _.trys.pop(); continue;
51
+ }
52
+ op = body.call(thisArg, _);
53
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
+ }
56
+ };
57
+ var __read = (this && this.__read) || function (o, n) {
58
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
59
+ if (!m) return o;
60
+ var i = m.call(o), r, ar = [], e;
61
+ try {
62
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
63
+ }
64
+ catch (error) { e = { error: error }; }
65
+ finally {
66
+ try {
67
+ if (r && !r.done && (m = i["return"])) m.call(i);
68
+ }
69
+ finally { if (e) throw e.error; }
70
+ }
71
+ return ar;
72
+ };
73
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
74
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
75
+ to[j] = from[i];
76
+ return to;
77
+ };
78
+ var __values = (this && this.__values) || function(o) {
79
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
80
+ if (m) return m.call(o);
81
+ if (o && typeof o.length === "number") return {
82
+ next: function () {
83
+ if (o && i >= o.length) o = void 0;
84
+ return { value: o && o[i++], done: !o };
85
+ }
86
+ };
87
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
88
+ };
89
+ var __importDefault = (this && this.__importDefault) || function (mod) {
90
+ return (mod && mod.__esModule) ? mod : { "default": mod };
91
+ };
92
+ Object.defineProperty(exports, "__esModule", { value: true });
93
+ exports.flexUIPackageDependencyVersion = exports.packageDependencyVersion = exports.isPluginDir = exports.getPackageVersion = exports.getDependencyVersion = exports.getPaths = exports._getFlexPluginWebpackPath = exports._getFlexPluginScripts = exports.resolveModulePath = exports.addCWDNodeModule = exports.checkRunPluginConfigurationExists = exports.checkPluginConfigurationExists = exports.findGlobs = exports.findGlobsIn = exports.resolveCwd = exports.rmRfSync = exports.copyTemplateDir = exports.mkdirpSync = exports.findUp = exports.updateAppVersion = exports.readAppPackageJson = exports.getPackageJsonPath = exports.checkAFileExists = exports.copyFile = exports.removeFile = exports.calculateSha256 = exports.checkFilesExist = exports.writeJSONFile = exports.writeFile = exports.readRunPluginsJson = exports.readPluginsJson = exports.getCliPaths = exports.readJsonFile = exports.readFileSync = exports.getCoreCwd = exports.setCoreCwd = exports.getCwd = exports.setCwd = exports.resolveRelative = exports.getFileSizeInMB = exports.getSileSizeInBytes = exports.readPackageJson = exports._setRequirePaths = exports._require = void 0;
94
+ var fs_1 = __importStar(require("fs"));
95
+ var path = __importStar(require("path"));
96
+ var os_1 = __importStar(require("os"));
97
+ var util_1 = require("util");
98
+ var crypto_1 = __importDefault(require("crypto"));
99
+ var globby_1 = require("globby");
100
+ var mkdirp_1 = __importDefault(require("mkdirp"));
101
+ var rimraf_1 = __importDefault(require("rimraf"));
102
+ var app_module_path_1 = __importDefault(require("app-module-path"));
103
+ var questions_1 = require("./questions");
104
+ var flexUI = '@twilio/flex-ui';
105
+ var react = 'react';
106
+ var reactDOM = 'react-dom';
107
+ exports.default = fs_1.default;
108
+ var packageJsonStr = 'package.json';
109
+ /**
110
+ * This is an alias for require. Useful for mocking out in tests
111
+ * @param filePath the file to require
112
+ * @private
113
+ */
114
+ /* istanbul ignore next */
115
+ // eslint-disable-next-line global-require, @typescript-eslint/no-require-imports, @typescript-eslint/explicit-module-boundary-types
116
+ var _require = function (filePath) { return require(filePath); };
117
+ exports._require = _require;
118
+ // Set working directory
119
+ var _setRequirePaths = function (requirePath) {
120
+ app_module_path_1.default.addPath(requirePath);
121
+ // Now try to specifically set the node_modules path
122
+ var requirePaths = (require.main && require.main.paths) || [];
123
+ if (!requirePaths.includes(requirePath)) {
124
+ requirePaths.push(requirePath);
125
+ }
126
+ };
127
+ exports._setRequirePaths = _setRequirePaths;
128
+ /**
129
+ * Reads a JSON file
130
+ *
131
+ * @param filePath the file path to read
132
+ */
133
+ var readPackageJson = function (filePath) {
134
+ return JSON.parse(fs_1.default.readFileSync(filePath, 'utf8'));
135
+ };
136
+ exports.readPackageJson = readPackageJson;
137
+ /**
138
+ * Returns the file size in bytes
139
+ * @param filePaths the path to the file
140
+ */
141
+ var getSileSizeInBytes = function () {
142
+ var filePaths = [];
143
+ for (var _i = 0; _i < arguments.length; _i++) {
144
+ filePaths[_i] = arguments[_i];
145
+ }
146
+ return fs_1.statSync(path.join.apply(path, __spreadArray([], __read(filePaths)))).size;
147
+ };
148
+ exports.getSileSizeInBytes = getSileSizeInBytes;
149
+ /**
150
+ * Returns the file size in MB
151
+ * @param filePaths the path to file
152
+ */
153
+ var getFileSizeInMB = function () {
154
+ var filePaths = [];
155
+ for (var _i = 0; _i < arguments.length; _i++) {
156
+ filePaths[_i] = arguments[_i];
157
+ }
158
+ return exports.getSileSizeInBytes.apply(void 0, __spreadArray([], __read(filePaths))) / (1024 * 1024);
159
+ };
160
+ exports.getFileSizeInMB = getFileSizeInMB;
161
+ /**
162
+ * Builds path relative to the given dir
163
+ * @param dir the dir
164
+ * @param paths the paths
165
+ */
166
+ var resolveRelative = function (dir) {
167
+ var paths = [];
168
+ for (var _i = 1; _i < arguments.length; _i++) {
169
+ paths[_i - 1] = arguments[_i];
170
+ }
171
+ if (paths.length === 0) {
172
+ return dir;
173
+ }
174
+ var lastElement = paths[paths.length - 1];
175
+ // Check if last element is an extension
176
+ if (lastElement.charAt(0) !== '.') {
177
+ return path.join.apply(path, __spreadArray([dir], __read(paths)));
178
+ }
179
+ // Only one entry as extension
180
+ if (paths.length === 1) {
181
+ return path.join("" + dir + lastElement);
182
+ }
183
+ var secondLastElement = paths[paths.length - 2];
184
+ var remainder = paths.slice(0, paths.length - 2);
185
+ return path.join.apply(path, __spreadArray([dir], __read(__spreadArray(__spreadArray([], __read(remainder)), ["" + secondLastElement + lastElement]))));
186
+ };
187
+ exports.resolveRelative = resolveRelative;
188
+ // Working directory
189
+ var internalCwd = fs_1.default.realpathSync(process.cwd());
190
+ var internalCoreCwd = fs_1.default.realpathSync(process.cwd());
191
+ /**
192
+ * Sets the working directory
193
+ * @param p the path to set
194
+ */
195
+ var setCwd = function (p) {
196
+ internalCwd = p;
197
+ exports._setRequirePaths(path.join(internalCwd, 'node_modules'));
198
+ };
199
+ exports.setCwd = setCwd;
200
+ /**
201
+ * Returns the working directory
202
+ */
203
+ var getCwd = function () { return internalCwd; };
204
+ exports.getCwd = getCwd;
205
+ /**
206
+ * Sets the core working directory
207
+ * @param p the path to set
208
+ */
209
+ var setCoreCwd = function (p) {
210
+ internalCoreCwd = p;
211
+ exports._setRequirePaths(path.join(internalCoreCwd, 'node_modules'));
212
+ };
213
+ exports.setCoreCwd = setCoreCwd;
214
+ /**
215
+ * The core cwd is the working directory of core packages such as flex-plugin-scripts and flex-plugin
216
+ */
217
+ var getCoreCwd = function () { return internalCoreCwd; };
218
+ exports.getCoreCwd = getCoreCwd;
219
+ /**
220
+ * Reads the file
221
+ * @param filePaths the file paths
222
+ */
223
+ var readFileSync = function () {
224
+ var filePaths = [];
225
+ for (var _i = 0; _i < arguments.length; _i++) {
226
+ filePaths[_i] = arguments[_i];
227
+ }
228
+ return fs_1.default.readFileSync(path.join.apply(path, __spreadArray([], __read(filePaths))), 'utf8');
229
+ };
230
+ exports.readFileSync = readFileSync;
231
+ /**
232
+ * Reads a JSON file (Templated)
233
+ *
234
+ * @param filePaths the file paths to read
235
+ */
236
+ var readJsonFile = function () {
237
+ var filePaths = [];
238
+ for (var _i = 0; _i < arguments.length; _i++) {
239
+ filePaths[_i] = arguments[_i];
240
+ }
241
+ return JSON.parse(exports.readFileSync.apply(void 0, __spreadArray([], __read(filePaths))));
242
+ };
243
+ exports.readJsonFile = readJsonFile;
244
+ /**
245
+ * Gets the CLI paths. This is separated out from getPaths because create-flex-plugin also needs to read it,
246
+ * but that script will not have flex-plugin-scripts installed which would cause an exception to be thrown.
247
+ */
248
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
249
+ var getCliPaths = function () {
250
+ var coreCwd = exports.getCoreCwd();
251
+ var coreNodeModulesDir = exports.resolveRelative(coreCwd, 'node_modules');
252
+ var homeDir = os_1.homedir();
253
+ var cliDir = exports.resolveRelative(homeDir, '/.twilio-cli');
254
+ var flexDir = exports.resolveRelative(cliDir, 'flex');
255
+ return {
256
+ dir: cliDir,
257
+ nodeModulesDir: coreNodeModulesDir,
258
+ flexDir: flexDir,
259
+ pluginsJsonPath: exports.resolveRelative(flexDir, 'plugins.json'),
260
+ localPluginsJsonPath: exports.resolveRelative(flexDir, 'locallyRunningPlugins.json'),
261
+ };
262
+ };
263
+ exports.getCliPaths = getCliPaths;
264
+ // Read plugins.json from Twilio CLI
265
+ var readPluginsJson = function () {
266
+ return exports.readJsonFile(exports.getCliPaths().pluginsJsonPath);
267
+ };
268
+ exports.readPluginsJson = readPluginsJson;
269
+ // Read plugins.json from Twilio CLI
270
+ var readRunPluginsJson = function () {
271
+ return exports.readJsonFile(exports.getCliPaths().localPluginsJsonPath);
272
+ };
273
+ exports.readRunPluginsJson = readRunPluginsJson;
274
+ /**
275
+ * Writes string to file
276
+ */
277
+ var writeFile = function (str) {
278
+ var paths = [];
279
+ for (var _i = 1; _i < arguments.length; _i++) {
280
+ paths[_i - 1] = arguments[_i];
281
+ }
282
+ return fs_1.writeFileSync(path.join.apply(path, __spreadArray([], __read(paths))), str);
283
+ };
284
+ exports.writeFile = writeFile;
285
+ /**
286
+ * Writes an object as a JSON string to the file
287
+ * @param obj the object to write
288
+ * @param paths the path to write to
289
+ */
290
+ var writeJSONFile = function (obj) {
291
+ var paths = [];
292
+ for (var _i = 1; _i < arguments.length; _i++) {
293
+ paths[_i - 1] = arguments[_i];
294
+ }
295
+ return exports.writeFile.apply(void 0, __spreadArray([JSON.stringify(obj, null, 2)], __read(paths)));
296
+ };
297
+ exports.writeJSONFile = writeJSONFile;
298
+ // The OS root directory
299
+ var rootDir = os_1.default.platform() === 'win32' ? exports.getCwd().split(path.sep)[0] : '/';
300
+ /*
301
+ * Promise version of {@link copyTempDir}
302
+ */
303
+ var promiseCopyTempDir = util_1.promisify(exports._require('copy-template-dir'));
304
+ /**
305
+ * Checks the provided array of files exist
306
+ *
307
+ * @param files the files to check that they exist
308
+ */
309
+ var checkFilesExist = function () {
310
+ var files = [];
311
+ for (var _i = 0; _i < arguments.length; _i++) {
312
+ files[_i] = arguments[_i];
313
+ }
314
+ return files.map(fs_1.default.existsSync).every(function (resp) { return resp; });
315
+ };
316
+ exports.checkFilesExist = checkFilesExist;
317
+ /**
318
+ * Calculates the sha of a file
319
+ * @param paths
320
+ */
321
+ /* istanbul ignore next */
322
+ var calculateSha256 = function () {
323
+ var paths = [];
324
+ for (var _i = 0; _i < arguments.length; _i++) {
325
+ paths[_i] = arguments[_i];
326
+ }
327
+ return __awaiter(void 0, void 0, void 0, function () {
328
+ return __generator(this, function (_a) {
329
+ return [2 /*return*/, new Promise(function (resolve, reject) {
330
+ var shasum = crypto_1.default.createHash('sha256');
331
+ var stream = fs_1.createReadStream(path.join.apply(path, __spreadArray([], __read(paths))));
332
+ stream.on('data', function (data) { return shasum.update(data); });
333
+ stream.on('error', function (err) { return reject(err); });
334
+ stream.on('end', function () { return resolve(shasum.digest('hex')); });
335
+ })];
336
+ });
337
+ });
338
+ };
339
+ exports.calculateSha256 = calculateSha256;
340
+ /**
341
+ * Removes a file
342
+ * @param paths
343
+ */
344
+ var removeFile = function () {
345
+ var paths = [];
346
+ for (var _i = 0; _i < arguments.length; _i++) {
347
+ paths[_i] = arguments[_i];
348
+ }
349
+ return fs_1.unlinkSync(path.join.apply(path, __spreadArray([], __read(paths))));
350
+ };
351
+ exports.removeFile = removeFile;
352
+ /**
353
+ * Copies from from src to dest
354
+ * @param srcPaths
355
+ * @param destPaths
356
+ */
357
+ var copyFile = function (srcPaths, destPaths) {
358
+ return fs_1.copyFileSync(path.join.apply(path, __spreadArray([], __read(srcPaths))), path.join.apply(path, __spreadArray([], __read(destPaths))));
359
+ };
360
+ exports.copyFile = copyFile;
361
+ /**
362
+ * Checks the provided file exists
363
+ *
364
+ * @param paths the paths to the file
365
+ */
366
+ var checkAFileExists = function () {
367
+ var paths = [];
368
+ for (var _i = 0; _i < arguments.length; _i++) {
369
+ paths[_i] = arguments[_i];
370
+ }
371
+ return fs_1.existsSync(path.join.apply(path, __spreadArray([], __read(paths))));
372
+ };
373
+ exports.checkAFileExists = checkAFileExists;
374
+ /**
375
+ * Gets package.json path
376
+ */
377
+ var getPackageJsonPath = function () { return path.join(exports.getCwd(), packageJsonStr); };
378
+ exports.getPackageJsonPath = getPackageJsonPath;
379
+ /**
380
+ * Reads app package.json from the rootDir.
381
+ */
382
+ var readAppPackageJson = function () {
383
+ return exports.readPackageJson(exports.getPackageJsonPath());
384
+ };
385
+ exports.readAppPackageJson = readAppPackageJson;
386
+ /**
387
+ * Updates the package.json version field
388
+ *
389
+ * @param version the new version
390
+ */
391
+ var updateAppVersion = function (version) {
392
+ var packageJson = exports.readAppPackageJson();
393
+ packageJson.version = version;
394
+ fs_1.default.writeFileSync(exports.getPackageJsonPath(), JSON.stringify(packageJson, null, 2));
395
+ };
396
+ exports.updateAppVersion = updateAppVersion;
397
+ /**
398
+ * Finds the closest up file relative to dir
399
+ *
400
+ * @param dir the directory
401
+ * @param file the file to look for
402
+ */
403
+ var findUp = function (dir, file) {
404
+ var resolved = path.resolve(dir);
405
+ if (resolved === rootDir) {
406
+ throw new Error("Reached OS root directory without finding " + file);
407
+ }
408
+ var filePath = path.join(resolved, file);
409
+ if (fs_1.default.existsSync(filePath)) {
410
+ return filePath;
411
+ }
412
+ return exports.findUp(path.resolve(resolved, '..'), file);
413
+ };
414
+ exports.findUp = findUp;
415
+ /**
416
+ * mkdir -p wrapper
417
+ */
418
+ exports.mkdirpSync = mkdirp_1.default.sync;
419
+ /**
420
+ * Copies a template by applying the variables
421
+ *
422
+ * @param source the source
423
+ * @param target the target
424
+ * @param variables the variables
425
+ */
426
+ /* istanbul ignore next */
427
+ // eslint-disable-next-line @typescript-eslint/ban-types
428
+ var copyTemplateDir = function (source, target, variables) { return __awaiter(void 0, void 0, void 0, function () {
429
+ return __generator(this, function (_a) {
430
+ return [2 /*return*/, promiseCopyTempDir(source, target, variables)];
431
+ });
432
+ }); };
433
+ exports.copyTemplateDir = copyTemplateDir;
434
+ /**
435
+ * rm -rf sync script
436
+ */
437
+ exports.rmRfSync = rimraf_1.default.sync;
438
+ /**
439
+ * Builds path relative to cwd
440
+ * @param paths the paths
441
+ */
442
+ var resolveCwd = function () {
443
+ var paths = [];
444
+ for (var _i = 0; _i < arguments.length; _i++) {
445
+ paths[_i] = arguments[_i];
446
+ }
447
+ return exports.resolveRelative.apply(void 0, __spreadArray([exports.getCwd()], __read(paths)));
448
+ };
449
+ exports.resolveCwd = resolveCwd;
450
+ /**
451
+ * Finds globs in any cwd directory
452
+ * @param dir the cwd to check for patterns
453
+ * @param patterns the patterns
454
+ */
455
+ var findGlobsIn = function (dir) {
456
+ var patterns = [];
457
+ for (var _i = 1; _i < arguments.length; _i++) {
458
+ patterns[_i - 1] = arguments[_i];
459
+ }
460
+ return globby_1.sync(patterns, { cwd: dir });
461
+ };
462
+ exports.findGlobsIn = findGlobsIn;
463
+ /**
464
+ * Finds globs in the src directory
465
+ * @param patterns the patterns
466
+ */
467
+ var findGlobs = function () {
468
+ var patterns = [];
469
+ for (var _i = 0; _i < arguments.length; _i++) {
470
+ patterns[_i] = arguments[_i];
471
+ }
472
+ return exports.findGlobsIn.apply(void 0, __spreadArray([path.join(exports.getCwd(), 'src')], __read(patterns)));
473
+ };
474
+ exports.findGlobs = findGlobs;
475
+ /**
476
+ * Touch ~/.twilio-cli/flex/plugins.json if it does not exist
477
+ * Check if this plugin is in this config file. If not, add it.
478
+ * @param name the plugin name
479
+ * @param dir the plugin directory
480
+ * @param promptForOverwrite whether to prompt for overwrite
481
+ * @return whether the plugin-directory was overwritten
482
+ */
483
+ var checkPluginConfigurationExists = function (name, dir, promptForOverwrite) {
484
+ if (promptForOverwrite === void 0) { promptForOverwrite = false; }
485
+ return __awaiter(void 0, void 0, void 0, function () {
486
+ var cliPaths, config, plugin, answer, _a;
487
+ return __generator(this, function (_b) {
488
+ switch (_b.label) {
489
+ case 0:
490
+ cliPaths = exports.getCliPaths();
491
+ if (!exports.checkFilesExist(cliPaths.pluginsJsonPath)) {
492
+ exports.mkdirpSync(cliPaths.flexDir);
493
+ exports.writeJSONFile({ plugins: [] }, cliPaths.pluginsJsonPath);
494
+ }
495
+ config = exports.readPluginsJson();
496
+ plugin = config.plugins.find(function (p) { return p.name === name; });
497
+ if (!plugin) {
498
+ config.plugins.push({ name: name, dir: dir });
499
+ exports.writeJSONFile(config, cliPaths.pluginsJsonPath);
500
+ return [2 /*return*/, true];
501
+ }
502
+ if (plugin.dir === dir) {
503
+ return [2 /*return*/, false];
504
+ }
505
+ if (!promptForOverwrite) return [3 /*break*/, 2];
506
+ return [4 /*yield*/, questions_1.confirm("You already have a plugin called " + plugin.name + " located at " + plugin.dir + ". Do you want to update it to " + dir + "?", 'N')];
507
+ case 1:
508
+ _a = _b.sent();
509
+ return [3 /*break*/, 3];
510
+ case 2:
511
+ _a = true;
512
+ _b.label = 3;
513
+ case 3:
514
+ answer = _a;
515
+ if (answer) {
516
+ plugin.dir = dir;
517
+ exports.writeJSONFile(config, cliPaths.pluginsJsonPath);
518
+ return [2 /*return*/, true];
519
+ }
520
+ return [2 /*return*/, false];
521
+ }
522
+ });
523
+ });
524
+ };
525
+ exports.checkPluginConfigurationExists = checkPluginConfigurationExists;
526
+ /**
527
+ * Touch ~/.twilio-cli/flex/locallyRunningPlugins.json if it does not exist,
528
+ * and if it does exist, clear the file so it is ready for a new run
529
+ */
530
+ var checkRunPluginConfigurationExists = function (localPlugins) { return __awaiter(void 0, void 0, void 0, function () {
531
+ var cliPaths, runConfig, localPlugins_1, localPlugins_1_1, plugin;
532
+ var e_1, _a;
533
+ return __generator(this, function (_b) {
534
+ cliPaths = exports.getCliPaths();
535
+ if (!exports.checkFilesExist(cliPaths.localPluginsJsonPath)) {
536
+ exports.mkdirpSync(cliPaths.flexDir);
537
+ }
538
+ runConfig = { plugins: [], loadedPlugins: [] };
539
+ try {
540
+ for (localPlugins_1 = __values(localPlugins), localPlugins_1_1 = localPlugins_1.next(); !localPlugins_1_1.done; localPlugins_1_1 = localPlugins_1.next()) {
541
+ plugin = localPlugins_1_1.value;
542
+ runConfig.plugins.push(plugin);
543
+ }
544
+ }
545
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
546
+ finally {
547
+ try {
548
+ if (localPlugins_1_1 && !localPlugins_1_1.done && (_a = localPlugins_1.return)) _a.call(localPlugins_1);
549
+ }
550
+ finally { if (e_1) throw e_1.error; }
551
+ }
552
+ exports.writeJSONFile(runConfig, cliPaths.localPluginsJsonPath);
553
+ return [2 /*return*/];
554
+ });
555
+ }); };
556
+ exports.checkRunPluginConfigurationExists = checkRunPluginConfigurationExists;
557
+ /**
558
+ * Adds the node_modules to the app module.
559
+ * This is needed because we spawn different scripts when running start/build/test and so we lose
560
+ * the original cwd directory
561
+ */
562
+ var addCWDNodeModule = function () {
563
+ var args = [];
564
+ for (var _i = 0; _i < arguments.length; _i++) {
565
+ args[_i] = arguments[_i];
566
+ }
567
+ var indexCoreCwd = args.indexOf('--core-cwd');
568
+ if (indexCoreCwd !== -1) {
569
+ var coreCwd = args[indexCoreCwd + 1];
570
+ if (coreCwd) {
571
+ exports.setCoreCwd(coreCwd);
572
+ }
573
+ }
574
+ var indexCwd = args.indexOf('--cwd');
575
+ if (indexCwd === -1) {
576
+ // This is to setup the app environment
577
+ exports.setCwd(exports.getCwd());
578
+ }
579
+ else {
580
+ var cwd = args[indexCwd + 1];
581
+ if (cwd) {
582
+ exports.setCwd(cwd);
583
+ }
584
+ }
585
+ };
586
+ exports.addCWDNodeModule = addCWDNodeModule;
587
+ /**
588
+ * Returns the absolute path to the pkg if found
589
+ * @param pkg the package to lookup
590
+ */
591
+ /* istanbul ignore next */
592
+ var resolveModulePath = function (pkg) {
593
+ var paths = [];
594
+ for (var _i = 1; _i < arguments.length; _i++) {
595
+ paths[_i - 1] = arguments[_i];
596
+ }
597
+ try {
598
+ return require.resolve(pkg);
599
+ }
600
+ catch (_a) {
601
+ // Now try to specifically set the node_modules path
602
+ var requirePaths = (require.main && require.main.paths) || [];
603
+ requirePaths.push.apply(requirePaths, __spreadArray([], __read(paths)));
604
+ try {
605
+ return require.resolve(pkg, { paths: requirePaths });
606
+ }
607
+ catch (_b) {
608
+ return false;
609
+ }
610
+ }
611
+ };
612
+ exports.resolveModulePath = resolveModulePath;
613
+ /**
614
+ * Returns the path to flex-plugin-scripts
615
+ */
616
+ var _getFlexPluginScripts = function () {
617
+ var flexPluginScriptPath = exports.resolveModulePath('@twilio/flex-plugin-scripts');
618
+ if (flexPluginScriptPath === false) {
619
+ throw new Error('Could not resolve @twilio/flex-plugin-scripts');
620
+ }
621
+ return path.join(path.dirname(flexPluginScriptPath), '..');
622
+ };
623
+ exports._getFlexPluginScripts = _getFlexPluginScripts;
624
+ /**
625
+ * Returns the path to flex-plugin-webpack
626
+ */
627
+ var _getFlexPluginWebpackPath = function (scriptsNodeModulesDir) {
628
+ var flexPluginWebpackPath = exports.resolveModulePath('@twilio/flex-plugin-webpack', scriptsNodeModulesDir);
629
+ if (flexPluginWebpackPath === false) {
630
+ throw new Error("Could not resolve @twilio/flex-plugin-webpack");
631
+ }
632
+ return path.join(path.dirname(flexPluginWebpackPath), '..');
633
+ };
634
+ exports._getFlexPluginWebpackPath = _getFlexPluginWebpackPath;
635
+ /**
636
+ * Returns the paths to all modules and directories used in the plugin-builder
637
+ */
638
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
639
+ var getPaths = function () {
640
+ var cwd = exports.getCwd();
641
+ var nodeModulesDir = exports.resolveCwd('node_modules');
642
+ var scriptsDir = exports._getFlexPluginScripts();
643
+ var scriptsNodeModulesDir = exports.resolveRelative(scriptsDir, 'node_modules');
644
+ var devAssetsDir = exports.resolveRelative(scriptsDir, 'dev_assets');
645
+ var publicDir = exports.resolveCwd('public');
646
+ var buildDir = exports.resolveCwd('build');
647
+ var srcDir = exports.resolveCwd('src');
648
+ var flexUIDir = exports.resolveRelative(nodeModulesDir, flexUI);
649
+ var tsConfigPath = exports.resolveCwd('tsconfig.json');
650
+ var webpackDir = exports._getFlexPluginWebpackPath(scriptsNodeModulesDir);
651
+ // package.json information
652
+ var pkgName = '';
653
+ var pkgVersion = '';
654
+ // This file can be required in locations that don't have package.json
655
+ try {
656
+ var pkg = exports.readAppPackageJson();
657
+ pkgName = pkg.name;
658
+ pkgVersion = pkg.version;
659
+ }
660
+ catch (e) {
661
+ // no-op
662
+ }
663
+ return {
664
+ cwd: cwd,
665
+ // flex-plugin-webpack paths
666
+ webpack: {
667
+ dir: webpackDir,
668
+ nodeModulesDir: exports.resolveRelative(webpackDir, 'node_modules'),
669
+ },
670
+ // flex-plugin-scripts paths
671
+ scripts: {
672
+ dir: scriptsDir,
673
+ nodeModulesDir: scriptsNodeModulesDir,
674
+ devAssetsDir: devAssetsDir,
675
+ indexHTMLPath: exports.resolveRelative(devAssetsDir, 'index.html'),
676
+ tsConfigPath: exports.resolveRelative(devAssetsDir, 'tsconfig.json'),
677
+ },
678
+ // twilio-cli/flex/plugins.json paths
679
+ cli: exports.getCliPaths(),
680
+ // plugin-app (the customer app)
681
+ app: {
682
+ dir: cwd,
683
+ name: pkgName,
684
+ version: pkgVersion,
685
+ pkgPath: exports.resolveCwd(packageJsonStr),
686
+ jestConfigPath: exports.resolveCwd('jest.config.js'),
687
+ webpackConfigPath: exports.resolveCwd('webpack.config.js'),
688
+ devServerConfigPath: exports.resolveCwd('webpack.dev.js'),
689
+ tsConfigPath: tsConfigPath,
690
+ isTSProject: function () { return exports.checkFilesExist(tsConfigPath); },
691
+ setupTestsPaths: [exports.resolveCwd('setupTests.js'), exports.resolveRelative(srcDir, 'setupTests.js')],
692
+ // .env file support
693
+ envPath: exports.resolveCwd('/.env'),
694
+ hasEnvFile: function () { return exports.checkFilesExist(exports.resolveCwd('/.env')); },
695
+ envExamplePath: exports.resolveCwd('/.env.example'),
696
+ hasEnvExampleFile: function () { return exports.checkFilesExist(exports.resolveCwd('/.env.example')); },
697
+ envDefaultsPath: exports.resolveCwd('/.env.defaults'),
698
+ hasEnvDefaultsPath: function () { return exports.checkFilesExist(exports.resolveCwd('/.env.defaults')); },
699
+ // build/*
700
+ buildDir: buildDir,
701
+ bundlePath: exports.resolveRelative(buildDir, pkgName, '.js'),
702
+ sourceMapPath: exports.resolveRelative(buildDir, pkgName, '.js.map'),
703
+ // src/*
704
+ srcDir: srcDir,
705
+ entryPath: exports.resolveRelative(srcDir, 'index'),
706
+ // node_modules/*,
707
+ nodeModulesDir: nodeModulesDir,
708
+ flexUIDir: flexUIDir,
709
+ flexUIPkgPath: exports.resolveRelative(flexUIDir, packageJsonStr),
710
+ // public/*
711
+ publicDir: publicDir,
712
+ appConfig: exports.resolveRelative(publicDir, 'appConfig.js'),
713
+ // dependencies
714
+ dependencies: {
715
+ react: {
716
+ version: exports.readPackageJson(exports.resolveRelative(nodeModulesDir, react, packageJsonStr)).version,
717
+ },
718
+ reactDom: {
719
+ version: exports.readPackageJson(exports.resolveRelative(nodeModulesDir, reactDOM, packageJsonStr)).version,
720
+ },
721
+ flexUI: {
722
+ version: exports.readPackageJson(exports.resolveRelative(nodeModulesDir, flexUI, packageJsonStr)).version,
723
+ },
724
+ },
725
+ },
726
+ // others
727
+ assetBaseUrlTemplate: "/plugins/" + pkgName + "/%PLUGIN_VERSION%",
728
+ extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
729
+ };
730
+ };
731
+ exports.getPaths = getPaths;
732
+ /**
733
+ * Returns the version of the dependency that is installed in node_modules
734
+ * @param pkgName the package name
735
+ * @return the version of the package installed
736
+ */
737
+ /* istanbul ignore next */
738
+ // eslint-disable-next-line import/no-unused-modules
739
+ var getDependencyVersion = function (pkgName) {
740
+ try {
741
+ return exports._require(pkgName + "/package.json").version;
742
+ }
743
+ catch (_a) {
744
+ try {
745
+ return exports._require(exports.resolveRelative(exports.getPaths().app.nodeModulesDir, pkgName, packageJsonStr)).version;
746
+ }
747
+ catch (_b) {
748
+ return exports._require(exports.resolveRelative(exports.getPaths().scripts.nodeModulesDir, pkgName, packageJsonStr)).version;
749
+ }
750
+ }
751
+ };
752
+ exports.getDependencyVersion = getDependencyVersion;
753
+ /**
754
+ * Returns the package.json version field of the package
755
+ * @param name the package
756
+ */
757
+ /* istanbul ignore next */
758
+ var getPackageVersion = function (name) {
759
+ var installedPath = exports.resolveRelative(exports.getPaths().app.nodeModulesDir, name, packageJsonStr);
760
+ return exports.readPackageJson(installedPath).version;
761
+ };
762
+ exports.getPackageVersion = getPackageVersion;
763
+ /**
764
+ * Determines whether the directory is plugin based on the package.json
765
+ * @param packageJson the package json
766
+ */
767
+ var isPluginDir = function (packageJson) {
768
+ return Boolean(packageJson.dependencies[flexUI] || packageJson.devDependencies[flexUI]);
769
+ };
770
+ exports.isPluginDir = isPluginDir;
771
+ /**
772
+ * Fetches the version corresponding to the dependency inside the given package
773
+ * @param pkg the package.json to check
774
+ * @param name the package to look for
775
+ */
776
+ var packageDependencyVersion = function (pkg, name) {
777
+ if (pkg.dependencies && name in pkg.dependencies) {
778
+ return pkg.dependencies[name];
779
+ }
780
+ if (pkg.devDependencies && name in pkg.devDependencies) {
781
+ return pkg.devDependencies[name];
782
+ }
783
+ if (pkg.peerDependencies && name in pkg.peerDependencies) {
784
+ return pkg.peerDependencies[name];
785
+ }
786
+ return null;
787
+ };
788
+ exports.packageDependencyVersion = packageDependencyVersion;
789
+ /**
790
+ * Fetches the version corresponding to the dependency inside the flex-ui package.json
791
+ * @param name the package to check
792
+ */
793
+ var flexUIPackageDependencyVersion = function (name) {
794
+ return exports.packageDependencyVersion(exports._require(exports.getPaths().app.flexUIPkgPath), name);
795
+ };
796
+ exports.flexUIPackageDependencyVersion = flexUIPackageDependencyVersion;
797
+ //# sourceMappingURL=fs.js.map