Skip to content

Commit

Permalink
feat: move utils away from root directory (#3028)
Browse files Browse the repository at this point in the history
Co-authored-by: srwang <srwang@users.noreply.github.com>
  • Loading branch information
srwang and srwang committed Apr 3, 2024
1 parent ca2154e commit f5a5c05
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bin/paragon-scripts.js
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion component-generator/index.js
Expand Up @@ -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)
Expand Down
25 changes: 23 additions & 2 deletions lib/utils.js
@@ -1,9 +1,30 @@
// 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 '';
}
return str.charAt(0).toUpperCase() + str.slice(1);
}

module.exports = { capitalize };
module.exports = { sendTrackInfo, capitalize };
23 changes: 0 additions & 23 deletions utils.js

This file was deleted.

0 comments on commit f5a5c05

Please sign in to comment.