style: run format (#28532)

PR Close #28532
This commit is contained in:
Greg Magolan 2019-02-05 11:49:49 -08:00 committed by Matias Niemelä
parent 7a6237bc50
commit 4142db0828
2 changed files with 62 additions and 62 deletions

View File

@ -8,12 +8,12 @@
* @fileoverview Schematics for ng-new project that builds with Bazel. * @fileoverview Schematics for ng-new project that builds with Bazel.
*/ */
import { SchematicContext, apply, applyTemplates, chain, mergeWith, move, Rule, schematic, Tree, url, SchematicsException, UpdateRecorder, } from '@angular-devkit/schematics'; import {SchematicContext, apply, applyTemplates, chain, mergeWith, move, Rule, schematic, Tree, url, SchematicsException, UpdateRecorder,} from '@angular-devkit/schematics';
import { parseJsonAst, JsonAstObject, strings, JsonValue } from '@angular-devkit/core'; import {parseJsonAst, JsonAstObject, strings, JsonValue} from '@angular-devkit/core';
import { findPropertyInAstObject, insertPropertyInAstObjectInOrder } from '@schematics/angular/utility/json-utils'; import {findPropertyInAstObject, insertPropertyInAstObjectInOrder} from '@schematics/angular/utility/json-utils';
import { validateProjectName } from '@schematics/angular/utility/validation'; import {validateProjectName} from '@schematics/angular/utility/validation';
import { getWorkspacePath } from '@schematics/angular/utility/config'; import {getWorkspacePath} from '@schematics/angular/utility/config';
import { Schema } from './schema'; import {Schema} from './schema';
/** /**
* Packages that build under Bazel require additional dev dependencies. This * Packages that build under Bazel require additional dev dependencies. This
@ -40,7 +40,7 @@ function addDevDependenciesToPackageJson(options: Schema) {
} }
const angularCoreVersion = angularCoreNode.value as string; const angularCoreVersion = angularCoreNode.value as string;
const devDependencies: { [ k: string ]: string } = { const devDependencies: {[k: string]: string} = {
'@angular/bazel': angularCoreVersion, '@angular/bazel': angularCoreVersion,
// TODO(kyliau): Consider moving this to latest-versions.ts // TODO(kyliau): Consider moving this to latest-versions.ts
'@bazel/bazel': '^0.22.1', '@bazel/bazel': '^0.22.1',
@ -51,7 +51,7 @@ function addDevDependenciesToPackageJson(options: Schema) {
const recorder = host.beginUpdate(packageJson); const recorder = host.beginUpdate(packageJson);
for (const packageName of Object.keys(devDependencies)) { for (const packageName of Object.keys(devDependencies)) {
const version = devDependencies[ packageName ]; const version = devDependencies[packageName];
const indent = 4; const indent = 4;
insertPropertyInAstObjectInOrder(recorder, devDeps, packageName, version, indent); insertPropertyInAstObjectInOrder(recorder, devDeps, packageName, version, indent);
} }
@ -103,23 +103,23 @@ function updateGitignore() {
} }
function replacePropertyInAstObject( function replacePropertyInAstObject(
recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue, recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue,
indent: number) { indent: number) {
const property = findPropertyInAstObject(node, propertyName); const property = findPropertyInAstObject(node, propertyName);
if (property === null) { if (property === null) {
throw new Error(`Property ${propertyName} does not exist in JSON object`); throw new Error(`Property ${propertyName} does not exist in JSON object`);
} }
const { start, text } = property; const {start, text} = property;
recorder.remove(start.offset, text.length); recorder.remove(start.offset, text.length);
const indentStr = '\n' + const indentStr = '\n' +
' '.repeat(indent); ' '.repeat(indent);
const content = JSON.stringify(value, null, ' ').replace(/\n/g, indentStr); const content = JSON.stringify(value, null, ' ').replace(/\n/g, indentStr);
recorder.insertLeft(start.offset, content); recorder.insertLeft(start.offset, content);
} }
function updateAngularJsonToUseBazelBuilder(options: Schema): Rule { function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
return (host: Tree, context: SchematicContext) => { return (host: Tree, context: SchematicContext) => {
const { name } = options; const {name} = options;
const workspacePath = getWorkspacePath(host); const workspacePath = getWorkspacePath(host);
if (!workspacePath) { if (!workspacePath) {
throw new Error('Could not find angular.json'); throw new Error('Could not find angular.json');
@ -137,61 +137,61 @@ function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
const recorder = host.beginUpdate(workspacePath); const recorder = host.beginUpdate(workspacePath);
const indent = 8; const indent = 8;
const architect = const architect =
findPropertyInAstObject(project as JsonAstObject, 'architect') as JsonAstObject; findPropertyInAstObject(project as JsonAstObject, 'architect') as JsonAstObject;
replacePropertyInAstObject( replacePropertyInAstObject(
recorder, architect, 'build', { recorder, architect, 'build', {
builder: '@angular/bazel:build', builder: '@angular/bazel:build',
options: { options: {
targetLabel: '//src:bundle.js', targetLabel: '//src:bundle.js',
bazelCommand: 'build', bazelCommand: 'build',
}, },
configurations: { configurations: {
production: { production: {
targetLabel: '//src:bundle', targetLabel: '//src:bundle',
},
}, },
}, },
}, indent);
indent);
replacePropertyInAstObject( replacePropertyInAstObject(
recorder, architect, 'serve', { recorder, architect, 'serve', {
builder: '@angular/bazel:build', builder: '@angular/bazel:build',
options: { options: {
targetLabel: '//src:devserver', targetLabel: '//src:devserver',
bazelCommand: 'run', bazelCommand: 'run',
}, },
configurations: { configurations: {
production: { production: {
targetLabel: '//src:prodserver', targetLabel: '//src:prodserver',
},
}, },
}, },
}, indent);
indent);
replacePropertyInAstObject( replacePropertyInAstObject(
recorder, architect, 'test', { recorder, architect, 'test', {
builder: '@angular/bazel:build', builder: '@angular/bazel:build',
options: { 'bazelCommand': 'test', 'targetLabel': '//src/...' }, options: {'bazelCommand': 'test', 'targetLabel': '//src/...'},
}, },
indent); indent);
const e2e = `${options.name}-e2e`; const e2e = `${options.name}-e2e`;
const e2eNode = findPropertyInAstObject(projects as JsonAstObject, e2e); const e2eNode = findPropertyInAstObject(projects as JsonAstObject, e2e);
if (e2eNode) { if (e2eNode) {
const architect = const architect =
findPropertyInAstObject(e2eNode as JsonAstObject, 'architect') as JsonAstObject; findPropertyInAstObject(e2eNode as JsonAstObject, 'architect') as JsonAstObject;
replacePropertyInAstObject( replacePropertyInAstObject(
recorder, architect, 'e2e', { recorder, architect, 'e2e', {
builder: '@angular/bazel:build', builder: '@angular/bazel:build',
options: { options: {
bazelCommand: 'test', bazelCommand: 'test',
targetLabel: '//e2e:devserver_test', targetLabel: '//e2e:devserver_test',
},
configurations: {
production: {
targetLabel: '//e2e:prodserver_test',
}, },
} configurations: {
}, production: {
indent); targetLabel: '//e2e:prodserver_test',
},
}
},
indent);
} }
host.commitUpdate(recorder); host.commitUpdate(recorder);
@ -210,13 +210,13 @@ function backupAngularJson(): Rule {
return; return;
} }
host.create( host.create(
`${workspacePath}.bak`, '// This is a backup file of the original angular.json. ' + `${workspacePath}.bak`, '// This is a backup file of the original angular.json. ' +
'This file is needed in case you want to revert to the workflow without Bazel.\n\n' + 'This file is needed in case you want to revert to the workflow without Bazel.\n\n' +
host.read(workspacePath)); host.read(workspacePath));
}; };
} }
export default function (options: Schema): Rule { export default function(options: Schema): Rule {
return (host: Tree) => { return (host: Tree) => {
validateProjectName(options.name); validateProjectName(options.name);

View File

@ -8,11 +8,11 @@
* @fileoverview Schematics for ng-new project that builds with Bazel. * @fileoverview Schematics for ng-new project that builds with Bazel.
*/ */
import { Rule, Tree, chain, externalSchematic, schematic } from '@angular-devkit/schematics'; import {Rule, Tree, chain, externalSchematic, schematic} from '@angular-devkit/schematics';
import { validateProjectName } from '@schematics/angular/utility/validation'; import {validateProjectName} from '@schematics/angular/utility/validation';
import { Schema } from './schema'; import {Schema} from './schema';
export default function (options: Schema): Rule { export default function(options: Schema): Rule {
return (host: Tree) => { return (host: Tree) => {
validateProjectName(options.name); validateProjectName(options.name);