Skip to content

Commit 0d83022

Browse files
committed
Watch documents, readme, and CSS (TypeStrong#2675)
1 parent 4307dfd commit 0d83022

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/lib/application.ts

+19
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ export class Application extends AbstractComponent<
506506

507507
let successFinished = true;
508508
let currentProgram: ts.Program | undefined;
509+
let watches: ts.FileWatcher[] = []
509510

510511
const runSuccess = () => {
511512
if (!currentProgram) {
@@ -528,6 +529,24 @@ export class Application extends AbstractComponent<
528529
return;
529530
}
530531
const project = this.converter.convert(entryPoints);
532+
watches.forEach(w => w.close())
533+
watches = []
534+
const lastProgram = currentProgram;
535+
const addWatch = (path: string) => void watches.push(host.watchFile(path, () => {
536+
if (!currentProgram) {
537+
currentProgram = lastProgram
538+
if (successFinished) runSuccess()
539+
}
540+
}))
541+
for(const d of project.documents || []) {
542+
const path = project.files.getReflectionPath(d)
543+
if (path) addWatch(path)
544+
}
545+
const css = this.options.getValue("customCss")
546+
if (css) addWatch(css)
547+
const js = this.options.getValue("customJs")
548+
if (js) addWatch(js)
549+
if (project.readmeFile) addWatch(project.readmeFile)
531550
currentProgram = undefined;
532551
successFinished = false;
533552
void success(project).then(() => {

src/lib/converter/plugins/PackagePlugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export class PackagePlugin extends ConverterComponent {
135135
);
136136

137137
project.readme = content;
138+
project.readmeFile = this.readmeFile
138139

139140
// This isn't ideal, but seems better than figuring out the readme
140141
// path over in the include plugin...

src/lib/models/reflections/project.ts

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export class ProjectReflection extends ContainerReflection {
6868
*/
6969
readme?: CommentDisplayPart[];
7070

71+
/**
72+
* The path to the readme.md file, if found
73+
*/
74+
readmeFile?: string
75+
7176
/**
7277
* Object which describes where to find content for relative links.
7378
*/

0 commit comments

Comments
 (0)