forked from serverless/serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostinstall.js
41 lines (34 loc) · 1.28 KB
/
postinstall.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
'use strict';
const path = require('path');
/* eslint-disable no-console */
/* eslint-disable no-use-before-define */
const Serverless = require('../lib/Serverless');
const execSync = require('child_process').execSync;
try {
const serverless = new Serverless();
(() => serverless.init()
.then(() => serverless.utils.logStat(serverless, 'install'))
.then(() => setupAutocomplete())
.catch(() => Promise.resolve())
)();
} catch (error) {
// fail silently
}
function setupAutocomplete() {
return new Promise((resolve, reject) => {
const indexRegex = new RegExp(path.join(path.sep, 'index.js'));
const tabtabPath = require.resolve('tabtab').replace(indexRegex, '');
const tabtabCliPath = path.join(tabtabPath, 'src', 'cli.js');
try {
execSync(`node "${tabtabCliPath}" install --name serverless --auto`);
execSync(`node "${tabtabCliPath}" install --name sls --auto`);
return resolve();
} catch (error) {
execSync(`node "${tabtabCliPath}" install --name serverless --stdout`);
execSync(`node "${tabtabCliPath}" install --name sls --stdout`);
console.log('Could not auto-install serverless autocomplete script.');
console.log('Please copy / paste the script above into your shell.');
return reject(error);
}
});
}