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

fix(contented): programmatic execution #795

Merged
merged 1 commit into from
Feb 14, 2024
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
3 changes: 1 addition & 2 deletions packages/contented/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { runExit } from 'clipanion';

import { BuildCommand } from './commands/BuildCommand.js';
import { GenerateCommand } from './commands/GenerateCommand.js';
import { WatchCommand } from './commands/WatchCommand.js';
import { WriteCommand } from './commands/WriteCommand.js';

// eslint-disable-next-line @typescript-eslint/no-floating-promises
runExit([BuildCommand, GenerateCommand, WatchCommand, WriteCommand]);
runExit([BuildCommand, GenerateCommand, WriteCommand]);
20 changes: 0 additions & 20 deletions packages/contented/src/commands/WatchCommand.ts

This file was deleted.

20 changes: 9 additions & 11 deletions packages/contented/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as process from 'node:process';

import { Config as ProcessorConfig } from '@contentedjs/contented-processor';
import { Cli } from 'clipanion';

import { BaseCommand } from './commands/BaseCommand';
import { BuildCommand } from './commands/BuildCommand.js';
import { GenerateCommand } from './commands/GenerateCommand.js';
import { WatchCommand } from './commands/WatchCommand.js';
import { WriteCommand } from './commands/WriteCommand.js';

export * from '@contentedjs/contented-processor';
Expand Down Expand Up @@ -33,21 +34,18 @@ export default {
* await contented.build()
*/
async build({ watch = process.env.NODE_ENV === 'development' } = {}): Promise<void> {
if (watch) {
await new WatchCommand().execute();
} else {
await new BuildCommand().execute();
}
const build = new BuildCommand();
build.context = Cli.defaultContext;
build.watch = watch;
await build.execute();
},
/**
* import contented from '@contentedjs/contented';
* await contented.preview()
*/
async preview({ watch = process.env.NODE_ENV === 'development' } = {}): Promise<void> {
if (watch) {
await new WriteCommand().execute();
} else {
await new GenerateCommand().execute();
}
const command: BaseCommand = watch ? new WriteCommand() : new GenerateCommand();
command.context = Cli.defaultContext;
await command.execute();
},
};