Skip to content

Commit c93537f

Browse files
committed
Clean up instances of 'import * as', default and named exports; update eslint to use ecmaVersion 8
1 parent 11873eb commit c93537f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+527
-451
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"mocha": true
55
},
66
"parserOptions": {
7-
"ecmaVersion": 7,
7+
"ecmaVersion": 8,
88
"sourceType": "module",
99
"ecmaFeatures": {
1010
"experimentalObjectRestSpread": true

src/cli.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import yargs from 'yargs';
44

55
import getHomeDir from './home-dir';
66
import autoUpdate from './commands/update-cli';
7-
import * as analytics from './services/analytics';
87
import { isAscii, containsSpace } from './services/validation';
9-
import { authorizeRequests, getRefreshToken } from './clients/auth-service';
8+
import analytics from './services/analytics';
9+
import authService from './clients/auth-service';
1010
import apiUrls from '../config/services';
1111

1212
require('yargonaut')
@@ -28,10 +28,11 @@ analytics.setArgv(process.argv);
2828

2929
(async () => {
3030
if (await autoUpdate(cliArgs)) {
31-
return null;
31+
return;
3232
}
33-
const refreshToken = await getRefreshToken();
34-
authorizeRequests(refreshToken);
33+
34+
const refreshToken = await authService.getRefreshToken();
35+
authService.authorizeRequests(refreshToken);
3536

3637
const cli = yargs.usage('Usage: shoutem [command] [-h]')
3738
.option('version', {

src/cli/extension/publish.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import path from 'path';
2-
import {executeAndHandleError} from "../../services/error-handler";
3-
import {ensureUserIsLoggedIn} from "../../commands/login";
4-
import {getPlatformConfig, getPlatformExtensionsDir} from "../../services/platform";
51
import fs from 'fs-extra';
6-
import {uploadExtension} from "../../commands/push";
7-
import {publishExtension} from "../../commands/publish";
8-
import {updateExtension, getInstallation, installExtension} from "../../clients/app-manager";
9-
import confirmer from "../../services/confirmer";
10-
import {getExtension} from "../../clients/extension-manager";
2+
import path from 'path';
3+
4+
import confirmer from '../../services/confirmer';
5+
import { executeAndHandleError } from '../../services/error-handler';
6+
import { getPlatformConfig, getPlatformExtensionsDir } from '../../services/platform';
7+
import { ensureUserIsLoggedIn } from '../../commands/login';
8+
import { uploadExtension } from '../../commands/push';
9+
import { publishExtension } from '../../commands/publish';
10+
import { updateExtension, getInstallation, installExtension } from '../../clients/app-manager';
11+
import { getExtension } from '../../clients/extension-manager';
1112

1213
export const description = 'Publish an extension from the app in the working directory';
1314
export const command = 'publish <name>';
14-
export const builder = yargs => {
15-
return yargs
16-
.usage(`shoutem ${command}\n\n${description}`);
17-
};
15+
export const builder = yargs => yargs.usage(`shoutem ${command}\n\n${description}`);
1816

1917
export async function offerInstallationUpdate(extensionId, extensionName, newVersion) {
2018
const { appId } = getPlatformConfig();
@@ -23,7 +21,10 @@ export async function offerInstallationUpdate(extensionId, extensionName, newVer
2321
const canonical = `${dev.name}.${extensionName}`;
2422

2523
try {
26-
const { id: installationId, extension: oldExtensionId } = await getInstallation(appId, canonical);
24+
const {
25+
id: installationId,
26+
extension: oldExtensionId,
27+
} = await getInstallation(appId, canonical);
2728
const { version: oldVersion } = await getExtension(oldExtensionId);
2829

2930
const versionMsg = `${canonical}@${oldVersion} => @${newVersion}`;
@@ -43,7 +44,7 @@ export async function offerInstallationUpdate(extensionId, extensionName, newVer
4344
}
4445
}
4546

46-
async function publish (name) {
47+
async function publish(name) {
4748
const dev = await ensureUserIsLoggedIn();
4849
const extensionPath = path.join(getPlatformExtensionsDir(), `${dev.name}.${name}`);
4950

@@ -57,4 +58,4 @@ async function publish (name) {
5758
console.log('Success'.green.bold);
5859
}
5960

60-
export const handler = ({ name }) => executeAndHandleError(publish, name);
61+
export const handler = ({ name }) => executeAndHandleError(publish, name);

src/cli/run.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,26 @@ import path from 'path';
33

44
export const description = 'Run shoutem application on using Shoutem preview app';
55
export const command = 'run';
6-
export const builder = yargs => {
7-
return yargs
8-
.options({
9-
local: {
10-
alias: 'l',
11-
description: 'don\'t use tunneling for Shoutem app, connect directly to packager. Note: ' +
12-
'this computer and iphone/android must be connected to the same network and port 8081 must be opened.',
13-
type: 'boolean'
14-
},
15-
small: {
16-
alias: 's',
17-
description: 'display smaller ASCII QR code which could be unreadable in some fonts',
18-
type: 'boolean'
19-
}
20-
})
21-
.usage(`shoutem ${command} [options]\n\n${description}`);
22-
};
6+
export const builder = yargs => yargs.options({
7+
local: {
8+
alias: 'l',
9+
description: 'don\'t use tunneling for Shoutem app, connect directly to packager. Note: ' +
10+
'this computer and iphone/android must be connected to the same network and port 8081 must be opened.',
11+
type: 'boolean',
12+
},
13+
small: {
14+
alias: 's',
15+
description: 'display smaller ASCII QR code which could be unreadable in some fonts',
16+
type: 'boolean',
17+
},
18+
}).usage(`shoutem ${command} [options]\n\n${description}`);
19+
2320
export async function handler(args) {
2421
const nodeArgs = [
2522
path.join(__dirname, '..', 'scripts', 'shoutem-run.js'),
2623
'--local', !!args.local,
27-
'--small', !!args.small
24+
'--small', !!args.small,
2825
];
2926

30-
forkTerminal('node', nodeArgs, { cwd: process.cwd() })
27+
forkTerminal('node', nodeArgs, { cwd: process.cwd() });
3128
}

src/cli/show.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import show from '../commands/show.js';
1+
import show from '../commands/show';
22
import { executeAndHandleError } from '../services/error-handler';
33

44
export const command = 'show';
@@ -10,7 +10,7 @@ export function builder(yargs) {
1010
all: {
1111
type: 'boolean',
1212
default: false,
13-
}
13+
},
1414
})
1515
.usage(`shoutem ${command}\n\n${description}`);
1616
}

src/cli/uninstall.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import { uninstallExtension, getExtInstallations } from '../clients/app-manager';
2-
import * as localExtensions from '../clients/local-extensions';
2+
import { getLocalExtensionCanonicalName } from '../clients/local-extensions';
33
import { getExtensionId } from '../clients/extension-manager';
4-
import msg from '../user_messages';
54
import { handleError } from '../services/error-handler';
5+
import msg from '../user_messages';
66

7-
export const description = `Uninstall current extension from an app.`;
7+
export const description = 'Uninstall current extension from an app.';
88
export const command = 'uninstall';
9-
export const builder = yargs => {
10-
return yargs
11-
.options({
12-
app: {
13-
alias: 'a',
14-
description: 'uninstall local extension from an app',
15-
requiresArg: true,
16-
demand: true
17-
}
18-
})
19-
.usage(`shoutem ${command} [options]\n\n${description}`);
20-
};
9+
export const builder = yargs => yargs
10+
.options({
11+
app: {
12+
alias: 'a',
13+
description: 'uninstall local extension from an app',
14+
requiresArg: true,
15+
demand: true,
16+
},
17+
})
18+
.usage(`shoutem ${command} [options]\n\n${description}`);
2119

2220
export async function handler(args) {
2321
const appId = args.app;
2422

2523
try {
26-
const canonicalName = await localExtensions.getExtensionCanonicalName();
24+
const canonicalName = await getLocalExtensionCanonicalName();
2725
const extensionId = await getExtensionId(canonicalName);
2826

2927
if (!extensionId) {

src/cli/use.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setHostEnvName } from '../clients/server-env';
2-
import { getValue } from '../services/cache-env';
2+
import cache from '../services/cache-env';
33
import msg from '../user_messages';
44

55
export const description = null;
@@ -10,7 +10,7 @@ const production = {
1010
description: 'Switch to shoutem live env',
1111
handler() {
1212
setHostEnvName('production');
13-
console.log(msg.use.complete('production', getValue('developer')));
13+
console.log(msg.use.complete('production', cache.getValue('developer')));
1414
},
1515
};
1616

@@ -19,7 +19,7 @@ const dev = {
1919
description: 'Switch to sauros dev env',
2020
handler() {
2121
setHostEnvName('dev');
22-
console.log(msg.use.complete('dev', getValue('developer')));
22+
console.log(msg.use.complete('dev', cache.getValue('developer')));
2323
},
2424
};
2525

@@ -28,7 +28,7 @@ const local = {
2828
description: 'Use api endpoints set in OS env variables',
2929
handler() {
3030
setHostEnvName('local');
31-
console.log(msg.use.complete('local', getValue('developer')));
31+
console.log(msg.use.complete('local', cache.getValue('developer')));
3232
},
3333
};
3434

@@ -37,7 +37,7 @@ const qa = {
3737
description: 'Switch to using sauros qa env',
3838
handler() {
3939
setHostEnvName('qa');
40-
console.log(msg.use.complete('qa', getValue('developer')));
40+
console.log(msg.use.complete('qa', cache.getValue('developer')));
4141
},
4242
};
4343

src/cli/whoami.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import msg from '../user_messages';
2-
import { getValue } from '../services/cache-env';
2+
import cache from '../services/cache-env';
33

44
export const command = 'whoami';
55
export const description = 'Username of the current user.';
6-
export async function handler() {
6+
7+
export function handler() {
78
try {
8-
const dev = await getValue('developer');
9+
const dev = cache.getValue('developer');
910
if (dev) {
1011
console.log(msg.login.complete(dev));
1112
} else {

src/clients/_tests_/auth-service.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert } from 'chai';
2-
import * as authService from '../auth-service';
2+
import authService from '../auth-service';
33

44
describe('Auth service client integration tests', () => {
55

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
import { assert } from 'chai';
2-
import * as authService from '../auth-service';
3-
import * as extManager from '../extension-manager';
1+
import authService from '../auth-service';
2+
import { getDeveloper } from '../extension-manager';
43

54
describe('Extension manager client integration tests', () => {
6-
75
describe('Fetch developer info', () => {
8-
96
it('should fetch developer info', async () => {
107
const refreshToken = await authService.getRefreshToken({ email: '[email protected]', password: 'password' });
118
await authService.authorizeRequests(refreshToken);
12-
const dev = await extManager.getDeveloper();
9+
const dev = await getDeveloper();
1310
console.log(dev);
1411
});
15-
16-
17-
18-
})
19-
});
12+
});
13+
});

0 commit comments

Comments
 (0)