This repository was archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate new theme / clone slate repo (#7)
* Clone a repo to your project folder * Changes * changes * Changes * Change * refactor some code * install dependencies * remove random files * git init and replace slate pkg * add git/yeoman tpl files/env questions * finish todos and start commenting code * remove extra logs * update comment on private function * add last private function comment * absolute dep * commit stuff * get generator files from slate repo * pull templates from cache * fix indent
- Loading branch information
Ryan Macdonald
authored and
Thomas Kelly
committed
Jul 28, 2017
1 parent
1b14b01
commit 490bbd6
Showing
6 changed files
with
253 additions
and
56 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
packages/slate-cli/generators/slate-shopify/includes/cloneRepo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
var NodeGit = require('nodegit'); | ||
var Promise = require('bluebird'); | ||
var path = require('path'); | ||
var rimraf = Promise.promisify(require('rimraf')); | ||
var _ = require('lodash'); | ||
|
||
module.exports = { | ||
|
||
/** | ||
* Uses NodeGit to clone git repository and writes it to the destination path | ||
* | ||
* @param repo {String} - the location (url) of git repository | ||
* @param destination {String} - the local destination path to write repository | ||
*/ | ||
_cloneRepo: function(repo, destination) { | ||
var cache = path.join(this.cacheRoot(), repo); | ||
var options = {}; | ||
|
||
_.set(options, 'fetchOpts.callbacks.certificateCheck', checkCertificate); | ||
_.set(options, 'fetchOpts.callbacks.credentials', getCredentials); | ||
|
||
return rimraf(cache) | ||
.then(function() { | ||
return NodeGit.Clone(repo, cache, options); | ||
}) | ||
.then(function() { | ||
var glob = [ | ||
cache + '/**', | ||
'!' + cache + '/.git/**', | ||
'!' + cache + '/jsdoc-conf.json', | ||
'!' + cache + '/docs/**', | ||
'!' + cache + '/package.json', | ||
'!' + cache + '/tasks/includes/config.js', | ||
'!' + cache + '/generators/**' | ||
]; | ||
|
||
this.fs.copy(glob, destination, { | ||
globOptions: { | ||
dot: true | ||
} | ||
}); | ||
|
||
this.fs.copyTpl( | ||
path.join(cache, '/generators/config.yml.ejs'), | ||
path.join(destination, '/config.yml'), { | ||
environments: this.environments | ||
} | ||
); | ||
|
||
this.fs.copyTpl( | ||
path.join(cache, '/generators/package.json.ejs'), | ||
path.join(destination, '/package.json'), { | ||
name: this.dirname, | ||
hasGitRepo: this.initGit, | ||
repositoryUrl: this.repositoryUrl | ||
} | ||
); | ||
|
||
this.fs.copyTpl( | ||
path.join(cache, '/generators/tasks/includes/config.js.ejs'), | ||
path.join(destination, '/tasks/includes/config.js'), { | ||
env: this.defaultEnv | ||
} | ||
); | ||
}.bind(this)); | ||
}, | ||
|
||
/** | ||
* Uses NodeGit to initalize git repository | ||
* | ||
* @param repo {String} - the local path to the repository | ||
* @param isBare {Boolean} - whether to use provided path as the working directory | ||
*/ | ||
_initRepo: function(repo, isBare) { | ||
return NodeGit.Repository.init(repo, isBare); | ||
}, | ||
|
||
/** | ||
* Uses NodeGit to add remote to git repository | ||
* | ||
* @param repo {String} - the local path to the repository | ||
* @param name {String} - the name of the git remote | ||
* @param url {String} - the url of the git remote | ||
*/ | ||
_addRemote: function(repo, name, url) { | ||
return NodeGit.Remote.create(repo, name, url) | ||
.catch(function(err) { | ||
this.log(err); | ||
}.bind(this)); | ||
} | ||
}; | ||
|
||
/** | ||
* OS X libgit2 is unable to look up GitHub certificates correctly. | ||
* In order to bypass this problem, we're going to passthrough | ||
* the certificate check. | ||
* | ||
* @returns {Boolean} | ||
* @private | ||
*/ | ||
function checkCertificate() { | ||
return 1; | ||
} | ||
|
||
/** | ||
* In order to authorize the clone operation, we'll need to respond | ||
* to a low-level callback that expects credentials to be passed. | ||
* This function will respond back with the credentials from the | ||
* agent. You'll notice we handle the second argument passed to | ||
* credentials, userName. | ||
* | ||
* @param url {String} | ||
* @param userName {String} | ||
* @returns {String} - The newly created credential object. | ||
* @private | ||
*/ | ||
function getCredentials(url, userName) { | ||
return NodeGit.Cred.sshKeyFromAgent(userName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,59 @@ | ||
module.exports = { | ||
theme: function(generator) { | ||
var questions = [ | ||
{ | ||
type: 'confirm', | ||
name: 'multiEnv', | ||
message: 'Will you be deploying this theme to multiple environments?' | ||
}, | ||
{ | ||
type: 'checkbox', | ||
name: 'environments', | ||
message: 'Which environments would you like to use?', | ||
choices: [ | ||
{name: 'production', checked: true}, | ||
{name: 'staging', checked: true}, | ||
{name: 'development', checked: true}, | ||
{name: 'custom'} | ||
], | ||
when: hasMultipleEnvironments, | ||
validate: function(answer) { | ||
return answer.length < 1 | ||
? 'You must create at least one environment.' | ||
: true; | ||
} | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'customEnv', | ||
message: 'Enter the environment names you would like to create (comma separated)', | ||
when: hasCustomEnvironments | ||
var questions = [{ | ||
type: 'confirm', | ||
name: 'multiEnv', | ||
message: 'Will you be deploying this theme to multiple environments?' | ||
}, { | ||
type: 'checkbox', | ||
name: 'environments', | ||
message: 'Which environments would you like to use?', | ||
choices: [{ | ||
name: 'production', | ||
checked: true | ||
}, { | ||
name: 'staging', | ||
checked: true | ||
}, { | ||
name: 'development', | ||
checked: true | ||
}, { | ||
name: 'custom' | ||
}], | ||
when: hasMultipleEnvironments, | ||
validate: requireEnv | ||
}, { | ||
type: 'input', | ||
name: 'customEnv', | ||
message: 'Enter the custom environment names you would like to create (comma separated)', | ||
when: hasCustomEnvironments | ||
}, { | ||
type: 'list', | ||
name: 'defaultEnv', | ||
message: 'Which environment would you like to use as default?', | ||
choices: getDefaultEnvSelect, | ||
when: hasMultipleEnvironments, | ||
validate: requireEnv | ||
}, { | ||
type: 'input', | ||
name: 'repo', | ||
message: 'Which repo would you like to start with?', | ||
default: '[email protected]:Shopify/slate.git' | ||
}, { | ||
type: 'confirm', | ||
name: 'initGit', | ||
message: 'Will you be tracking this theme in git?' | ||
}, { | ||
type: 'input', | ||
name: 'repositoryUrl', | ||
message: 'Enter the URL of your git repository', | ||
when: hasGitRepo, | ||
validate: function(answer) { | ||
return answer.length < 1 | ||
? 'You must provide a URL for your git repository.' | ||
: true; | ||
} | ||
]; | ||
}]; | ||
|
||
if (!generator.dirname) { | ||
questions.unshift({ | ||
|
@@ -77,3 +101,35 @@ function hasCustomEnvironments(answers) { | |
}); | ||
return hasCustom; | ||
} | ||
|
||
/** | ||
* | ||
* @param answers {Object} | ||
* @returns {Boolean} | ||
* @private | ||
*/ | ||
function hasGitRepo(answers) { | ||
return answers.initGit; | ||
} | ||
|
||
/** | ||
* | ||
* @param answers {Object} | ||
* @returns {Boolean} | ||
* @private | ||
*/ | ||
function getDefaultEnvSelect(answers) { | ||
return answers.environments; | ||
} | ||
|
||
/** | ||
* | ||
* @param answers {Object} | ||
* @returns {Boolean} | ||
* @private | ||
*/ | ||
function requireEnv(answer) { | ||
return answer.length < 1 | ||
? 'You must create at least one environment.' | ||
: true; | ||
} |
10 changes: 0 additions & 10 deletions
10
packages/slate-cli/generators/slate-shopify/templates/config.yml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters