Skip to content

Commit

Permalink
fix(vscode-ui): Correctly populate defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku committed Nov 21, 2019
1 parent ecbd0ee commit 7cb20e8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/vscode-ui/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export const MOCK_COMPONENT_ARCHITECT = {
type: 'enum',
description:
'The view encapsulation strategy to use in the new component.',
defaultValue: null,
defaultValue: 'ShadowDom',
required: false,
positional: false,
__typename: 'Schema',
Expand Down
3 changes: 2 additions & 1 deletion apps/vscode/src/app/select-schematic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Schematic } from '@angular-console/schema';
import { readAllSchematicCollections } from '@angular-console/server';
import { QuickPickItem, window } from 'vscode';
import { join } from 'path';

export function selectSchematic(workspacePath: string) {
interface GenerateQuickPickItem extends QuickPickItem {
Expand All @@ -10,7 +11,7 @@ export function selectSchematic(workspacePath: string) {

const schematics = readAllSchematicCollections(
workspacePath,
'tools/schematics', // TODO: Make these values auto detectable / configurable
join('tools', 'schematics'), // TODO: Make these values auto detectable / configurable
'workspace-schematic' // TODO: Make these values auto detectable / configurable
)
.map((c): GenerateQuickPickItem[] =>
Expand Down
32 changes: 21 additions & 11 deletions libs/server/src/lib/utils/read-schematic-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
readAndCacheJsonFile,
listOfUnnestedNpmPackages,
normalizeSchema,
listFiles
listFiles,
readAndParseJson
} from './utils';

export function readAllSchematicCollections(
Expand Down Expand Up @@ -37,15 +38,26 @@ export function readAllSchematicCollections(
}

function readAngularJsonDefaults(basedir: string): any {
const defaults = readAndCacheJsonFile('angular.json', basedir).json
.schematics;
const collectionDefaults = Object.keys(defaults ? defaults : {}).reduce(
const defaults =
readAndParseJson(path.join(basedir, 'angular.json')).schematics || {};
const collectionDefaults = Object.keys(defaults).reduce(
(collectionDefaultsMap: any, key) => {
const [collectionName, schematicName] = key.split(':');
if (!collectionDefaultsMap[collectionName]) {
collectionDefaultsMap[collectionName] = {};
if (key.includes(':')) {
const [collectionName, schematicName] = key.split(':');
if (!collectionDefaultsMap[collectionName]) {
collectionDefaultsMap[collectionName] = {};
}
collectionDefaultsMap[collectionName][schematicName] = defaults[key];
} else {
const collectionName = key;
if (!collectionDefaultsMap[collectionName]) {
collectionDefaultsMap[collectionName] = {};
}
Object.keys(defaults[collectionName]).forEach(schematicName => {
collectionDefaultsMap[collectionName][schematicName] =
defaults[collectionName][schematicName];
});
}
collectionDefaultsMap[collectionName][schematicName] = defaults[key];
return collectionDefaultsMap;
},
{}
Expand Down Expand Up @@ -93,13 +105,11 @@ function readWorkspaceSchematicsCollection(
const collectionName = '@nrwl/workspace';
if (fileExistsSync(path.join(collectionDir, 'collection.json'))) {
const collection = readAndCacheJsonFile('collection.json', collectionDir);
const defaults = readAngularJsonDefaults(basedir);

return readCollectionSchematics(
collectionName,
collection.path,
collection.json,
defaults
collection.json
);
} else {
const schematics = listFiles(collectionDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#selectControl
(change)="updateValue($event.target.value)"
role="combobox"
[value]="value"
[id]="field.name"
[required]="field.required"
[disabled]="disabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class TaskExecutionFormComponent implements OnInit, AfterViewChecked {
const defaultValues: { [key: string]: string } = {};
architect.schema.forEach(field => {
defaultValues[field.name] =
field.defaultValue || field.type === 'boolean' ? 'false' : '';
field.defaultValue || (field.type === 'boolean' ? 'false' : '');
});

if (architect.options) {
Expand Down

0 comments on commit 7cb20e8

Please sign in to comment.