-
Notifications
You must be signed in to change notification settings - Fork 57
/
runtime.js
58 lines (48 loc) · 1.39 KB
/
runtime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const twilio = require('twilio');
const { basename } = require('path');
const { readdirSync } = require('fs');
const debug = require('debug')('twilio-run:runtime');
const { getPaths } = require('./runtime-paths');
function safeReadDirectory(path) {
try {
debug('Reading directory %s', path);
const files = readdirSync(path);
return files;
} catch (err) {
debug('Failed to read directory. %O', err);
return null;
}
}
function getAssets() {
const { ASSETS_PATH } = getPaths();
const files = safeReadDirectory(ASSETS_PATH);
if (files === null) {
return files;
}
const assets = {};
for (const path of files) {
const filename = basename(path);
assets[filename] = { path };
}
debug('Found the following assets available: %O', assets);
return assets;
}
function getFunctions() {
const { FUNCTIONS_PATH } = getPaths();
const files = safeReadDirectory(FUNCTIONS_PATH);
if (files === null) {
return files;
}
const functions = {};
for (const path of files) {
const filename = basename(path);
functions[filename] = { path };
}
debug('Found the following functions available: %O', functions);
return functions;
}
function getSync({ serviceName = 'default' }) {
const client = twilio(process.env.ACCOUNT_SID, process.env.AUTH_TOKEN);
return client.sync.services(serviceName);
}
module.exports = { getSync, getAssets, getFunctions };