Skip to content

Commit a5882b2

Browse files
committed
#1 #3 #4 - Add vscode message during the process
1 parent 7ca8435 commit a5882b2

File tree

2 files changed

+49
-27
lines changed

2 files changed

+49
-27
lines changed

tooling/src/index.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import * as child from 'child_process';
33
import * as jsonforms from '@jsonforms/core';
44
import { writeFile, readFile } from 'fs';
55

6-
export function cloneAndInstall(repo: String, path: string) {
6+
/**
7+
export function cloneAndInstall(repo: String, path: string, callback: (result: string, type?: string) => void) {
78
var url = '';
89
switch(repo) {
910
case 'example':
@@ -14,32 +15,34 @@ export function cloneAndInstall(repo: String, path: string) {
1415
break;
1516
}
1617
const git = simplegit();
17-
console.log('Starting to clone repo');
18+
callback('Starting to clone repo');
1819
git.clone(url, path)
19-
.then(function() {
20-
console.log('Finished to clone repo');
21-
console.log('Running npm install');
22-
child.exec('cd /${path} && npm install', (error, stdout, stderr) => {
23-
if (error) {
24-
console.error(`exec error: ${error}`);
25-
return;
26-
}
27-
console.log(`stdout: ${stdout}`);
28-
console.log(`stderr: ${stderr}`);
29-
});
30-
})
31-
.catch((err: any) => console.error('failed: ', err));
20+
.then(function() {
21+
callback('Finished to clone repo');
22+
callback('Running npm install');
23+
child.exec(`cd /${path} | npm install`, (error, stdout, stderr) => {
24+
if (error) {
25+
callback(`exec error: ${error}`, 'err');
26+
return;
27+
}
28+
callback(`stdout: ${stdout}`);
29+
callback(`stderr: ${stderr}`, 'err');
30+
});
31+
})
32+
.catch((err: any) => {callback(err.message, 'err')});
3233
}
3334

34-
export function generateUISchema(path: string) {
35+
/**
36+
export function generateUISchema(path: string, callback: (result: string, type?: string) => void) {
3537
readFile(path, 'utf8', (err, data) => {
36-
if (err) throw err;
38+
if (err) callback(err.message, 'err');
3739
var content = JSON.parse(data);
3840
var jsonSchema = jsonforms.generateJsonSchema(content);
3941
var jsonUISchema = jsonforms.generateDefaultUISchema(jsonSchema);
4042
var newPath = removeLastPathElement(path);
4143
writeFile(newPath+'\\ui-schema.json', JSON.stringify(jsonUISchema,null, 2), (err) => {
42-
if (err) throw err;
44+
if (err) callback(err.message, 'err');
45+
callback('Successfully generated UI schema');
4346
});
4447
});
4548
}

vscode-extension/src/extension.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,40 @@ export function activate(context: vscode.ExtensionContext) {
1313
// The commandId parameter must match the command field in package.json
1414
let createExampleProject = vscode.commands.registerCommand('extension.createExampleProject', (args: any) => {
1515
if(!args) {
16-
vscode.window.showInformationMessage('You can only run this on a folder');
16+
showMessage('You can only run this on a folder', 'err');
1717
return;
1818
} else {
1919
let path = args.fsPath;
20-
vscode.window.showInformationMessage('Creating example project: '+path);
21-
tooling.cloneAndInstall('example', path);
20+
showMessage('Creating example project: '+path);
21+
tooling.cloneAndInstall('example', path, function(result: string, type: string) {
22+
showMessage(result, type);
23+
});
2224
}
2325
});
2426

2527
let createSeedProject = vscode.commands.registerCommand('extension.createSeedProject', (args: any) => {
2628
if(!args) {
27-
vscode.window.showInformationMessage('You can only run this on a folder');
29+
showMessage('You can only run this on a folder', 'err');
2830
return;
2931
} else {
3032
let path = args.fsPath;
31-
vscode.window.showInformationMessage('Creating seed project: '+path);
32-
tooling.cloneAndInstall('seed', path);
33+
showMessage('Creating seed project: '+path);
34+
tooling.cloneAndInstall('seed', path, function(result: string, type: string) {
35+
showMessage(result, type);
36+
});
3337
}
3438
});
3539

3640
let generateUISchema = vscode.commands.registerCommand('extension.generateUISchema', (args: any) => {
3741
if(!args) {
38-
vscode.window.showInformationMessage('You can only run this on a json file');
42+
showMessage('You can only run this on a json file', 'err');
3943
return;
4044
} else {
4145
let path = args.fsPath;
42-
vscode.window.showInformationMessage('Generating UI Schema: '+path);
43-
tooling.generateUISchema(path);
46+
showMessage('Generating UI Schema: '+path);
47+
tooling.generateUISchema(path, function(result: string, type: string) {
48+
showMessage(result, type);
49+
});
4450
}
4551
});
4652

@@ -49,6 +55,19 @@ export function activate(context: vscode.ExtensionContext) {
4955
context.subscriptions.push(generateUISchema);
5056
}
5157

58+
function showMessage(message: string, type?: string) {
59+
switch(type) {
60+
case 'err':
61+
vscode.window.showErrorMessage(message);
62+
break;
63+
case 'war':
64+
vscode.window.showWarningMessage(message);
65+
break;
66+
default:
67+
vscode.window.showInformationMessage(message);
68+
}
69+
}
70+
5271
// this method is called when your extension is deactivated
5372
export function deactivate() {
5473
}

0 commit comments

Comments
 (0)