Skip to content

Commit

Permalink
feat: do not include --dry-run calls to the recent command list
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Nov 3, 2018
1 parent f451d84 commit da62601
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
1 change: 0 additions & 1 deletion apps/angular-console/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.


/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export class SchematicComponent implements OnInit {

return this.serializer.normalizeSchematic(schematic);
}),
tap((schematic: Schematic|null) => {
if (! schematic) return;
tap((schematic: Schematic | null) => {
if (!schematic) return;
const uiFlags = (this.elementRef
.nativeElement as HTMLElement).querySelector('.ui-flags-container');

Expand Down
18 changes: 10 additions & 8 deletions server/src/api/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class Commands {
workspace: string,
command: string,
factory: any,
detailedStatusCalculator: DetailedStatusCalculator<any>
detailedStatusCalculator: DetailedStatusCalculator<any>,
addToRecent: boolean = true
) {
const item = {
id,
Expand All @@ -44,7 +45,9 @@ export class Commands {
commandRunning: null
};
this.insertIntoHistory(item);
this.insertIntoRecent(item);
if (addToRecent) {
this.insertIntoRecent(item);
}
}

restartCommand(id: string) {
Expand Down Expand Up @@ -82,15 +85,15 @@ export class Commands {
}

startCommand(id: string) {
const command = this.findMatchingCommand(id, this.recent);
const command = this.findMatchingCommand(id, this.history);
if (command) {
command.commandRunning = command.factory();
command.status = 'in-progress';
}
}

addOut(id: string, out: string) {
const c = this.findMatchingCommand(id, this.recent);
const c = this.findMatchingCommand(id, this.history);
if (c) {
c.out += out;
c.outChunk += out;
Expand All @@ -107,15 +110,15 @@ export class Commands {

// TOOD: vsavkin should convert status into an enum
setFinalStatus(id: string, status: string) {
const c = this.findMatchingCommand(id, this.recent);
const c = this.findMatchingCommand(id, this.history);
if (c && (c.status === 'in-progress' || c.status === 'waiting')) {
this.setStatus(id, status);
}
}

// TOOD: vsavkin should convert status into an enum
setStatus(id: string, status: string) {
const c = this.findMatchingCommand(id, this.recent);
const c = this.findMatchingCommand(id, this.history);
if (c) {
c.status = status;
try {
Expand Down Expand Up @@ -144,8 +147,7 @@ export class Commands {
}

findMatchingCommand(id: string, commands: CommandInformation[]) {
const matchingCommand = commands.find(c => c.id === id);
return matchingCommand;
return [...commands].reverse().find(c => c.id === id);
}

private insertIntoRecent(c: CommandInformation) {
Expand Down
14 changes: 12 additions & 2 deletions server/src/api/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createDetailedStatusCalculator } from './detailed-status-calculator';
import { normalizeCommands } from '../architect-utils';

// noinspection TsLint
// tslint:disable-next-line:no-var-requires
const spawn = require('node-pty-prebuilt').spawn;

let commandRunIndex = 0;
Expand All @@ -15,7 +16,8 @@ export function runCommand(
cwd: string,
programName: string,
program: string,
cmds: string[]
cmds: string[],
addToRecent: boolean = true
) {
const workspace =
type === 'new' ? null : readJsonFile('./package.json', cwd).json.name;
Expand All @@ -24,7 +26,15 @@ export function runCommand(
const factory = createExecutableCommand(id, cwd, program, cmds);
const statusCalculator = createDetailedStatusCalculator(cwd, cmds);

commands.addCommand(type, id, workspace, command, factory, statusCalculator);
commands.addCommand(
type,
id,
workspace,
command,
factory,
statusCalculator,
addToRecent
);
commands.startCommand(id);
return { id };
}
Expand Down
13 changes: 8 additions & 5 deletions server/src/schema/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const Database: DatabaseResolvers.Resolvers = {
commands(_root: any, args: any) {
try {
if (args.id) {
const c = commands.recent.find(c => c.id === args.id);
const c = commands.history.find(cc => cc.id === args.id);
if (!c) return [];
const r = serializeCommand(c);
c.outChunk = '';
Expand Down Expand Up @@ -269,11 +269,14 @@ const Mutation: MutationResolvers.Resolvers = {
async generate(_root: any, args: any) {
try {
const dryRun = args.dryRun ? ['--dry-run'] : [];
return runCommand('generate', args.path, 'ng', findClosestNg(args.path), [
return runCommand(
'generate',
...args.genCommand,
...dryRun
]);
args.path,
'ng',
findClosestNg(args.path),
['generate', ...args.genCommand, ...dryRun],
!args.dryRun
);
} catch (e) {
console.log(e);
throw new Error(
Expand Down
16 changes: 16 additions & 0 deletions server/test/api/commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ describe('Commands', () => {
expect(c.command).toEqual('command');
});

it('should not store the record in recent when addToRecent if false', () => {
const r = new Commands(1, 1);
r.addCommand(
'type',
'id',
'workspace',
'command',
() => {},
createStatusCalculator(),
false
);

expect(r.history[0]).toBeDefined();
expect(r.recent[0]).toBeUndefined();
});

it('should store the same record in history', () => {
const r = new Commands(1, 1);
r.addCommand(
Expand Down

0 comments on commit da62601

Please sign in to comment.