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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

This is a [Yeoman](http://yeoman.io) generator for [Particle](https://github.com/phase2/pattern-lab-starter), a modern design-system driven Drupal theme.

## Install

To install generator-pattern-lab-starter from npm, run:

```bash
npm install -g generator-pattern-lab-starter
```

## Usage

*Note that this template will generate files in the current directory, so be sure to change to a new directory first if you don't want to overwrite existing files.*

Finally, initiate the generator:
Expand All @@ -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?

```

### Options

* **release**: Run with `--release=<branch-tag-or-hash>` to override the default use of master branch.

## Docker-based Development

You can perform local development of this generator using our Docker integration.
Expand Down
109 changes: 67 additions & 42 deletions generators/app/index.js
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({
Expand All @@ -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.

));
}
//options.themeName = _.last(this.env.cwd.split('/')); // parent folder
// options.themePath = '';

options = _.assign(options, this.options);
},

Expand All @@ -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);
}
},

Expand Down Expand Up @@ -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.");
}
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"dependencies": {
"chalk": "^1.1.3",
"fs-extra": "^4.0.2",
"lodash": "^4.17.4",
"yeoman-generator": "^1.1.0",
"yosay": "^1.2.1"
Expand Down