avo 3.2.9 → 3.2.11-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +2 -2
  2. package/cli.js +34 -13
  3. package/package.json +3 -3
  4. package/reporter.js +28 -0
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Better event tracking, **faster**.
4
4
 
5
- ![https://www.avo.app](https://cdn.avo.app/assets/avo-cado.png)
5
+ ![https://www.avo.app](https://cdn.avo.app/assets/avo-find-fix-prevent.png)
6
6
 
7
7
  The Avo CLI gives you access to [Avo Codegen](https://www.avo.app/docs/implementation/devs-101) right from your command line. It allows you to pull [your Avo tracking plan](http://avo.app/schemas/default) as type-safe functions for each of your events, making analytics implementation quick and seamless. Avo Codegen supports a variety of [platforms, programming languages and destinations](https://www.avo.app/docs/implementation/supported-programming-languages).
8
8
 
@@ -47,6 +47,6 @@ For more documentation, visit [https://www.avo.app/docs/implementation/cli](http
47
47
 
48
48
  **To create a release:**
49
49
  1. Verify that the changes in the _Unreleased_ section in CHANGELOG.md are accurate, create a new heading with the correct semantic version then move the content from the _Unreleased_ section there
50
- 2. Udate the semantic version in `package.json` to match the one you just created in the changelog
50
+ 2. Update the semantic version in `package.json` to match the one you just created in the changelog
51
51
  3. Commit with the message `Release <version>` and push the changes
52
52
  4. Publish the package to npm (you'll need to be a maintainer of the avo project in npm): `npm publish`
package/cli.js CHANGED
@@ -15,7 +15,6 @@ import pify from 'pify';
15
15
  import portfinder from 'portfinder';
16
16
  import querystring from 'querystring';
17
17
  import got from 'got'; // eslint-disable-line import/no-unresolved
18
- import report from 'yurnalist';
19
18
  import semver from 'semver';
20
19
  import updateNotifier from 'update-notifier';
21
20
  import url from 'url';
@@ -30,6 +29,7 @@ import yargs from 'yargs';
30
29
  import { hideBin } from 'yargs/helpers';
31
30
  import httpShutdown from 'http-shutdown';
32
31
  import fuzzypath from 'inquirer-fuzzy-path';
32
+ import * as report from './reporter.js';
33
33
  import Avo from './Avo.js';
34
34
  const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url), 'utf-8'));
35
35
  /// //////////////////////////////////////////////////////////////////////
@@ -1035,7 +1035,7 @@ function findMatches(data, regex) {
1035
1035
  lastIndex += lines.length;
1036
1036
  return fileMatches;
1037
1037
  }
1038
- function getEventMap(data) {
1038
+ function getEventMap(data, verbose) {
1039
1039
  const searchFor = 'AVOEVENTMAP:';
1040
1040
  const lines = data.split('\n').filter((line) => line.indexOf(searchFor) > -1);
1041
1041
  if (lines.length === 1) {
@@ -1044,9 +1044,12 @@ function getEventMap(data) {
1044
1044
  const eventMap = JSON.parse(line);
1045
1045
  return eventMap;
1046
1046
  }
1047
+ if (verbose) {
1048
+ report.error('No event map found');
1049
+ }
1047
1050
  return null;
1048
1051
  }
1049
- function getModuleMap(data) {
1052
+ function getModuleMap(data, verbose) {
1050
1053
  const searchFor = 'AVOMODULEMAP:';
1051
1054
  const lines = data.split('\n').filter((line) => line.indexOf(searchFor) > -1);
1052
1055
  if (lines.length === 1) {
@@ -1055,6 +1058,9 @@ function getModuleMap(data) {
1055
1058
  const moduleMap = JSON.parse(line);
1056
1059
  return moduleMap;
1057
1060
  }
1061
+ if (verbose) {
1062
+ report.error('No module map found');
1063
+ }
1058
1064
  return null;
1059
1065
  }
1060
1066
  function getSource(argv, json) {
@@ -1090,21 +1096,30 @@ function status(source, json, argv) {
1090
1096
  follow: false,
1091
1097
  }).then((results) => Promise.all(results
1092
1098
  .filter((result) => !result.startsWith('.git'))
1093
- .map((resultPath) => pify(fs.lstat)(resultPath).then((stats) => {
1099
+ .map((resultPath) => pify(fs.lstat)(resultPath)
1100
+ .then((stats) => {
1094
1101
  if (stats.isSymbolicLink()) {
1095
1102
  return [];
1096
1103
  }
1097
- return pify(fs.readFile)(resultPath, 'utf8').then((data) => [
1098
- resultPath,
1099
- data,
1100
- ]);
1104
+ return pify(fs.readFile)(resultPath, 'utf8')
1105
+ .then((data) => [resultPath, data])
1106
+ .catch(() => {
1107
+ if (argv.verbose) {
1108
+ report.warn(`Failed to parse file: ${resultPath}`);
1109
+ }
1110
+ });
1111
+ })
1112
+ .catch(() => {
1113
+ if (argv.verbose) {
1114
+ report.warn(`Failed to read file stats: ${resultPath}`);
1115
+ }
1101
1116
  }))).then((cachePairs) => Object.fromEntries(cachePairs)));
1102
1117
  fileCache
1103
1118
  .then((cache) => {
1104
1119
  sources = Promise.all(sources.map((source) => pify(fs.readFile)(source.path, 'utf8').then((data) => {
1105
- const eventMap = getEventMap(data);
1120
+ const eventMap = getEventMap(data, argv.verbose);
1106
1121
  if (eventMap !== null) {
1107
- const moduleMap = getModuleMap(data);
1122
+ const moduleMap = getModuleMap(data, argv.verbose);
1108
1123
  const sourcePath = path.parse(source.path);
1109
1124
  const moduleName = source.analysis?.module ??
1110
1125
  moduleMap ??
@@ -1148,13 +1163,19 @@ function status(source, json, argv) {
1148
1163
  lookup[cachePath] = value;
1149
1164
  }
1150
1165
  });
1166
+ if (argv.verbose) {
1167
+ const combinedPaths = [];
1168
+ Object.entries(lookup).forEach(([path, _data]) => {
1169
+ combinedPaths.push(path);
1170
+ });
1171
+ report.info(`Looking for events: ${eventMap.join('\n')}`);
1172
+ report.info(`Looking in module: ${moduleName}`);
1173
+ report.info(`Looking in files: ${combinedPaths.join('\n')}`);
1174
+ }
1151
1175
  return Promise.all(eventMap.map((eventName) => {
1152
1176
  const re = new RegExp(`(${moduleName}\\.${eventName}|\\[${moduleName} ${eventName})`);
1153
1177
  const results = Object.entries(lookup)
1154
1178
  .map(([path, data]) => {
1155
- if (argv.verbose) {
1156
- report.info(`Looking for events in ${path}`);
1157
- }
1158
1179
  const results = findMatches(data, re);
1159
1180
  return results.length ? [[path, results]] : [];
1160
1181
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avo",
3
- "version": "3.2.9",
3
+ "version": "3.2.11-alpha.0",
4
4
  "type": "module",
5
5
  "description": "The command-line interface for Avo",
6
6
  "author": "Avo (https://www.avo.app)",
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "files": [
28
28
  "cli.js",
29
+ "reporter.js",
29
30
  "Avo.js"
30
31
  ],
31
32
  "dependencies": {
@@ -51,8 +52,7 @@
51
52
  "uuid": "^9.0.0",
52
53
  "write": "^2.0.0",
53
54
  "write-json-file": "^5.0.0",
54
- "yargs": "^17.2.1",
55
- "yurnalist": "^2.1.0"
55
+ "yargs": "^17.2.1"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/ignore-walk": "^4.0.0",
package/reporter.js ADDED
@@ -0,0 +1,28 @@
1
+ import chalk from 'chalk';
2
+ export function log(text) {
3
+ console.log(text);
4
+ }
5
+ export function info(text) {
6
+ console.log(chalk.blue('info'), text);
7
+ }
8
+ export function success(text) {
9
+ console.log(chalk.green('success'), text);
10
+ }
11
+ export function warn(text) {
12
+ console.log(chalk.yellow('warn'), text);
13
+ }
14
+ export function error(text) {
15
+ console.log(chalk.red('error'), text);
16
+ }
17
+ export function tree(text, children) {
18
+ function recursiveTree(name = '', nodes = [], prefix = '') {
19
+ nodes.sort((a, b) => a.name.localeCompare(b.name));
20
+ return `${name}\n${nodes
21
+ .map((node, index) => {
22
+ const last = index === nodes.length - 1;
23
+ return `${prefix}${last ? '└' : '├'}─ ${recursiveTree(node.name, node.children, `${prefix}${last ? ' ' : '│'} `)}`;
24
+ })
25
+ .join('')}`;
26
+ }
27
+ console.log(recursiveTree(text, children));
28
+ }