Skip to content

Commit

Permalink
Update questions
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Apr 6, 2016
1 parent c770637 commit f36927e
Showing 1 changed file with 106 additions and 21 deletions.
127 changes: 106 additions & 21 deletions generators/beta/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const path = require('path');
const yeoman = require('yeoman-generator');
const inquirer = require('inquirer');
const chalk = require('chalk');
const yosay = require('yosay');
const changeCase = require('change-case');
Expand Down Expand Up @@ -29,24 +30,25 @@ module.exports = yeoman.Base.extend({
initializing: {
initProps() {
this.props = {
source: {}
source: {},
repository: {},
testing: {}
};
},
loadRepo() {
const repository = { init: true };
collectingLocalInfo.push(NodeGit.Repository.open(path.resolve('.')).then((repo) => {
const done = this.async();
Promise.all([repo.getRemote('origin').then((remote) => {
repository.url = remote.url();
})]).then(() => {
this.props.repository = repository;
this.repository = repo;
done();
});
}, () => {
repository.init = false;
this.props.repository = repository;
}));
collectingLocalInfo.push(
NodeGit.Repository.open(path.resolve('.')).then(
(repo) => {
this.repository = repo;
const repositoryPath = repo.path();
this.props.repository.name = path.basename(path.join(repositoryPath, '..'));
this.props.repository.organization = path.basename(path.join(repositoryPath, '..', '..'));
return repo.getRemote('origin')
.then(
(remote) => this.props.repsitory.url = remote.url(),
() => { });
},
() => { }));
}
},
prompting: {
Expand Down Expand Up @@ -251,14 +253,97 @@ module.exports = yeoman.Base.extend({
process.exit(1);
});
},
askTypingsHost() {
askTemplateInfo() {
let configTemplate = this.config.get('configTemplate');
if (!configTemplate) {
configTemplate = {
repository: {
namePrefix: 'typed-',
organization: 'typed-typings',
hosting: 'github'
},
license: {
type: 'MIT',
username: undefined,
fullName: undefined,
email: undefined,
homepage: undefined,
},
testing: {
node: 'blue-tape',
browser: 'blue-tape',
browserRunner: 'tape-run'
},
auth: {
username: undefined,
}
};

this.log('Seems like this is the first time you use this generator.');
this.log(`The default configuration will create the typings repository as follow:`);
}
else {
this.log('Using your config template, the typings repository will be created like this:');
}

this.props.repository.name = this.props.repository.name || configTemplate.repository.namePrefix + this.props.source.name;
this.props.repository.organization = this.props.repository.organization || configTemplate.repository.organization;
this.props.repository.url = this.props.repository.url || configTemplate.repository.hosting? `https://github.com/${this.props.repository.organization}/${this.props.repository.name}.git` : '';

this.props.license = configTemplate.license;

if (~this.props.source.platforms.indexOf('node')) {
this.props.testing.node = configTemplate.testing.node;
}

if (~this.props.source.platforms.indexOf('browser')) {
this.props.testing.browser = configTemplate.testing.browser;
this.props.testing.browserRunner = configTemplate.testing.browserRunner;
}

// print config;

this.prompt([
{
type: 'confirm',
name: 'noChange',
message: `Do you want to make any changes?`,
default: false
}
]);
if (this.repository) {
const done = this.async();
console.log('path', this.repository.path());
console.log('isEmpty()', this.repository.isEmpty() == true);
Promise.all([this.repository.getRemote('origin').then((remote) => {
console.log('getRemote()', remote.url());
})]).then(() => done());
this.log('I notice you have already created a git repository:');
this.prompt(
[
{
type: 'input',
name: 'name',
message: `Repository Name:`,
default: this.props.repository.name,
validate: (value) => value.length > 0
},
{
type: 'input',
name: 'author',
message: `Author or Organization:`,
default: this.props.repository.organization,
validate: (value) => value.length > 0
},
{
type: 'input',
name: 'remoteUrl',
message: `Remote Url:`,
default: this.props.repository.url,
validate: (value) => value.length > 0
},
],
(props) => {
this.props.repository.name = props.name;
this.props.repository.organization = props.organization,
this.props.repository.url = props.url;
done();
});
}
else {
console.log('no repository');
Expand Down

0 comments on commit f36927e

Please sign in to comment.