Skip to content

Commit

Permalink
Fix undefined args issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZoker committed Mar 6, 2019
1 parent ac7f322 commit e9528c3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
11 changes: 5 additions & 6 deletions generator-jsonforms/src/generators/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// tslint:disable:no-var-requires
// tslint:disable:no-require-imports
'use strict';

import * as Generator from 'yeoman-generator';
import chalk from 'chalk';
const clear = require('clear');
const figlet = require('figlet');
const validate = require('validate-npm-package-name');
import { textSync } from 'figlet';
import { join, sep } from 'path';
import { readFile, writeFile } from 'fs';
const clear = require('clear');
const validate = require('validate-npm-package-name');

enum ProjectRepo {
Example = 'make-it-happen-react',
Expand Down Expand Up @@ -55,7 +54,7 @@ export class JsonformsGenerator extends Generator {
clear();
this.log(
chalk.blue(
figlet.textSync('JSONForms Tooling', { horizontalLayout: 'full' }),
textSync('JSONForms Tooling', { horizontalLayout: 'full' }),
),
);
if (!this.skipPrompting) {
Expand Down Expand Up @@ -143,7 +142,7 @@ export class JsonformsGenerator extends Generator {
const packagePath = this.path + sep + 'package.json';
readFile(packagePath, 'utf8', (readError, data) => {

if ((readError != null) && readError.message) {
if ((readError !== null) && readError.message) {
this.log(chalk.red(readError.message));
return;
}
Expand Down
24 changes: 14 additions & 10 deletions jsonforms-tooling-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// tslint:disable:no-require-imports
// tslint:disable:no-use-before-declare

import * as jsonforms from '@jsonforms/core';
import { generateDefaultUISchema } from '@jsonforms/core';
import { readFile, writeFile } from 'fs';
import * as Ajv from 'ajv';
import { sep } from 'path';
Expand Down Expand Up @@ -75,18 +75,22 @@ export const generateUISchema = (editorInstance: any, path: string) => {
const asyncGenerateUiSchema = (editorInstance: any, path: string) => {
editorInstance.window.showInputBox(editorInstance.InputBoxOptions = {
prompt: 'Label: ',
placeHolder: 'Enter a filename for your UI Schema (default: ui-schema.json)',
placeHolder: 'Enter a filename for your UI Schema (default: uischema.json)',
}).then((name: string) => {
let fileName = name;
if (!fileName) {
fileName = 'ui-schema.json';
if (fileName === undefined) {
showMessage(editorInstance, 'UI schema generation canceled', 'err');
return;
}
if (fileName === '') {
fileName = 'uischema.json';
}
showMessage(editorInstance, `Generating UI Schema: ${path}`);
// Read JSON Schema file
readFile(path, 'utf8', (readError, data) => {
if (readError.message) {
showMessage(editorInstance, readError.message, 'err');
return;
if ((readError !== null) && readError.message) {
showMessage(editorInstance, readError.message, 'err');
return;
}

const jsonSchema = JSON.parse(data);
Expand All @@ -96,15 +100,15 @@ const asyncGenerateUiSchema = (editorInstance: any, path: string) => {
return;
}

const jsonUISchema = jsonforms.generateDefaultUISchema(jsonSchema);
const jsonUISchema = generateDefaultUISchema(jsonSchema);

// Check if windows or linux filesystem
let newPath = path.substring(0, path.lastIndexOf(sep));
newPath = newPath + sep + name;
newPath = newPath + sep + fileName;

// Write UI Schema file
writeFile(newPath, JSON.stringify(jsonUISchema, null, 2), writeError => {
if (writeError.message) {
if ((writeError !== null) && writeError.message) {
showMessage(editorInstance, writeError.message, 'err');
return;
}
Expand Down
9 changes: 9 additions & 0 deletions theia-plugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const start = (context: theia.PluginContext) => {
createExampleProjectCommandOptions,
(args: any) => {
if (!args) {
if (args === undefined) {
args = {fsPath: null};
}
createProject(theia, args.fsPath, Project.Example);
}
}
Expand All @@ -22,6 +25,9 @@ export const start = (context: theia.PluginContext) => {
const createSeedProjectCommand = theia.commands.registerCommand(
createSeedProjectCommandOptions,
(args: any) => {
if (args === undefined) {
args = {fsPath: null};
}
createProject(theia, args.fsPath, Project.Seed);
}
);
Expand All @@ -33,6 +39,9 @@ export const start = (context: theia.PluginContext) => {
const generateUISchemaCommand = theia.commands.registerCommand(
generateUISchemaCommandOptions,
(args: any) => {
if (args === undefined) {
args = {fsPath: null};
}
generateUISchema(theia, args.fsPath);
}
);
Expand Down
9 changes: 9 additions & 0 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ export const activate = (context: vscode.ExtensionContext) => {
const createExampleProjectCommand = vscode.commands.registerCommand(
'extension.createExampleProject',
(args: any) => {
if (args === undefined) {
args = {fsPath: null};
}
createProject(vscode, args.fsPath, Project.Example);
}
);

const createSeedProjectCommand = vscode.commands.registerCommand(
'extension.createSeedProject',
(args: any) => {
if (args === undefined) {
args = {fsPath: null};
}
createProject(vscode, args.fsPath, Project.Seed);
}
);

const generateUISchemaCommand = vscode.commands.registerCommand(
'extension.generateUISchema',
(args: any) => {
if (args === undefined) {
args = {fsPath: null};
}
generateUISchema(vscode, args.fsPath);
});

Expand Down

0 comments on commit e9528c3

Please sign in to comment.