Skip to content

Commit 7db19e2

Browse files
committed
feat(flow): add Flow support
1 parent d8346f9 commit 7db19e2

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

src/generators/app/index.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,11 @@ export class Generator extends Base {
130130
}[val];
131131
}
132132
}, {
133-
// TODO: enable once Babel setup supports Flow
134-
// type: 'confirm',
135-
// name: 'flow',
136-
// message: 'Would you like to use Flow types with Babel?',
137-
// when: answers => answers.transpiler === 'babel'
138-
// }, {
133+
type: 'confirm',
134+
name: 'flow',
135+
message: 'Would you like to use Flow types with Babel?',
136+
when: answers => answers.transpiler === 'babel'
137+
}, {
139138
type: 'list',
140139
name: 'markup',
141140
message: 'What would you like to write markup with?',
@@ -453,15 +452,16 @@ export class Generator extends Base {
453452
]);
454453
*/
455454

455+
const flow = this.filters.flow;
456+
456457
let babelPlugins = [
457458
'babel-plugin-syntax-flow',
458459
'babel-plugin-syntax-class-properties'
459460
];
460461

461-
// TODO: enable once Babel setup supports Flow
462-
// if(this.filters.babel && !this.filters.flow) {
462+
if(this.filters.babel && !flow) {
463463
babelPlugins.push('babel-plugin-transform-flow-strip-types');
464-
// }
464+
}
465465

466466
let jsFilter = filter(['client/**/*.js'], {restore: true});
467467
this.registerTransformStream([
@@ -470,7 +470,14 @@ export class Generator extends Base {
470470
plugins: babelPlugins.map(require.resolve),
471471
/* Babel get's confused about these if you're using an `npm link`ed
472472
generator-angular-fullstack, thus the `require.resolve` */
473-
// retainLines: true,
473+
shouldPrintComment(commentContents) {
474+
if(flow) {
475+
return true;
476+
} else {
477+
// strip `// @flow` comments if not using flow
478+
return !(/@flow)/.test(commentContents));
479+
}
480+
},
474481
babelrc: false // don't grab the generator's `.babelrc`
475482
}),
476483
beaufityStream({

templates/app/.flowconfig(flow)

Whitespace-only changes.

templates/app/_.babelrc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
22
"presets": ["es2015"],
3-
"plugins": ["transform-class-properties"]
4-
}
3+
"plugins": [
4+
<%_ if(filters.flow) { -%>
5+
"transform-flow-comments",
6+
<%_ } -%>
7+
"transform-class-properties"
8+
]
9+
}

templates/app/_package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
"autoprefixer": "^6.0.0",
6565
"babel-core": "^6.6.5",
6666
"babel-register": "^6.6.5",
67+
<%_ if(filters.flow) { -%>
68+
"flow-bin": "^0.27.0",
69+
"babel-plugin-syntax-flow": "^6.8.0",
70+
"babel-plugin-transform-flow-comments": "^6.8.0",<% } %>
6771
"babel-plugin-transform-class-properties": "^6.6.0",
6872
"babel-plugin-transform-runtime": "^6.6.0",
6973
"babel-preset-es2015": "^6.6.0",<% if(filters.gulp) { %>

templates/app/client/components/auth(auth)/auth.service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
// @flow
23

34
export function AuthService($location, $http, $cookies, $q, appConfig, Util, User) {
45
'ngInject';

0 commit comments

Comments
 (0)