Skip to content

Commit

Permalink
Update react prompt logic. Correct terminate process at the end. Fixe…
Browse files Browse the repository at this point in the history
…s issue #217.
  • Loading branch information
beth-panx committed Mar 30, 2017
1 parent bebbc10 commit 74f7a24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The Microsoft Office client application that can host the add-in. The supported
- Optional

### `framework`
Framework to use for the project. The supported arguments include JQuery (`jquery`), and Angular (`angular`). You can also use Manifest Only (`manifest-only`) which will create only the `manifest.xml` for an Office Add-in.
Framework to use for the project. The supported arguments include JQuery (`jquery`), Angular (`angular`), and React (`react`). You can also use Manifest Only (`manifest-only`) which will create only the `manifest.xml` for an Office Add-in.
- Type: String
- Optional

Expand All @@ -102,4 +102,6 @@ Specifying `--js` tells the generator to use JavaScript.
- Default: False
- Optional

>**Note:** Do not use this flag when you pass `react` as framework argument.
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
43 changes: 30 additions & 13 deletions src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import * as path from 'path';
import * as appInsights from 'applicationinsights';
import * as chalk from 'chalk';
import * as _ from 'lodash';

let opn = require('opn');
let uuid = require('uuid/v4');
let yosay = require('yosay');
let yo = require('yeoman-generator');
import * as opn from 'opn';
import * as uuid from 'uuid/v4';
import * as yosay from 'yosay';
import * as yo from 'yeoman-generator';
let insight = appInsights.getClient('68a8ef35-112c-4d33-a118-3c346947f2fe');

module.exports = yo.extend({
Expand Down Expand Up @@ -152,19 +151,20 @@ module.exports = yo.extend({
type: 'confirm',
message: 'Would you like to use TypeScript?',
default: true,
when: (this.options.js == null) && (!this.project.isManifestOnly)
when: (this.options.js == null) && (!this.project.isManifestOnly) && (this.options.framework !== 'react')
}
];
let answerForTs = await this.prompt(askForTs);
let endForTs = (new Date()).getTime();
let durationForTs = (endForTs - startForTs) / 1000;

this.project.ts = answerForTs.ts;
if (!(this.options.js == null)) {
this.project.ts = !this.options.js;
}
else {
this.project.ts = answerForTs.ts;
this.project.ts = answerForTs.ts || false;
}
if (this.options.framework === 'react') {
this.project.ts = true;
}

/** technology used to create the addin (html / angular / etc) */
Expand All @@ -176,15 +176,15 @@ module.exports = yo.extend({
type: 'list',
default: 'react',
choices: tsTemplates.map(template => ({ name: _.capitalize(template), value: template })),
when: (this.project.framework == null) && answerForTs.ts && !answerForManifestOnly.isManifestOnly
when: (this.project.framework == null) && this.project.ts && !this.options.js && !answerForManifestOnly.isManifestOnly
},
{
name: 'framework',
message: 'Choose a framework:',
type: 'list',
default: 'jquery',
choices: jsTemplates.map(template => ({ name: _.capitalize(template), value: template })),
when: (this.project.framework == null) && !answerForTs.ts && !answerForManifestOnly.isManifestOnly
when: (this.project.framework == null) && !this.project.ts && this.options.js && !answerForManifestOnly.isManifestOnly
}
];
let answerForFramework = await this.prompt(askForFramework);
Expand Down Expand Up @@ -269,7 +269,7 @@ module.exports = yo.extend({
}
else {
this.log('----------------------------------------------------------------------------------\n');
this.log(` Creating manifest for ${chalk.bold.green(this.project.projectDisplayName)} add-in`);
this.log(` Creating manifest for ${chalk.bold.green(this.project.projectDisplayName)} add-in\n`);
this.log('----------------------------------------------------------------------------------\n\n');
}

Expand Down Expand Up @@ -306,11 +306,23 @@ module.exports = yo.extend({
}
else {
if (this.project.framework !== 'manifest-only') {
this._postInstallHints();
this.installDependencies({
npm: false,
bower: false,
callback: this._postInstallHints.bind(this)
});
}
else {
this.installDependencies({
npm: false,
bower: false,
callback: this._exitProcess.bind(this)
});
}
}
} catch (err) {
insight.trackException(new Error('Installation Error: ' + err));
process.exitCode = 1;
}
},

Expand All @@ -322,6 +334,11 @@ module.exports = yo.extend({
this.log(` trust the Self-Signed Certificate for the site if you haven't done that)`);
this.log(` 2. Sideload the add-in into your Office application.\n`);
this.log('----------------------------------------------------------------------------------------------------------\n');
this._exitProcess();
},

_exitProcess: function () {
process.exit();
}
} as any);

Expand Down

0 comments on commit 74f7a24

Please sign in to comment.