Skip to content

Commit

Permalink
refactor: migrate to @oclif/core
Browse files Browse the repository at this point in the history
  • Loading branch information
john-u committed Feb 8, 2022
1 parent 862bb89 commit c0a677c
Show file tree
Hide file tree
Showing 123 changed files with 4,795 additions and 2,456 deletions.
3,011 changes: 2,315 additions & 696 deletions package-lock.json

Large diffs are not rendered by default.

3,662 changes: 2,209 additions & 1,453 deletions packages/cli/README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions packages/cli/bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'

require('ts-node').register({project})

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
3 changes: 3 additions & 0 deletions packages/cli/bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
5 changes: 0 additions & 5 deletions packages/cli/bin/devrun

This file was deleted.

6 changes: 3 additions & 3 deletions packages/cli/bin/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node

require('@oclif/command').run()
.then(require('@oclif/command/flush'))
.catch(require('@oclif/errors/handle'))
const oclif = require('@oclif/core')

oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
25 changes: 12 additions & 13 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@
"bin": "smartthings",
"plugins": [
"@smartthings/plugin-cli-edge",
"@oclif/plugin-help",
"@oclif/plugin-autocomplete",
"@oclif/plugin-not-found",
"@oclif/plugin-plugins"
],
"hooks": {
"init": "./lib/hooks/init/init-config"
},
"repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/cli/<%- commandPath %>"
"repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/cli/<%- commandPath %>",
"additionalHelpFlags": [
"-h"
]
},
"pkg": {
"scripts": [
Expand All @@ -57,13 +59,10 @@
]
},
"dependencies": {
"@oclif/command": "1.8.16",
"@oclif/config": "1.18.2",
"@oclif/errors": "1.3.5",
"@oclif/plugin-autocomplete": "^0.3.0",
"@oclif/plugin-help": "^3.3.1",
"@oclif/plugin-not-found": "^1.2.6",
"@oclif/plugin-plugins": "^1.10.11",
"@oclif/core": "^1.3.2",
"@oclif/plugin-autocomplete": "^1.2.0",
"@oclif/plugin-not-found": "^2.3.1",
"@oclif/plugin-plugins": "^2.1.0",
"@smartthings/cli-lib": "^0.0.0-pre.36",
"@smartthings/core-sdk": "^3.0.0",
"@smartthings/plugin-cli-edge": "^1.7.0",
Expand All @@ -76,7 +75,6 @@
"yeoman-environment": "^2.9.1"
},
"devDependencies": {
"@oclif/dev-cli": "^1.26.10",
"@smartthings/cli-testlib": "^0.0.0-pre.36",
"@types/cli-table": "^0.3.0",
"@types/inquirer": "^7.3.3",
Expand All @@ -94,6 +92,7 @@
"eslint-plugin-jest": "^24.1.3",
"jest": "^26.5.2",
"jest-extended": "^0.11.5",
"oclif": "^2.4.3",
"pkg": "4.4.9",
"ts-jest": "^26.4.1",
"ts-node": "^9.0.0",
Expand All @@ -105,13 +104,13 @@
"format": "eslint --ext ts src --fix",
"clean": "rm -rf lib && rm -f tsconfig.tsbuildinfo",
"compile": "tsc -b",
"readme": "oclif-dev readme",
"readme": "oclif readme",
"watch": "tsc -b -w",
"build": "npm run clean && npm run compile && npm run readme",
"test": "jest",
"postpack": "rm -f oclif.manifest.json",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"version": "oclif-dev readme && git add README.md",
"prepack": "rm -rf lib && tsc -b && oclif manifest && oclif readme",
"version": "oclif readme && git add README.md",
"package": "pkg package.json --out-path=dist_bin --targets=node12-linux-x64,node12-macos-x64,node12-win-x64",
"test-coverage": "jest --coverage=true"
}
Expand Down
22 changes: 0 additions & 22 deletions packages/cli/src/__tests__/commands/config.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/commands/locations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { v4 as uuid } from 'uuid'
import { outputListing, selectFromList } from '@smartthings/cli-lib'
import LocationsCommand, { chooseLocation } from '../../commands/locations'
import { LocationsEndpoint } from '@smartthings/core-sdk'
import { Config } from '@oclif/config'
import { Config } from '@oclif/core'


jest.mock('@smartthings/cli-lib', () => {
Expand Down
16 changes: 0 additions & 16 deletions packages/cli/src/__tests__/hooks/init-config.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from '@oclif/config'
import { Config } from '@oclif/core'
import { APICommand, ChooseOptions, chooseOptionsWithDefaults, ListDataFunction, Naming, selectFromList, SelectingConfig, SmartThingsCommandInterface, Sorting, stringTranslateToId } from '@smartthings/cli-lib'
import { App, AppsEndpoint, NoOpAuthenticator, SmartThingsClient } from '@smartthings/core-sdk'
import { chooseApp } from '../../../../lib/commands/apps/apps-util'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Location, LocationsEndpoint, NoOpAuthenticator, Room, RoomsEndpoint, Sm
import { getRoomsByLocation, chooseRoom } from '../../../../../lib/commands/locations/rooms/rooms-util'
import * as roomsUtil from '../../../../../lib/commands/locations/rooms/rooms-util'
import { v4 as uuid } from 'uuid'
import { Config } from '@oclif/config'
import { Config } from '@oclif/core'
import { APICommand, selectFromList } from '@smartthings/cli-lib'


Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/commands/apps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flags } from '@oclif/command'
import { Flags } from '@oclif/core'
import { App, AppType, AppClassification, AppListOptions } from '@smartthings/core-sdk'
import { APICommand, outputListing } from '@smartthings/cli-lib'
import { tableFieldDefinitions } from '../lib/commands/apps/apps-util'
Expand All @@ -10,20 +10,20 @@ export default class AppsCommand extends APICommand {
static flags = {
...APICommand.flags,
...outputListing.flags,
type: flags.string({
type: Flags.string({
description: 'filter results by appType, WEBHOOK_SMART_APP, LAMBDA_SMART_APP, API_ONLY',
multiple: false,
}),
classification: flags.string({
classification: Flags.string({
description: 'filter results by one or more classifications, AUTOMATION, SERVICE, DEVICE, CONNECTED_SERVICE',
multiple: true,
}),
// TODO -- uncomment when implemented
// tag: flags.string({
// tag: Flags.string({
// description: 'filter results by one or more tags, e.g. --tag=industry:energy',
// multiple: true,
// }),
verbose: flags.boolean({
verbose: Flags.boolean({
description: 'include URLs and ARNs in table output',
char: 'v',
}),
Expand All @@ -35,7 +35,7 @@ export default class AppsCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppsCommand)
const { args, argv, flags } = await this.parse(AppsCommand)
await super.setup(args, argv, flags)

const config = {
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class AppsCommand extends APICommand {
(app.lambdaSmartApp ? (app.lambdaSmartApp?.functions?.length ? app.lambdaSmartApp?.functions[0] : '') :
(app.apiOnly?.subscription?.targetUrl ?? ''))) ?? ''

const arnURL = uri.length < 96 ? uri : uri.slice(0,95) + '...'
const arnURL = uri.length < 96 ? uri : uri.slice(0, 95) + '...'
app['ARN/URL'] = arnURL
}
return list
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class AppsAuthorizeCommand extends SmartThingsCommand {
]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppsAuthorizeCommand)
const { args, argv, flags } = await this.parse(AppsAuthorizeCommand)
await super.setup(args, argv, flags)

const message = await addPermission(args.arn, flags.principal, flags['statement-id'])
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/src/commands/apps/create.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { flags } from '@oclif/command'
import { Flags, Errors } from '@oclif/core'
import { AppRequest, AppCreationResponse } from '@smartthings/core-sdk'
import { APICommand, inputAndOutputItem, lambdaAuthFlags } from '@smartthings/cli-lib'
import { addPermission } from '../../lib/aws-utils'
import { CLIError } from '@oclif/errors'
import { tableFieldDefinitions } from '../../lib/commands/apps/apps-util'


Expand All @@ -12,14 +11,14 @@ export default class AppCreateCommand extends APICommand {
static flags = {
...APICommand.flags,
...inputAndOutputItem.flags,
authorize: flags.boolean({
authorize: Flags.boolean({
description: 'authorize Lambda functions to be called by SmartThings',
}),
...lambdaAuthFlags,
}

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppCreateCommand)
const { args, argv, flags } = await this.parse(AppCreateCommand)
await super.setup(args, argv, flags)

const createApp = async (_: void, data: AppRequest): Promise<AppCreationResponse> => {
Expand All @@ -33,7 +32,7 @@ export default class AppCreateCommand extends APICommand {
await Promise.all(requests)
}
} else {
throw new CLIError('Authorization is not applicable to WebHook SmartApps')
throw new Errors.CLIError('Authorization is not applicable to WebHook SmartApps')
}
}
return this.client.apps.create(data)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class AppDeleteCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppDeleteCommand)
const { args, argv, flags } = await this.parse(AppDeleteCommand)
await super.setup(args, argv, flags)

const id = await chooseApp(this, args.id)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class AppOauthCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppOauthCommand)
const { args, argv, flags } = await this.parse(AppOauthCommand)
await super.setup(args, argv, flags)

const id = await chooseApp(this, args.id, { allowIndex: true })
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/oauth/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class AppOauthGenerateCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppOauthGenerateCommand)
const { args, argv, flags } = await this.parse(AppOauthGenerateCommand)
await super.setup(args, argv, flags)

const appId = await chooseApp(this, args.id)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/oauth/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class AppOauthUpdateCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppOauthUpdateCommand)
const { args, argv, flags } = await this.parse(AppOauthUpdateCommand)
await super.setup(args, argv, flags)

const appId = await chooseApp(this, args.id)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class AppRegisterCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppRegisterCommand)
const { args, argv, flags } = await this.parse(AppRegisterCommand)
await super.setup(args, argv, flags)

const config: SelectingConfig<App> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class AppSettingsCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppSettingsCommand)
const { args, argv, flags } = await this.parse(AppSettingsCommand)
await super.setup(args, argv, flags)

const id = await chooseApp(this, args.id, { allowIndex: true })
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/apps/settings/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class AppSettingsUpdateCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppSettingsUpdateCommand)
const { args, argv, flags } = await this.parse(AppSettingsUpdateCommand)
await super.setup(args, argv, flags)

const appId = await chooseApp(this, args.id)
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/apps/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flags } from '@oclif/command'
import { Flags } from '@oclif/core'
import { App, AppRequest } from '@smartthings/core-sdk'
import { ActionFunction, APICommand, inputAndOutputItem, TableCommonOutputProducer, lambdaAuthFlags } from '@smartthings/cli-lib'
import { addPermission } from '../../lib/aws-utils'
Expand All @@ -11,7 +11,7 @@ export default class AppUpdateCommand extends APICommand {
static flags = {
...APICommand.flags,
...inputAndOutputItem.flags,
authorize: flags.boolean({
authorize: Flags.boolean({
description: 'authorize Lambda functions to be called by SmartThings',
}),
...lambdaAuthFlags,
Expand All @@ -23,7 +23,7 @@ export default class AppUpdateCommand extends APICommand {
}]

async run(): Promise<void> {
const { args, argv, flags } = this.parse(AppUpdateCommand)
const { args, argv, flags } = await this.parse(AppUpdateCommand)
await super.setup(args, argv, flags)

const appId = await chooseApp(this, args.id)
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/commands/capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import inquirer from 'inquirer'
import { flags } from '@oclif/command'
import { Flags } from '@oclif/core'

import { Capability, CapabilityArgument, CapabilitySummary, CapabilityJSONSchema, CapabilityNamespace,
SmartThingsClient } from '@smartthings/core-sdk'
Expand Down Expand Up @@ -270,11 +270,11 @@ export default class CapabilitiesCommand extends APIOrganizationCommand {
...APIOrganizationCommand.flags,
...outputGenericListing.flags,
...allOrganizationsFlags,
namespace: flags.string({
namespace: Flags.string({
char: 'n',
description: 'a specific namespace to query; will use all by default',
}),
standard: flags.boolean({
standard: Flags.boolean({
char: 's',
description: 'show standard SmartThings capabilities',
}),
Expand All @@ -283,7 +283,7 @@ export default class CapabilitiesCommand extends APIOrganizationCommand {
static args = capabilityIdOrIndexInputArgs

async run(): Promise<void> {
const { args, argv, flags } = this.parse(CapabilitiesCommand)
const { args, argv, flags } = await this.parse(CapabilitiesCommand)
await super.setup(args, argv, flags)

const idOrIndex = args.version ? { id: args.id, version: args.version } : args.id
Expand Down
Loading

0 comments on commit c0a677c

Please sign in to comment.