Skip to content

Commit

Permalink
feat(core): add tty progress and compilation feature #OSP-163 (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Sep 17, 2021
1 parent 8dcb876 commit f635042
Show file tree
Hide file tree
Showing 39 changed files with 1,024 additions and 521 deletions.
4 changes: 3 additions & 1 deletion packages/cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { yargsOptionsGenerate } from './util/yargs-options-generate';
import { Option } from '@angular/cli/models/interface';
import { VERSION } from './version';
const ngBuildOptions: Option[] = JSON.parse(fs.readFileSync(path.resolve(__dirname, './ng-build-options.json')).toString());
export const buildCommand: CommandModule = {
command: ['build'],
Expand Down Expand Up @@ -36,7 +37,8 @@ export const buildCommand: CommandModule = {
const docgeni = new Docgeni({
watch: argv.watch,
config,
cmdArgs: normalizeCommandArgsForAngular(config, ngBuildOptions)
cmdArgs: normalizeCommandArgsForAngular(config, ngBuildOptions),
version: VERSION
});
await docgeni.run();
}
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { yargsOptionsGenerate } from './util/yargs-options-generate';
import { Option } from '@angular/cli/models/interface';
import { VERSION } from './version';

const ngServeOptions: Option[] = JSON.parse(fs.readFileSync(path.resolve(__dirname, './ng-serve-options.json')).toString());

Expand Down Expand Up @@ -33,7 +34,8 @@ export const serveCommand: CommandModule = {
const docgeni = new Docgeni({
watch: true,
config,
cmdArgs: normalizeCommandArgsForAngular(config, ngServeOptions)
cmdArgs: normalizeCommandArgsForAngular(config, ngServeOptions),
version: VERSION
});
await docgeni.run();
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@angular-devkit/core": "~11.2.14",
"@angular-devkit/schematics": "~11.2.14",
"@docgeni/toolkit": "^1.1.0-next.4",
"@types/text-table": "^0.2.2",
"chokidar": "^3.3.1",
"cosmiconfig": "^6.0.0",
"fancy-log": "^1.3.3",
Expand All @@ -42,6 +43,7 @@
"prismjs": "^1.20.0",
"semver": "7.3.2",
"tapable": "^1.1.3",
"text-table": "^0.2.0",
"through2": "^3.0.1",
"ts-morph": "^7.0.2",
"vinyl": "^2.2.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/builders/components-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DocgeniContext } from '../docgeni.interface';
import { DocgeniHost } from '../docgeni-host';
import { toolkit } from '@docgeni/toolkit';
import { normalize, relative, resolve, HostWatchEventType } from '../fs';
import { getSummaryStr } from '../utils';

export interface ComponentDef {
name: string;
Expand Down Expand Up @@ -69,11 +70,11 @@ export class ComponentsBuilder {
if (!this.docgeni.watch) {
return;
}
toolkit.print.info(`Components: start watching ${this.componentsSourcePath}`);
// toolkit.print.info(`Components: start watching ${this.componentsSourcePath}`);
return this.docgeni.host.watch(this.componentsSourcePath, { ignoreInitial: true, recursive: true }).subscribe(async item => {
try {
const type: HostWatchEventType = item.type as any;
toolkit.print.info(`Components: ${item.path}, type: ${HostWatchEventType[item.type]}`);
toolkit.print.info(`Components: ${getSummaryStr(item.path)}, type: ${HostWatchEventType[item.type]}`);
const { name, componentPath } = this.getComponentOfFile(item.path);
if (!name) {
return;
Expand Down
24 changes: 8 additions & 16 deletions packages/core/src/builders/doc-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
});

Expand All @@ -44,8 +43,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
expect(() => {
const name = docSourceFile.name;
Expand Down Expand Up @@ -84,8 +82,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
});

Expand Down Expand Up @@ -130,8 +127,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
await docSourceFile.build();
expect(docSourceFile.output).toContain(`<p>getting-started content</p>`);
Expand All @@ -152,8 +148,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
await docSourceFile.build();
await docSourceFile.emit('/dest/root');
Expand All @@ -175,8 +170,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
await docSourceFile.build();
await docSourceFile.emit('/dest/root');
Expand All @@ -198,8 +192,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
await docSourceFile.build();
await docSourceFile.emit('/dest/root');
Expand All @@ -221,8 +214,7 @@ describe('DocSourceFile', () => {
base: root,
locale: 'zh-cn'
},
docgeniHost,
undefined
docgeniHost
);
expect(docSourceFile.isEmpty()).toEqual(true);
await docSourceFile.build();
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/builders/doc-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DocType } from '../enums';
import { Markdown } from '../markdown';
import { normalize, relative } from '@angular-devkit/core';
import { DocgeniHost } from '../docgeni-host';
import { DocgeniConfig } from '../interfaces';

export interface DocSourceFileOptions {
cwd: string;
Expand All @@ -26,7 +25,7 @@ export class DocSourceFile<TMeta extends DocMeta = DocMeta> {
public type: DocType;
public content: string;
public meta?: TMeta;
public output: string;
public output: string = '';
/**
* @example "docs/guide/getting-started.md" when base is cwd and path=/../docs/guide/getting-started.md
*/
Expand Down Expand Up @@ -68,7 +67,7 @@ export class DocSourceFile<TMeta extends DocMeta = DocMeta> {
return path.basename(this.path, this.extname);
}

constructor(options: DocSourceFileOptions, host: DocgeniHost, private docConfig: DocgeniConfig) {
constructor(options: DocSourceFileOptions, host: DocgeniHost) {
this.cwd = options.cwd;
this.base = options.base;
this.path = options.path;
Expand All @@ -94,7 +93,7 @@ export class DocSourceFile<TMeta extends DocMeta = DocMeta> {

public async emit(destRootPath: string) {
if (this.emitted) {
return;
return {};
}
const outputPath = this.getOutputPath(destRootPath);
await this.host.writeFile(outputPath, this.output);
Expand All @@ -103,6 +102,7 @@ export class DocSourceFile<TMeta extends DocMeta = DocMeta> {
}
this.outputPath = outputPath;
this.emitted = true;
return { outputPath: outputPath, content: this.output };
}

public async clear() {
Expand Down

0 comments on commit f635042

Please sign in to comment.