Skip to content

Commit

Permalink
Clean up instances of 'import * as', default and named exports; updat…
Browse files Browse the repository at this point in the history
…e eslint to use ecmaVersion 8
  • Loading branch information
aesqe committed May 15, 2019
1 parent 11873eb commit c93537f
Show file tree
Hide file tree
Showing 47 changed files with 527 additions and 451 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"mocha": true
},
"parserOptions": {
"ecmaVersion": 7,
"ecmaVersion": 8,
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
Expand Down
11 changes: 6 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import yargs from 'yargs';

import getHomeDir from './home-dir';
import autoUpdate from './commands/update-cli';
import * as analytics from './services/analytics';
import { isAscii, containsSpace } from './services/validation';
import { authorizeRequests, getRefreshToken } from './clients/auth-service';
import analytics from './services/analytics';
import authService from './clients/auth-service';
import apiUrls from '../config/services';

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

(async () => {
if (await autoUpdate(cliArgs)) {
return null;
return;
}
const refreshToken = await getRefreshToken();
authorizeRequests(refreshToken);

const refreshToken = await authService.getRefreshToken();
authService.authorizeRequests(refreshToken);

const cli = yargs.usage('Usage: shoutem [command] [-h]')
.option('version', {
Expand Down
33 changes: 17 additions & 16 deletions src/cli/extension/publish.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import path from 'path';
import {executeAndHandleError} from "../../services/error-handler";
import {ensureUserIsLoggedIn} from "../../commands/login";
import {getPlatformConfig, getPlatformExtensionsDir} from "../../services/platform";
import fs from 'fs-extra';
import {uploadExtension} from "../../commands/push";
import {publishExtension} from "../../commands/publish";
import {updateExtension, getInstallation, installExtension} from "../../clients/app-manager";
import confirmer from "../../services/confirmer";
import {getExtension} from "../../clients/extension-manager";
import path from 'path';

import confirmer from '../../services/confirmer';
import { executeAndHandleError } from '../../services/error-handler';
import { getPlatformConfig, getPlatformExtensionsDir } from '../../services/platform';
import { ensureUserIsLoggedIn } from '../../commands/login';
import { uploadExtension } from '../../commands/push';
import { publishExtension } from '../../commands/publish';
import { updateExtension, getInstallation, installExtension } from '../../clients/app-manager';
import { getExtension } from '../../clients/extension-manager';

export const description = 'Publish an extension from the app in the working directory';
export const command = 'publish <name>';
export const builder = yargs => {
return yargs
.usage(`shoutem ${command}\n\n${description}`);
};
export const builder = yargs => yargs.usage(`shoutem ${command}\n\n${description}`);

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

try {
const { id: installationId, extension: oldExtensionId } = await getInstallation(appId, canonical);
const {
id: installationId,
extension: oldExtensionId,
} = await getInstallation(appId, canonical);
const { version: oldVersion } = await getExtension(oldExtensionId);

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

async function publish (name) {
async function publish(name) {
const dev = await ensureUserIsLoggedIn();
const extensionPath = path.join(getPlatformExtensionsDir(), `${dev.name}.${name}`);

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

export const handler = ({ name }) => executeAndHandleError(publish, name);
export const handler = ({ name }) => executeAndHandleError(publish, name);
35 changes: 16 additions & 19 deletions src/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@ import path from 'path';

export const description = 'Run shoutem application on using Shoutem preview app';
export const command = 'run';
export const builder = yargs => {
return yargs
.options({
local: {
alias: 'l',
description: 'don\'t use tunneling for Shoutem app, connect directly to packager. Note: ' +
'this computer and iphone/android must be connected to the same network and port 8081 must be opened.',
type: 'boolean'
},
small: {
alias: 's',
description: 'display smaller ASCII QR code which could be unreadable in some fonts',
type: 'boolean'
}
})
.usage(`shoutem ${command} [options]\n\n${description}`);
};
export const builder = yargs => yargs.options({
local: {
alias: 'l',
description: 'don\'t use tunneling for Shoutem app, connect directly to packager. Note: ' +
'this computer and iphone/android must be connected to the same network and port 8081 must be opened.',
type: 'boolean',
},
small: {
alias: 's',
description: 'display smaller ASCII QR code which could be unreadable in some fonts',
type: 'boolean',
},
}).usage(`shoutem ${command} [options]\n\n${description}`);

export async function handler(args) {
const nodeArgs = [
path.join(__dirname, '..', 'scripts', 'shoutem-run.js'),
'--local', !!args.local,
'--small', !!args.small
'--small', !!args.small,
];

forkTerminal('node', nodeArgs, { cwd: process.cwd() })
forkTerminal('node', nodeArgs, { cwd: process.cwd() });
}
4 changes: 2 additions & 2 deletions src/cli/show.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import show from '../commands/show.js';
import show from '../commands/show';
import { executeAndHandleError } from '../services/error-handler';

export const command = 'show';
Expand All @@ -10,7 +10,7 @@ export function builder(yargs) {
all: {
type: 'boolean',
default: false,
}
},
})
.usage(`shoutem ${command}\n\n${description}`);
}
Expand Down
30 changes: 14 additions & 16 deletions src/cli/uninstall.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import { uninstallExtension, getExtInstallations } from '../clients/app-manager';
import * as localExtensions from '../clients/local-extensions';
import { getLocalExtensionCanonicalName } from '../clients/local-extensions';
import { getExtensionId } from '../clients/extension-manager';
import msg from '../user_messages';
import { handleError } from '../services/error-handler';
import msg from '../user_messages';

export const description = `Uninstall current extension from an app.`;
export const description = 'Uninstall current extension from an app.';
export const command = 'uninstall';
export const builder = yargs => {
return yargs
.options({
app: {
alias: 'a',
description: 'uninstall local extension from an app',
requiresArg: true,
demand: true
}
})
.usage(`shoutem ${command} [options]\n\n${description}`);
};
export const builder = yargs => yargs
.options({
app: {
alias: 'a',
description: 'uninstall local extension from an app',
requiresArg: true,
demand: true,
},
})
.usage(`shoutem ${command} [options]\n\n${description}`);

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

try {
const canonicalName = await localExtensions.getExtensionCanonicalName();
const canonicalName = await getLocalExtensionCanonicalName();
const extensionId = await getExtensionId(canonicalName);

if (!extensionId) {
Expand Down
10 changes: 5 additions & 5 deletions src/cli/use.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setHostEnvName } from '../clients/server-env';
import { getValue } from '../services/cache-env';
import cache from '../services/cache-env';
import msg from '../user_messages';

export const description = null;
Expand All @@ -10,7 +10,7 @@ const production = {
description: 'Switch to shoutem live env',
handler() {
setHostEnvName('production');
console.log(msg.use.complete('production', getValue('developer')));
console.log(msg.use.complete('production', cache.getValue('developer')));
},
};

Expand All @@ -19,7 +19,7 @@ const dev = {
description: 'Switch to sauros dev env',
handler() {
setHostEnvName('dev');
console.log(msg.use.complete('dev', getValue('developer')));
console.log(msg.use.complete('dev', cache.getValue('developer')));
},
};

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

Expand All @@ -37,7 +37,7 @@ const qa = {
description: 'Switch to using sauros qa env',
handler() {
setHostEnvName('qa');
console.log(msg.use.complete('qa', getValue('developer')));
console.log(msg.use.complete('qa', cache.getValue('developer')));
},
};

Expand Down
7 changes: 4 additions & 3 deletions src/cli/whoami.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import msg from '../user_messages';
import { getValue } from '../services/cache-env';
import cache from '../services/cache-env';

export const command = 'whoami';
export const description = 'Username of the current user.';
export async function handler() {

export function handler() {
try {
const dev = await getValue('developer');
const dev = cache.getValue('developer');
if (dev) {
console.log(msg.login.complete(dev));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/clients/_tests_/auth-service.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from 'chai';
import * as authService from '../auth-service';
import authService from '../auth-service';

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

Expand Down
16 changes: 5 additions & 11 deletions src/clients/_tests_/extension-manager.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { assert } from 'chai';
import * as authService from '../auth-service';
import * as extManager from '../extension-manager';
import authService from '../auth-service';
import { getDeveloper } from '../extension-manager';

describe('Extension manager client integration tests', () => {

describe('Fetch developer info', () => {

it('should fetch developer info', async () => {
const refreshToken = await authService.getRefreshToken({ email: '[email protected]', password: 'password' });
await authService.authorizeRequests(refreshToken);
const dev = await extManager.getDeveloper();
const dev = await getDeveloper();
console.log(dev);
});



})
});
});
});
2 changes: 1 addition & 1 deletion src/clients/app-manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import URI from 'urijs';
import * as jsonApi from './json-api-client';
import jsonApi from './json-api-client';
import { appManager } from '../../config/services';
import { getDeveloper } from './extension-manager';

Expand Down
Loading

0 comments on commit c93537f

Please sign in to comment.