-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathlocal.js
35 lines (30 loc) · 965 Bytes
/
local.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
const {spawnSync} = require('child_process');
const path = require('path');
const fs = require('fs');
/**
* @param {import('./serverless').Serverless} serverless
* @param {import('./serverless').CliOptions} options
*/
function runLocal(serverless, options) {
if (options.data && options.path) {
throw new serverless.classes.Error('You cannot provide both --data and --path');
}
let data = options.data;
if (!data && options.path) {
if (typeof options.path !== 'string') {
throw new serverless.classes.Error('The --path option must be a string');
}
data = fs.readFileSync(options.path).toString();
}
// @ts-ignore
const fn = serverless.service.getFunction(options.function);
const args = [
path.join(__dirname, '../src/bref-local'),
fn.handler,
data || '',
];
spawnSync('php', args, {
stdio: 'inherit',
});
}
module.exports = {runLocal};