@trycourier/cli 2.1.3 → 2.1.4

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.
package/dist/cli.js CHANGED
@@ -1,57 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import React, { useEffect, useState } from 'react';
3
- import { Box, Text, render } from 'ink';
2
+ import { render } from 'ink';
3
+ import React from 'react';
4
+ import { CliContextProvider } from './components/Context.js';
4
5
  import args from './lib/args.js';
5
6
  import loadEnv from './lib/load-env.js';
6
- import { CliContextProvider } from './components/Context.js';
7
- import { execa } from 'execa';
8
- import _ from 'lodash';
9
- import VERSION from './version.js';
10
- import constants from './constants.js';
7
+ import Version from './version.js';
11
8
  const CLI = async () => {
12
9
  process.removeAllListeners('warning');
13
10
  await loadEnv();
14
11
  const params = args(process.argv);
15
12
  const mappings = (await import('./mappings.js')).default;
16
13
  const Router = (await import('./components/Router.js')).default;
17
- const [version, setVersion] = useState({});
18
- useEffect(() => {
19
- getVersion();
20
- }, []);
21
- const getVersion = async () => {
22
- if (VERSION !== 'local') {
23
- try {
24
- const exc = await execa('npm', ['-g', 'outdated', constants.package_name, '--json'], {
25
- shell: true,
26
- reject: false,
27
- });
28
- const stdout = JSON.parse(exc.stdout);
29
- setVersion({
30
- current: _.get(stdout, [constants.package_name, 'current']),
31
- latest: _.get(stdout, [constants.package_name, 'latest']),
32
- });
33
- }
34
- catch (e) {
35
- console.log(e);
36
- }
37
- }
38
- };
39
- const version_text = version.current && version.latest && version.current !== version.latest
40
- ? `Upgrade available (${version.current} > ${version.latest}), run courier upgrade`
41
- : undefined;
42
- render(React.createElement(CliContextProvider, { args: params, mappings, ...version },
14
+ render(React.createElement(CliContextProvider, { args: params, mappings },
43
15
  React.createElement(Router, null),
44
- version_text ? (React.createElement(Box, { flexDirection: "column", marginY: 1, flexShrink: 1, width: version_text.length + 2, borderColor: "gray", borderStyle: 'single' },
45
- React.createElement(Text, null,
46
- "Upgrade available (",
47
- version.current,
48
- " ",
49
- '>',
50
- " ",
51
- version.latest,
52
- "), run",
53
- ' ',
54
- React.createElement(Text, { color: "green" }, "courier upgrade")))) : (React.createElement(React.Fragment, null))));
16
+ React.createElement(Version, null)));
55
17
  };
56
18
  (async () => {
57
19
  await CLI();
@@ -7,30 +7,33 @@ import { Box } from 'ink';
7
7
  import { execa } from 'execa';
8
8
  import constants from '../constants.js';
9
9
  export default () => {
10
- const { latest } = useCliContext();
10
+ const { version } = useCliContext();
11
11
  const running = useBoolean(true);
12
12
  const [error, setError] = useState();
13
13
  useEffect(() => {
14
- upgrade();
15
- }, []);
16
- const upgrade = async () => {
17
- try {
18
- await execa('npm', ['upgrade', '-g', `${constants.package_name}@${latest}`], {
19
- shell: true,
20
- });
21
- }
22
- catch (e) {
23
- setError(e.message);
24
- }
25
- finally {
26
- running.setFalse();
14
+ if (version.latest) {
15
+ upgrade();
27
16
  }
17
+ }, [version.latest]);
18
+ const upgrade = async () => {
19
+ if (version)
20
+ try {
21
+ await execa('npm', ['upgrade', '-g', `${constants.package_name}@${version.latest}`], {
22
+ shell: true,
23
+ });
24
+ }
25
+ catch (e) {
26
+ setError(e.message);
27
+ }
28
+ finally {
29
+ running.setFalse();
30
+ }
28
31
  };
29
32
  if (running.value) {
30
- return React.createElement(Spinner, { text: `Upgrading Courier CLI ${latest}` });
33
+ return React.createElement(Spinner, { text: `Upgrading Courier CLI ${version.latest}` });
31
34
  }
32
35
  else {
33
- const text = `Courier CLI upgraded to ${latest}`;
36
+ const text = `Courier CLI upgraded to ${version.latest}`;
34
37
  return (React.createElement(Box, { width: error ? undefined : text.length + 8 }, error?.length ? (React.createElement(Alert, { variant: "error", title: 'Error' }, error)) : (React.createElement(Alert, { variant: "success", title: 'Upgraded' }, text))));
35
38
  }
36
39
  };
@@ -29,13 +29,19 @@ interface ICliContext {
29
29
  args: string[];
30
30
  url: string;
31
31
  courier: CourierClient;
32
- current?: string;
33
- latest?: string;
32
+ version: {
33
+ current?: string;
34
+ latest?: string;
35
+ };
36
+ setVersion: React.Dispatch<React.SetStateAction<{
37
+ current?: string;
38
+ latest?: string;
39
+ }>>;
34
40
  getJWT: TGetJWT;
35
41
  }
36
42
  type IUseCliContext = () => ICliContext;
37
43
  export declare const useCliContext: IUseCliContext;
38
- export declare const CliContextProvider: ({ args, mappings, current, latest, children, }: ICliContextProvider) => React.JSX.Element;
44
+ export declare const CliContextProvider: ({ args, mappings, children, }: ICliContextProvider) => React.JSX.Element;
39
45
  export declare const getApiKeyFlags: ({ environment, routing, document_scope, }: {
40
46
  environment: TEnvironment;
41
47
  routing: TAPIRouting;
@@ -1,10 +1,11 @@
1
1
  import { CourierClient } from '@trycourier/courier';
2
- import React, { createContext, useContext } from 'react';
2
+ import React, { createContext, useContext, useState } from 'react';
3
3
  import yargsParser from 'yargs-parser';
4
4
  const CliContext = createContext({});
5
5
  const PREFIX = 'COURIER_AUTH_TOKEN';
6
6
  export const useCliContext = () => useContext(CliContext);
7
- export const CliContextProvider = ({ args, mappings, current, latest, children, }) => {
7
+ export const CliContextProvider = ({ args, mappings, children, }) => {
8
+ const [version, setVersion] = useState({});
8
9
  const [map, ...params] = args;
9
10
  const mapping = mappings.get(map || '');
10
11
  const parsedParams = yargsParser(params);
@@ -53,9 +54,9 @@ export const CliContextProvider = ({ args, mappings, current, latest, children,
53
54
  courier,
54
55
  url,
55
56
  map,
56
- current,
57
- latest,
58
57
  getJWT,
58
+ version,
59
+ setVersion,
59
60
  };
60
61
  return React.createElement(CliContext.Provider, { value: context }, children);
61
62
  };
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- let VERSION = '2.1.3';
1
+ let VERSION = '2.1.4';
2
2
  export default VERSION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/cli",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "courier": "dist/cli.js"