Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactoring and Purging #243

Merged
merged 23 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
49ed208
:loud_sound: Add more verbose logs
rubenaeg Sep 30, 2021
4639e0a
:bug: Resolve modules with CLI exec path
rubenaeg Sep 30, 2021
c927704
:sparkles: Add topic descriptions
rubenaeg Oct 4, 2021
eb343e4
:truck: Rename resources and remove $-sign
rubenaeg Oct 4, 2021
cdf03a8
:truck: Rename build to build:platform
rubenaeg Oct 4, 2021
05566b0
:truck: Rename build to build:platform
rubenaeg Oct 4, 2021
58a14d2
:children_crossing: Improve UX of deploy commands
rubenaeg Oct 4, 2021
df1f4bf
:truck: Rename get to get:platform
rubenaeg Oct 4, 2021
7d51a5e
:children_crossing: Improve UX of new commands
rubenaeg Oct 4, 2021
8c83737
:children_crossing: Improve UX of run commands
rubenaeg Oct 4, 2021
4e1552b
:wastebasket: Generate default preset if it doesnt exist
rubenaeg Oct 4, 2021
6f56434
:sparkles: Add support for multiple arguments
rubenaeg Oct 4, 2021
2842c8e
:fire: Remove targets
rubenaeg Oct 4, 2021
db733a6
:label: Improve typings
rubenaeg Oct 4, 2021
24ad92c
:art::label: Adjust Lex integration to renaming, improve typings
rubenaeg Oct 4, 2021
8829c5e
:art: Adjust Serverless integration to renaming
rubenaeg Oct 4, 2021
9d782e0
Merge branch 'v4/dev' of github.com:jovotech/jovo-cli into v4/improve…
rubenaeg Oct 4, 2021
c741728
:rotating_light: Satisfy linter
rubenaeg Oct 4, 2021
7d15ac9
:bug: Fix ambient context
rubenaeg Oct 4, 2021
6aadd81
:children_crossing: Ask for overwriting server file
rubenaeg Oct 4, 2021
12f9a39
:white_check_mark: Update unit tests
rubenaeg Oct 5, 2021
9c7ca82
Merge branch 'v4/dev' of github.com:jovotech/jovo-cli into v4/improve…
rubenaeg Oct 5, 2021
b097e12
:bug: Fix merging bug
rubenaeg Oct 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@
"./dist/hooks/VersionHook.js",
"./dist/hooks/InitHook.js"
]
},
"topics": {
"build": {
"description": "Build your Jovo app using the following commands:"
},
"deploy": {
"description": "Deploy your Jovo app using the following commands:"
},
"get": {
"description": "Synchronize your Jovo app using the following commands:"
}
}
},
"gitHead": "9edb66662ac080853fd9fe02524c2d2ed88aa952"
Expand Down
3 changes: 2 additions & 1 deletion cli/src/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class Collector extends Plugin {
command: commandId,
};

Log.verbose('Installing CLI plugins');
for (const plugin of plugins) {
plugin.install(cli, emitter, context);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand All @@ -49,7 +50,7 @@ export class Collector extends Plugin {

// Load hooks from project configuration.
if (cli.isInProjectDirectory()) {
const hooks: ConfigHooks = cli.$project!.$config.getParameter('hooks') as ConfigHooks;
const hooks: ConfigHooks = cli.project!.config.getParameter('hooks') as ConfigHooks;
if (hooks) {
for (const [eventKey, events] of Object.entries(hooks)) {
for (const event of events) {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/hooks/VersionHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const hook: Hook<'init'> = async function () {
// Check for versions of Jovo modules within a project
const cli: JovoCli = JovoCli.getInstance();
if (cli.isInProjectDirectory()) {
const versions: PackageVersions = await getPackageVersions(/^@jovotech/, cli.$projectPath);
const versions: PackageVersions = await getPackageVersions(/^@jovotech/, cli.projectPath);
if (Object.keys(versions).length) {
const output: string[] = [];
let updatesAvailable: boolean = false;
Expand Down
5 changes: 4 additions & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
process.env.JOVO_CLI_RUNTIME = '1';
import { dirname } from 'path';

process.env.FORCE_COLOR = '1';
process.env.JOVO_CLI_RUNTIME = '1';
process.env.JOVO_CLI_EXEC_PATH = dirname(__dirname);

export { run } from '@oclif/command';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DeployCodeEvents, DeployPlatformEvents } from '@jovotech/cli-command-deploy';
import { DeployPlatformEvents } from '@jovotech/cli-command-deploy';
import {
checkForProjectDirectory,
CliArgs,
CliFlags,
EventEmitter,
flags,
Expand All @@ -10,9 +11,6 @@ import {
PluginContext,
printSubHeadline,
TADA,
TARGET_ALL,
TARGET_INFO,
TARGET_MODEL,
Task,
wait,
} from '@jovotech/cli-core';
Expand All @@ -21,71 +19,72 @@ import _merge from 'lodash.merge';
import BuildCommand from '..';
import { promptForPlatform } from '../utilities';

export type BuildFlags = CliFlags<typeof Build>;

export interface BuildContext extends PluginContext {
flags: BuildFlags;
export interface BuildPlatformContext extends PluginContext {
args: CliArgs<typeof BuildPlatform>;
flags: CliFlags<typeof BuildPlatform>;
platforms: string[];
locales: string[];
target: string;
}

export type BuildEvents = 'before.build' | 'build' | 'after.build' | 'reverse.build';
export type BuildPlatformEvents =
| 'before.build:platform'
| 'build:platform'
| 'build:platform.reverse'
| 'after.build:platform';

export class Build extends PluginCommand<BuildEvents | DeployCodeEvents | DeployPlatformEvents> {
static id = 'build';
static description = 'Build platform-specific language models based on jovo models folder.';
static examples: string[] = ['jovo build --platform alexaSkill', 'jovo build --target zip'];
export class BuildPlatform extends PluginCommand<BuildPlatformEvents | DeployPlatformEvents> {
static id = 'build:platform';
static description = 'Build platform-specific language models based on jovo models folder';
static examples = ['jovo build:platform alexa'];
static availablePlatforms: string[] = [];
static flags = {
clean: flags.boolean({
description:
'Deletes all platform folders and executes a clean build. If --platform is specified, it deletes only the respective platforms folder.',
description: 'Delete the relevant folders in build at the beginning of the process',
}),
deploy: flags.boolean({
char: 'd',
description: 'Runs deploy after build.',
description:
'Directly deploy the platform after the build process. Run "deploy:platform --help" command for more information.',
exclusive: ['reverse'],
}),
force: flags.boolean({
description: 'Forces overwrite of existing project for reverse build.',
dependsOn: ['reverse'],
}),
locale: flags.string({
char: 'l',
description: 'Locale of the language model.\n<en|de|etc>',
multiple: true,
}),
platform: flags.string({
char: 'p',
description: 'Specifies a build platform.',
options: Build.availablePlatforms,
description: 'The locales to be built from the models folder',
multiple: true,
}),
reverse: flags.boolean({
char: 'r',
description: 'Builds Jovo language model from platform specific language model.',
description: 'Turn contents of the build folder into Jovo Model files',
exclusive: ['deploy'],
}),
target: flags.string({
char: 't',
description: 'Target of build.',
options: [TARGET_ALL, TARGET_INFO, TARGET_MODEL],
default: TARGET_ALL,
}),
...PluginCommand.flags,
};
$context!: BuildContext;

static install(cli: JovoCli, plugin: BuildCommand, emitter: EventEmitter<BuildEvents>): void {
static args = [
<const>{
name: 'platform',
description: 'Specifies a build platform',
options: BuildPlatform.availablePlatforms,
multiple: true,
},
];
// Allow multiple arguments by disabling argument length validation
static strict = false;

$context!: BuildPlatformContext;

static install(
cli: JovoCli,
plugin: BuildCommand,
emitter: EventEmitter<BuildPlatformEvents>,
): void {
// Override PluginCommand.install() to fill options for --platform.
this.availablePlatforms.push(...cli.getPlatforms());
super.install(cli, plugin, emitter);
}

install(): void {
this.middlewareCollection = {
build: [this.prepareBuild.bind(this)],
'build:platform': [this.prepareBuild.bind(this)],
};
}

Expand All @@ -101,7 +100,7 @@ export class Build extends PluginCommand<BuildEvents | DeployCodeEvents | Deploy
},
);
const collectModelsTask: Task = new Task(
`Collecting Jovo language model files from ./${this.$cli.$project!.getModelsDirectory()} folder.`,
`Collecting Jovo language model files from ./${this.$cli.project!.getModelsDirectory()} folder.`,
async () => {
await wait(500);
return `Locales: ${this.$context.locales.join(',')}`;
Expand All @@ -113,7 +112,7 @@ export class Build extends PluginCommand<BuildEvents | DeployCodeEvents | Deploy
await initTask.run();

// Create build/ folder depending on user config.
const buildPath: string = this.$cli.$project!.getBuildPath();
const buildPath: string = this.$cli.project!.getBuildPath();
if (!existsSync(buildPath)) {
mkdirSync(buildPath);
}
Expand All @@ -123,17 +122,17 @@ export class Build extends PluginCommand<BuildEvents | DeployCodeEvents | Deploy
checkForProjectDirectory(this.$cli.isInProjectDirectory());

Log.spacer();
Log.info(`jovo build: ${Build.description}`);
Log.info(`jovo build:platform: ${BuildPlatform.description}`);
Log.info(printSubHeadline('Learn more: https://jovo.tech/docs/cli/build\n'));

const { flags }: { flags: BuildFlags } = this.parse(Build);
const { args, flags } = this.parse(BuildPlatform);

// Build plugin context, containing information about the current command environment.
_merge(this.$context, {
args,
flags,
locales: flags.locale || this.$cli.$project!.getLocales(),
platforms: flags.platform || this.$cli.getPlatforms(),
target: flags.target,
locales: flags.locale || this.$cli.project!.getLocales(),
platforms: args.platform.length ? args.platform : this.$cli.getPlatforms(),
});

// If --reverse flag has been set and more than one platform has been specified, prompt for one.
Expand All @@ -146,17 +145,17 @@ export class Build extends PluginCommand<BuildEvents | DeployCodeEvents | Deploy
// On build --reverse, omit selecting default locales with $project.getLocales()
this.$context.locales = flags.locale || [];

await this.$emitter.run('reverse.build');
await this.$emitter.run('build:platform.reverse');

Log.spacer();
Log.info(`${TADA} Reverse build completed.`);
Log.spacer();
return;
}

await this.$emitter.run('before.build');
await this.$emitter.run('build');
await this.$emitter.run('after.build');
await this.$emitter.run('before.build:platform');
await this.$emitter.run('build:platform');
await this.$emitter.run('after.build:platform');

if (flags.deploy) {
Log.spacer();
Expand Down
10 changes: 5 additions & 5 deletions commands/command-build/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { JovoCliPlugin, PluginCommand, PluginType } from '@jovotech/cli-core';
import { Build } from './commands/build';
import { BuildPlatform } from './commands/build.platform';

export * from './commands/build';
export * from './commands/build.platform';

export class BuildCommand extends JovoCliPlugin {
$id: string = 'build';
$type: PluginType = 'command';
id: string = 'build';
type: PluginType = 'command';

getCommands(): typeof PluginCommand[] {
return [Build];
return [BuildPlatform];
}
}

Expand Down
40 changes: 16 additions & 24 deletions commands/command-deploy/src/commands/deploy.code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,40 @@ import {
import _merge from 'lodash.merge';
import DeployCommand from '..';

export type DeployCodeFlags = CliFlags<typeof DeployCode>;
export type DeployCodeArgs = CliArgs<typeof DeployCode>;

export interface DeployCodeContext extends PluginContext {
args: DeployCodeArgs;
flags: DeployCodeFlags;
args: CliArgs<typeof DeployCode>;
flags: CliFlags<typeof DeployCode>;
target: string[];
locales: string[];
src?: string;
}

export type DeployCodeEvents = 'before.deploy:code' | 'deploy:code' | 'after.deploy:code';

export class DeployCode extends PluginCommand<DeployCodeEvents> {
static id: string = 'deploy:code';
static description: string = 'Deploys project code.';
static examples: string[] = [
'jovo deploy --locale en-US --platform alexaSkill --stage dev',
'jovo deploy --target zip',
];
static description: string = 'Upload the source code to a cloud provider';
static examples: string[] = ['jovo deploy:code serverless'];
// Includes all available targets, which will be initialized on install().
static availableTargets: string[] = [];
static flags = {
locale: flags.string({
char: 'l',
description: 'Locale of the language model.\n<en|de|etc>',
multiple: true,
}),
src: flags.string({
char: 's',
description: 'Path to source files.',
description: 'Path to source files',
}),
...PluginCommand.flags,
};
static args = [
<const>{
name: 'target',
description: 'Deploys.',
required: true,
description: 'Specify the cloud provider to be deployed to',
multiple: true,
options: DeployCode.availableTargets,
},
];
// Allow multiple arguments by disabling argument length validation
static strict = false;

$context!: DeployCodeContext;

static install(
Expand All @@ -63,7 +56,7 @@ export class DeployCode extends PluginCommand<DeployCodeEvents> {
emitter: EventEmitter<DeployCodeEvents>,
): void {
// Override PluginComponent.install() to fill options for --platform.
this.availableTargets.push(...cli.getPluginsWithType('target').map((plugin) => plugin.$id));
this.availableTargets.push(...cli.getPluginsWithType('target').map((plugin) => plugin.id));
super.install(cli, plugin, emitter);
}

Expand All @@ -72,16 +65,15 @@ export class DeployCode extends PluginCommand<DeployCodeEvents> {

Log.spacer();
Log.info(`jovo deploy:code: ${DeployCode.description}`);
Log.info(printSubHeadline('Learn more: https://jovo.tech/docs/cli/deploy-code\n'));
Log.info(printSubHeadline('Learn more: https://jovo.tech/docs/cli/deploy-code'));
Log.spacer();

const { args, flags }: { args: DeployCodeArgs; flags: DeployCodeFlags } =
this.parse(DeployCode);
const { args, flags } = this.parse(DeployCode);

_merge(this.$context, {
args,
flags,
locales: flags.locale || this.$cli.$project!.getLocales(),
target: args.target ? [args.target] : DeployCode.availableTargets,
target: args.target,
src: flags.src,
});

Expand Down
Loading