Skip to content

Commit

Permalink
Merge pull request electrodejs#49 from donsalari/create-directory
Browse files Browse the repository at this point in the history
create new directory for app, generateInto clean up
  • Loading branch information
caoyangs authored Nov 2, 2016
2 parents 41bab19 + 23d3132 commit 77585da
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
44 changes: 31 additions & 13 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ module.exports = generators.Base.extend({
constructor: function () {
generators.Base.apply(this, arguments);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
});

this.option('travis', {
type: Boolean,
required: false,
Expand Down Expand Up @@ -103,53 +96,71 @@ module.exports = generators.Base.extend({

var prompts = [
{
type: "input",
name: 'name',
message: 'Application Name',
when: !this.props.name,
default: path.basename(process.cwd())
},
{
type: "input",
name: 'description',
message: 'Description',
when: !this.props.description
},
{
type: "input",
name: 'homepage',
message: 'Project homepage url',
when: !this.props.homepage
},
{
type: "input",
name: 'authorName',
message: 'Author\'s Name',
when: !this.props.authorName,
default: this.user.git.name(),
store: true
},
{
type: "input",
name: 'authorEmail',
message: 'Author\'s Email',
when: !this.props.authorEmail,
default: this.user.git.email(),
store: true
},
{
type: "input",
name: 'authorUrl',
message: 'Author\'s Homepage',
when: !this.props.authorUrl,
store: true
},
{
type: "input",
name: 'keywords',
message: 'Package keywords (comma to split)',
when: _.isEmpty(this.pkg.keywords),
filter: function (words) {
return words.split(/\s*,\s*/g).filter((x) => x);
}
},
{
type: "confirm",
name: "createDirectory",
message: "Would you like to create a new directory for your project?",
default: true
}
];

return this.prompt(prompts).then((props) => {
this.props = extend(this.props, props);

if (this.props.createDirectory) {
var newRoot = this.destinationPath() + '/' + _.kebabCase(_.deburr(this.props.name));
this.destinationRoot(newRoot);
}
});
},

Expand Down Expand Up @@ -217,13 +228,13 @@ module.exports = generators.Base.extend({

this.fs.copy(
this.templatePath('babelrc'),
this.destinationPath(this.options.generateInto, '.babelrc')
this.destinationPath('.babelrc')
);

['gulpfile.js', 'client', 'config', 'server', 'test'].forEach((f) => {
this.fs.copy(
this.templatePath(f),
this.destinationPath(this.options.generateInto, f)
this.destinationPath(f)
);
});
},
Expand Down Expand Up @@ -286,10 +297,7 @@ module.exports = generators.Base.extend({
}

if (!this.fs.exists(this.destinationPath('server/plugins/webapp'))) {
this.composeWith('electrode:webapp', {
options: {
}
}, {
this.composeWith('electrode:webapp', {}, {
local: require.resolve('../webapp')
});
}
Expand All @@ -299,5 +307,15 @@ module.exports = generators.Base.extend({
this.installDependencies({
bower: false
});
},

end: function() {
var chdir = this.props.createDirectory ? "'cd " + _.kebabCase(_.deburr(this.props.name)) + "' then " : "";
this.log(
"\n" + chalk.green.underline("Your new Electrode application is ready!") +
"\n" +
"\nType " + chdir + "'gulp dev' to start the server." +
"\n"
);
}
});
9 changes: 1 addition & 8 deletions generators/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ module.exports = generators.Base.extend({
constructor: function () {
generators.Base.apply(this, arguments);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
});

this.option('name', {
type: String,
required: true,
Expand All @@ -23,7 +16,7 @@ module.exports = generators.Base.extend({
writing: function () {
this.fs.copyTpl(
this.templatePath('default.json'),
this.destinationPath(this.options.generateInto, 'config/default.json'),
this.destinationPath('config/default.json'),
{
projectName: this.options.name
}
Expand Down
9 changes: 1 addition & 8 deletions generators/editorconfig/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ var generators = require('yeoman-generator');
module.exports = generators.Base.extend({
constructor: function () {
generators.Base.apply(this, arguments);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
});
},

initializing: function () {
this.fs.copy(
this.templatePath('editorconfig'),
this.destinationPath(this.options.generateInto, '.editorconfig')
this.destinationPath('.editorconfig')
);
}
});
21 changes: 7 additions & 14 deletions generators/git/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ module.exports = generators.Base.extend({
constructor: function () {
generators.Base.apply(this, arguments);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
});

this.option('name', {
type: String,
required: true,
Expand All @@ -29,15 +22,15 @@ module.exports = generators.Base.extend({
initializing: function () {
this.fs.copy(
this.templatePath('gitattributes'),
this.destinationPath(this.options.generateInto, '.gitattributes')
this.destinationPath('.gitattributes')
);

this.fs.copy(
this.templatePath('gitignore'),
this.destinationPath(this.options.generateInto, '.gitignore')
this.destinationPath('.gitignore')
);

return originUrl(this.destinationPath(this.options.generateInto))
return originUrl(this.destinationPath())
.then(function (url) {
this.originUrl = url;
}.bind(this), function () {
Expand All @@ -46,7 +39,7 @@ module.exports = generators.Base.extend({
},

writing: function () {
this.pkg = this.fs.readJSON(this.destinationPath(this.options.generateInto, 'package.json'), {});
this.pkg = this.fs.readJSON(this.destinationPath('package.json'), {});

var repository = '';
if (this.originUrl) {
Expand All @@ -61,12 +54,12 @@ module.exports = generators.Base.extend({
this.pkg.repository.url = repository;
}

this.fs.writeJSON(this.destinationPath(this.options.generateInto, 'package.json'), this.pkg);
this.fs.writeJSON(this.destinationPath('package.json'), this.pkg);
},

end: function () {
this.spawnCommandSync('git', ['init'], {
cwd: this.destinationPath(this.options.generateInto)
cwd: this.destinationPath()
});

if (!this.originUrl) {
Expand All @@ -76,7 +69,7 @@ module.exports = generators.Base.extend({
repoSSH = '[email protected]:' + this.pkg.repository + '.git';
}
this.spawnCommandSync('git', ['remote', 'add', 'origin', repoSSH], {
cwd: this.destinationPath(this.options.generateInto)
cwd: this.destinationPath()
});
}
}
Expand Down
11 changes: 2 additions & 9 deletions generators/readme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ module.exports = generators.Base.extend({
constructor: function () {
generators.Base.apply(this, arguments);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
desc: 'Relocate the location of the generated files.'
});

this.option('name', {
type: String,
required: true,
Expand Down Expand Up @@ -57,10 +50,10 @@ module.exports = generators.Base.extend({
},

writing: function () {
var pkg = this.fs.readJSON(this.destinationPath(this.options.generateInto, 'package.json'), {});
var pkg = this.fs.readJSON(this.destinationPath('package.json'), {});
this.fs.copyTpl(
this.templatePath('README.md'),
this.destinationPath(this.options.generateInto, 'README.md'),
this.destinationPath('README.md'),
{
projectName: this.options.name,
safeProjectName: _.camelCase(this.options.name),
Expand Down

0 comments on commit 77585da

Please sign in to comment.