|
1 | 1 | import * as process from 'node:process';
|
2 | 2 |
|
3 | 3 | import { Config as ProcessorConfig } from '@contentedjs/contented-processor';
|
| 4 | +import { Cli } from 'clipanion'; |
4 | 5 |
|
| 6 | +import { BaseCommand } from './commands/BaseCommand'; |
5 | 7 | import { BuildCommand } from './commands/BuildCommand.js';
|
6 | 8 | import { GenerateCommand } from './commands/GenerateCommand.js';
|
7 |
| -import { WatchCommand } from './commands/WatchCommand.js'; |
8 | 9 | import { WriteCommand } from './commands/WriteCommand.js';
|
9 | 10 |
|
10 | 11 | export * from '@contentedjs/contented-processor';
|
@@ -33,21 +34,18 @@ export default {
|
33 | 34 | * await contented.build()
|
34 | 35 | */
|
35 | 36 | async build({ watch = process.env.NODE_ENV === 'development' } = {}): Promise<void> {
|
36 |
| - if (watch) { |
37 |
| - await new WatchCommand().execute(); |
38 |
| - } else { |
39 |
| - await new BuildCommand().execute(); |
40 |
| - } |
| 37 | + const build = new BuildCommand(); |
| 38 | + build.context = Cli.defaultContext; |
| 39 | + build.watch = watch; |
| 40 | + await build.execute(); |
41 | 41 | },
|
42 | 42 | /**
|
43 | 43 | * import contented from '@contentedjs/contented';
|
44 | 44 | * await contented.preview()
|
45 | 45 | */
|
46 | 46 | async preview({ watch = process.env.NODE_ENV === 'development' } = {}): Promise<void> {
|
47 |
| - if (watch) { |
48 |
| - await new WriteCommand().execute(); |
49 |
| - } else { |
50 |
| - await new GenerateCommand().execute(); |
51 |
| - } |
| 47 | + const command: BaseCommand = watch ? new WriteCommand() : new GenerateCommand(); |
| 48 | + command.context = Cli.defaultContext; |
| 49 | + await command.execute(); |
52 | 50 | },
|
53 | 51 | };
|
0 commit comments