@@ -12,6 +12,7 @@ import tap from 'gulp-tap';
12
12
import filter from 'gulp-filter' ;
13
13
import eslint from 'gulp-eslint' ;
14
14
import semver from 'semver' ;
15
+ import jscodeshift from 'jscodeshift' ;
15
16
16
17
export class Generator extends Base {
17
18
constructor ( ...args ) {
@@ -458,52 +459,51 @@ export class Generator extends Base {
458
459
get writing ( ) {
459
460
return {
460
461
generateProject : function ( ) {
461
- /**
462
- * var tap = require('gulp-tap');
463
- this.registerTransformStream([
464
- extensionFilter,
465
- tap(function(file, t) {
466
- var contents = file.contents.toString();
467
- contents = beautify_js(contents, config);
468
- file.contents = new Buffer(contents);
469
- }),
470
- //prettifyJs(config),
471
- extensionFilter.restore
472
- ]);
473
- */
474
-
475
462
const flow = this . filters . flow ;
476
463
477
- let babelPlugins = [
478
- 'babel-plugin-syntax-flow' ,
479
- 'babel-plugin-syntax-class-properties' ,
480
- 'babel-plugin-syntax-decorators' ,
481
- 'babel-plugin-syntax-export-extensions' ,
482
- ] ;
483
-
484
- if ( this . filters . babel && ! flow ) {
485
- babelPlugins . push ( 'babel-plugin-transform-flow-strip-types' ) ;
486
- }
487
-
488
464
const genDir = path . join ( __dirname , '../../' ) ;
489
465
466
+ // TODO: remove babel stuff from dependencies
467
+ const codeshiftStream = tap ( function ( file , t ) {
468
+ var contents = file . contents . toString ( ) ;
469
+
470
+ // remove `implements Foo` from class declarations
471
+ contents = jscodeshift ( contents )
472
+ . find ( jscodeshift . ClassDeclaration )
473
+ . forEach ( path => {
474
+ path . value . implements = null ;
475
+ } )
476
+ . toSource ( ) ;
477
+
478
+ // remove any type annotations
479
+ contents = jscodeshift ( contents )
480
+ . find ( jscodeshift . TypeAnnotation )
481
+ . remove ( )
482
+ . toSource ( ) ;
483
+ contents = jscodeshift ( contents )
484
+ . find ( jscodeshift . GenericTypeAnnotation )
485
+ . remove ( )
486
+ . toSource ( ) ;
487
+
488
+ // remove any `type Foo = { .. }` declarations
489
+ contents = jscodeshift ( contents )
490
+ . find ( jscodeshift . TypeAlias )
491
+ . remove ( )
492
+ . toSource ( ) ;
493
+
494
+ // remove any flow directive comments
495
+ contents = jscodeshift ( contents )
496
+ . find ( jscodeshift . Comment , path => path . type === 'CommentLine' && path . value . includes ( '@flow' ) )
497
+ . forEach ( path => path . prune ( ) )
498
+ . toSource ( ) ;
499
+
500
+ file . contents = new Buffer ( contents ) ;
501
+ } ) ;
502
+
490
503
let clientJsFilter = filter ( [ 'client/**/*.js' ] , { restore : true } ) ;
491
504
this . registerTransformStream ( [
492
505
clientJsFilter ,
493
- babelStream ( {
494
- plugins : babelPlugins . map ( require . resolve ) ,
495
- /* Babel get's confused about these if you're using an `npm link`ed
496
- generator-angular-fullstack, thus the `require.resolve` */
497
- shouldPrintComment ( commentContents ) {
498
- if ( flow ) {
499
- return true ;
500
- } else {
501
- // strip `// @flow` comments if not using flow
502
- return ! ( / @ f l o w / . test ( commentContents ) ) ;
503
- }
504
- } ,
505
- babelrc : false // don't grab the generator's `.babelrc`
506
- } ) ,
506
+ codeshiftStream ,
507
507
eslint ( {
508
508
fix : true ,
509
509
configFile : path . join ( genDir , 'templates/app/client/.eslintrc(babel)' )
0 commit comments