mirror of https://github.com/openedx/paragon.git
feat: move utils away from root directory (#3028)
Co-authored-by: srwang <srwang@users.noreply.github.com>
This commit is contained in:
parent
ca2154e37f
commit
f5a5c057a7
|
|
@ -5,7 +5,7 @@ const helpCommand = require('../lib/help');
|
|||
const buildTokensCommand = require('../lib/build-tokens');
|
||||
const replaceVariablesCommand = require('../lib/replace-variables');
|
||||
const buildScssCommand = require('../lib/build-scss');
|
||||
const { sendTrackInfo } = require('../utils');
|
||||
const { sendTrackInfo } = require('../lib/utils');
|
||||
const versionCommand = require('../lib/version');
|
||||
|
||||
const commandAliases = {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const {
|
|||
addComponentToExports,
|
||||
addComponentToGit,
|
||||
} = require('./utils');
|
||||
const { sendTrackInfo } = require('../utils');
|
||||
const { sendTrackInfo } = require('../lib/utils');
|
||||
|
||||
program
|
||||
.argument('<ComponentName>', 'Component must have a name', validateComponentName)
|
||||
|
|
|
|||
25
lib/utils.js
25
lib/utils.js
|
|
@ -1,4 +1,25 @@
|
|||
// eslint-disable-next-line import/prefer-default-export
|
||||
const axios = require('axios');
|
||||
|
||||
/**
|
||||
* Sends request to the Netlify function to inform about specified event.
|
||||
* @param {string} eventId - tracking event id
|
||||
* @param {object} properties - tracking properties
|
||||
*/
|
||||
function sendTrackInfo(eventId, properties) {
|
||||
const { BASE_URL, TRACK_ANONYMOUS_ANALYTICS } = process.env;
|
||||
if (TRACK_ANONYMOUS_ANALYTICS) {
|
||||
const url = `${BASE_URL}/.netlify/functions/sendTrackData`;
|
||||
axios.post(url, { eventId, properties })
|
||||
.then(result => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Track info is successfully sent (status ${result.status})`);
|
||||
}).catch(error => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Track info request failed (${error})`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function capitalize(str) {
|
||||
if (typeof str !== 'string' || str.length === 0) {
|
||||
return '';
|
||||
|
|
@ -6,4 +27,4 @@ function capitalize(str) {
|
|||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
|
||||
module.exports = { capitalize };
|
||||
module.exports = { sendTrackInfo, capitalize };
|
||||
|
|
|
|||
23
utils.js
23
utils.js
|
|
@ -1,23 +0,0 @@
|
|||
const axios = require('axios');
|
||||
|
||||
/**
|
||||
* Sends request to the Netlify function to inform about specified event.
|
||||
* @param {string} eventId - tracking event id
|
||||
* @param {object} properties - tracking properties
|
||||
*/
|
||||
function sendTrackInfo(eventId, properties) {
|
||||
const { BASE_URL, TRACK_ANONYMOUS_ANALYTICS } = process.env;
|
||||
if (TRACK_ANONYMOUS_ANALYTICS) {
|
||||
const url = `${BASE_URL}/.netlify/functions/sendTrackData`;
|
||||
axios.post(url, { eventId, properties })
|
||||
.then(result => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Track info is successfully sent (status ${result.status})`);
|
||||
}).catch(error => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Track info request failed (${error})`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { sendTrackInfo };
|
||||
Loading…
Reference in New Issue