mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
remove file creation from slsStats and use serverlessRC instead
This commit is contained in:
parent
a356ae83fa
commit
82b63a524b
@ -1,10 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fse = require('fs-extra');
|
||||
const os = require('os');
|
||||
const userStats = require('../../utils/userStats');
|
||||
const setConfig = require('../../utils/config').set;
|
||||
const config = require('../../utils/config');
|
||||
|
||||
class SlStats {
|
||||
constructor(serverless, options) {
|
||||
@ -35,41 +32,23 @@ class SlStats {
|
||||
};
|
||||
}
|
||||
|
||||
createStatsFile(oldPath, newPath) {
|
||||
const oldFileExists = this.serverless.utils.fileExistsSync(oldPath);
|
||||
const newFileExists = this.serverless.utils.fileExistsSync(newPath);
|
||||
const isFileToBeRenamed = !newFileExists && oldFileExists;
|
||||
const isFileToBeCreated = !newFileExists;
|
||||
if (isFileToBeRenamed) {
|
||||
fse.renameSync(oldPath, newPath);
|
||||
} else if (isFileToBeCreated) {
|
||||
this.serverless.utils.writeFileSync(newPath);
|
||||
}
|
||||
}
|
||||
|
||||
toggleStats() {
|
||||
try {
|
||||
const serverlessDirPath = path.join(os.homedir(), '.serverless');
|
||||
const statsDisabledFilePath = path.join(serverlessDirPath, 'stats-disabled');
|
||||
const statsEnabledFilePath = path.join(serverlessDirPath, 'stats-enabled');
|
||||
const isStatsEnabled = this.options.enable && !this.options.disable;
|
||||
const isStatsDisabled = this.options.disable && !this.options.enable;
|
||||
if (isStatsEnabled) {
|
||||
// stats file to be depricated in future release
|
||||
this.createStatsFile(statsDisabledFilePath, statsEnabledFilePath);
|
||||
// set new `trackingDisabled` key in .serverlessrc config
|
||||
userStats.track('user_enabledTracking', { force: true }).then(() => {
|
||||
setConfig('trackingDisabled', false);
|
||||
const enableStats = this.options.enable && !this.options.disable;
|
||||
const disabledStats = this.options.disable && !this.options.enable;
|
||||
const data = { force: true };
|
||||
if (enableStats) {
|
||||
userStats.track('user_enabledTracking', data).then(() => {
|
||||
// set .serverlessrc config
|
||||
config.set('trackingDisabled', false);
|
||||
this.serverless.cli.log('Stats successfully enabled');
|
||||
});
|
||||
this.serverless.cli.log('Stats successfully enabled');
|
||||
} else if (isStatsDisabled) {
|
||||
// stats file to be depricated in future release
|
||||
this.createStatsFile(statsEnabledFilePath, statsDisabledFilePath);
|
||||
// set new `trackingDisabled` key in .serverlessrc config
|
||||
userStats.track('user_disabledTracking', { force: true }).then(() => {
|
||||
setConfig('trackingDisabled', true);
|
||||
} else if (disabledStats) {
|
||||
userStats.track('user_disabledTracking', data).then(() => {
|
||||
// set .serverlessrc config
|
||||
config.set('trackingDisabled', true);
|
||||
this.serverless.cli.log('Stats successfully disabled');
|
||||
});
|
||||
this.serverless.cli.log('Stats successfully disabled');
|
||||
}
|
||||
} catch (error) {
|
||||
throw new this.serverless.classes
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user