Skip to content

Commit

Permalink
generator-electrode: [patch] copy entire archetype again for componen…
Browse files Browse the repository at this point in the history
…t-add (electrode-io#391)
  • Loading branch information
animesh10 authored and jchip committed Jun 20, 2017
1 parent a65511b commit e8383fc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
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 @@ -266,7 +266,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 @@ -302,13 +301,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

0 comments on commit e8383fc

Please sign in to comment.