Skip to content

Commit cf2c5a6

Browse files
committed
Merge pull request #1820 from angular-fullstack/feat/gen-stream-write-through-babel
Stream files through babel while writing
2 parents 5022763 + 7ed2585 commit cf2c5a6

File tree

4 files changed

+82
-14
lines changed

4 files changed

+82
-14
lines changed

Diff for: app/generator.js

+71-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {Base} from 'yeoman-generator';
77
import {genBase} from '../generator-base';
88
import insight from '../insight-init';
99
import {exec} from 'child_process';
10+
import babelStream from 'gulp-babel';
11+
import beaufityStream from 'gulp-beautify';
12+
import filter from 'gulp-filter';
1013

1114
export default class Generator extends Base {
1215
constructor(...args) {
@@ -119,6 +122,12 @@ export default class Generator extends Base {
119122
}[val];
120123
}
121124
}, {
125+
// TODO: enable once Babel setup supports Flow
126+
// type: 'confirm',
127+
// name: 'flow',
128+
// message: 'Would you like to use Flow types with Babel?',
129+
// when: answers => answers.transpiler === 'babel'
130+
// }, {
122131
type: 'list',
123132
name: 'markup',
124133
message: 'What would you like to write markup with?',
@@ -152,6 +161,9 @@ export default class Generator extends Base {
152161
this.filters[answers.transpiler] = true;
153162
insight.track('transpiler', answers.transpiler);
154163

164+
this.filters.flow = !!answers.flow;
165+
insight.track('flow', !!answers.flow);
166+
155167
this.filters[answers.markup] = true;
156168
insight.track('markup', answers.markup);
157169

@@ -425,15 +437,67 @@ export default class Generator extends Base {
425437
get writing() {
426438
return {
427439
generateProject: function() {
440+
/**
441+
* var tap = require('gulp-tap');
442+
this.registerTransformStream([
443+
extensionFilter,
444+
tap(function(file, t) {
445+
var contents = file.contents.toString();
446+
contents = beautify_js(contents, config);
447+
file.contents = new Buffer(contents);
448+
}),
449+
//prettifyJs(config),
450+
extensionFilter.restore
451+
]);
452+
*/
453+
454+
let babelPlugins = [
455+
'babel-plugin-syntax-flow',
456+
'babel-plugin-syntax-class-properties'
457+
];
458+
459+
// TODO: enable once Babel setup supports Flow
460+
// if(this.filters.babel && !this.filters.flow) {
461+
babelPlugins.push('babel-plugin-transform-flow-strip-types');
462+
// }
463+
464+
const jsFilter = filter(['client/**/*.js'], {restore: true});
465+
this.registerTransformStream([
466+
jsFilter,
467+
babelStream({
468+
plugins: babelPlugins.map(require.resolve),
469+
/* Babel get's confused about these if you're using an `npm link`ed
470+
generator-angular-fullstack, thus the `require.resolve` */
471+
// retainLines: true,
472+
babelrc: false // don't grab the generator's `.babelrc`
473+
}),
474+
beaufityStream({
475+
"indent_size": 2,
476+
"indent_char": " ",
477+
"indent_level": 0,
478+
"indent_with_tabs": false,
479+
"preserve_newlines": true,
480+
"max_preserve_newlines": 10,
481+
"jslint_happy": false,
482+
"space_after_anon_function": false,
483+
"brace_style": "collapse",
484+
"keep_array_indentation": false,
485+
"keep_function_indentation": false,
486+
"space_before_conditional": true,
487+
"break_chained_methods": true,
488+
"eval_code": false,
489+
"unescape_strings": false,
490+
"wrap_line_length": 100,
491+
"wrap_attributes": "auto",
492+
"wrap_attributes_indent_size": 4,
493+
"end_with_newline": true
494+
}),
495+
jsFilter.restore
496+
]);
497+
428498
let self = this;
429499
this.sourceRoot(path.join(__dirname, './templates'));
430-
this.processDirectory('.', '.', function(dest) {
431-
if(self.filters.ts && dest.indexOf('client') > -1 && dest.indexOf('.json') === -1) {
432-
dest = dest.replace('.js', '.ts');
433-
}
434-
435-
return dest;
436-
});
500+
this.processDirectory('.', '.');
437501
},
438502
generateEndpoint: function() {
439503
var models;

Diff for: app/templates/client/components/auth(auth)/auth.service.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function AuthService($location, $http, $cookies, $q, appConfig, Util, User) {
2020
* @param {Function} callback - optional, function(error, user)
2121
* @return {Promise}
2222
*/
23-
login({email, password}, callback) {
23+
login({email, password}, callback: Function) {
2424
return $http.post('/auth/local', {
2525
email: email,
2626
password: password

Diff for: package.json

+6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@
3535
},
3636
"dependencies": {
3737
"babel-core": "^6.7.0",
38+
"babel-plugin-syntax-class-properties": "^6.5.0",
39+
"babel-plugin-syntax-flow": "^6.5.0",
3840
"babel-plugin-transform-class-properties": "^6.6.0",
41+
"babel-plugin-transform-flow-strip-types": "^6.7.0",
3942
"babel-preset-es2015": "^6.6.0",
4043
"babel-register": "^6.6.5",
4144
"chalk": "^1.1.0",
4245
"generator-ng-component": "~0.2.1",
4346
"glob": "^7.0.3",
47+
"gulp-babel": "^6.1.2",
48+
"gulp-beautify": "^2.0.0",
49+
"gulp-filter": "^4.0.0",
4450
"insight": "~0.8.1",
4551
"lodash": "^4.6.1",
4652
"underscore.string": "^3.1.1",

Diff for: util.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,10 @@ function templateIsUsable(self, filteredFile) {
105105
return true;
106106
}
107107

108-
function defaultIteratee(dest) {
109-
return dest;
110-
}
111-
112108
/**
113109
*
114110
*/
115-
export function processDirectory(source, destination, iteratee = defaultIteratee) {
111+
export function processDirectory(source, destination) {
116112
var self = this;
117113
var root = path.isAbsolute(source) ? source : path.join(self.sourceRoot(), source);
118114
var files = expandFiles('**', { dot: true, cwd: root });
@@ -132,7 +128,9 @@ export function processDirectory(source, destination, iteratee = defaultIteratee
132128
src = path.join(root, f);
133129
dest = path.join(destination, name);
134130

135-
dest = iteratee(dest);
131+
if(self.filters.ts && dest.indexOf('client') > -1 && dest.indexOf('.json') === -1) {
132+
dest = dest.replace('.js', '.ts');
133+
}
136134

137135
if(path.basename(dest).indexOf('_') === 0) {
138136
stripped = path.basename(dest).replace(/^_/, '');

0 commit comments

Comments
 (0)