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

cli: fix help message #9842

Merged
merged 6 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 31 additions & 15 deletions dev-packages/application-manager/src/application-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,37 @@ import * as cp from 'child_process';
import { ApplicationPackage, ApplicationPackageOptions } from '@theia/application-package';
import { WebpackGenerator, FrontendGenerator, BackendGenerator } from './generator';
import { ApplicationProcess } from './application-process';
import { GeneratorOptions } from './generator/abstract-generator';
import yargs = require('yargs');

export class ApplicationPackageManager {

static defineGeneratorOptions<T>(cli: yargs.Argv<T>): yargs.Argv<T & {
mode: 'development' | 'production'
splitFrontend?: boolean
}> {
return cli
.option('mode', {
description: 'Generation mode to use',
choices: ['development', 'production'],
default: 'production' as const,
})
.option('split-frontend', {
description: 'Split frontend modules into separate chunks. By default enabled in the `development` mode and disabled in the `production` mode.',
type: 'boolean'
});
}

readonly pck: ApplicationPackage;
/** application process */
readonly process: ApplicationProcess;
/** manager process */
protected readonly __process: ApplicationProcess;
protected readonly webpack: WebpackGenerator;
protected readonly backend: BackendGenerator;
protected readonly frontend: FrontendGenerator;

constructor(options: ApplicationPackageOptions) {
this.pck = new ApplicationPackage(options);
this.process = new ApplicationProcess(this.pck, options.projectPath);
this.__process = new ApplicationProcess(this.pck, path.join(__dirname, '..'));
this.webpack = new WebpackGenerator(this.pck);
this.backend = new BackendGenerator(this.pck);
this.frontend = new FrontendGenerator(this.pck);
}

protected async remove(fsPath: string): Promise<void> {
Expand All @@ -48,24 +60,28 @@ export class ApplicationPackageManager {
}

async clean(): Promise<void> {
await this.remove(this.pck.lib());
await this.remove(this.pck.srcGen());
await this.remove(this.webpack.genConfigPath);
await Promise.all([
this.remove(this.pck.lib()),
this.remove(this.pck.srcGen()),
this.remove(new WebpackGenerator(this.pck).genConfigPath)
]);
}

async generate(): Promise<void> {
await this.webpack.generate();
await this.backend.generate();
await this.frontend.generate();
async generate(options: GeneratorOptions = {}): Promise<void> {
await Promise.all([
new WebpackGenerator(this.pck, options).generate(),
new BackendGenerator(this.pck, options).generate(),
new FrontendGenerator(this.pck, options).generate(),
]);
}

async copy(): Promise<void> {
await fs.ensureDir(this.pck.lib());
await fs.copy(this.pck.frontend('index.html'), this.pck.lib('index.html'));
}

async build(args: string[] = []): Promise<void> {
await this.generate();
async build(args: string[] = [], options: GeneratorOptions = {}): Promise<void> {
await this.generate(options);
await this.copy();
return this.__process.run('webpack', args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,22 @@

import * as os from 'os';
import * as fs from 'fs-extra';
import * as yargs from 'yargs';
import { ApplicationPackage } from '@theia/application-package';

const argv = yargs.option('mode', {
description: 'Mode to use',
choices: ['development', 'production'],
default: 'production' as 'development' | 'production',
}).option('split-frontend', {
description: 'Split frontend modules into separate chunks. By default enabled in the dev mode and disabled in the prod mode.',
type: 'boolean',
}).option('app-target', {
description: 'The target application type. Overrides ["theia.target"] in the application\'s package.json.',
choices: ['browser', 'electron'],
}).argv;
const splitFrontend: boolean = argv['split-frontend'] ?? argv.mode === 'development';
export interface GeneratorOptions {
mode?: 'development' | 'production'
splitFrontend?: boolean
}

export abstract class AbstractGenerator {

constructor(
protected readonly pck: ApplicationPackage
protected readonly pck: ApplicationPackage,
protected options: GeneratorOptions = {}
) { }

protected compileFrontendModuleImports(modules: Map<string, string>): string {
const splitFrontend = this.options.splitFrontend ?? this.options.mode !== 'production';
return this.compileModuleImports(modules, splitFrontend ? 'import' : 'require');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

/* eslint-disable @typescript-eslint/indent */

import { AbstractGenerator } from './abstract-generator';
import { AbstractGenerator, GeneratorOptions } from './abstract-generator';
import { existsSync, readFileSync } from 'fs';

export class FrontendGenerator extends AbstractGenerator {

async generate(): Promise<void> {
async generate(options: GeneratorOptions = {}): Promise<void> {
const frontendModules = this.pck.targetFrontendModules;
await this.write(this.pck.frontend('index.html'), this.compileIndexHtml(frontendModules));
await this.write(this.pck.frontend('index.js'), this.compileIndexJs(frontendModules));
Expand Down
3 changes: 1 addition & 2 deletions dev-packages/cli/src/test-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default async function newTestPage(options: TestPageOptions): Promise<pup
};

// quick check whether test files exist
collectFiles(fileOptions);
const files = collectFiles(fileOptions);

const page = await newPage();
page.on('dialog', dialog => dialog.dismiss());
Expand Down Expand Up @@ -121,7 +121,6 @@ export default async function newTestPage(options: TestPageOptions): Promise<pup
await onWillRun();
}

const files = collectFiles(fileOptions);
for (const file of files) {
await page.addScriptTag({ path: file });
}
Expand Down
Loading