Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator-electrode: [patch] copy entire archetype again for component-add #391

Merged
merged 1 commit into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
copy entire archetype for component-add
  • Loading branch information
animesh10 committed Jun 20, 2017
commit a19f2c60aaf1c4cb121644abd423c8442e38d1f6
49 changes: 36 additions & 13 deletions packages/generator-electrode/component-add/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var extend = _.merge;
var parseAuthor = require("parse-author");
var githubUsername = require("github-username");
var glob = require("glob");
var nodeFS = require("fs");
var demoHelperPath = require.resolve('electrode-demo-helper');

/*
* This generator should check that it is invoked from within a packages folder
Expand All @@ -24,14 +26,14 @@ var glob = require("glob");
*/

module.exports = generators.Base.extend({
constructor: function() {
constructor: function () {
generators.Base.apply(this, arguments);
this.packageName = this.options.packageName || "demo-app";
this.developerName = this.options.developerName || "demoDeveloper";
this.className = this.options.className;
},

initializing: function() {
initializing: function () {
let appPkgPath = "";
let homeComponentPath = "";
this.demoAppName = "";
Expand Down Expand Up @@ -79,11 +81,11 @@ module.exports = generators.Base.extend({
},

prompting: {
greeting: function() {
greeting: function () {
this.log(yosay("Welcome to the " + chalk.red("Electrode Add Component") + " generator!"));
},

askFor: function() {
askFor: function () {
var prompts = [
{
type: "input",
Expand All @@ -105,14 +107,14 @@ module.exports = generators.Base.extend({
this.packageName = this.props.name;
this.componentName = _.kebabCase(_.deburr(this.props.componentName))
.replace(/^\s+|\s+$/g, "")
.replace(/(^|[-_ ])+(.)/g, function(match, first, second) {
.replace(/(^|[-_ ])+(.)/g, function (match, first, second) {
return second.toUpperCase();
});
});
}
},

default: function() {
default: function () {
let options = {
isAddon: true,
name: this.packageName,
Expand All @@ -128,7 +130,17 @@ module.exports = generators.Base.extend({
}
);
},
writing: function() {
writing: function () {

let getDemoFilePath = function (filepath) {
try {
let demoFilePath = path.resolve(demoHelperPath, '..', filepath);
return demoFilePath;
} catch (e) {
console.log(e);
}
};

//add new package to the dependencies
let dependencies = {};
dependencies[this.packageName] = "../packages/" + this.packageName;
Expand Down Expand Up @@ -166,13 +178,24 @@ module.exports = generators.Base.extend({
this.destinationPath("../../" + this.demoAppName + "/src/client/components/home.jsx"),
newHomeString
);

let directories = nodeFS.readdirSync(this.destinationPath(".."));
this.fs.copyTpl(
this.templatePath(getDemoFilePath('archetype')),
this.destinationPath('../../demo-app/archetype'),
{ components: directories }
);

},

end: function() {
// run npmi for the demo app again
process.chdir(this.destinationPath("../../" + this.demoAppName));
this.installDependencies({
bower: false
});
end: function () {
this.log(
"\n" + chalk.green.underline("Your new Electrode component is ready!") +
"\n" +
"\nYour component is in " + this.packageName + " and your demo app is in ../" + this.demoAppName +
"\n" +
"\nType 'cd ../" + this.demoAppName + "' then 'gulp dev' to run the development build for the demo app." +
"\n"
);
}
});
10 changes: 3 additions & 7 deletions packages/generator-electrode/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ var ReactComponentGenerator = yeoman.Base.extend({
: this.destinationPath() + "/" + this.rootPath;

this.destinationRoot(packageDirectory);
console.log("PACKAGE DIRECTORY:::::", this.destinationPath());

this.spawnCommandSync("npm", ["install"], {
cwd: this.destinationPath()
Expand Down Expand Up @@ -301,13 +300,10 @@ var ReactComponentGenerator = yeoman.Base.extend({
"\n" +
chalk.green.underline("Your new Electrode component is ready!") +
"\n" +
"\nYour component is in packages/" +
this.packageName +
" and your demo app is " +
this.appName +
"Your component is in " + this.packageName + "/packages" +
" and your demo app is " + this.packageName + "/" + this.appName +
"\n" +
"\nType 'cd ../" +
this.appName +
"\nType 'cd " + this.packageName + "/" + this.appName +
"' then 'gulp dev' to run the development build for the demo app." +
"\n"
);
Expand Down
7 changes: 4 additions & 3 deletions packages/generator-electrode/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,10 @@ module.exports = generators.Base.extend({
//copy files from the demoHelper if this is the demo-app
if (this.isDemoApp) {
//copy archetype webpack config extension
this.fs.copy(
getDemoFilePath('archetype/config.js'),
this.destinationPath('archetype/config.js')
this.fs.copyTpl(
this.templatePath(getDemoFilePath('archetype')),
this.destinationPath('archetype'),
{ components: [packageName] }
);

//copy home file
Expand Down