From a4fcea902325bdb64731c30887e6c7de8c56370c Mon Sep 17 00:00:00 2001 From: Erik Lieben Date: Sun, 25 Sep 2016 20:32:34 +0200 Subject: [PATCH] feat(commands): add new, generate, test, and build commands --- dist/src/aureliaCLICommands.js | 86 +++++++++++++++++++++++++ dist/src/aureliaCLICommands.js.map | 1 + dist/src/extension.js | 3 + dist/src/extension.js.map | 2 +- package.json | 29 ++++++++- src/aureliaCLICommands.ts | 90 ++++++++++++++++++++++++++ src/extension.ts | 4 ++ test/aureliaCLICommands.test.ts | 65 +++++++++++++++++++ test/package.json.test.ts | 100 +++++++++++++++++++++++++++++ test/test-util.ts | 9 +++ 10 files changed, 386 insertions(+), 3 deletions(-) create mode 100644 dist/src/aureliaCLICommands.js create mode 100644 dist/src/aureliaCLICommands.js.map create mode 100644 src/aureliaCLICommands.ts create mode 100644 test/aureliaCLICommands.test.ts create mode 100644 test/package.json.test.ts create mode 100644 test/test-util.ts diff --git a/dist/src/aureliaCLICommands.js b/dist/src/aureliaCLICommands.js new file mode 100644 index 00000000..9bab273a --- /dev/null +++ b/dist/src/aureliaCLICommands.js @@ -0,0 +1,86 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +const vscode = require('vscode'); +const cp = require('child_process'); +const path = require('path'); +const fs = require('fs'); +const run_in_terminal_1 = require('run-in-terminal'); +class AureliaCliCommands { + static registerCommands(outputChannel) { + 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))); + } + static auNew(outputChannel) { + return __awaiter(this, void 0, void 0, function* () { + let projectName = yield vscode.window.showInputBox({ placeHolder: 'Please enter a name for your new project' }); + this.runCommand(['new', projectName], outputChannel, true); + }); + } + static auGenerate(outputChannel) { + return __awaiter(this, void 0, void 0, function* () { + let param = ['generate']; + let type = yield vscode.window.showQuickPick(this.getGeneratorTypes(), { matchOnDescription: false, placeHolder: 'Select type' }); + param.push(type); + let name = yield vscode.window.showInputBox({ placeHolder: `What would you like to call the ${type}?` }); + param.push(name); + this.runCommand(param, outputChannel, false); + }); + } + static auBuild(outputChannel) { + return __awaiter(this, void 0, void 0, function* () { + let param = ['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); + }); + }); + } + 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; + } + static showOutput(outputChannel) { + outputChannel.show(vscode.ViewColumn.One); + } + static runCommand(args, outputChannel, useTerminal) { + let cwd = vscode.workspace.rootPath; + if (useTerminal) { + this.runCommandInTerminal(args, cwd); + } + else { + this.runCommandInOutputWindow(args, cwd, outputChannel); + } + } + static runCommandInOutputWindow(args, cwd, outputChannel) { + let cmd = 'au ' + args.join(' '); + let childProcess = cp.exec(cmd, { cwd: cwd, env: process.env }); + childProcess.stderr.on('data', data => outputChannel.append(data)); + childProcess.stdout.on('data', data => outputChannel.append(data)); + this.showOutput(outputChannel); + } + static runCommandInTerminal(args, cwd) { + run_in_terminal_1.runInTerminal('au', args, { cwd: cwd, env: process.env }); + } +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = AureliaCliCommands; +//# sourceMappingURL=aureliaCLICommands.js.map \ No newline at end of file diff --git a/dist/src/aureliaCLICommands.js.map b/dist/src/aureliaCLICommands.js.map new file mode 100644 index 00000000..190894fb --- /dev/null +++ b/dist/src/aureliaCLICommands.js.map @@ -0,0 +1 @@ +{"version":3,"file":"aureliaCLICommands.js","sourceRoot":"","sources":["../../src/aureliaCLICommands.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAY,MAAM,WAAM,QAAQ,CAAC,CAAA;AACjC,MAAY,EAAE,WAAM,eAAe,CAAC,CAAA;AACpC,MAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAC7B,MAAY,EAAE,WAAM,IAAI,CAAC,CAAA;AACzB,kCAA8B,iBAAiB,CAAC,CAAA;AAEhD;IAEE,OAAc,gBAAgB,CAAC,aAAmC;QAChE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAC3B,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,iBAAiB,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,EACnF,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,sBAAsB,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,EAC7F,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,kBAAkB,EAAE,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,EAC1G,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED,OAAqB,KAAK,CAAC,aAAa;;YACtC,IA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/extension.js +++ b/dist/src/extension.js @@ -1,10 +1,13 @@ "use strict"; const vscode_1 = require('vscode'); +const aureliaCliCommands_1 = require('./aureliaCliCommands'); let outputChannel; function activate(context) { // Create default output channel outputChannel = vscode_1.window.createOutputChannel('aurelia'); context.subscriptions.push(outputChannel); + // Register CLI commands + context.subscriptions.push(aureliaCliCommands_1.default.registerCommands(outputChannel)); } exports.activate = activate; //# sourceMappingURL=extension.js.map \ No newline at end of file diff --git a/dist/src/extension.js.map b/dist/src/extension.js.map index bfd38020..b5a3d3ab 100644 --- a/dist/src/extension.js.map +++ b/dist/src/extension.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":";AAAA,yBAAwD,QAAQ,CAAC,CAAA;AAEjE,IAAI,aAA4B,CAAC;AAEjC,kBAAyB,OAAyB;IAEhD,gCAAgC;IAChC,aAAa,GAAG,eAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC;AALe,gBAAQ,WAKvB,CAAA"} \ No newline at end of file +{"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":";AAAA,yBAAwD,QAAQ,CAAC,CAAA;AACjE,qCAA+B,sBAAsB,CAAC,CAAA;AAEtD,IAAI,aAA4B,CAAC;AAEjC,kBAAyB,OAAyB;IAEhD,gCAAgC;IAChC,aAAa,GAAG,eAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAE1C,wBAAwB;IACxB,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,4BAAkB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC;AACjF,CAAC;AARe,gBAAQ,WAQvB,CAAA"} \ No newline at end of file diff --git a/package.json b/package.json index c2c9f850..50451b91 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,33 @@ "categories": [ "Other" ], - "activationEvents": [], + "activationEvents": [ + "onCommand:extension.auNew", + "onCommand:extension.auGenerate", + "onCommand:extension.auTest", + "onCommand:extension.auBuild" + ], "main": "./dist/src/extension", - "contributes": {}, + "contributes": { + "commands": [ + { + "command": "extension.auNew", + "title": "au new" + }, + { + "command": "extension.auGenerate", + "title": "au generate" + }, + { + "command": "extension.auBuild", + "title": "au build" + }, + { + "command": "extension.auTest", + "title": "au test" + } + ] + }, "scripts": { "vscode:prepublish": "node ./node_modules/vscode/bin/compile", "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", @@ -42,5 +66,6 @@ "vscode": "^0.11.18" }, "dependencies": { + "run-in-terminal": "0.0.3" } } diff --git a/src/aureliaCLICommands.ts b/src/aureliaCLICommands.ts new file mode 100644 index 00000000..c271033e --- /dev/null +++ b/src/aureliaCLICommands.ts @@ -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( data)); + childProcess.stdout.on('data', data => outputChannel.append( data)); + + this.showOutput(outputChannel); + } + + private static runCommandInTerminal(args: string[], cwd: string): void { + runInTerminal('au', args, { cwd: cwd, env: process.env }); + } +} diff --git a/src/extension.ts b/src/extension.ts index 184a848c..854d2d79 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,5 @@ import { ExtensionContext, OutputChannel, window } from 'vscode'; +import AureliaCliCommands from './aureliaCliCommands'; let outputChannel: OutputChannel; @@ -7,4 +8,7 @@ export function activate(context: ExtensionContext) { // Create default output channel outputChannel = window.createOutputChannel('aurelia'); context.subscriptions.push(outputChannel); + + // Register CLI commands + context.subscriptions.push(AureliaCliCommands.registerCommands(outputChannel)); } diff --git a/test/aureliaCLICommands.test.ts b/test/aureliaCLICommands.test.ts new file mode 100644 index 00000000..d1d46577 --- /dev/null +++ b/test/aureliaCLICommands.test.ts @@ -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); + }); + }); +}); diff --git a/test/package.json.test.ts b/test/package.json.test.ts new file mode 100644 index 00000000..f00a49fb --- /dev/null +++ b/test/package.json.test.ts @@ -0,0 +1,100 @@ +import * as assert from 'assert'; + +suite('The package.json', () => { + + test('must contain an activation events onCommand au new', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.activationEvents.filter( + evt => evt === 'onCommand:extension.auNew'); + + // assert + assert.equal(results.length, 1); + }); + + test('must contain an activation events onCommand au generate', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.activationEvents.filter( + evt => evt === 'onCommand:extension.auGenerate'); + + // assert + assert.equal(results.length, 1); + }); + + test('must contain an activation events onCommand au test', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.activationEvents.filter( + evt => evt === 'onCommand:extension.auTest'); + + // assert + assert.equal(results.length, 1); + }); + + test('must contain an activation events onCommand au build', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.activationEvents.filter( + evt => evt === 'onCommand:extension.auBuild'); + + // assert + assert.equal(results.length, 1); + }); + + test('must contain an contribution command for au new', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.contributes.commands.filter( + cmd => cmd.command === 'extension.auNew'); + + // assert + assert.equal(results.length, 1); + }); + + test('must contain an contribution command for au generate', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.contributes.commands.filter( + cmd => cmd.command === 'extension.auGenerate'); + + // assert + assert.equal(results.length, 1); + }); + + test('must contain an contribution command for au test', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.contributes.commands.filter( + cmd => cmd.command === 'extension.auTest'); + + // assert + assert.equal(results.length, 1); + }); + + test('must contain an contribution command for au build', () => { + // arrange + let packageConfig = require('./../../package.json'); + + // act + let results = packageConfig.contributes.commands.filter( + cmd => cmd.command === 'extension.auBuild'); + + // assert + assert.equal(results.length, 1); + }); +}); diff --git a/test/test-util.ts b/test/test-util.ts new file mode 100644 index 00000000..fb63c229 --- /dev/null +++ b/test/test-util.ts @@ -0,0 +1,9 @@ +import { Disposable } from 'vscode'; + +export default function using(resource: T, func: (resource: T) => void) { + try { + func(resource); + } finally { + resource.dispose(); + } +}