Skip to content
This repository has been archived by the owner on Jun 17, 2019. It is now read-only.

Commit

Permalink
Adding support for Service Hooks generator (#15)
Browse files Browse the repository at this point in the history
* Update index.js

removing unnecessary process.chdir causes failure on macOS

* Update index.js

removing unnecessary process.chdir causes failure on macOS

* Update index.js

removing unnecessary process.chdir causes failure on macOS

* Update README.md

Adding debugging instructions

* Adding support for servicehook generator

* PR#15 comments
  • Loading branch information
hkamel authored and Willy-Peter Schaub committed May 21, 2017
1 parent b7106fe commit dcc33c2
Show file tree
Hide file tree
Showing 16 changed files with 636 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Yeoman generator",
"program": "${workspaceRoot}/node_modules/yo/lib/cli.js",
"args": [
"team-services-extension"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -12,6 +12,7 @@ The extension type can be :
- New hub extension
- Custom build or release task
- Widget dashboard
- Service hooks consumer

## Requirements

Expand Down
7 changes: 7 additions & 0 deletions generators/app/index.js
Expand Up @@ -55,6 +55,10 @@ function input() {
{
name: 'Widget dashboard',
value: 'widget'
},
{
name: 'Service hooks consumer',
value: 'servicehook'
}
],
when: function () {
Expand All @@ -78,6 +82,9 @@ function configGenerators() {
} else if (this.type === 'widget') {
this.composeWith('team-services-extension:widget');
}
else if(this.type =='servicehook'){
this.composeWith('team-services-extension:servicehook');
}

}

Expand Down
28 changes: 24 additions & 4 deletions generators/app/utility.js
Expand Up @@ -107,6 +107,27 @@ function setJsonTaskScript(scriptMode, taskname) {
return jsonproperty;
}

function setEventsText(eventsList) {
var jsonproperty = {
"id": "performAction",
"name": "PerformAction",
"description": "Posts a standard event payload",
"supportedEventTypes": [
],
"publishEvent": {
"url": "{{{url}}}",
"resourceDetailsToSend": "all",
"messagesToSend": "all",
"detailedMessagesToSend": "all"
}
}
var stringArray = new Array();
eventsList.forEach(function (entry) {
jsonproperty.supportedEventTypes.push(entry);
});
return JSON.stringify(jsonproperty);
}

module.exports = {

// Exports the portions of the file we want to share with files that require
Expand All @@ -123,9 +144,8 @@ module.exports = {
validateTaskFiendlyName: validateTaskFiendlyName,
validateTaskType: validateTaskType,
validateTaskVisibility: validateTaskVisibility,
validateTaskScripting :validateTaskScripting,
validateTaskScripting: validateTaskScripting,
getHubPoint: getHubPoint,
setJsonTaskScript: setJsonTaskScript


setJsonTaskScript: setJsonTaskScript,
setEventsText: setEventsText
};
258 changes: 258 additions & 0 deletions generators/servicehook/index.js
@@ -0,0 +1,258 @@
'use strict';
const path = require('path');
const util = require(`../app/utility`);
var generators = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var uuid = require('uuid');
var ejs = require('ejs');

function construct() {
// Calling the super constructor is important so our generator is correctly set up
generators.Base.apply(this, arguments);

this.argument('extName', { type: String, required: false, desc: 'Name of the extension' });
}

function input() {

// Collect any missing data from the user.
// This gives me access to the generator in the
// when callbacks of prompt
let cmdLnInput = this;

return this.prompt([
{
type: 'input',
name: 'extName',
store: true,
message: 'Please enter the (friendly) name of your extension:',
validate: util.validateExtensionName,
default: 'My Extension',
when: answers => {
return cmdLnInput.extName === undefined;
}
}, {
type: 'input',
name: 'extId',
store: true,
message: 'Please enter an ID of your extension:',
default: 'myextension',
validate: util.validateExtensionId,
when: answers => {
return cmdLnInput.extId === undefined;
}
}, {
type: 'input',
name: 'extDescription',
store: true,
message: 'Please enter a description of your extension:',
default: 'My extension makes hubs great again',
when: answers => {
return cmdLnInput.extDescription === undefined;
}
}, {
type: 'input',
name: 'publisherId',
store: true,
message: 'Please enter the name of your Marketplace publisher ID:',
default: 'fabrikam',
when: answers => {
return cmdLnInput.publisherId === undefined;
}
},

{
type: 'input',
name: 'connsumername',
message: 'Please enter the consumer name (Id) of your service hooks:',
store: true,
default: 'consumer',
validate: util.validateTaskName,
when: answers => {
return cmdLnInput.taskName === undefined;
}
}, {
type: 'input',
name: 'friendlyName',
message: 'Please enter the friendly (display) name of your consumer service:',
store: true,
default: 'My Task',
validate: util.validateTaskFiendlyName,
when: answers => {
return cmdLnInput.friendlyName === undefined;
}
}, {
type: 'input',
name: 'serviceDescription',
message: 'Please enter a description for your consumer service:',
store: true,
default: 'My Task makes tasks great again',
when: answers => {
return cmdLnInput.taskDescription === undefined;
}
},
{
type: 'checkbox',
name: 'events',
message: 'Please select the service hooks events:',
choices: ['Build completed', 'Release created', 'Release abandoned', 'Release deployment approval completed', 'Release deployment approval pending',
'Release deployment completed', 'Release deployment started', 'Code checked in', 'Code pushed', 'Pull request created', 'Pull request merge commit created',
'Pull request updated', 'Work item commented on', 'Work item created', 'Work item deleted', 'Work item restored', 'Work item updated'
],
store: true,
when: answers => {
return cmdLnInput.events === undefined;
}
},
{
type: 'confirm',
name: 'useVS',
store: true,
message: 'Do you intend to use Visual Studio ?',
when: answers => {
return cmdLnInput.useVS === undefined;
}
}]).then(function (a) {
// Transfer answers to local object for use in the rest of the generator
this.extName = util.reconcileValue(a.extName, cmdLnInput.extName);
this.extId = util.reconcileValue(a.extId, cmdLnInput.extId);
this.extDescription = util.reconcileValue(a.extDescription, cmdLnInput.extDescription);
this.publisherId = util.reconcileValue(a.publisherId, cmdLnInput.publisherId);
this.connsumername = util.reconcileValue(a.connsumername, cmdLnInput.connsumername);
this.friendlyName = util.reconcileValue(a.friendlyName, cmdLnInput.friendlyName);
this.events = util.reconcileValue(a.events, cmdLnInput.events);
this.serviceDescription = util.reconcileValue(a.serviceDescription, cmdLnInput.serviceDescription);
this.useVS = util.reconcileValue(a.useVS, cmdLnInput.useVS);
}.bind(this));
}


function writeFiles() {

var tokens = {
ExtensionName: this.extName,
PublisherId: this.publisherId,
Description: this.extDescription,
ExtensionID: this.extId,
connsumername: this.connsumername,
events: util.setEventsText(this.events).normalize(),
guid: uuid(),
taskDescription: this.taskDescription,
friendlyName: this.friendlyName
}

var src = this.sourceRoot();
var root = this.extId;
var extensionFolder = root + "/" + this.extId
if (!this.useVS) {
extensionFolder = root
}

this.fs.copy(
this.templatePath('static/**/*'),
this.destinationPath(extensionFolder + '/static/')
);

this.fs.copyTpl(
this.templatePath('vss-extension.json'),
this.destinationPath(extensionFolder + '/vss-extension.json'), tokens
);
this.fs.copyTpl(
this.templatePath('package.json'),
this.destinationPath(extensionFolder + '/package.json'),
tokens
);

this.fs.copyTpl(
this.templatePath('license.md'),
this.destinationPath(extensionFolder + '/license.md'), tokens
);

this.fs.copyTpl(
this.templatePath('overview.md'),
this.destinationPath(extensionFolder + '/overview.md'), tokens
);



this.fs.copyTpl(
this.templatePath('ThirdPartyNotices.txt'),
this.destinationPath(extensionFolder + '/ThirdPartyNotices.txt')
);

//Copy gitignore
this.fs.copyTpl(
this.templatePath('file.gitignore'),
this.destinationPath(this.extId + '/' + '.gitignore')
);

if (this.useVS) {
this.fs.copyTpl(
this.templatePath('extId.csproj'),
this.destinationPath(extensionFolder + '/' + this.extId + '.csproj'), tokens
);


this.fs.copyTpl(
this.templatePath('extId.sln'),
this.destinationPath(this.extId + '/' + this.extId + '.sln'), tokens
);

}
}

function install() {
var npmdir = process.cwd() + '/' + this.extId;
process.chdir(npmdir);
//console.log(JSON.stringify(this.taskScope));
this.installDependencies();
}


function install() {

var done = this.async();
var that = this;
var extensionFolder = this.extId + "/" + this.extId
if (!this.useVS) {
extensionFolder = this.extId
}

process.chdir(`${extensionFolder}`);
this.log(`+ Running npm install on ${extensionFolder}`);


this.log(`+ Running npm run package for vsix generating`);

this.spawnCommandSync('npm', ['run', 'package'], { stdio: ['pipe', 'pipe', process.stderr] });

done();
this.log(`Done`);
}



module.exports = generators.Base.extend({
// 1. Your initialization methods (checking current project state, getting configs, etc)
initializing: undefined,

// 2. Where you prompt users for options (where you'd call this.prompt())
prompting: input,

// 3. Saving configurations and configure the project (creating .editorconfig files and other metadata files)
configuring: undefined,

// 4. default - If the method name doesn't match a priority, it will be pushed to this group.

// 5. Where you write the generator specific files (routes, controllers, etc)
writing: writeFiles,

// 6. conflicts - Where conflicts are handled (used internally)

// 7. Where installation are run (npm, bower)
install: install,

// 8. Called last, cleanup, say good bye, etc
end: undefined
});

0 comments on commit dcc33c2

Please sign in to comment.