-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commands): add new, generate, test, and build commands
- Loading branch information
1 parent
28b0a8f
commit a4fcea9
Showing
10 changed files
with
386 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import * as vscode from 'vscode'; | ||
import * as cp from 'child_process'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import { runInTerminal } from 'run-in-terminal'; | ||
|
||
export default class AureliaCliCommands { | ||
|
||
public static registerCommands(outputChannel: vscode.OutputChannel): vscode.Disposable { | ||
return vscode.Disposable.from( | ||
vscode.commands.registerCommand('extension.auNew', () => this.auNew(outputChannel)), | ||
vscode.commands.registerCommand('extension.auGenerate', () => this.auGenerate(outputChannel)), | ||
vscode.commands.registerCommand('extension.auTest', () => this.runCommand(['test'], outputChannel, false)), | ||
vscode.commands.registerCommand('extension.auBuild', () => this.auBuild(outputChannel))); | ||
} | ||
|
||
private static async auNew(outputChannel) { | ||
let projectName = await vscode.window.showInputBox({ placeHolder: 'Please enter a name for your new project' }); | ||
this.runCommand(['new', projectName], outputChannel, true); | ||
} | ||
|
||
private static async auGenerate(outputChannel) { | ||
|
||
let param: string[] = ['generate']; | ||
let type = await vscode.window.showQuickPick( | ||
this.getGeneratorTypes(), | ||
{ matchOnDescription: false, placeHolder: 'Select type' }); | ||
param.push(type); | ||
|
||
let name = await vscode.window.showInputBox({ placeHolder: `What would you like to call the ${type}?` }); | ||
param.push(name); | ||
|
||
this.runCommand(param, outputChannel, false); | ||
} | ||
|
||
private static async auBuild(outputChannel) { | ||
let param: string[] = ['build']; | ||
let auTemplatePath = path.join(vscode.workspace.rootPath, 'aurelia_project/environments'); | ||
let items = []; | ||
|
||
fs.readdirSync(auTemplatePath).forEach((name) => { | ||
if (path.extname(name) === '.ts' || path.extname(name) === '.js') { | ||
items.push(path.basename(name.replace('.ts', '').replace('.js', ''))); | ||
} | ||
}); | ||
|
||
let options = { matchOnDescription: false, placeHolder: 'Select environment to build' }; | ||
vscode.window.showQuickPick(items, options).then((data) => { | ||
param.push('--env ' + data); | ||
this.runCommand(param, outputChannel, false); | ||
}); | ||
} | ||
|
||
private static getGeneratorTypes() { | ||
let items = []; | ||
fs.readdirSync(path.join(vscode.workspace.rootPath, 'aurelia_project/generators')).forEach(name => { | ||
if (path.extname(name) === '.ts' || path.extname(name) === '.js') { | ||
items.push(path.basename(name.replace('.ts', '').replace('.js', ''))); | ||
} | ||
}); | ||
return items; | ||
} | ||
|
||
private static showOutput(outputChannel: vscode.OutputChannel): void { | ||
outputChannel.show(vscode.ViewColumn.One); | ||
} | ||
|
||
private static runCommand(args: string[], outputChannel: vscode.OutputChannel, useTerminal?: boolean): void { | ||
let cwd = vscode.workspace.rootPath; | ||
if (useTerminal) { | ||
this.runCommandInTerminal(args, cwd); | ||
} else { | ||
this.runCommandInOutputWindow(args, cwd, outputChannel); | ||
} | ||
} | ||
|
||
private static runCommandInOutputWindow(args: string[], cwd: string, outputChannel: vscode.OutputChannel) { | ||
|
||
let cmd = 'au ' + args.join(' '); | ||
let childProcess = cp.exec(cmd, { cwd: cwd, env: process.env }); | ||
childProcess.stderr.on('data', data => outputChannel.append(<string> data)); | ||
childProcess.stdout.on('data', data => outputChannel.append(<string> data)); | ||
|
||
this.showOutput(outputChannel); | ||
} | ||
|
||
private static runCommandInTerminal(args: string[], cwd: string): void { | ||
runInTerminal('au', args, { cwd: cwd, env: process.env }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as assert from 'assert'; | ||
import using from './test-util'; | ||
import { commands } from 'vscode'; | ||
import AureliaCliCommands from '../src/aureliaCLICommands'; | ||
|
||
let sut = AureliaCliCommands; | ||
|
||
suite('The Aurelia CLI Commands', () => { | ||
|
||
test('must register command au new', () => { | ||
|
||
// arrange | ||
let outputChannel = undefined; | ||
|
||
// act | ||
using(sut.registerCommands(outputChannel), async () => { | ||
|
||
// assert | ||
let result = (await commands.getCommands(true)).filter(x => x === 'extension.auNew'); | ||
assert.equal(result.length, 1); | ||
}); | ||
}); | ||
|
||
test('must register command au generate', () => { | ||
|
||
// arrange | ||
let outputChannel = undefined; | ||
|
||
// act | ||
using(sut.registerCommands(outputChannel), async () => { | ||
|
||
// assert | ||
let result = (await commands.getCommands(true)).filter(x => x === 'extension.auGenerate'); | ||
assert.equal(result.length, 1); | ||
}); | ||
}); | ||
|
||
test('must register command au test', () => { | ||
|
||
// arrange | ||
let outputChannel = undefined; | ||
|
||
// act | ||
using(sut.registerCommands(outputChannel), async () => { | ||
|
||
// assert | ||
let result = (await commands.getCommands(true)).filter(x => x === 'extension.auTest'); | ||
assert.equal(result.length, 1); | ||
}); | ||
}); | ||
|
||
test('must register command au build', () => { | ||
|
||
// arrange | ||
let outputChannel = undefined; | ||
|
||
// act | ||
using(sut.registerCommands(outputChannel), async () => { | ||
|
||
// assert | ||
let result = (await commands.getCommands(true)).filter(x => x === 'extension.auBuild'); | ||
assert.equal(result.length, 1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.