Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Generate analytics file with {enabled: false} (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Richter authored Dec 9, 2019
1 parent 72a2d2b commit 25719be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/utils/usage-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import * as fs from 'fs';
import * as path from 'path';

export async function usageAnalytics(projectDir: string, agreeToAnalytics: boolean, salt?: string) {
const analyticsFilePath = path.resolve(projectDir, 'sap-cloud-sdk-analytics.json');
if (agreeToAnalytics === false) {
return;
return fs.writeFileSync(analyticsFilePath, JSON.stringify({ enabled: false }));
}

if (agreeToAnalytics || (await cli.confirm('Do you want to provide anonymous usage analytics to help us improve the SDK? (y|n)'))) {
const jsonContent = salt ? { enabled: true, salt } : { enabled: true };
fs.writeFileSync(path.resolve(projectDir, 'sap-cloud-sdk-analytics.json'), JSON.stringify(jsonContent));
fs.writeFileSync(analyticsFilePath, JSON.stringify(jsonContent));
} else {
fs.writeFileSync(analyticsFilePath, JSON.stringify({ enabled: false }));
}
}
9 changes: 9 additions & 0 deletions test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,13 @@ describe('Init', () => {

expect(JSON.parse(fs.readFileSync(`${projectDir}/sap-cloud-sdk-analytics.json`, 'utf8'))).toEqual({ enabled: true, salt: 'SAPCLOUDSDK4LIFE' });
}, 60000);

it('should add a disabled analytics file', async () => {
const projectDir = getCleanProjectDir('add-to-gitignore');
fs.copySync(expressAppDir, projectDir, { recursive: true });

await Init.run(['--projectName=testingApp', '--startCommand="npm start"', `--projectDir=${projectDir}`, '--no-analytics']);

expect(JSON.parse(fs.readFileSync(`${projectDir}/sap-cloud-sdk-analytics.json`, 'utf8'))).toEqual({ enabled: false });
}, 60000);
});

0 comments on commit 25719be

Please sign in to comment.