Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

Commit 3dbae3f

Browse files
authored
fix(contented): programmatic execution (#795)
#### What this PR does / why we need it: As per title.
1 parent 273d033 commit 3dbae3f

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

packages/contented/src/cli.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { runExit } from 'clipanion';
33

44
import { BuildCommand } from './commands/BuildCommand.js';
55
import { GenerateCommand } from './commands/GenerateCommand.js';
6-
import { WatchCommand } from './commands/WatchCommand.js';
76
import { WriteCommand } from './commands/WriteCommand.js';
87

98
// eslint-disable-next-line @typescript-eslint/no-floating-promises
10-
runExit([BuildCommand, GenerateCommand, WatchCommand, WriteCommand]);
9+
runExit([BuildCommand, GenerateCommand, WriteCommand]);

packages/contented/src/commands/WatchCommand.ts

-20
This file was deleted.

packages/contented/src/index.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as process from 'node:process';
22

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

6+
import { BaseCommand } from './commands/BaseCommand';
57
import { BuildCommand } from './commands/BuildCommand.js';
68
import { GenerateCommand } from './commands/GenerateCommand.js';
7-
import { WatchCommand } from './commands/WatchCommand.js';
89
import { WriteCommand } from './commands/WriteCommand.js';
910

1011
export * from '@contentedjs/contented-processor';
@@ -33,21 +34,18 @@ export default {
3334
* await contented.build()
3435
*/
3536
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();
4141
},
4242
/**
4343
* import contented from '@contentedjs/contented';
4444
* await contented.preview()
4545
*/
4646
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();
5250
},
5351
};

0 commit comments

Comments
 (0)