@slack/bolt 4.0.0-nextGen.9 → 4.0.0-rc.2

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 (218) hide show
  1. package/README.md +22 -16
  2. package/dist/App.d.ts +39 -80
  3. package/dist/App.d.ts.map +1 -1
  4. package/dist/App.js +223 -234
  5. package/dist/App.js.map +1 -1
  6. package/dist/CustomFunction.d.ts +58 -0
  7. package/dist/CustomFunction.d.ts.map +1 -0
  8. package/dist/CustomFunction.js +144 -0
  9. package/dist/CustomFunction.js.map +1 -0
  10. package/dist/WorkflowStep.d.ts +89 -36
  11. package/dist/WorkflowStep.d.ts.map +1 -1
  12. package/dist/WorkflowStep.js +29 -8
  13. package/dist/WorkflowStep.js.map +1 -1
  14. package/dist/conversation-store.d.ts +1 -1
  15. package/dist/conversation-store.d.ts.map +1 -1
  16. package/dist/conversation-store.js +3 -3
  17. package/dist/conversation-store.js.map +1 -1
  18. package/dist/errors.d.ts +12 -7
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/errors.js +42 -53
  21. package/dist/errors.js.map +1 -1
  22. package/dist/helpers.d.ts +16 -3
  23. package/dist/helpers.d.ts.map +1 -1
  24. package/dist/helpers.js +43 -11
  25. package/dist/helpers.js.map +1 -1
  26. package/dist/index.d.ts +4 -5
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +16 -11
  29. package/dist/index.js.map +1 -1
  30. package/dist/middleware/builtin.d.ts +20 -23
  31. package/dist/middleware/builtin.d.ts.map +1 -1
  32. package/dist/middleware/builtin.js +93 -110
  33. package/dist/middleware/builtin.js.map +1 -1
  34. package/dist/middleware/process.d.ts +3 -3
  35. package/dist/middleware/process.d.ts.map +1 -1
  36. package/dist/middleware/process.js +1 -1
  37. package/dist/middleware/process.js.map +1 -1
  38. package/dist/receivers/AwsLambdaReceiver.d.ts +77 -16
  39. package/dist/receivers/AwsLambdaReceiver.d.ts.map +1 -1
  40. package/dist/receivers/AwsLambdaReceiver.js +53 -25
  41. package/dist/receivers/AwsLambdaReceiver.js.map +1 -1
  42. package/dist/receivers/BufferedIncomingMessage.d.ts +2 -1
  43. package/dist/receivers/BufferedIncomingMessage.d.ts.map +1 -1
  44. package/dist/receivers/ExpressReceiver.d.ts +13 -13
  45. package/dist/receivers/ExpressReceiver.d.ts.map +1 -1
  46. package/dist/receivers/ExpressReceiver.js +70 -70
  47. package/dist/receivers/ExpressReceiver.js.map +1 -1
  48. package/dist/receivers/HTTPModuleFunctions.d.ts +18 -20
  49. package/dist/receivers/HTTPModuleFunctions.d.ts.map +1 -1
  50. package/dist/receivers/HTTPModuleFunctions.js +189 -171
  51. package/dist/receivers/HTTPModuleFunctions.js.map +1 -1
  52. package/dist/receivers/HTTPReceiver.d.ts +14 -14
  53. package/dist/receivers/HTTPReceiver.d.ts.map +1 -1
  54. package/dist/receivers/HTTPReceiver.js +102 -48
  55. package/dist/receivers/HTTPReceiver.js.map +1 -1
  56. package/dist/receivers/HTTPResponseAck.d.ts +7 -7
  57. package/dist/receivers/HTTPResponseAck.d.ts.map +1 -1
  58. package/dist/receivers/HTTPResponseAck.js +37 -5
  59. package/dist/receivers/HTTPResponseAck.js.map +1 -1
  60. package/dist/receivers/ParamsIncomingMessage.d.ts +14 -0
  61. package/dist/receivers/ParamsIncomingMessage.d.ts.map +1 -0
  62. package/dist/{types/block-suggestion/index.js → receivers/ParamsIncomingMessage.js} +1 -1
  63. package/dist/receivers/ParamsIncomingMessage.js.map +1 -0
  64. package/dist/receivers/SocketModeFunctions.d.ts +3 -5
  65. package/dist/receivers/SocketModeFunctions.d.ts.map +1 -1
  66. package/dist/receivers/SocketModeFunctions.js +14 -23
  67. package/dist/receivers/SocketModeFunctions.js.map +1 -1
  68. package/dist/receivers/SocketModeReceiver.d.ts +10 -9
  69. package/dist/receivers/SocketModeReceiver.d.ts.map +1 -1
  70. package/dist/receivers/SocketModeReceiver.js +41 -25
  71. package/dist/receivers/SocketModeReceiver.js.map +1 -1
  72. package/dist/receivers/custom-routes.d.ts +4 -3
  73. package/dist/receivers/custom-routes.d.ts.map +1 -1
  74. package/dist/receivers/custom-routes.js +10 -9
  75. package/dist/receivers/custom-routes.js.map +1 -1
  76. package/dist/receivers/verify-redirect-opts.d.ts +1 -1
  77. package/dist/receivers/verify-redirect-opts.d.ts.map +1 -1
  78. package/dist/receivers/verify-redirect-opts.js +3 -3
  79. package/dist/receivers/verify-redirect-opts.js.map +1 -1
  80. package/dist/receivers/verify-request.d.ts +1 -12
  81. package/dist/receivers/verify-request.d.ts.map +1 -1
  82. package/dist/receivers/verify-request.js +4 -18
  83. package/dist/receivers/verify-request.js.map +1 -1
  84. package/dist/types/actions/block-action.d.ts +41 -22
  85. package/dist/types/actions/block-action.d.ts.map +1 -1
  86. package/dist/types/actions/dialog-action.d.ts +0 -4
  87. package/dist/types/actions/dialog-action.d.ts.map +1 -1
  88. package/dist/types/actions/index.d.ts +25 -11
  89. package/dist/types/actions/index.d.ts.map +1 -1
  90. package/dist/types/actions/index.js +1 -0
  91. package/dist/types/actions/index.js.map +1 -1
  92. package/dist/types/actions/interactive-message.d.ts +3 -3
  93. package/dist/types/actions/interactive-message.d.ts.map +1 -1
  94. package/dist/types/actions/workflow-step-edit.d.ts +7 -7
  95. package/dist/types/actions/workflow-step-edit.d.ts.map +1 -1
  96. package/dist/types/command/index.d.ts +1 -2
  97. package/dist/types/command/index.d.ts.map +1 -1
  98. package/dist/types/events/index.d.ts +26 -24
  99. package/dist/types/events/index.d.ts.map +1 -1
  100. package/dist/types/events/index.js +4 -15
  101. package/dist/types/events/index.js.map +1 -1
  102. package/dist/types/index.d.ts +0 -2
  103. package/dist/types/index.d.ts.map +1 -1
  104. package/dist/types/index.js +0 -2
  105. package/dist/types/index.js.map +1 -1
  106. package/dist/types/middleware.d.ts +30 -30
  107. package/dist/types/middleware.d.ts.map +1 -1
  108. package/dist/types/middleware.js +3 -0
  109. package/dist/types/middleware.js.map +1 -1
  110. package/dist/types/options/index.d.ts +23 -59
  111. package/dist/types/options/index.d.ts.map +1 -1
  112. package/dist/types/receiver.d.ts +3 -3
  113. package/dist/types/receiver.d.ts.map +1 -1
  114. package/dist/types/shortcuts/global-shortcut.d.ts.map +1 -1
  115. package/dist/types/shortcuts/index.d.ts +14 -9
  116. package/dist/types/shortcuts/index.d.ts.map +1 -1
  117. package/dist/types/shortcuts/message-shortcut.d.ts.map +1 -1
  118. package/dist/types/utilities.d.ts +23 -13
  119. package/dist/types/utilities.d.ts.map +1 -1
  120. package/dist/types/utilities.js +7 -0
  121. package/dist/types/utilities.js.map +1 -1
  122. package/dist/types/view/index.d.ts +148 -12
  123. package/dist/types/view/index.d.ts.map +1 -1
  124. package/package.json +32 -61
  125. package/dist/Manifest.d.ts +0 -5
  126. package/dist/Manifest.d.ts.map +0 -1
  127. package/dist/Manifest.js +0 -16
  128. package/dist/Manifest.js.map +0 -1
  129. package/dist/SlackFunction.d.ts +0 -190
  130. package/dist/SlackFunction.d.ts.map +0 -1
  131. package/dist/SlackFunction.js +0 -441
  132. package/dist/SlackFunction.js.map +0 -1
  133. package/dist/Subscription.d.ts +0 -61
  134. package/dist/Subscription.d.ts.map +0 -1
  135. package/dist/Subscription.js +0 -169
  136. package/dist/Subscription.js.map +0 -1
  137. package/dist/cli/check-update.d.ts +0 -3
  138. package/dist/cli/check-update.d.ts.map +0 -1
  139. package/dist/cli/check-update.js +0 -13
  140. package/dist/cli/check-update.js.map +0 -1
  141. package/dist/cli/get-hooks.d.ts +0 -2
  142. package/dist/cli/get-hooks.d.ts.map +0 -1
  143. package/dist/cli/get-hooks.js +0 -19
  144. package/dist/cli/get-hooks.js.map +0 -1
  145. package/dist/cli/get-manifest.d.ts +0 -3
  146. package/dist/cli/get-manifest.d.ts.map +0 -1
  147. package/dist/cli/get-manifest.js +0 -16
  148. package/dist/cli/get-manifest.js.map +0 -1
  149. package/dist/cli/hook-utils/get-check-update-data.d.ts +0 -49
  150. package/dist/cli/hook-utils/get-check-update-data.d.ts.map +0 -1
  151. package/dist/cli/hook-utils/get-check-update-data.js +0 -252
  152. package/dist/cli/hook-utils/get-check-update-data.js.map +0 -1
  153. package/dist/cli/hook-utils/get-check-update-data.spec.d.ts +0 -2
  154. package/dist/cli/hook-utils/get-check-update-data.spec.d.ts.map +0 -1
  155. package/dist/cli/hook-utils/get-check-update-data.spec.js +0 -266
  156. package/dist/cli/hook-utils/get-check-update-data.spec.js.map +0 -1
  157. package/dist/cli/hook-utils/get-manifest-data.d.ts +0 -7
  158. package/dist/cli/hook-utils/get-manifest-data.d.ts.map +0 -1
  159. package/dist/cli/hook-utils/get-manifest-data.js +0 -30
  160. package/dist/cli/hook-utils/get-manifest-data.js.map +0 -1
  161. package/dist/cli/hook-utils/get-manifest-data.spec.d.ts +0 -2
  162. package/dist/cli/hook-utils/get-manifest-data.spec.d.ts.map +0 -1
  163. package/dist/cli/hook-utils/get-manifest-data.spec.js +0 -113
  164. package/dist/cli/hook-utils/get-manifest-data.spec.js.map +0 -1
  165. package/dist/cli/hook-utils/manifest.d.ts +0 -30
  166. package/dist/cli/hook-utils/manifest.d.ts.map +0 -1
  167. package/dist/cli/hook-utils/manifest.js +0 -103
  168. package/dist/cli/hook-utils/manifest.js.map +0 -1
  169. package/dist/cli/hook-utils/manifest.spec.d.ts +0 -2
  170. package/dist/cli/hook-utils/manifest.spec.d.ts.map +0 -1
  171. package/dist/cli/hook-utils/manifest.spec.js +0 -79
  172. package/dist/cli/hook-utils/manifest.spec.js.map +0 -1
  173. package/dist/cli/run.d.ts +0 -2
  174. package/dist/cli/run.d.ts.map +0 -1
  175. package/dist/cli/run.js +0 -37
  176. package/dist/cli/run.js.map +0 -1
  177. package/dist/cli/start.d.ts +0 -3
  178. package/dist/cli/start.d.ts.map +0 -1
  179. package/dist/cli/start.js +0 -40
  180. package/dist/cli/start.js.map +0 -1
  181. package/dist/receivers/http-utils.d.ts +0 -5
  182. package/dist/receivers/http-utils.d.ts.map +0 -1
  183. package/dist/receivers/http-utils.js +0 -19
  184. package/dist/receivers/http-utils.js.map +0 -1
  185. package/dist/receivers/render-html-for-install-path.d.ts +0 -3
  186. package/dist/receivers/render-html-for-install-path.d.ts.map +0 -1
  187. package/dist/receivers/render-html-for-install-path.js +0 -32
  188. package/dist/receivers/render-html-for-install-path.js.map +0 -1
  189. package/dist/types/block-suggestion/index.d.ts +0 -97
  190. package/dist/types/block-suggestion/index.d.ts.map +0 -1
  191. package/dist/types/block-suggestion/index.js.map +0 -1
  192. package/dist/types/events/base-events.d.ts +0 -1135
  193. package/dist/types/events/base-events.d.ts.map +0 -1
  194. package/dist/types/events/base-events.js +0 -5
  195. package/dist/types/events/base-events.js.map +0 -1
  196. package/dist/types/events/message-events.d.ts +0 -348
  197. package/dist/types/events/message-events.d.ts.map +0 -1
  198. package/dist/types/events/message-events.js +0 -3
  199. package/dist/types/events/message-events.js.map +0 -1
  200. package/dist/types/functions/index.d.ts +0 -26
  201. package/dist/types/functions/index.d.ts.map +0 -1
  202. package/dist/types/functions/index.js +0 -3
  203. package/dist/types/functions/index.js.map +0 -1
  204. package/dist/types/helpers.d.ts +0 -17
  205. package/dist/types/helpers.d.ts.map +0 -1
  206. package/dist/types/helpers.js +0 -3
  207. package/dist/types/helpers.js.map +0 -1
  208. package/dist/types/subscription/index.d.ts +0 -80
  209. package/dist/types/subscription/index.d.ts.map +0 -1
  210. package/dist/types/subscription/index.js +0 -3
  211. package/dist/types/subscription/index.js.map +0 -1
  212. package/src/cli/check-update.js +0 -13
  213. package/src/cli/get-hooks.js +0 -17
  214. package/src/cli/get-manifest.js +0 -16
  215. package/src/cli/hook-utils/get-check-update-data.js +0 -292
  216. package/src/cli/hook-utils/get-manifest-data.js +0 -39
  217. package/src/cli/hook-utils/manifest.js +0 -108
  218. package/src/cli/start.js +0 -43
@@ -1,292 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const util = require('util');
4
- const exec = util.promisify(require('child_process').exec);
5
-
6
- const SLACK_BOLT_SDK = '@slack/bolt';
7
- let checkUpdateExports = {};
8
-
9
- /**
10
- * Wraps and parses the output of the exec() function
11
- * @param command the command being run by the exec() function
12
- */
13
- async function execWrapper (command) {
14
- const { stdout } = await exec(command);
15
- return stdout.trim();
16
- }
17
-
18
- /**
19
- * Checks for available SDK updates for specified dependencies, creates a version map,
20
- * and then wraps everything up into a response to be passed to the CLI.
21
- * @param cwd the current working directory
22
- */
23
- async function checkForSDKUpdates(cwd) {
24
- const { versionMap, inaccessibleFiles } = await createVersionMap(cwd);
25
- const updateResp = createUpdateResp(versionMap, inaccessibleFiles);
26
- return updateResp;
27
- }
28
-
29
- /**
30
- * Create a version map that contains each (Slack) dependency, detailing info about
31
- * current and latest versions, as well as if breaking changes are present or if there
32
- * were any errors with getting version retrieval.
33
- * @param cwd the current working directory of the CLI project
34
- */
35
- async function createVersionMap(cwd) {
36
- const { versionMap, inaccessibleFiles } = await readProjectDependencies(cwd);
37
-
38
- if (versionMap && versionMap[SLACK_BOLT_SDK]) {
39
- const current = versionMap[SLACK_BOLT_SDK].current || '';
40
- let latest = '',
41
- error = null;
42
-
43
- try {
44
- latest = await fetchLatestModuleVersion(SLACK_BOLT_SDK);
45
- } catch (err) {
46
- error = err;
47
- }
48
- const update = !!current && !!latest && current !== latest;
49
- const breaking = hasBreakingChange(current, latest);
50
-
51
- versionMap[SLACK_BOLT_SDK] = {
52
- ...versionMap[SLACK_BOLT_SDK],
53
- latest,
54
- update,
55
- breaking,
56
- error,
57
- };
58
- }
59
-
60
- return { versionMap, inaccessibleFiles };
61
- }
62
-
63
- /**
64
- * Reads project dependencies - cycles through project dependency files, extracts
65
- * the listed dependencies, and adds it in to the version map with version info.
66
- * @param cwd the current working directory of the CLI project
67
- */
68
- async function readProjectDependencies(cwd) {
69
- const versionMap = {};
70
- const { dependencyFile, inaccessibleFiles } = await gatherDependencyFiles(
71
- cwd
72
- );
73
-
74
- try {
75
- const [sdk, value] =
76
- await checkUpdateExports.extractDependencies(dependencyFile.body, dependencyFile.name);
77
-
78
- if (sdk !== '' && sdk === SLACK_BOLT_SDK) {
79
- versionMap[SLACK_BOLT_SDK] = {
80
- name: sdk,
81
- current: value.version,
82
- };
83
- }
84
- } catch (err) {
85
- inaccessibleFiles.push({ name: dependencyFile.name, error: err });
86
- }
87
-
88
- return { versionMap, inaccessibleFiles };
89
- }
90
-
91
- /**
92
- * Reads and parses JSON file - if it works, returns the file contents.
93
- * If not, returns an empty object
94
- * @param filePath the path of the file being read
95
- */
96
- async function getJSON(filePath) {
97
- let fileContents = {};
98
- try {
99
- if (fs.existsSync(filePath)) {
100
- fileContents = JSON.parse(fs.readFileSync(filePath, 'utf8'));
101
- } else {
102
- throw new Error('Cannot find a file at path ' + filePath);
103
- }
104
- } catch (err) {
105
- throw new Error(err);
106
- }
107
- return fileContents;
108
- }
109
-
110
- /**
111
- * Gathers all related dependency files for the CLI project (package.json).
112
- * @param cwd the current working directory of the CLI project
113
- */
114
- async function gatherDependencyFiles(cwd) {
115
- const { jsonDepFile, inaccessibleFiles } = await getJSONFiles(cwd);
116
- const dependencyFile = jsonDepFile;
117
- return { dependencyFile, inaccessibleFiles };
118
- }
119
-
120
- /**
121
- * Gets the needed files that contain dependency info (package.json).
122
- * @param cwd the current working directory of the CLI project
123
- */
124
- async function getJSONFiles(cwd) {
125
- const packageJSON = 'package.json';
126
- const jsonDepFile = {};
127
- const inaccessibleFiles = [];
128
-
129
- try {
130
- const jsonFile = await getJSON(`${cwd}/${packageJSON}`);
131
- const jsonIsParsable =
132
- jsonFile &&
133
- typeof jsonFile === 'object' &&
134
- !Array.isArray(jsonFile) &&
135
- jsonFile.dependencies;
136
-
137
- if (jsonIsParsable) {
138
- jsonDepFile.name = packageJSON;
139
- jsonDepFile.body= jsonFile;
140
- }
141
- } catch (err) {
142
- inaccessibleFiles.push({ name: packageJSON, error: err });
143
- }
144
-
145
- return { jsonDepFile, inaccessibleFiles };
146
- }
147
-
148
- /**
149
- * Pulls dependencies from a given file and JSON structure.
150
- * @param json JSON information that includes dependencies
151
- * @param fileName name of the file that the dependency list is coming from
152
- */
153
- checkUpdateExports.extractDependencies = async (json, fileName) => {
154
- // Determine if the JSON passed is an object
155
- const jsonIsParsable =
156
- json !== null && typeof json === 'object' && !Array.isArray(json);
157
-
158
- if (jsonIsParsable) {
159
- let boltCurrentVersion = '';
160
- if (json['dependencies']['@slack/bolt']) {
161
- const boltCurrentVersionOutput = JSON.parse(
162
- await checkUpdateExports.getBoltCurrentVersion()
163
- );
164
-
165
- if (boltCurrentVersionOutput !== '') {
166
- boltCurrentVersion =
167
- boltCurrentVersionOutput['dependencies']['@slack/bolt']['version'];
168
- }
169
- }
170
-
171
- return [
172
- '@slack/bolt',
173
- {
174
- version: boltCurrentVersion,
175
- },
176
- ];
177
- }
178
-
179
- return [];
180
- };
181
-
182
- /**
183
- * Gets the latest module version.
184
- * @param moduleName the module that the latest version is being queried for
185
- */
186
- async function fetchLatestModuleVersion(moduleName) {
187
- let command = '';
188
- if (moduleName === '@slack/bolt') {
189
- command = `npm info ${moduleName} version --tag next-gen`;
190
- } else if (moduleName === '@slack/deno-slack-sdk') {
191
- command = `npm info ${moduleName} version --tag latest`;
192
- }
193
- const stdout = await execWrapper(command);
194
-
195
- return stdout;
196
- }
197
-
198
- /**
199
- * Checks if a dependency's upgrade from a current to the latest version will cause a
200
- * breaking change.
201
- * @param current current dependency version in project
202
- * @param latest most up-to-date dependency version available on NPM
203
- */
204
- function hasBreakingChange(current, latest) {
205
- return current !== latest;
206
- }
207
-
208
- /**
209
- * Creates the update response - returns an object in the expected response format.
210
- * @param versionMap version map of checked dependencies, current versions, and info on upgrade + breaking changes
211
- * @param inaccessibleFiles array of files that could not be read or accessed
212
- */
213
- function createUpdateResp(versionMap, inaccessibleFiles) {
214
- const name = 'the Slack SDK';
215
- const releases = [];
216
- const url = 'https://api.slack.com/future/changelog';
217
- const fileErrorMsg = createFileErrorMsg(inaccessibleFiles);
218
-
219
- let error = null;
220
- let errorMsg = '';
221
- let message = '';
222
-
223
-
224
- // Output information for each dependency
225
- for (const sdk of Object.values(versionMap)) {
226
- // Dependency has an update OR the fetch of update failed
227
- if (sdk) {
228
- releases.push(sdk);
229
-
230
- // Add the dependency that failed to be fetched to the top-level error message
231
- if (sdk.error && sdk.error.message) {
232
- errorMsg += errorMsg
233
- ? `, ${sdk}`
234
- : `An error occurred fetching updates for the following packages: ${sdk.name}`;
235
- }
236
- }
237
- }
238
-
239
- // Surface release notes for breaking changes
240
- if (releases && releases[0] && releases[0].breaking) {
241
- message = `Learn more about the breaking change at https://github.com/slackapi/bolt-js/releases/tag/@slack/bolt@${releases[0].latest}`
242
- }
243
-
244
- // If there were issues accessing dependency files, append error message(s)
245
- if (inaccessibleFiles.length) {
246
- errorMsg += errorMsg ? `\n\n ${fileErrorMsg}` : fileErrorMsg;
247
- }
248
-
249
- if (errorMsg) {
250
- error = { message: errorMsg };
251
- }
252
-
253
- return {
254
- name,
255
- message,
256
- releases,
257
- url,
258
- error,
259
- };
260
- }
261
-
262
- /**
263
- * Returns error when dependency files cannot be read.
264
- * @param inaccessibleFiles array of files that could not be read or accessed
265
- */
266
- function createFileErrorMsg(inaccessibleFiles) {
267
- let fileErrorMsg = '';
268
-
269
- // There were issues with reading some of the files that were found
270
- for (const file of inaccessibleFiles) {
271
- fileErrorMsg += fileErrorMsg
272
- ? `\n ${file.name}: ${file.error.message}`
273
- : `An error occurred while reading the following files: \n\n ${file.name}: ${file.error.message}`;
274
- }
275
-
276
- return fileErrorMsg;
277
- }
278
-
279
- /**
280
- * Queries for current Bolt version of the project.
281
- */
282
- checkUpdateExports.getBoltCurrentVersion = async () => {
283
- const stdout = await execWrapper('npm list @slack/bolt --depth=0 --json');
284
- return stdout;
285
- };
286
-
287
- module.exports = {
288
- checkForSDKUpdates,
289
- getJSON,
290
- getJSONFiles,
291
- checkUpdateExports,
292
- };
@@ -1,39 +0,0 @@
1
- const {
2
- readManifestJSONFile,
3
- readImportedManifestFile,
4
- hasManifest,
5
- unionMerge,
6
- } = require('./manifest.js');
7
- const merge = require('deepmerge');
8
-
9
-
10
- /**
11
- * Returns any manifest data, if it exists.
12
- * Otherwise throws an error
13
- * @param searchDir path to begin searching at
14
- */
15
- function getManifestData(searchDir) {
16
- const file = 'manifest';
17
- let manifest = {};
18
-
19
- // look for a manifest JSON
20
- const manifestJSON = readManifestJSONFile(searchDir, `${file}.json`);
21
- // look for manifest.js
22
- let manifestJS = readImportedManifestFile(searchDir, `${file}.js`);
23
-
24
- if (!hasManifest(manifestJS, manifestJSON)) {
25
- const msg = 'Unable to find a manifest file in this project';
26
- throw new Error(msg);
27
- }
28
-
29
- // manage manifest merge
30
- if (manifestJSON) {
31
- manifest = merge(manifest, manifestJSON, { arrayMerge: unionMerge });
32
- }
33
- if (manifestJS) {
34
- manifest = merge(manifest, manifestJS, { arrayMerge: unionMerge });
35
- }
36
- return manifest;
37
- }
38
-
39
- module.exports = { getManifestData };
@@ -1,108 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- /**
5
- * Union merge of arrays
6
- */
7
- function unionMerge(array1, array2) {
8
- return [...new Set(array1.concat(array2))];
9
- }
10
-
11
- /**
12
- * Returns a manifest.json if it exists, null otherwise
13
- * @param searchDir typically current working directory
14
- * @param filename file to search for
15
- */
16
- function readManifestJSONFile(searchDir, filename) {
17
- let jsonFilePath, manifestJSON;
18
- try {
19
- jsonFilePath = find(searchDir, filename);
20
- if (fs.existsSync(jsonFilePath)) {
21
- manifestJSON = JSON.parse(fs.readFileSync(jsonFilePath, 'utf8'));
22
- }
23
- } catch (error) {
24
- return null;
25
- }
26
- return manifestJSON;
27
- }
28
-
29
- /**
30
- * Returns a manifest object if it exists, null otherwise
31
- * @param searchDir typically current working directory
32
- * @param filename file to search for
33
- */
34
- function readImportedManifestFile(searchDir, filename) {
35
- let importedManifestFilePath, manifestImported;
36
-
37
- try {
38
- importedManifestFilePath = find(searchDir, filename);
39
- if (fs.existsSync(importedManifestFilePath)) {
40
- manifestImported = require(`${importedManifestFilePath}`);
41
-
42
- // if a default key is provided, assumes default export contains manifest
43
- if (manifestImported["default"]) {
44
- manifestImported = manifestImported["default"]
45
- }
46
- // stringify and parses the JSON in order to ensure that objects with .toJSON() functions
47
- // resolve properly. This is a known behavior for CustomType
48
- manifestImported = JSON.parse(JSON.stringify(manifestImported));
49
- }
50
- } catch (error) {
51
- console.log(error);
52
- return null;
53
- }
54
- return manifestImported;
55
- }
56
-
57
- /**
58
- * @param entries
59
- * @returns true if any non-empty manifest has been supplied
60
- * */
61
- function hasManifest(...entries) {
62
- for (let ent of entries) {
63
- if (ent && (Object.keys(ent).length > 0)) {
64
- return true;
65
- }
66
- }
67
- return false;
68
- }
69
-
70
- /**
71
- * Search for provided file path.
72
- * Returns full path when filename is found or null if no file found.
73
- * @param currentPath string of current path
74
- * @param targetFilename filename to match
75
- * @returns full file path string relative to starting path or null
76
- * */
77
- function find(currentPath, targetFilename) {
78
- // TODO Cache searched paths and check that they haven't been explored already
79
- // This guards against rare edge case of a subdir in the file tree which is
80
- // symlinked back to root or in such a way that creates a cycle. Can also implement
81
- // max depth check.
82
- if (currentPath.endsWith(`/${targetFilename}`)) {
83
- return currentPath;
84
- }
85
-
86
- if (fs.existsSync(currentPath) && fs.lstatSync(currentPath).isDirectory()) {
87
- let foundEntry;
88
- let dirents = fs.readdirSync(currentPath);
89
- for (let entry of dirents) {
90
- if (entry !== 'node_modules') {
91
- let newPath = path.resolve(currentPath, entry);
92
- foundEntry = find(newPath, targetFilename);
93
- if (foundEntry) {
94
- return foundEntry;
95
- }
96
- }
97
- }
98
- return null;
99
- }
100
- }
101
-
102
- module.exports = {
103
- unionMerge,
104
- readManifestJSONFile,
105
- readImportedManifestFile,
106
- hasManifest,
107
- find,
108
- }
package/src/cli/start.js DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
- const { spawn } = require('child_process');
3
- const path = require('path');
4
- const fs = require('fs');
5
- const { main: pkgJSONMain } = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
6
-
7
- // Run script hook verifies that requirements for running an App in
8
- // in developerMode (via Socket Mode) are met
9
- (function _(cwd, customPath) {
10
- // TODO - Format so that its less miss-able in output
11
- console.log('Preparing local run in developer mode (Socket Mode)');
12
- // Check required local run tokens
13
- validate();
14
-
15
- // tries the provided path, then package.json main, then defaults to index.js in the current
16
- // working directory
17
- const pkgJSONDefault = 'index.js';
18
- const fullPath = path.resolve(cwd, customPath ? customPath : pkgJSONMain ? pkgJSONMain : pkgJSONDefault);
19
- console.log(fullPath);
20
-
21
- // Kick off a subprocess to run the app in development mode
22
- const app = spawn('node', [`${fullPath}`]);
23
- app.stdout.setEncoding('utf-8');
24
- app.stdout.on('data', (data) => {
25
- process.stdout.write(data);
26
- });
27
- app.stderr.on('data', (data) => {
28
- process.stderr.write(data);
29
- });
30
-
31
- app.on('close', (code) => {
32
- console.log(`bolt-app local run exited with code ${code}`);
33
- });
34
- }(process.cwd(), process.env.SLACK_CLI_CUSTOM_FILE_PATH));
35
-
36
- function validate() {
37
- if (!process.env.SLACK_CLI_XOXB) {
38
- throw new Error('Missing local run bot token. Please see slack-cli maintainers to troubleshoot.');
39
- }
40
- if (!process.env.SLACK_CLI_XAPP) {
41
- throw new Error('Missing local run app token. Please see slack-cli maintainers to troubleshoot');
42
- }
43
- }