From d1a687e8f5ae1037b7bc64c55065cf7d4e97f379 Mon Sep 17 00:00:00 2001 From: Will Browar Date: Wed, 25 May 2016 13:23:34 -0400 Subject: [PATCH 1/2] Added Bitbucket support --- README.md | 18 +++++++++++++++ app/index.js | 27 +++++++++++++++++++++++ app/templates/advanced_craft_install.json | 2 ++ app/templates/basic_craft_install.json | 2 ++ 4 files changed, 49 insertions(+) diff --git a/README.md b/README.md index fcf874f..493b467 100755 --- a/README.md +++ b/README.md @@ -179,6 +179,24 @@ Because your `CRAFT_PLUGINS` are added as submodules, when you want to `git clon If you want to update the submodules in your repo, do `git submodule foreach git pull origin master` and it'll update all of your submodules for you. +### BITBUCKET_ACCOUNT + +To use Bitbucket to store your site in a git repo, add your Bitbucket information to `BITBUCKET_ACCTOUNT`. This will create the repo on Bitbucket—using your `appName`—and make the first commit. + +By default, this creates a private repo, but you can change this in the settings. Here's an example: + +``` + "BITBUCKET_ACCOUNT": [ + { + "user": "username", + "password": "password", + "repoOwner": "repoowner", + "isPrivate": "true", + "forkPolicy": "no_public_forks" + } + ], +``` + ### END_INSTALL_COMMANDS A list of arbitrary shell commands to execute in sequence at the [ End ] phase of the generator diff --git a/app/index.js b/app/index.js index d5c7e81..c802949 100755 --- a/app/index.js +++ b/app/index.js @@ -310,6 +310,33 @@ module.exports = yo.generators.Base.extend({ console.log(chalk.green('> Pushing git repository to origin master')); child_process.execSync('git push origin master'); } + +/* -- Create a repository on BitBucket */ + + for (var i = 0; i < this.install.BITBUCKET_ACCOUNT.length; i++) { + var bitbucket = this.install.BITBUCKET_ACCOUNT[i]; + + console.log(chalk.green('> Creating BitBucket repo')); + child_process.execSync('curl -X POST -v -u ' + bitbucket.user + ':' + bitbucket.password + ' -H "Content-Type: application/json" https://api.bitbucket.org/2.0/repositories/' + bitbucket.repoOwner + '/' + this.answers.appName.toLowerCase() + ' -d \'{"scm": "git", "is_private": "' + bitbucket.isPrivate + '", "fork_policy": "' + bitbucket.forkPolicy + '" }\''); + +/* -- Initialize the local git directory, add all of the files, commit them, and push them to origin master */ + + console.log(chalk.green('> Making first commit')); + child_process.execSync('git init'); + child_process.execSync('git remote add origin https://' + bitbucket.user + '@bitbucket.org/' + bitbucket.repoOwner + '/' + this.answers.appName.toLowerCase() + '.git'); + for (var i = 0; i < this.install.CRAFT_PLUGINS.length; i++) { + var plugin = this.install.CRAFT_PLUGINS[i]; + console.log('+ ' + chalk.green(plugin.name) + ' added as submodule'); + child_process.execSync('git submodule add -f ' + plugin.url + ' ' + plugin.path.replace('craft/', this.answers.appName + '_craft/')); + } + console.log(chalk.green('> Adding project files to git repository')); + child_process.execSync('git add -A'); + child_process.execSync('git add -f craft/storage/.gitignore'); + console.log(chalk.green('> Doing initial commit to git repository')); + child_process.execSync('git commit -m "initial commit"'); + console.log(chalk.green('> Pushing git repository to origin master')); + child_process.execSync('git push origin master'); + } /* -- Install Bower modules */ diff --git a/app/templates/advanced_craft_install.json b/app/templates/advanced_craft_install.json index 920d6b3..66c7dcf 100644 --- a/app/templates/advanced_craft_install.json +++ b/app/templates/advanced_craft_install.json @@ -94,6 +94,8 @@ } ], "REMOTE_GIT_ORIGIN": "", + "BITBUCKET_ACCOUNT": [ + ], "BOWER_OPTIONS": [ ], "NPM_OPTIONS": [ diff --git a/app/templates/basic_craft_install.json b/app/templates/basic_craft_install.json index 09bb2d8..2a3e9f0 100644 --- a/app/templates/basic_craft_install.json +++ b/app/templates/basic_craft_install.json @@ -54,6 +54,8 @@ "CRAFT_PLUGINS": [ ], "REMOTE_GIT_ORIGIN": "", + "BITBUCKET_ACCOUNT": [ + ], "BOWER_OPTIONS": [ ], "NPM_OPTIONS": [ From 010f24d9c91345de3770661112c1acd5e2157917 Mon Sep 17 00:00:00 2001 From: Will Browar Date: Wed, 25 May 2016 13:26:15 -0400 Subject: [PATCH 2/2] Updated submodule loop --- app/index.js | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/index.js b/app/index.js index c802949..9bd67fa 100755 --- a/app/index.js +++ b/app/index.js @@ -314,28 +314,28 @@ module.exports = yo.generators.Base.extend({ /* -- Create a repository on BitBucket */ for (var i = 0; i < this.install.BITBUCKET_ACCOUNT.length; i++) { - var bitbucket = this.install.BITBUCKET_ACCOUNT[i]; - - console.log(chalk.green('> Creating BitBucket repo')); - child_process.execSync('curl -X POST -v -u ' + bitbucket.user + ':' + bitbucket.password + ' -H "Content-Type: application/json" https://api.bitbucket.org/2.0/repositories/' + bitbucket.repoOwner + '/' + this.answers.appName.toLowerCase() + ' -d \'{"scm": "git", "is_private": "' + bitbucket.isPrivate + '", "fork_policy": "' + bitbucket.forkPolicy + '" }\''); - -/* -- Initialize the local git directory, add all of the files, commit them, and push them to origin master */ - - console.log(chalk.green('> Making first commit')); - child_process.execSync('git init'); - child_process.execSync('git remote add origin https://' + bitbucket.user + '@bitbucket.org/' + bitbucket.repoOwner + '/' + this.answers.appName.toLowerCase() + '.git'); - for (var i = 0; i < this.install.CRAFT_PLUGINS.length; i++) { - var plugin = this.install.CRAFT_PLUGINS[i]; - console.log('+ ' + chalk.green(plugin.name) + ' added as submodule'); - child_process.execSync('git submodule add -f ' + plugin.url + ' ' + plugin.path.replace('craft/', this.answers.appName + '_craft/')); - } - console.log(chalk.green('> Adding project files to git repository')); - child_process.execSync('git add -A'); - child_process.execSync('git add -f craft/storage/.gitignore'); - console.log(chalk.green('> Doing initial commit to git repository')); - child_process.execSync('git commit -m "initial commit"'); - console.log(chalk.green('> Pushing git repository to origin master')); - child_process.execSync('git push origin master'); + var bitbucket = this.install.BITBUCKET_ACCOUNT[i]; + + console.log(chalk.green('> Creating BitBucket repo')); + child_process.execSync('curl -X POST -v -u ' + bitbucket.user + ':' + bitbucket.password + ' -H "Content-Type: application/json" https://api.bitbucket.org/2.0/repositories/' + bitbucket.repoOwner + '/' + this.answers.appName.toLowerCase() + ' -d \'{"scm": "git", "is_private": "' + bitbucket.isPrivate + '", "fork_policy": "' + bitbucket.forkPolicy + '" }\''); + + /* -- Initialize the local git directory, add all of the files, commit them, and push them to origin master */ + + console.log(chalk.green('> Making first commit')); + child_process.execSync('git init'); + child_process.execSync('git remote add origin https://' + bitbucket.user + '@bitbucket.org/' + bitbucket.repoOwner + '/' + this.answers.appName.toLowerCase() + '.git'); + for (var i = 0; i < this.install.CRAFT_PLUGINS.length; i++) { + var plugin = this.install.CRAFT_PLUGINS[i]; + console.log('+ ' + chalk.green(plugin.name) + ' added as submodule'); + child_process.execSync('git submodule add -f ' + plugin.url + ' ' + plugin.path); + } + console.log(chalk.green('> Adding project files to git repository')); + child_process.execSync('git add -A'); + child_process.execSync('git add -f craft/storage/.gitignore'); + console.log(chalk.green('> Doing initial commit to git repository')); + child_process.execSync('git commit -m "initial commit"'); + console.log(chalk.green('> Pushing git repository to origin master')); + child_process.execSync('git push origin master'); } /* -- Install Bower modules */