Skip to content

Commit

Permalink
fix(nx): parse schema boolean properties as booleans for workspace-sc…
Browse files Browse the repository at this point in the history
…hematic

fix #1952
  • Loading branch information
ZachJW34 authored and vsavkin committed Oct 31, 2019
1 parent e563396 commit 99bc6df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions e2e/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ forEachCli(() => {
type: 'string',
description: 'lib directory'
};
json.properties['skipTsConfig'] = {
type: 'boolean',
description: 'skip changes to tsconfig'
};
updateFile(
`tools/schematics/${custom}/schema.json`,
JSON.stringify(json)
Expand All @@ -186,17 +190,18 @@ forEachCli(() => {
`tools/schematics/${custom}/index.ts`,
indexFile.replace(
'name: schema.name',
'name: schema.name, directory: schema.directory'
'name: schema.name, directory: schema.directory, skipTsConfig: schema.skipTsConfig'
)
);

const workspace = uniq('workspace');
const dryRunOutput = runCommand(
`npm run workspace-schematic ${custom} ${workspace} -- --no-interactive --directory=dir -d`
`npm run workspace-schematic ${custom} ${workspace} -- --no-interactive --directory=dir --skipTsConfig=true -d`
);
expect(exists(`libs/dir/${workspace}/src/index.ts`)).toEqual(false);
expect(dryRunOutput).toContain(`UPDATE ${workspaceConfigName()}`);
expect(dryRunOutput).toContain('UPDATE nx.json');
expect(dryRunOutput).not.toContain('UPDATE tsconfig.json');

const output = runCommand(
`npm run workspace-schematic ${custom} ${workspace} -- --no-interactive --directory=dir`
Expand Down
20 changes: 15 additions & 5 deletions packages/workspace/src/command-line/workspace-schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ import { copySync, removeSync } from 'fs-extra';
import * as inquirer from 'inquirer';
import * as path from 'path';
import * as yargsParser from 'yargs-parser';
import { fileExists } from '../utils/fileutils';
import { fileExists, readJsonFile } from '../utils/fileutils';
import { appRootPath } from '../utils/app-root';
import { output } from './output';
import { platform } from 'os';

const rootDirectory = appRootPath;

export function workspaceSchematic(args: string[]) {
const parsedArgs = parseOptions(args);
const outDir = compileTools();
const parsedArgs = parseOptions(args, outDir);
const logger = createConsoleLogger(
parsedArgs.verbose,
process.stdout,
process.stderr
);
const outDir = compileTools();
if (parsedArgs.listSchematics) {
return listSchematics(
path.join(outDir, 'workspace-schematics.json'),
Expand Down Expand Up @@ -334,9 +334,19 @@ async function executeSchematic(
}
}

function parseOptions(args: string[]): { [k: string]: any } {
function parseOptions(args: string[], outDir: string): { [k: string]: any } {
const schemaPath = path.join(outDir, args[0], 'schema.json');
let booleanProps = [];
if (fileExists(schemaPath)) {
const { properties } = readJsonFile(
path.join(outDir, args[0], 'schema.json')
);
booleanProps = Object.keys(properties).filter(
key => properties[key].type === 'boolean'
);
}
return yargsParser(args, {
boolean: ['dryRun', 'listSchematics', 'interactive'],
boolean: ['dryRun', 'listSchematics', 'interactive', ...booleanProps],
alias: {
dryRun: ['d'],
listSchematics: ['l']
Expand Down

0 comments on commit 99bc6df

Please sign in to comment.