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

Overhaul on upstream retrieval. #27

Merged
merged 3 commits into from
Dec 21, 2017
Merged

Overhaul on upstream retrieval. #27

merged 3 commits into from
Dec 21, 2017

Conversation

grayside
Copy link
Contributor

A few little changes, but the heart of this is to minimize the amount of exec'd commands. I wanted to use a library such as tarball-extract (alluded to in #25) but that project depends on an ancient release of a node wget library that can't follow redirects, which immediately slams against Github's infrastructure.

This change adds a new --release flag to facilitate testing/using the generator with code other than master on the particle project.

There is also some general robustness improvements, such as failing earlier if curl asplodes, removing extra file copy and delete operations, and supporting the generator recursively creating the base directory of the theme in case someone specified a deeply nested location.

With this change I suppose I'll follow up with a v3.1.0 release.

var exec = require('child_process').execSync;
var fs = require('fs-extra');
var path = require('path');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're cool with const down below (node 6+) then we're cool with const up here.

@@ -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.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParticleStarter instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still going to be pulling down PLS v9 for awhile.

},

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const release_path = `${release}.tar.gz`;

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above for template literal approach to this.

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

particle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not trying to bring this to generator-particle just yet, simply continue to pull down the PLS 9 repo. I suppose you could have created a whole new repo... meh.


// @todo replace tarball retrieval & extraction with a Node library.
try {
this.log('Retrieving template from ' + download_url + '...');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already know that I'm going to suggest a template literal.

try {
this.log('Retrieving template from ' + download_url + '...');
exec([
'curl --fail --silent -OL ' + download_url,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template literal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one will be a literal template.

this.log('Retrieving template from ' + download_url + '...');
exec([
'curl --fail --silent -OL ' + download_url,
'tar -xzf ' + compressed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template literal.

} catch(error) {
console.error('Could not "mkdir -p" the themePath.');
this.log.error('Could not create the theme path: ' + error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template literal.

fs.renameSync(decompressed, themePathFull)
} catch(error) {
console.error(error);
this.log.error('Could not move theme into position: ' + error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template literal.

@@ -22,6 +26,10 @@ Extras can be installed with:
yo pattern-lab-starter:extras
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different name here?

Copy link
Contributor Author

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?

@grayside grayside dismissed illepic’s stale review December 21, 2017 19:04

Because I addressed all understandable feedback.

@grayside grayside merged commit aa59717 into master Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants