-
Notifications
You must be signed in to change notification settings - Fork 5
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
Overhaul on upstream retrieval. #27
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,11 +1,14 @@ | ||
'use strict'; | ||
var Generator = require('yeoman-generator'); | ||
var myPrompts = require('./prompts.js'); | ||
var chalk = require('chalk'); | ||
var yosay = require('yosay'); | ||
var path = require('path'); | ||
var exec = require('child_process').execSync; | ||
var _ = require('lodash'); | ||
|
||
const Generator = require('yeoman-generator'); | ||
const chalk = require('chalk'); | ||
const exec = require('child_process').execSync; | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const yosay = require('yosay'); | ||
const _ = require('lodash'); | ||
const myPrompts = require('./prompts.js'); | ||
|
||
var options = {}; | ||
|
||
module.exports = Generator.extend({ | ||
|
@@ -18,8 +21,7 @@ module.exports = Generator.extend({ | |
'Welcome to the remarkable ' + chalk.red('PatternLabStarter') + ' generator! ' + this.pkg.version + '\nPlease be in the folder you want files in now.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still going to be pulling down PLS v9 for awhile. |
||
)); | ||
} | ||
//options.themeName = _.last(this.env.cwd.split('/')); // parent folder | ||
// options.themePath = ''; | ||
|
||
options = _.assign(options, this.options); | ||
}, | ||
|
||
|
@@ -35,57 +37,80 @@ module.exports = Generator.extend({ | |
return this.prompt(prompts).then(function (props) { | ||
options = _.assign(options, props); | ||
}); | ||
|
||
// disabling this for now as pattern lab starter v8 doesn't really have drupal 7 or drupal 8 differences | ||
// this.composeWith('pattern-lab-starter:extras', {options: options}, { | ||
// local: path.resolve(__dirname, '../extras') | ||
// }); | ||
|
||
}, | ||
|
||
configuring: function () { | ||
|
||
}, | ||
|
||
default: function () { | ||
var dest = options.themePath ? path.resolve(process.cwd(), options.themePath) : './'; | ||
const release = options['release'] || 'master' | ||
const release_path = `${release}.tar.gz`; | ||
const compressed = _.last(_.split(release_path, '/')); | ||
const decompressed = _.replace('particle-' + release, '/', '-'); | ||
const download_url = `https://github.com/phase2/particle/archive/${release_path}`; | ||
const dest = options.themePath ? path.resolve(process.cwd(), options.themePath) : './'; | ||
const themeName = 'patternlab'; | ||
const themePathFull = path.join(dest, themeName); | ||
|
||
var cmd = [ | ||
'rm -Rf master.tar.gz particle-master patternlab' + ' ' + dest + '/patternlab' , | ||
'curl -OL https://github.com/phase2/particle/archive/master.tar.gz', | ||
'tar -xzf master.tar.gz', | ||
'mv particle-master patternlab', | ||
'rm master.tar.gz' | ||
].join(' && '); | ||
this.log(`Assembling your Pattern Lab Starter/Particle theme on version ${release}...`); | ||
|
||
try { | ||
exec(cmd, { | ||
fs.removeSync(compressed); | ||
} catch (err) { | ||
if (err.code != 'ENOENT') { | ||
console.error(err); | ||
process.exit(2); | ||
} | ||
} | ||
try { | ||
fs.removeSync(decompressed) | ||
} catch (err) { | ||
if (err.code != 'ENOENT') { | ||
console.error(err); | ||
process.exit(2); | ||
} | ||
} | ||
try { | ||
fs.removeSync(themePathFull) | ||
} catch (err) { | ||
if (err.code != 'ENOENT') { | ||
console.error(err); | ||
process.exit(2); | ||
} | ||
} | ||
|
||
// @todo replace tarball retrieval & extraction with a Node library. | ||
try { | ||
this.log(`Retrieving template from ${download_url}...`); | ||
exec([ | ||
`curl --fail --silent -OL ${download_url}`, | ||
`tar -xzf ${compressed}` | ||
].join(' && '), { | ||
encoding: 'utf8' | ||
}); | ||
} catch(error) { | ||
console.error('An error happened while trying to run this command: '); | ||
console.log(cmd); | ||
// console.log(error); | ||
} catch(err) { | ||
this.log.error('An error occurred running retrieving and extracting the template.'); | ||
process.exit(1); | ||
} | ||
// Remove the successfully decompressed archive source. | ||
fs.removeSync(compressed); | ||
|
||
if (options.themePath) { | ||
var dest = path.resolve(process.cwd(), options.themePath); | ||
if (!fs.existsSync(dest)) { | ||
try { | ||
exec('mkdir -p "' + dest + '"', { | ||
encoding: 'utf8' | ||
}); | ||
fs.mkdirpSync(dest); | ||
} catch(error) { | ||
console.error('Could not "mkdir -p" the themePath.'); | ||
this.log.error(`Could not create the theme path: ${error}`); | ||
process.exit(2); | ||
} | ||
} | ||
|
||
try { | ||
exec('mv patternlab "' + dest + '"', { | ||
encoding: 'utf8' | ||
}); | ||
} catch (error) { | ||
console.error('Could not move theme into themePath.'); | ||
} | ||
try { | ||
fs.renameSync(decompressed, themePathFull) | ||
} catch(error) { | ||
console.error(error); | ||
this.log.error(`Could not move theme into position: ${error}`); | ||
process.exit(2); | ||
} | ||
}, | ||
|
||
|
@@ -116,6 +141,6 @@ module.exports = Generator.extend({ | |
} | ||
|
||
this.log(yosay(finalWords)); | ||
console.log('If you don\'t see your prompt, try hitting enter.'); | ||
this.log("If you don't see your prompt, try hitting enter."); | ||
} | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you're getting at?