build: basic command wiki documentation tool

This commit is contained in:
Charles Lyding 2018-04-25 23:05:49 -07:00 committed by Filipe Silva
parent 24dc9b0943
commit f15af9f662
8 changed files with 6371 additions and 20 deletions

6156
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@
"scripts": {
"crazy2e": "echo This is crazy! Youre INSANE; npm run test:e2e -- --noproject ''; npm run test:e2e -- --nb-shards=4 --shard=0 --nobuild --nolink & npm run test:e2e -- --nb-shards=4 --shard=1 --nobuild --nolink & npm run test:e2e -- --nb-shards=4 --shard=2 --nobuild --nolink & npm run test:e2e -- --nb-shards=4 --shard=3 --nobuild --nolink & wait",
"build": "node scripts/run-tool.js publish build",
"docs": "node scripts/run-tool.js publish docs",
"test": "npm-run-all -c test:packages test:cli test:deps test:licenses test:messages",
"e2e": "npm run test:e2e",
"e2e:nightly": "node tests/run_e2e.js --nightly",
@ -57,6 +58,7 @@
},
"devDependencies": {
"@ngtools/json-schema": "^1.1.0",
"@angular-devkit/build-angular": "github:angular/angular-devkit-build-angular-builds",
"@types/common-tags": "^1.2.4",
"@types/express": "^4.0.32",
"@types/fs-extra": "^4.0.0",

View File

@ -221,7 +221,7 @@ export abstract class ArchitectCommand<T = any> extends Command<T> {
private _loadWorkspaceAndArchitect() {
const workspaceLoader = new WorkspaceLoader(this._host);
return workspaceLoader.loadWorkspace().pipe(
return workspaceLoader.loadWorkspace(this.project.root).pipe(
tap((workspace: experimental.workspace.Workspace) => this._workspace = workspace),
concatMap((workspace: experimental.workspace.Workspace) => {
return new Architect(workspace).loadArchitect();

View File

@ -314,7 +314,7 @@ export abstract class SchematicCommand extends Command {
const workspaceLoader = new WorkspaceLoader(this._host);
try {
workspaceLoader.loadWorkspace().pipe(take(1))
workspaceLoader.loadWorkspace(this.project.root).pipe(take(1))
.subscribe(
(workspace: experimental.workspace.Workspace) => this._workspace = workspace,
(err: Error) => {

View File

@ -30,8 +30,8 @@ export class WorkspaceLoader {
);
}
loadWorkspace(): Observable<experimental.workspace.Workspace | null> {
return this._getProjectWorkspaceFilePath().pipe(
loadWorkspace(projectPath?: string): Observable<experimental.workspace.Workspace | null> {
return this._getProjectWorkspaceFilePath(projectPath).pipe(
concatMap(globalWorkspacePath => this._loadWorkspaceFromPath(globalWorkspacePath))
);
}

View File

@ -0,0 +1,138 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"docs6": {
"root": "",
"sourceRoot": "/src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/docs6",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets"
}
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "docs6:build"
},
"configurations": {
"production": {
"browserTarget": "docs6:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "docs6:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"styles.css"
],
"scripts": [],
"assets": [
{
"glob": "favicon.ico",
"input": "src/",
"output": "/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets"
}
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"docs6-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "docs6:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "docs6"
}

View File

@ -0,0 +1,86 @@
import * as fs from 'fs';
import * as path from 'path';
import { logging, tags } from '@angular-devkit/core';
export default async function () {
const commandsPath = __dirname + '/../../../packages/@angular/cli/commands';
const commandFiles = fs.readdirSync(commandsPath);
for (const commandFile of commandFiles) {
const commandConstructor = require(path.join(commandsPath, commandFile)).default;
const command = new commandConstructor(
{ project: { root: path.join(__dirname, '../fake_root/') } },
new logging.NullLogger(),
);
if (command.hidden) {
continue;
}
try {
await command.initialize({});
} catch (e) {
console.log(`initialize failed [${commandFile}]: ` + e.toString());
}
let optionText;
if (!command.options) {
optionText = '';
} else {
optionText = (command.options as any[])
.filter(option => !option.hidden)
.map(option => {
let defaultText = '';
if (option.default) {
defaultText = `<em>default value: ${option.default}</em>`;
}
let aliasText = '';
if (option.aliases && option.aliases.length > 0) {
aliasText = (option.aliases as string[])
.map(alias => '<code>' + (alias.length === 1 ? '-' : '--') + alias + '</code>')
.join(',');
aliasText = ` (alias: ${aliasText})`;
}
return tags.stripIndent`
<details>
<summary>${option.name}</summary>
<p>
<code>--${option.name}</code>${aliasText} ${defaultText}
</p>
<p>
${option.description}
</p>
</details>
`;
}).join('\n');
}
const docFile = path.join(
__dirname,
'../../../docs/documentation/',
path.basename(commandFile, '.ts') + '.md');
let docText;
if (fs.existsSync(docFile)) {
docText = fs.readFileSync(docFile, 'utf8');
docText = docText.slice(0, docText.indexOf('## Options') + 10);
} else {
// tslint:disable:max-line-length
docText = tags.stripIndent`
<!-- Links in /docs/documentation should NOT have \`.md\` at the end, because they end up in our wiki at release. -->
# ng ${command.name}
## Overview
${command.description}
## Options
`;
// tslint:enable:max-line-length
}
const finalText = docText + '\n' + (optionText ? optionText : 'None.') + '\n';
fs.writeFileSync(docFile, finalText);
}
}

View File

@ -43,6 +43,7 @@ switch (command) {
case 'build-schema': commandFn = require('./build-schema').default; break;
case 'update-version': commandFn = require('./update-version').default; break;
case 'changelog': commandFn = require('./changelog').default; break;
case 'docs': commandFn = require('./generate-docs').default; break;
}
if (commandFn) {