avo 3.1.1 → 3.2.2

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 (2) hide show
  1. package/cli.js +63 -6
  2. package/package.json +3 -2
package/cli.js CHANGED
@@ -135,8 +135,20 @@ function responseToError(response) {
135
135
  }
136
136
  }
137
137
  if (!body.error) {
138
+ const getMessage = (statusCode) => {
139
+ switch (statusCode) {
140
+ case 401:
141
+ return 'Unauthorized';
142
+ case 403:
143
+ return 'Forbidden. Do you have the required permissions? Some commands editor or admin access.';
144
+ case 404:
145
+ return 'Not Found';
146
+ default:
147
+ return 'Unknown Error';
148
+ }
149
+ };
138
150
  body.error = {
139
- message: response.statusCode === 404 ? 'Not Found' : 'Unknown Error',
151
+ message: getMessage(response.statusCode),
140
152
  };
141
153
  }
142
154
  const message = `HTTP Error: ${response.statusCode}, ${body.error.message ?? body.error}`;
@@ -776,6 +788,7 @@ function codegen(json, { schema, sources: targets, warnings, success, errors })
776
788
  name: target.name,
777
789
  id: target.id,
778
790
  path: source.path,
791
+ interfacePath: source.interfacePath,
779
792
  branchId: target.branchId,
780
793
  updatedAt: target.updatedAt,
781
794
  };
@@ -890,18 +903,61 @@ function selectSource(sourceToAdd, json) {
890
903
  },
891
904
  });
892
905
  }
893
- return inquirer.prompt(prompts).then((answer) => {
894
- const relativePath = path.relative(process.cwd(), path.join(path.resolve(answer.folder), answer.filename));
906
+ return inquirer.prompt(prompts).then(async (answer) => {
907
+ let answerSource;
908
+ if (sourceToAdd) {
909
+ answerSource = sources.find((soruceToFind) => matchesSource(soruceToFind, sourceToAdd));
910
+ }
911
+ else {
912
+ answerSource = answer.source;
913
+ }
914
+ const moreAnswers = await inquirer.prompt(answerSource.canHaveInterfaceFile === true
915
+ ? [
916
+ {
917
+ type: 'fuzzypath',
918
+ name: 'folder',
919
+ excludePath: (maybeExcludePath) => maybeExcludePath.startsWith('node_modules') ||
920
+ maybeExcludePath.startsWith('.git'),
921
+ itemType: 'directory',
922
+ rootPath: '.',
923
+ message: 'Select a folder to save the analytics wrapper interface file in',
924
+ default: '.',
925
+ suggestOnly: false,
926
+ depthLimit: 10,
927
+ },
928
+ {
929
+ type: 'input',
930
+ name: 'interfaceFilename',
931
+ message: (_answers) => 'Select a filename for the analytics wrapper interface file',
932
+ // @ts-ignore
933
+ default() {
934
+ return answerSource.filenameHint;
935
+ },
936
+ },
937
+ ]
938
+ : []);
939
+ const hasMultiPath = moreAnswers.interfaceFilename != null;
940
+ const relativeMainPath = path.relative(process.cwd(), path.join(path.resolve(answer.folder), answer.filename));
941
+ let relativeInterfacePath = relativeMainPath;
942
+ if (hasMultiPath) {
943
+ relativeInterfacePath = path.relative(process.cwd(), path.join(path.resolve(answer.folder), moreAnswers.interfaceFilename));
944
+ }
895
945
  let source;
896
946
  if (sourceToAdd) {
897
947
  source = sources.find((sourceToFind) => matchesSource(sourceToFind, sourceToAdd));
898
- source = { id: source.id, name: source.name, path: relativePath };
948
+ source = {
949
+ id: source.id,
950
+ name: source.name,
951
+ path: relativeMainPath,
952
+ interfacePath: relativeInterfacePath,
953
+ };
899
954
  }
900
955
  else {
901
956
  source = {
902
957
  id: answer.source.id,
903
958
  name: answer.source.name,
904
- path: relativePath,
959
+ path: relativeMainPath,
960
+ interfacePath: relativeInterfacePath,
905
961
  };
906
962
  }
907
963
  sources = (json.sources ?? []).concat([source]);
@@ -934,6 +990,7 @@ function pull(sourceFilter, json) {
934
990
  sources: sources.map((source) => ({
935
991
  id: source.id,
936
992
  path: source.path,
993
+ interfacePath: source.interfacePath,
937
994
  })),
938
995
  force: json.force ?? false,
939
996
  forceFeatures: json.forceFeatures,
@@ -1359,7 +1416,7 @@ yargs(hideBin(process.argv)) // eslint-disable-line no-unused-expressions
1359
1416
  type: 'boolean',
1360
1417
  })
1361
1418
  .option('forceFeatures', {
1362
- describe: 'Optional comma separated list of features to force enable',
1419
+ describe: 'Optional comma separated list of features to force enable, pass unsupported name to get the list of available features',
1363
1420
  default: undefined,
1364
1421
  type: 'string',
1365
1422
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "avo",
3
- "version": "3.1.1",
3
+ "version": "3.2.2",
4
4
  "type": "module",
5
5
  "description": "The command-line interface for Avo",
6
6
  "author": "Avo (https://www.avo.app)",
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "scripts": {
20
20
  "postinstall": "node cli.js track-install; true",
21
+ "prepublishOnly": "npm run compile",
21
22
  "lint": "eslint cli.ts",
22
23
  "format": "prettier --write cli.ts",
23
24
  "check-format": "prettier --check cli.ts",
@@ -34,7 +35,7 @@
34
35
  "got": "^12.1.0",
35
36
  "http-shutdown": "^1.2.0",
36
37
  "ignore-walk": "^5.0.1",
37
- "inquirer": "^9.0",
38
+ "inquirer": "^8.0.0",
38
39
  "inquirer-fuzzy-path": "^2.3.0",
39
40
  "jsonwebtoken": "^8.4.0",
40
41
  "load-json-file": "^7.0.1",