Skip to content

Commit

Permalink
chore(contented): with programmatic execution
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh committed Feb 14, 2024
1 parent b686a1c commit 85f99b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
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();
},
};

0 comments on commit 85f99b8

Please sign in to comment.